]> granicus.if.org Git - llvm/commitdiff
[InstCombine][ValueTracking] When computing known bits for Srem make sure we don...
authorCraig Topper <craig.topper@gmail.com>
Sun, 16 Apr 2017 21:46:12 +0000 (21:46 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sun, 16 Apr 2017 21:46:12 +0000 (21:46 +0000)
If we already called computeKnownBits for the RHS being a constant power of 2, we've already computed everything we can and should just stop. I think previously we would still recurse if we had determined the result was negative or had not determined the sign bit at all.

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

lib/Analysis/ValueTracking.cpp
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

index d871e83f222a7e40d5fd07c95a9eb898e3b57922..eb4f9b216379d6558dd5794b9e3d538d41340a31 100644 (file)
@@ -1178,19 +1178,16 @@ static void computeKnownBitsFromOperator(const Operator *I, APInt &KnownZero,
           KnownOne |= ~LowBits;
 
         assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
+        break;
       }
     }
 
     // The sign bit is the LHS's sign bit, except when the result of the
     // remainder is zero.
-    if (KnownZero.isNonNegative()) {
-      APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
-      computeKnownBits(I->getOperand(0), LHSKnownZero, LHSKnownOne, Depth + 1,
-                       Q);
-      // If it's known zero, our sign bit is also zero.
-      if (LHSKnownZero.isNegative())
-        KnownZero.setSignBit();
-    }
+    computeKnownBits(I->getOperand(0), KnownZero2, KnownOne2, Depth + 1, Q);
+    // If it's known zero, our sign bit is also zero.
+    if (KnownZero2.isNegative())
+      KnownZero.setSignBit();
 
     break;
   case Instruction::URem: {
index 246fd6bdf5a450de3a16d1d02cfb5a6d3a62f003..abc7d07d4512bcb904240e959b80bcc4ff5afceb 100644 (file)
@@ -644,13 +644,13 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
           KnownOne |= ~LowBits;
 
         assert(!(KnownZero & KnownOne) && "Bits known to be one AND zero?");
+        break;
       }
     }
 
     // The sign bit is the LHS's sign bit, except when the result of the
     // remainder is zero.
-    if (DemandedMask.isNegative() && KnownZero.isNonNegative()) {
-      APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
+    if (DemandedMask.isNegative()) {
       computeKnownBits(I->getOperand(0), LHSKnownZero, LHSKnownOne, Depth + 1,
                        CxtI);
       // If it's known zero, our sign bit is also zero.