diff options
author | Cameron Zwarich <zwarich@apple.com> | 2011-02-24 10:00:20 +0000 |
---|---|---|
committer | Cameron Zwarich <zwarich@apple.com> | 2011-02-24 10:00:20 +0000 |
commit | 9b6af8de58140566a0e6567508bf906027422e7c (patch) | |
tree | 66e1ac3bf4aca9859c4a97981206d2f8752722d6 | |
parent | 324a24f6aa5d6752c57c39e1e19f00b8c8a4ceec (diff) |
Add a getNumSignBits() method to APInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126379 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/APInt.h | 6 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 7 |
2 files changed, 7 insertions, 6 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index b91d5dc9bc..d1fd3e5034 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -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. diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 2fb2f2d8aa..0b7cbcc47e 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -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: |