]> granicus.if.org Git - llvm/commitdiff
[APInt] Use trailing bit counting methods instead of population count method in isAll...
authorCraig Topper <craig.topper@intel.com>
Fri, 23 Jun 2017 20:28:49 +0000 (20:28 +0000)
committerCraig Topper <craig.topper@intel.com>
Fri, 23 Jun 2017 20:28:49 +0000 (20:28 +0000)
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

include/llvm/ADT/APInt.h

index 0482e3a44bd1f8f7660ccab870678eff3ff56a5e..1289335fd2a038de88a57a173b463c8a0d132fab 100644 (file)
@@ -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.