]> granicus.if.org Git - llvm/commitdiff
[APInt] Remove unnecessary early out from getLowBitsSet. The same case is handled...
authorCraig Topper <craig.topper@gmail.com>
Sun, 26 Feb 2017 19:28:45 +0000 (19:28 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sun, 26 Feb 2017 19:28:45 +0000 (19:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296299 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h
unittests/ADT/APIntTest.cpp

index fa4233a0aa99310001ef23c1c9d2ac2e4cd90db7..21be50aa49cab77371550d1d07363b3e0df0e447 100644 (file)
@@ -538,8 +538,6 @@ public:
     // Handle a degenerate case, to avoid shifting by word size
     if (loBitsSet == 0)
       return APInt(numBits, 0);
-    if (loBitsSet == APINT_BITS_PER_WORD)
-      return APInt(numBits, UINT64_MAX);
     // For small values, return quickly.
     if (loBitsSet <= APINT_BITS_PER_WORD)
       return APInt(numBits, UINT64_MAX >> (APINT_BITS_PER_WORD - loBitsSet));
index 30da181a10558ad561425c312bb9425f7b70d243..fa499bdf22bc98a95a01c446c73cf0cfdd703ff3 100644 (file)
@@ -1521,3 +1521,13 @@ TEST(APIntTest, extractBits) {
   EXPECT_EQ(static_cast<int64_t>(0xFFFFFFFFFF80007Full),
             i257.extractBits(129, 1).getSExtValue());
 }
+
+TEST(APIntTest, getLowBitsSet) {
+  APInt i128lo64 = APInt::getLowBitsSet(128, 64);
+  EXPECT_EQ(0u, i128lo64.countLeadingOnes());
+  EXPECT_EQ(64u, i128lo64.countLeadingZeros());
+  EXPECT_EQ(64u, i128lo64.getActiveBits());
+  EXPECT_EQ(0u, i128lo64.countTrailingZeros());
+  EXPECT_EQ(64u, i128lo64.countTrailingOnes());
+  EXPECT_EQ(64u, i128lo64.countPopulation());
+}