[InstCombine] When checking to see if we can turn subtracts of 2^n - 1 into xor,...
authorCraig Topper <craig.topper@gmail.com>
Thu, 6 Apr 2017 21:06:03 +0000 (21:06 +0000)
committerCraig Topper <craig.topper@gmail.com>
Thu, 6 Apr 2017 21:06:03 +0000 (21:06 +0000)
Calling computeKnownBits on the RHS should allows us to recurse one step further. isMask is equivalent to the isPowerOf2(C+1) except in the case where C is all ones. But that was already handled earlier by creating a not which is an Xor with all ones. So this should be fine.

llvm-svn: 299710

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

index b9c73370f965dbff91a07440712ab217c10c1000..a0d74677dc6ed917b5dbcc383459599a66f55b9a 100644 (file)
@@ -1621,12 +1621,14 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
 
     // Turn this into a xor if LHS is 2^n-1 and the remaining bits are known
     // zero.
-    if ((*Op0C + 1).isPowerOf2()) {
-      APInt KnownZero(BitWidth, 0);
-      APInt KnownOne(BitWidth, 0);
-      computeKnownBits(&I, KnownZero, KnownOne, 0, &I);
-      if ((*Op0C | KnownZero).isAllOnesValue())
+    if (Op0C->isMask()) {
+      APInt RHSKnownZero(BitWidth, 0);
+      APInt RHSKnownOne(BitWidth, 0);
+      computeKnownBits(Op1, RHSKnownZero, RHSKnownOne, 0, &I);
+      if ((*Op0C | RHSKnownZero).isAllOnesValue()) {
+        assert(0);
         return BinaryOperator::CreateXor(Op1, Op0);
+      }
     }
   }