[llvm] r298745 - Revert r298711 "[InstCombine] Provide a way to calculate KnownZero/One for Add/Sub in SimplifyDemandedUseBits without recursing into ComputeKnownBits"

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 15:12:10 PDT 2017


Author: ctopper
Date: Fri Mar 24 17:12:10 2017
New Revision: 298745

URL: http://llvm.org/viewvc/llvm-project?rev=298745&view=rev
Log:
Revert r298711 "[InstCombine] Provide a way to calculate KnownZero/One for Add/Sub in SimplifyDemandedUseBits without recursing into ComputeKnownBits"

Tsan bot is failing.


Modified:
    llvm/trunk/include/llvm/Analysis/ValueTracking.h
    llvm/trunk/lib/Analysis/ValueTracking.cpp
    llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=298745&r1=298744&r2=298745&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original)
+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Fri Mar 24 17:12:10 2017
@@ -55,11 +55,6 @@ template <typename T> class ArrayRef;
                         const Instruction *CxtI = nullptr,
                         const DominatorTree *DT = nullptr,
                         OptimizationRemarkEmitter *ORE = nullptr);
-  /// Compute known bits for add/sub using LHS/RHS known bits.
-  void computeKnownBitsForAddSub(bool Add, bool NSW,
-                                 APInt &KnownZero, APInt &KnownOne,
-                                 APInt &LHSKnownZero, APInt &LHSKnownOne,
-                                 APInt &RHSKnownZero, APInt &RHSKnownOne);
   /// Compute known bits from the range metadata.
   /// \p KnownZero the set of bits that are known to be zero
   /// \p KnownOne the set of bits that are known to be one

Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=298745&r1=298744&r2=298745&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri Mar 24 17:12:10 2017
@@ -250,29 +250,37 @@ unsigned llvm::ComputeNumSignBits(const
   return ::ComputeNumSignBits(V, Depth, Query(DL, AC, safeCxtI(V, CxtI), DT));
 }
 
-/// Compute known bits for add/sub using LHS/RHS known bits.
-void llvm::computeKnownBitsForAddSub(bool Add, bool NSW,
-                                     APInt &KnownZero, APInt &KnownOne,
-                                     APInt &LHSKnownZero, APInt &LHSKnownOne,
-                                     APInt &RHSKnownZero, APInt &RHSKnownOne) {
+static void computeKnownBitsAddSub(bool Add, const Value *Op0, const Value *Op1,
+                                   bool NSW,
+                                   APInt &KnownZero, APInt &KnownOne,
+                                   APInt &KnownZero2, APInt &KnownOne2,
+                                   unsigned Depth, const Query &Q) {
+  unsigned BitWidth = KnownZero.getBitWidth();
+
+  // If an initial sequence of bits in the result is not needed, the
+  // corresponding bits in the operands are not needed.
+  APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
+  computeKnownBits(Op0, LHSKnownZero, LHSKnownOne, Depth + 1, Q);
+  computeKnownBits(Op1, KnownZero2, KnownOne2, Depth + 1, Q);
+
   // Carry in a 1 for a subtract, rather than a 0.
   uint64_t CarryIn = 0;
   if (!Add) {
     // Sum = LHS + ~RHS + 1
-    std::swap(RHSKnownZero, RHSKnownOne);
+    std::swap(KnownZero2, KnownOne2);
     CarryIn = 1;
   }
 
-  APInt PossibleSumZero = ~LHSKnownZero + ~RHSKnownZero + CarryIn;
-  APInt PossibleSumOne = LHSKnownOne + RHSKnownOne + CarryIn;
+  APInt PossibleSumZero = ~LHSKnownZero + ~KnownZero2 + CarryIn;
+  APInt PossibleSumOne = LHSKnownOne + KnownOne2 + CarryIn;
 
   // Compute known bits of the carry.
-  APInt CarryKnownZero = ~(PossibleSumZero ^ LHSKnownZero ^ RHSKnownZero);
-  APInt CarryKnownOne = PossibleSumOne ^ LHSKnownOne ^ RHSKnownOne;
+  APInt CarryKnownZero = ~(PossibleSumZero ^ LHSKnownZero ^ KnownZero2);
+  APInt CarryKnownOne = PossibleSumOne ^ LHSKnownOne ^ KnownOne2;
 
   // Compute set of known bits (where all three relevant bits are known).
   APInt LHSKnown = LHSKnownZero | LHSKnownOne;
-  APInt RHSKnown = RHSKnownZero | RHSKnownOne;
+  APInt RHSKnown = KnownZero2 | KnownOne2;
   APInt CarryKnown = CarryKnownZero | CarryKnownOne;
   APInt Known = LHSKnown & RHSKnown & CarryKnown;
 
@@ -288,36 +296,14 @@ void llvm::computeKnownBitsForAddSub(boo
     if (NSW) {
       // Adding two non-negative numbers, or subtracting a negative number from
       // a non-negative one, can't wrap into negative.
-      if (LHSKnownZero.isNegative() && RHSKnownZero.isNegative())
+      if (LHSKnownZero.isNegative() && KnownZero2.isNegative())
         KnownZero.setSignBit();
       // Adding two negative numbers, or subtracting a non-negative number from
       // a negative one, can't wrap into non-negative.
-      else if (LHSKnownOne.isNegative() && RHSKnownOne.isNegative())
+      else if (LHSKnownOne.isNegative() && KnownOne2.isNegative())
         KnownOne.setSignBit();
     }
   }
-
-  // Put the RHS/LHS back how we found them.
-  if (!Add) {
-    std::swap(RHSKnownZero, RHSKnownOne);
-  }
-}
-
-static void computeKnownBitsAddSub(bool Add, const Value *Op0, const Value *Op1,
-                                   bool NSW,
-                                   APInt &KnownZero, APInt &KnownOne,
-                                   APInt &KnownZero2, APInt &KnownOne2,
-                                   unsigned Depth, const Query &Q) {
-  unsigned BitWidth = KnownZero.getBitWidth();
-
-  // If an initial sequence of bits in the result is not needed, the
-  // corresponding bits in the operands are not needed.
-  APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
-  computeKnownBits(Op0, LHSKnownZero, LHSKnownOne, Depth + 1, Q);
-  computeKnownBits(Op1, KnownZero2, KnownOne2, Depth + 1, Q);
-
-  computeKnownBitsForAddSub(Add, NSW, KnownZero, KnownOne, LHSKnownZero,
-                            LHSKnownOne, KnownZero2, KnownOne2);
 }
 
 static void computeKnownBitsMul(const Value *Op0, const Value *Op1, bool NSW,

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp?rev=298745&r1=298744&r2=298745&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp Fri Mar 24 17:12:10 2017
@@ -538,7 +538,7 @@ Value *InstCombiner::SimplifyDemandedUse
                                LHSKnownZero, LHSKnownOne, Depth + 1) ||
           ShrinkDemandedConstant(I, 1, DemandedFromOps) ||
           SimplifyDemandedBits(I->getOperandUse(1), DemandedFromOps,
-                               RHSKnownZero, RHSKnownOne, Depth + 1)) {
+                               LHSKnownZero, LHSKnownOne, Depth + 1)) {
         // Disable the nsw and nuw flags here: We can no longer guarantee that
         // we won't wrap after simplification. Removing the nsw/nuw flags is
         // legal here because the top bit is not demanded.
@@ -549,10 +549,9 @@ Value *InstCombiner::SimplifyDemandedUse
       }
     }
 
-    // Otherwise compute the known bits using the RHS/LHS known bits.
-    bool NSW = cast<OverflowingBinaryOperator>(I)->hasNoSignedWrap();
-    computeKnownBitsForAddSub(V, NSW, KnownZero, KnownOne, LHSKnownZero,
-                              LHSKnownOne, RHSKnownZero, RHSKnownOne);
+    // Otherwise just hand the add/sub off to computeKnownBits to fill in
+    // the known zeros and ones.
+    computeKnownBits(V, KnownZero, KnownOne, Depth, CxtI);
     break;
   }
   case Instruction::Shl:




More information about the llvm-commits mailing list