summaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index ac2075cb4af4..392c41f74b43 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -2788,4 +2788,52 @@ TEST_F(ConstantRangeTest, isSizeLargerThan) {
EXPECT_FALSE(One.isSizeLargerThan(1));
}
+TEST_F(ConstantRangeTest, MakeMaskNotEqualRange) {
+ // Mask: 0b0001, C: 0b0001. MMNE() = [2, 1)
+ ConstantRange CR(APInt(4, 2), APInt(4, 1));
+ EXPECT_EQ(CR, ConstantRange::makeMaskNotEqualRange(APInt(4, 1), APInt(4, 1)));
+ EXPECT_NE(CR, ConstantRange::makeMaskNotEqualRange(APInt(4, 0),
+ APInt(4, -1, true)));
+ EXPECT_TRUE(CR.contains(APInt(4, 7)));
+ EXPECT_TRUE(CR.contains(APInt(4, 15)));
+
+ // Mask: 0b0100, C: 0b0100. MMNE() = [-8, 4)
+ ConstantRange CR2(APInt(4, -8, true), APInt(4, 4));
+ auto MMNE = ConstantRange::makeMaskNotEqualRange(APInt(4, 4), APInt(4, 4));
+ EXPECT_EQ(CR2, MMNE);
+ EXPECT_NE(ConstantRange::getNonEmpty(APInt(4, 0), APInt(4, -4, true)), MMNE);
+
+ // CR: [-16, -8). MMNE() = [-8, -16)
+ ConstantRange CR3(APInt(8, 240), APInt(8, 248));
+ EXPECT_EQ(CR3.inverse(),
+ ConstantRange::makeMaskNotEqualRange(APInt(8, 248), APInt(8, 240)));
+
+ // Mask: 0, C: 0b1111: unsatisfiable.
+ EXPECT_EQ(ConstantRange::getFull(4),
+ ConstantRange::makeMaskNotEqualRange(APInt(4, 0), APInt(4, 15)));
+}
+
+TEST_F(ConstantRangeTest, MakeMaskNotEqualRangeExhaustive) {
+ unsigned Bits = 4;
+ unsigned Max = 1 << Bits;
+
+ EnumerateAPInts(Bits, [&](const APInt &Mask) {
+ EnumerateAPInts(Bits, [&](const APInt &C) {
+ SmallBitVector Elems(Max);
+ for (unsigned N = 0; N < Max; ++N) {
+ APInt Num(Bits, N);
+ if ((Num & Mask) == C)
+ continue;
+ Elems.set(Num.getZExtValue());
+ }
+
+ // Only test optimality with PreferSmallest. E.g., given Mask = 0b0001, C
+ // = 0b0001, a possible better range would be [0, 15) when preferring the
+ // smallest unsigned, however we conservatively return [2, 1).
+ TestRange(ConstantRange::makeMaskNotEqualRange(Mask, C), Elems,
+ PreferSmallest, {});
+ });
+ });
+}
+
} // anonymous namespace