[llvm-commits] [llvm] r126379 - in /llvm/trunk: include/llvm/ADT/APInt.h lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Cameron Zwarich
zwarich at apple.com
Thu Feb 24 02:00:20 PST 2011
Author: zwarich
Date: Thu Feb 24 04:00:20 2011
New Revision: 126379
URL: http://llvm.org/viewvc/llvm-project?rev=126379&view=rev
Log:
Add a getNumSignBits() method to APInt.
Modified:
llvm/trunk/include/llvm/ADT/APInt.h
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=126379&r1=126378&r2=126379&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Thu Feb 24 04:00:20 2011
@@ -1193,6 +1193,12 @@
/// @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.
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=126379&r1=126378&r2=126379&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Thu Feb 24 04:00:20 2011
@@ -2088,12 +2088,7 @@
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:
More information about the llvm-commits
mailing list