Add a getNumSignBits() method to APInt.
authorCameron Zwarich <zwarich@apple.com>
Thu, 24 Feb 2011 10:00:20 +0000 (10:00 +0000)
committerCameron Zwarich <zwarich@apple.com>
Thu, 24 Feb 2011 10:00:20 +0000 (10:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126379 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h
lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index b91d5dc9bcf9ed95c8c7ec06e5b448f9b643e497..d1fd3e5034bf0fdb9ff6b5d1ef47c1654dfc2948 100644 (file)
@@ -1193,6 +1193,12 @@ public:
   /// @brief Count the number of leading one bits.
   unsigned countLeadingOnes() const;
 
+  /// Computes the number of leading bits of this APInt that are equal to its
+  /// sign bit.
+  unsigned getNumSignBits() const {
+    return isNegative() ? countLeadingOnes() : countLeadingZeros();
+  }
+
   /// countTrailingZeros - This function is an APInt version of the
   /// countTrailingZeros_{32,64} functions in MathExtras.h. It counts
   /// the number of zeros from the least significant bit to the first set bit.
index 2fb2f2d8aa1ed6ec14665408876e8966268888d3..0b7cbcc47e14e188e39e54fa0b60aeca643625ea 100644 (file)
@@ -2088,12 +2088,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, unsigned Depth) const{
 
   case ISD::Constant: {
     const APInt &Val = cast<ConstantSDNode>(Op)->getAPIntValue();
-    // If negative, return # leading ones.
-    if (Val.isNegative())
-      return Val.countLeadingOnes();
-
-    // Return # leading zeros.
-    return Val.countLeadingZeros();
+    return Val.getNumSignBits();
   }
 
   case ISD::SIGN_EXTEND: