forked from OSchip/llvm-project
[APInt] set all bits for getBitsSetWithWrap if loBit == hiBit
differentiate getBitsSetWithWrap & getBitsSet when loBit == hiBit getBitsSetWithWrap sets all bits; getBitsSet does nothing. Reviewed By: lkail, RKSimon, lebedev.ri Differential Revision: https://reviews.llvm.org/D81325
This commit is contained in:
parent
246d106094
commit
8aa52b19a7
|
@ -616,9 +616,11 @@ public:
|
|||
}
|
||||
|
||||
/// 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 @@ public:
|
|||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
|
|
|
@ -906,11 +906,6 @@ bool PPCMIPeephole::simplifyCode(void) {
|
|||
// 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;
|
||||
|
|
|
@ -2099,6 +2099,14 @@ TEST(APIntTest, getBitsSetWithWrap) {
|
|||
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) {
|
||||
|
|
Loading…
Reference in New Issue