llvm.org GIT mirror llvm / 3dfd987
Teach value tracking to make use of flags in more situations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126642 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 9 years ago
1 changed file(s) with 25 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
695695 return isPowerOfTwo(SI->getTrueValue(), TD, Depth) &&
696696 isPowerOfTwo(SI->getFalseValue(), TD, Depth);
697697
698 // An exact divide or right shift can only shift off zero bits, so the result
699 // is non-zero only if the first operand is non-zero.
700 if (match(V, m_Shr(m_Value(), m_Value())) ||
701 match(V, m_IDiv(m_Value(), m_Value()))) {
702 BinaryOperator *BO = cast(V);
703 if (BO->isExact())
704 return isPowerOfTwo(BO->getOperand(0), TD, Depth);
705 }
706
698707 return false;
699708 }
700709
731740 // shl X, Y != 0 if X is odd. Note that the value of the shift is undefined
732741 // if the lowest bit is shifted off the end.
733742 if (BitWidth && match(V, m_Shl(m_Value(X), m_Value(Y)))) {
743 // shl nuw can't remove any non-zero bits.
744 BinaryOperator *BO = cast(V);
745 if (BO->hasNoUnsignedWrap())
746 return isKnownNonZero(X, TD, Depth);
747
734748 APInt KnownZero(BitWidth, 0);
735749 APInt KnownOne(BitWidth, 0);
736750 ComputeMaskedBits(X, APInt(BitWidth, 1), KnownZero, KnownOne, TD, Depth);
740754 // shr X, Y != 0 if X is negative. Note that the value of the shift is not
741755 // defined if the sign bit is shifted off the end.
742756 else if (match(V, m_Shr(m_Value(X), m_Value(Y)))) {
757 // shr exact can only shift out zero bits.
758 BinaryOperator *BO = cast(V);
759 if (BO->isExact())
760 return isKnownNonZero(X, TD, Depth);
761
743762 bool XKnownNonNegative, XKnownNegative;
744763 ComputeSignBit(X, XKnownNonNegative, XKnownNegative, TD, Depth);
745764 if (XKnownNegative)
746765 return true;
766 }
767 // div exact can only produce a zero if the dividend is zero.
768 else if (match(V, m_IDiv(m_Value(X), m_Value()))) {
769 BinaryOperator *BO = cast(V);
770 if (BO->isExact())
771 return isKnownNonZero(X, TD, Depth);
747772 }
748773 // X + Y.
749774 else if (match(V, m_Add(m_Value(X), m_Value(Y)))) {