[llvm-commits] [llvm] r143211 - in /llvm/trunk: lib/Analysis/ValueTracking.cpp test/Transforms/InstSimplify/AndOrXor.ll

Duncan Sands baldrick at free.fr
Fri Oct 28 11:30:05 PDT 2011


Author: baldrick
Date: Fri Oct 28 13:30:05 2011
New Revision: 143211

URL: http://llvm.org/viewvc/llvm-project?rev=143211&view=rev
Log:
A shift of a power of two is a power of two or zero.
For completeness - not spotted in the wild.

Modified:
    llvm/trunk/lib/Analysis/ValueTracking.cpp
    llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll

Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=143211&r1=143210&r2=143211&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri Oct 28 13:30:05 2011
@@ -769,6 +769,12 @@
   if (Depth++ == MaxDepth)
     return false;
 
+  Value *X = 0, *Y = 0;
+  // A shift of a power of two is a power of two or zero.
+  if (OrZero && (match(V, m_Shl(m_Value(X), m_Value())) ||
+                 match(V, m_Shr(m_Value(X), m_Value()))))
+    return isPowerOfTwo(X, TD, /*OrZero*/true, Depth);
+
   if (ZExtInst *ZI = dyn_cast<ZExtInst>(V))
     return isPowerOfTwo(ZI->getOperand(0), TD, OrZero, Depth);
 
@@ -776,7 +782,6 @@
     return isPowerOfTwo(SI->getTrueValue(), TD, OrZero, Depth) &&
       isPowerOfTwo(SI->getFalseValue(), TD, OrZero, Depth);
 
-  Value *X = 0, *Y = 0;
   if (OrZero && match(V, m_And(m_Value(X), m_Value(Y)))) {
     // A power of two and'd with anything is a power of two or zero.
     if (isPowerOfTwo(X, TD, /*OrZero*/true, Depth) ||

Modified: llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll?rev=143211&r1=143210&r2=143211&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll Fri Oct 28 13:30:05 2011
@@ -10,3 +10,13 @@
   ret i64 %e2
 ; CHECK: ret i64 %e
 }
+
+define i64 @pow2b(i32 %x) {
+; CHECK: @pow2b
+  %sh = shl i32 2, %x
+  %e = zext i32 %sh to i64
+  %nege = sub i64 0, %e
+  %e2 = and i64 %e, %nege
+  ret i64 %e2
+; CHECK: ret i64 %e
+}





More information about the llvm-commits mailing list