[llvm] r296300 - [APInt] Use UINT64_MAX instead of ~0ULL. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 26 11:28:48 PST 2017


Author: ctopper
Date: Sun Feb 26 13:28:48 2017
New Revision: 296300

URL: http://llvm.org/viewvc/llvm-project?rev=296300&view=rev
Log:
[APInt] Use UINT64_MAX instead of ~0ULL. NFC

Modified:
    llvm/trunk/include/llvm/ADT/APInt.h
    llvm/trunk/unittests/ADT/APIntTest.cpp

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=296300&r1=296299&r2=296300&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Sun Feb 26 13:28:48 2017
@@ -406,7 +406,7 @@ public:
 
   /// If this value is smaller than the specified limit, return it, otherwise
   /// return the limit value.  This causes the value to saturate to the limit.
-  uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
+  uint64_t getLimitedValue(uint64_t Limit = UINT64_MAX) const {
     return (getActiveBits() > 64 || getZExtValue() > Limit) ? Limit
                                                             : getZExtValue();
   }
@@ -523,7 +523,7 @@ public:
     unsigned shiftAmt = numBits - hiBitsSet;
     // For small values, return quickly
     if (numBits <= APINT_BITS_PER_WORD)
-      return APInt(numBits, ~0ULL << shiftAmt);
+      return APInt(numBits, UINT64_MAX << shiftAmt);
     return getAllOnesValue(numBits).shl(shiftAmt);
   }
 

Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=296300&r1=296299&r2=296300&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APIntTest.cpp Sun Feb 26 13:28:48 2017
@@ -1531,3 +1531,13 @@ TEST(APIntTest, getLowBitsSet) {
   EXPECT_EQ(64u, i128lo64.countTrailingOnes());
   EXPECT_EQ(64u, i128lo64.countPopulation());
 }
+
+TEST(APIntTest, getHighBitsSet) {
+  APInt i64hi32 = APInt::getHighBitsSet(64, 32);
+  EXPECT_EQ(32u, i64hi32.countLeadingOnes());
+  EXPECT_EQ(0u, i64hi32.countLeadingZeros());
+  EXPECT_EQ(64u, i64hi32.getActiveBits());
+  EXPECT_EQ(32u, i64hi32.countTrailingZeros());
+  EXPECT_EQ(0u, i64hi32.countTrailingOnes());
+  EXPECT_EQ(32u, i64hi32.countPopulation());
+}




More information about the llvm-commits mailing list