[llvm] 8aa52b1 - [APInt] set all bits for getBitsSetWithWrap if loBit == hiBit
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 19:55:35 PDT 2020
Author: Chen Zheng
Date: 2020-06-08T22:55:24-04:00
New Revision: 8aa52b19a7f1be25e38c851cfe861233ca66900a
URL: https://github.com/llvm/llvm-project/commit/8aa52b19a7f1be25e38c851cfe861233ca66900a
DIFF: https://github.com/llvm/llvm-project/commit/8aa52b19a7f1be25e38c851cfe861233ca66900a.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/ADT/APInt.h
llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
llvm/unittests/ADT/APIntTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 9f0fb04794ea..c88d9651d68d 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -616,9 +616,11 @@ class LLVM_NODISCARD APInt {
}
/// 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 @@ class LLVM_NODISCARD APInt {
}
/// 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
index 7b42830070c8..d2aba6bd6e8d 100644
--- a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
+++ b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
@@ -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;
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 0efb10f9b32d..37ab21bcfaf2 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -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) {
More information about the llvm-commits
mailing list