[llvm] r296299 - [APInt] Remove unnecessary early out from getLowBitsSet. The same case is handled equally well by the next check.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 26 11:28:46 PST 2017
Author: ctopper
Date: Sun Feb 26 13:28:45 2017
New Revision: 296299
URL: http://llvm.org/viewvc/llvm-project?rev=296299&view=rev
Log:
[APInt] Remove unnecessary early out from getLowBitsSet. The same case is handled equally well by the next check.
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=296299&r1=296298&r2=296299&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Sun Feb 26 13:28:45 2017
@@ -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));
Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=296299&r1=296298&r2=296299&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APIntTest.cpp Sun Feb 26 13:28:45 2017
@@ -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());
+}
More information about the llvm-commits
mailing list