diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -616,9 +616,11 @@ } /// Wrap version of getBitsSet. - /// If \p hiBit is no less than \p loBit, this is same with getBitsSet. - /// If \p hiBit is less than \p loBit, the set bits "wrap". For example, with - /// parameters (32, 28, 4), you would get 0xF000000F. + /// If \p hiBit is bigger than \p loBit, this is same with getBitsSet. + /// If \p hiBit is not bigger than \p loBit, the set bits "wrap". For example, + /// with parameters (32, 28, 4), you would get 0xF000000F. + /// If \p hiBit is equal to \p loBit, you would get a result with all bits + /// set. static APInt getBitsSetWithWrap(unsigned numBits, unsigned loBit, unsigned hiBit) { APInt Res(numBits, 0); @@ -1448,12 +1450,13 @@ } /// Set the bits from loBit (inclusive) to hiBit (exclusive) to 1. - /// This function handles "wrap" case when \p loBit > \p hiBit, and calls - /// setBits when \p loBit <= \p hiBit. + /// This function handles "wrap" case when \p loBit >= \p hiBit, and calls + /// setBits when \p loBit < \p hiBit. + /// For \p loBit == \p hiBit wrap case, set every bit to 1. void setBitsWithWrap(unsigned loBit, unsigned hiBit) { assert(hiBit <= BitWidth && "hiBit out of range"); assert(loBit <= BitWidth && "loBit out of range"); - if (loBit <= hiBit) { + if (loBit < hiBit) { setBits(loBit, hiBit); return; } diff --git a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp --- a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp +++ b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp @@ -906,11 +906,6 @@ // while in PowerPC ISA, lowerest bit is at index 63. APInt MaskSrc = APInt::getBitsSetWithWrap(32, 32 - MESrc - 1, 32 - MBSrc); - // Current APInt::getBitsSetWithWrap sets all bits to 0 if loBit is - // equal to highBit. - // If MBSrc - MESrc == 1, we expect a full set mask instead of Null. - if (SrcMaskFull && (MBSrc - MESrc == 1)) - MaskSrc.setAllBits(); APInt RotatedSrcMask = MaskSrc.rotl(SHMI); APInt FinalMask = RotatedSrcMask & MaskMI; diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -2099,6 +2099,14 @@ EXPECT_EQ(0u, i127hi1lo1wrap.countTrailingZeros()); EXPECT_EQ(1u, i127hi1lo1wrap.countTrailingOnes()); EXPECT_EQ(2u, i127hi1lo1wrap.countPopulation()); + + APInt i32hiequallowrap = APInt::getBitsSetWithWrap(32, 10, 10); + EXPECT_EQ(32u, i32hiequallowrap.countLeadingOnes()); + EXPECT_EQ(0u, i32hiequallowrap.countLeadingZeros()); + EXPECT_EQ(32u, i32hiequallowrap.getActiveBits()); + EXPECT_EQ(0u, i32hiequallowrap.countTrailingZeros()); + EXPECT_EQ(32u, i32hiequallowrap.countTrailingOnes()); + EXPECT_EQ(32u, i32hiequallowrap.countPopulation()); } TEST(APIntTest, getHighBitsSet) {