From: Craig Topper Date: Sun, 26 Feb 2017 19:28:45 +0000 (+0000) Subject: [APInt] Remove unnecessary early out from getLowBitsSet. The same case is handled... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1973fd95b817badea760efc3f43bd625916c1dd;p=llvm [APInt] Remove unnecessary early out from getLowBitsSet. The same case is handled equally well by the next check. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296299 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index fa4233a0aa9..21be50aa49c 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -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)); diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp index 30da181a105..fa499bdf22b 100644 --- a/unittests/ADT/APIntTest.cpp +++ b/unittests/ADT/APIntTest.cpp @@ -1521,3 +1521,13 @@ TEST(APIntTest, extractBits) { EXPECT_EQ(static_cast(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()); +}