use the valuetracking isPowerOfTwo function, which is more powerful than checking
authorChris Lattner <sabre@nondot.org>
Mon, 23 May 2011 00:09:55 +0000 (00:09 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 23 May 2011 00:09:55 +0000 (00:09 +0000)
for a constant directly.  Thanks to Duncan for pointing this out.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131885 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

index 98a36545ad793a7bc94912c41afd92b2063546a3..fdec6407b800a2893bcb481f9d3e571fbdb67f12 100644 (file)
@@ -31,13 +31,13 @@ static Value *simplifyValueKnownNonZero(Value *V, InstCombiner &IC) {
   
   // ((1 << A) >>u B) --> (1 << (A-B))
   // Because V cannot be zero, we know that B is less than A.
-  Value *A = 0, *B = 0; ConstantInt *One = 0;
-  if (match(V, m_LShr(m_OneUse(m_Shl(m_ConstantInt(One), m_Value(A))),
+  Value *A = 0, *B = 0, *PowerOf2 = 0;
+  if (match(V, m_LShr(m_OneUse(m_Shl(m_Value(PowerOf2), m_Value(A))),
                       m_Value(B))) &&
       // The "1" can be any value known to be a power of 2.
-      One->getValue().isPowerOf2()) {
+      isPowerOfTwo(PowerOf2, IC.getTargetData())) {
     A = IC.Builder->CreateSub(A, B, "tmp");
-    return IC.Builder->CreateShl(One, A);
+    return IC.Builder->CreateShl(PowerOf2, A);
   }
   
   // TODO: Lots more we could do here: