[llvm] 2e91266 - [ConstantRangeTest] Migrate known bits test to generic infrastructure (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 18 06:20:42 PDT 2022
Author: Nikita Popov
Date: 2022-07-18T15:20:35+02:00
New Revision: 2e91266942509f9cabec925a1a59dab31bd07634
URL: https://github.com/llvm/llvm-project/commit/2e91266942509f9cabec925a1a59dab31bd07634
DIFF: https://github.com/llvm/llvm-project/commit/2e91266942509f9cabec925a1a59dab31bd07634.diff
LOG: [ConstantRangeTest] Migrate known bits test to generic infrastructure (NFC)
This can't make use of TestBinaryOpExhaustive, but it can make use
of the general TestRange approach that collects the precise elements
in a bit vector.
This allows us to remove the obsolete "op range gatherer" infrastructure.
Added:
Modified:
llvm/unittests/IR/ConstantRangeTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index e3fefe7d3308..3ddd04a4d942 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -242,54 +242,6 @@ static void TestBinaryOpExhaustive(BinaryRangeFn RangeFn, BinaryIntFn IntFn,
});
}
-struct OpRangeGathererBase {
- void account(const APInt &N);
- ConstantRange getRange();
-};
-
-struct UnsignedOpRangeGatherer : public OpRangeGathererBase {
- APInt Min;
- APInt Max;
-
- UnsignedOpRangeGatherer(unsigned Bits)
- : Min(APInt::getMaxValue(Bits)), Max(APInt::getMinValue(Bits)) {}
-
- void account(const APInt &N) {
- if (N.ult(Min))
- Min = N;
- if (N.ugt(Max))
- Max = N;
- }
-
- ConstantRange getRange() {
- if (Min.ugt(Max))
- return ConstantRange::getEmpty(Min.getBitWidth());
- return ConstantRange::getNonEmpty(Min, Max + 1);
- }
-};
-
-struct SignedOpRangeGatherer : public OpRangeGathererBase {
- APInt Min;
- APInt Max;
-
- SignedOpRangeGatherer(unsigned Bits)
- : Min(APInt::getSignedMaxValue(Bits)),
- Max(APInt::getSignedMinValue(Bits)) {}
-
- void account(const APInt &N) {
- if (N.slt(Min))
- Min = N;
- if (N.sgt(Max))
- Max = N;
- }
-
- ConstantRange getRange() {
- if (Min.sgt(Max))
- return ConstantRange::getEmpty(Min.getBitWidth());
- return ConstantRange::getNonEmpty(Min, Max + 1);
- }
-};
-
ConstantRange ConstantRangeTest::Full(16, true);
ConstantRange ConstantRangeTest::Empty(16, false);
ConstantRange ConstantRangeTest::One(APInt(16, 0xa));
@@ -2296,21 +2248,18 @@ TEST_F(ConstantRangeTest, FromKnownBitsExhaustive) {
if (Known.hasConflict() || Known.isUnknown())
continue;
- UnsignedOpRangeGatherer UR(Bits);
- SignedOpRangeGatherer SR(Bits);
+ SmallBitVector Elems(1 << Bits);
for (unsigned N = 0; N < Max; ++N) {
APInt Num(Bits, N);
if ((Num & Known.Zero) != 0 || (~Num & Known.One) != 0)
continue;
-
- UR.account(Num);
- SR.account(Num);
+ Elems.set(Num.getZExtValue());
}
- ConstantRange UnsignedCR = UR.getRange();
- ConstantRange SignedCR = SR.getRange();
- EXPECT_EQ(UnsignedCR, ConstantRange::fromKnownBits(Known, false));
- EXPECT_EQ(SignedCR, ConstantRange::fromKnownBits(Known, true));
+ TestRange(ConstantRange::fromKnownBits(Known, false),
+ Elems, PreferSmallestUnsigned, {});
+ TestRange(ConstantRange::fromKnownBits(Known, true),
+ Elems, PreferSmallestSigned, {});
}
}
}
More information about the llvm-commits
mailing list