[llvm] r357874 - [ConstantRangeTest] Generalize intersection testing code; NFC
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 7 11:55:45 PDT 2019
Author: nikic
Date: Sun Apr 7 11:55:45 2019
New Revision: 357874
URL: http://llvm.org/viewvc/llvm-project?rev=357874&view=rev
Log:
[ConstantRangeTest] Generalize intersection testing code; NFC
Extract the exhaustive intersection tests into a separate function,
so that it may be reused for unions as well.
Modified:
llvm/trunk/unittests/IR/ConstantRangeTest.cpp
Modified: llvm/trunk/unittests/IR/ConstantRangeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantRangeTest.cpp?rev=357874&r1=357873&r2=357874&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/ConstantRangeTest.cpp (original)
+++ llvm/trunk/unittests/IR/ConstantRangeTest.cpp Sun Apr 7 11:55:45 2019
@@ -363,7 +363,8 @@ TEST_F(ConstantRangeTest, IntersectWith)
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 15), APInt(32, 0)));
}
-TEST_F(ConstantRangeTest, IntersectWithExhaustive) {
+template<typename Fn1, typename Fn2>
+void testBinarySetOperationExhaustive(Fn1 OpFn, Fn2 InResultFn) {
unsigned Bits = 4;
EnumerateTwoConstantRanges(Bits,
[=](const ConstantRange &CR1, const ConstantRange &CR2) {
@@ -379,7 +380,7 @@ TEST_F(ConstantRangeTest, IntersectWithE
APInt Num(Bits, 0);
for (unsigned I = 0, Limit = 1 << Bits; I < Limit; ++I, ++Num) {
- if (!CR1.contains(Num) || !CR2.contains(Num)) {
+ if (!InResultFn(CR1, CR2, Num)) {
if (HaveRange3)
HaveInterrupt3 = true;
else if (HaveRange2)
@@ -409,12 +410,9 @@ TEST_F(ConstantRangeTest, IntersectWithE
assert(!HaveInterrupt3 && "Should have at most three ranges");
- ConstantRange SmallestCR =
- CR1.intersectWith(CR2, ConstantRange::Smallest);
- ConstantRange UnsignedCR =
- CR1.intersectWith(CR2, ConstantRange::Unsigned);
- ConstantRange SignedCR =
- CR1.intersectWith(CR2, ConstantRange::Signed);
+ ConstantRange SmallestCR = OpFn(CR1, CR2, ConstantRange::Smallest);
+ ConstantRange UnsignedCR = OpFn(CR1, CR2, ConstantRange::Unsigned);
+ ConstantRange SignedCR = OpFn(CR1, CR2, ConstantRange::Signed);
if (!HaveRange1) {
EXPECT_TRUE(SmallestCR.isEmptySet());
@@ -492,6 +490,17 @@ TEST_F(ConstantRangeTest, IntersectWithE
});
}
+TEST_F(ConstantRangeTest, IntersectWithExhaustive) {
+ testBinarySetOperationExhaustive(
+ [](const ConstantRange &CR1, const ConstantRange &CR2,
+ ConstantRange::PreferredRangeType Type) {
+ return CR1.intersectWith(CR2, Type);
+ },
+ [](const ConstantRange &CR1, const ConstantRange &CR2, const APInt &N) {
+ return CR1.contains(N) && CR2.contains(N);
+ });
+}
+
TEST_F(ConstantRangeTest, UnionWith) {
EXPECT_EQ(Wrap.unionWith(One),
ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
More information about the llvm-commits
mailing list