[llvm-commits] [llvm] r126642 - /llvm/trunk/lib/Analysis/ValueTracking.cpp

Eli Friedman eli.friedman at gmail.com
Mon Mar 21 14:26:56 PDT 2011


On Mon, Feb 28, 2011 at 12:02 AM, Nick Lewycky <nicholas at mxc.ca> wrote:
> Author: nicholas
> Date: Mon Feb 28 02:02:21 2011
> New Revision: 126642
>
> URL: http://llvm.org/viewvc/llvm-project?rev=126642&view=rev
> Log:
> Teach value tracking to make use of flags in more situations.
>
> Modified:
>    llvm/trunk/lib/Analysis/ValueTracking.cpp
>
> Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=126642&r1=126641&r2=126642&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
> +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Mon Feb 28 02:02:21 2011
> @@ -696,6 +696,15 @@
>     return isPowerOfTwo(SI->getTrueValue(), TD, Depth) &&
>       isPowerOfTwo(SI->getFalseValue(), TD, Depth);
>
> +  // An exact divide or right shift can only shift off zero bits, so the result
> +  // is non-zero only if the first operand is non-zero.
> +  if (match(V, m_Shr(m_Value(), m_Value())) ||
> +      match(V, m_IDiv(m_Value(), m_Value()))) {
> +    BinaryOperator *BO = cast<BinaryOperator>(V);
> +    if (BO->isExact())
> +      return isPowerOfTwo(BO->getOperand(0), TD, Depth);
> +  }
> +
>   return false;
>  }

Please see http://llvm.org/bugs/show_bug.cgi?id=9429; also, this
analysis isn't safe for signed divide/ashr (consider the case where
the LHS is INT_MIN).

-Eli

> @@ -732,6 +741,11 @@
>   // shl X, Y != 0 if X is odd.  Note that the value of the shift is undefined
>   // if the lowest bit is shifted off the end.
>   if (BitWidth && match(V, m_Shl(m_Value(X), m_Value(Y)))) {
> +    // shl nuw can't remove any non-zero bits.
> +    BinaryOperator *BO = cast<BinaryOperator>(V);
> +    if (BO->hasNoUnsignedWrap())
> +      return isKnownNonZero(X, TD, Depth);
> +
>     APInt KnownZero(BitWidth, 0);
>     APInt KnownOne(BitWidth, 0);
>     ComputeMaskedBits(X, APInt(BitWidth, 1), KnownZero, KnownOne, TD, Depth);
> @@ -741,11 +755,22 @@
>   // shr X, Y != 0 if X is negative.  Note that the value of the shift is not
>   // defined if the sign bit is shifted off the end.
>   else if (match(V, m_Shr(m_Value(X), m_Value(Y)))) {
> +    // shr exact can only shift out zero bits.
> +    BinaryOperator *BO = cast<BinaryOperator>(V);
> +    if (BO->isExact())
> +      return isKnownNonZero(X, TD, Depth);
> +
>     bool XKnownNonNegative, XKnownNegative;
>     ComputeSignBit(X, XKnownNonNegative, XKnownNegative, TD, Depth);
>     if (XKnownNegative)
>       return true;
>   }
> +  // div exact can only produce a zero if the dividend is zero.
> +  else if (match(V, m_IDiv(m_Value(X), m_Value()))) {
> +    BinaryOperator *BO = cast<BinaryOperator>(V);
> +    if (BO->isExact())
> +      return isKnownNonZero(X, TD, Depth);
> +  }
>   // X + Y.
>   else if (match(V, m_Add(m_Value(X), m_Value(Y)))) {
>     bool XKnownNonNegative, XKnownNegative;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list