APInt: Add a fast case for isAllOnesValue.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 15 Jun 2013 11:32:09 +0000 (11:32 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 15 Jun 2013 11:32:09 +0000 (11:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184042 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h

index e5797b8be238e45665e775711b1cd63665dfbefe..625a6dbfd6e2bff02d95db2a14c8a59f086cf8cf 100644 (file)
@@ -337,13 +337,17 @@ public:
   /// \brief Determine if all bits are set
   ///
   /// This checks to see if the value has all bits of the APInt are set or not.
-  bool isAllOnesValue() const { return countPopulation() == BitWidth; }
+  bool isAllOnesValue() const {
+    if (isSingleWord())
+      return VAL == ~integerPart(0) >> (APINT_BITS_PER_WORD - BitWidth);
+    return countPopulationSlowCase() == BitWidth;
+  }
 
   /// \brief Determine if this is the largest unsigned value.
   ///
   /// This checks to see if the value of this APInt is the maximum unsigned
   /// value for the APInt's bit width.
-  bool isMaxValue() const { return countPopulation() == BitWidth; }
+  bool isMaxValue() const { return isAllOnesValue(); }
 
   /// \brief Determine if this is the largest signed value.
   ///