OSDN Git Service

[APInt] Add clearSignBit method. Use it and setSignBit in a few places. NFCI
authorCraig Topper <craig.topper@gmail.com>
Fri, 28 Apr 2017 16:58:05 +0000 (16:58 +0000)
committerCraig Topper <craig.topper@gmail.com>
Fri, 28 Apr 2017 16:58:05 +0000 (16:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301656 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h
lib/Analysis/DemandedBits.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/Transforms/InstCombine/InstCombineAddSub.cpp
lib/Transforms/InstCombine/InstCombineCompares.cpp

index 2491944..0338bee 100644 (file)
@@ -1402,6 +1402,11 @@ public:
   /// Set the given bit to 0 whose position is given as "bitPosition".
   void clearBit(unsigned bitPosition);
 
+  /// Set the sign bit to 0.
+  void clearSignBit() {
+    clearBit(BitWidth - 1);
+  }
+
   /// \brief Toggle every bit to its opposite value.
   void flipAllBits() {
     if (isSingleWord()) {
index 285339d..9f5dc53 100644 (file)
@@ -181,7 +181,7 @@ void DemandedBits::determineLiveOperandBits(
         // bits, then we must keep the highest input bit.
         if ((AOut & APInt::getHighBitsSet(BitWidth, ShiftAmt))
             .getBoolValue())
-          AB.setBit(BitWidth-1);
+          AB.setSignBit();
 
         // If the shift is exact, then the low bits are not dead
         // (they must be zero).
@@ -239,7 +239,7 @@ void DemandedBits::determineLiveOperandBits(
     if ((AOut & APInt::getHighBitsSet(AOut.getBitWidth(),
                                       AOut.getBitWidth() - BitWidth))
         .getBoolValue())
-      AB.setBit(BitWidth-1);
+      AB.setSignBit();
     break;
   case Instruction::Select:
     if (OperandNo != 0)
index 2ab2e2f..dabfb8b 100644 (file)
@@ -2719,7 +2719,7 @@ void SelectionDAG::computeKnownBits(SDValue Op, KnownBits &Known,
 
     // We only know that the absolute values's MSB will be zero iff there is
     // a set bit that isn't the sign bit (otherwise it could be INT_MIN).
-    Known2.One.clearBit(BitWidth - 1);
+    Known2.One.clearSignBit();
     if (Known2.One.getBoolValue()) {
       Known.Zero = APInt::getSignMask(BitWidth);
       break;
index 2e2116c..4f1f194 100644 (file)
@@ -861,7 +861,7 @@ static bool checkRippleForAdd(const APInt &Op0KnownZero,
   // Find the most significant known 0 other than the sign bit.
   int BitWidth = Op0KnownZero.getBitWidth();
   APInt Op0KnownZeroTemp(Op0KnownZero);
-  Op0KnownZeroTemp.clearBit(BitWidth - 1);
+  Op0KnownZeroTemp.clearSignBit();
   int Op0ZeroPosition = BitWidth - Op0KnownZeroTemp.countLeadingZeros() - 1;
 
   int Op1OnePosition = BitWidth - Op1MaybeOne.countLeadingZeros() - 1;
index d3b462e..6097077 100644 (file)
@@ -190,8 +190,8 @@ static void computeSignedMinMaxValuesFromKnownBits(const KnownBits &Known,
   Max = Known.One|UnknownBits;
 
   if (UnknownBits.isNegative()) { // Sign bit is unknown
-    Min.setBit(Min.getBitWidth()-1);
-    Max.clearBit(Max.getBitWidth()-1);
+    Min.setSignBit();
+    Max.clearSignBit();
   }
 }