From f300b51fae4d6f4842c61ee1a566b681efb8da88 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 30 Apr 2017 07:45:01 +0000 Subject: [PATCH] [APInt] Remove support for wrapping from APInt::setBits. This features isn't used anywhere in tree. It's existence seems to be preventing selfhost builds from inlining any of the setBits methods including setLowBits, setHighBits, and setBitsFrom. This is because the code makes the method recursive. If anyone needs this feature in the future we could consider adding a setBitsWithWrap method. This way only the calls that need it would pay for it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301769 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/APInt.h | 6 +----- unittests/ADT/APIntTest.cpp | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 0f82654a88f..e08e28c99ae 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -1360,13 +1360,9 @@ public: void setBits(unsigned loBit, unsigned hiBit) { assert(hiBit <= BitWidth && "hiBit out of range"); assert(loBit <= BitWidth && "loBit out of range"); + assert(loBit <= hiBit && "loBit greater than hiBit"); if (loBit == hiBit) return; - if (loBit > hiBit) { - setLowBits(hiBit); - setHighBits(BitWidth - loBit); - return; - } if (loBit < APINT_BITS_PER_WORD && hiBit <= APINT_BITS_PER_WORD) { uint64_t mask = WORD_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit)); mask <<= loBit; diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp index 2235f271658..bb6cf35fe9e 100644 --- a/unittests/ADT/APIntTest.cpp +++ b/unittests/ADT/APIntTest.cpp @@ -1723,21 +1723,21 @@ TEST(APIntTest, getLowBitsSet) { } TEST(APIntTest, getBitsSet) { - APInt i64hi1lo1 = APInt::getBitsSet(64, 63, 1); - EXPECT_EQ(1u, i64hi1lo1.countLeadingOnes()); - EXPECT_EQ(0u, i64hi1lo1.countLeadingZeros()); - EXPECT_EQ(64u, i64hi1lo1.getActiveBits()); - EXPECT_EQ(0u, i64hi1lo1.countTrailingZeros()); - EXPECT_EQ(1u, i64hi1lo1.countTrailingOnes()); - EXPECT_EQ(2u, i64hi1lo1.countPopulation()); + APInt i64hi1lo1 = APInt::getBitsSet(64, 1, 63); + EXPECT_EQ(0u, i64hi1lo1.countLeadingOnes()); + EXPECT_EQ(1u, i64hi1lo1.countLeadingZeros()); + EXPECT_EQ(63u, i64hi1lo1.getActiveBits()); + EXPECT_EQ(1u, i64hi1lo1.countTrailingZeros()); + EXPECT_EQ(0u, i64hi1lo1.countTrailingOnes()); + EXPECT_EQ(62u, i64hi1lo1.countPopulation()); - APInt i127hi1lo1 = APInt::getBitsSet(127, 126, 1); - EXPECT_EQ(1u, i127hi1lo1.countLeadingOnes()); - EXPECT_EQ(0u, i127hi1lo1.countLeadingZeros()); - EXPECT_EQ(127u, i127hi1lo1.getActiveBits()); - EXPECT_EQ(0u, i127hi1lo1.countTrailingZeros()); - EXPECT_EQ(1u, i127hi1lo1.countTrailingOnes()); - EXPECT_EQ(2u, i127hi1lo1.countPopulation()); + APInt i127hi1lo1 = APInt::getBitsSet(127, 1, 126); + EXPECT_EQ(0u, i127hi1lo1.countLeadingOnes()); + EXPECT_EQ(1u, i127hi1lo1.countLeadingZeros()); + EXPECT_EQ(126u, i127hi1lo1.getActiveBits()); + EXPECT_EQ(1u, i127hi1lo1.countTrailingZeros()); + EXPECT_EQ(0u, i127hi1lo1.countTrailingOnes()); + EXPECT_EQ(125u, i127hi1lo1.countPopulation()); } TEST(APIntTest, getHighBitsSet) {