aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2017-06-23 20:28:49 +0000
committerCraig Topper <craig.topper@intel.com>2017-06-23 20:28:49 +0000
commit1a9610bd3caa4ac2af973d120bb2ffaa5e3c0e1d (patch)
treeadb30b501905d4f0234b186ae3d7c808c461bc0f
parent7584e452e62e9ec9aaaa551224560cbf6ddba9ea (diff)
downloadllvm-1a9610bd3caa4ac2af973d120bb2ffaa5e3c0e1d.tar.gz
[APInt] Use trailing bit counting methods instead of population count method in isAllOnesValue, isMaxSigendValue, and isMinSignedValue. NFCI
The trailing bit methods will early out if they find a bit of the opposite while popcount must always look at all bits. I also assume that more CPUs implement trailing bit counting with native instructions than population count. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306154 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/APInt.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index 0482e3a44bd..1289335fd2a 100644
--- a/include/llvm/ADT/APInt.h
+++ b/include/llvm/ADT/APInt.h
@@ -389,7 +389,7 @@ public:
bool isAllOnesValue() const {
if (isSingleWord())
return U.VAL == WORD_MAX >> (APINT_BITS_PER_WORD - BitWidth);
- return countPopulationSlowCase() == BitWidth;
+ return countTrailingOnesSlowCase() == BitWidth;
}
/// \brief Determine if all bits are clear
@@ -414,7 +414,7 @@ public:
/// This checks to see if the value of this APInt is the maximum signed
/// value for the APInt's bit width.
bool isMaxSignedValue() const {
- return !isNegative() && countPopulation() == BitWidth - 1;
+ return !isNegative() && countTrailingOnes() == BitWidth - 1;
}
/// \brief Determine if this is the smallest unsigned value.
@@ -428,7 +428,7 @@ public:
/// This checks to see if the value of this APInt is the minimum signed
/// value for the APInt's bit width.
bool isMinSignedValue() const {
- return isNegative() && isPowerOf2();
+ return isNegative() && countTrailingZeros() == BitWidth - 1;
}
/// \brief Check if this APInt has an N-bits unsigned integer value.