diff options
Diffstat (limited to 'unittests/IR/ConstantRangeTest.cpp')
-rw-r--r-- | unittests/IR/ConstantRangeTest.cpp | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/unittests/IR/ConstantRangeTest.cpp b/unittests/IR/ConstantRangeTest.cpp index fa03302..de4eec4 100644 --- a/unittests/IR/ConstantRangeTest.cpp +++ b/unittests/IR/ConstantRangeTest.cpp @@ -400,6 +400,13 @@ TEST_F(ConstantRangeTest, Multiply) { EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply( ConstantRange(APInt(4, 6), APInt(4, 2))), ConstantRange(4, /*isFullSet=*/true)); + + EXPECT_EQ(ConstantRange(APInt(8, 254), APInt(8, 0)).multiply( + ConstantRange(APInt(8, 252), APInt(8, 4))), + ConstantRange(APInt(8, 250), APInt(8, 9))); + EXPECT_EQ(ConstantRange(APInt(8, 254), APInt(8, 255)).multiply( + ConstantRange(APInt(8, 2), APInt(8, 4))), + ConstantRange(APInt(8, 250), APInt(8, 253))); } TEST_F(ConstantRangeTest, UMax) { @@ -502,11 +509,63 @@ TEST_F(ConstantRangeTest, Lshr) { EXPECT_EQ(Wrap.lshr(Wrap), Full); } -TEST(ConstantRange, MakeICmpRegion) { +TEST(ConstantRange, MakeAllowedICmpRegion) { // PR8250 ConstantRange SMax = ConstantRange(APInt::getSignedMaxValue(32)); - EXPECT_TRUE(ConstantRange::makeICmpRegion(ICmpInst::ICMP_SGT, - SMax).isEmptySet()); + EXPECT_TRUE(ConstantRange::makeAllowedICmpRegion(ICmpInst::ICMP_SGT, SMax) + .isEmptySet()); +} + +TEST(ConstantRange, MakeSatisfyingICmpRegion) { + ConstantRange LowHalf(APInt(8, 0), APInt(8, 128)); + ConstantRange HighHalf(APInt(8, 128), APInt(8, 0)); + ConstantRange EmptySet(8, /* isFullSet = */ false); + + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_NE, LowHalf), + HighHalf); + + EXPECT_EQ( + ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_NE, HighHalf), + LowHalf); + + EXPECT_TRUE(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_EQ, + HighHalf).isEmptySet()); + + ConstantRange UnsignedSample(APInt(8, 5), APInt(8, 200)); + + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_ULT, + UnsignedSample), + ConstantRange(APInt(8, 0), APInt(8, 5))); + + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_ULE, + UnsignedSample), + ConstantRange(APInt(8, 0), APInt(8, 6))); + + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_UGT, + UnsignedSample), + ConstantRange(APInt(8, 200), APInt(8, 0))); + + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_UGE, + UnsignedSample), + ConstantRange(APInt(8, 199), APInt(8, 0))); + + ConstantRange SignedSample(APInt(8, -5), APInt(8, 5)); + + EXPECT_EQ( + ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLT, SignedSample), + ConstantRange(APInt(8, -128), APInt(8, -5))); + + EXPECT_EQ( + ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLE, SignedSample), + ConstantRange(APInt(8, -128), APInt(8, -4))); + + EXPECT_EQ( + ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGT, SignedSample), + ConstantRange(APInt(8, 5), APInt(8, -128))); + + EXPECT_EQ( + ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGE, SignedSample), + ConstantRange(APInt(8, 4), APInt(8, -128))); } } // anonymous namespace |