summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2016-05-19 03:53:06 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2016-05-19 03:53:06 +0000
commit15c62f945a9f3b87f72a296f237a1b5a895671a3 (patch)
tree6450d11cc13139717e03cf3c02ec26247549079e /unittests
parent62dec0fa6b72ad06dbca7c16a6c5ce01426fbbf5 (diff)
[ConstantRange] Add an getEquivalentICmp helper
Currently only its unit test uses it, but this will be used in a later change to simplify some logic in the GuardWidening pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270018 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/IR/ConstantRangeTest.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/unittests/IR/ConstantRangeTest.cpp b/unittests/IR/ConstantRangeTest.cpp
index 953e68e0594..f7a8a82043b 100644
--- a/unittests/IR/ConstantRangeTest.cpp
+++ b/unittests/IR/ConstantRangeTest.cpp
@@ -716,4 +716,50 @@ TEST(ConstantRange, MakeGuaranteedNoWrapRegion) {
ConstantRange(APInt(32, 0), APInt(32, 1)));
}
+TEST(ConstantRange, GetEquivalentICmp) {
+ APInt RHS;
+ CmpInst::Predicate Pred;
+
+ EXPECT_TRUE(ConstantRange(APInt::getMinValue(32), APInt(32, 100))
+ .getEquivalentICmp(Pred, RHS));
+ EXPECT_EQ(Pred, CmpInst::ICMP_ULT);
+ EXPECT_EQ(RHS, APInt(32, 100));
+
+ EXPECT_TRUE(ConstantRange(APInt::getSignedMinValue(32), APInt(32, 100))
+ .getEquivalentICmp(Pred, RHS));
+ EXPECT_EQ(Pred, CmpInst::ICMP_SLT);
+ EXPECT_EQ(RHS, APInt(32, 100));
+
+ EXPECT_TRUE(ConstantRange(APInt(32, 100), APInt::getMinValue(32))
+ .getEquivalentICmp(Pred, RHS));
+ EXPECT_EQ(Pred, CmpInst::ICMP_UGE);
+ EXPECT_EQ(RHS, APInt(32, 100));
+
+ EXPECT_TRUE(ConstantRange(APInt(32, 100), APInt::getSignedMinValue(32))
+ .getEquivalentICmp(Pred, RHS));
+ EXPECT_EQ(Pred, CmpInst::ICMP_SGE);
+ EXPECT_EQ(RHS, APInt(32, 100));
+
+ EXPECT_TRUE(
+ ConstantRange(32, /*isFullSet=*/true).getEquivalentICmp(Pred, RHS));
+ EXPECT_EQ(Pred, CmpInst::ICMP_UGE);
+ EXPECT_EQ(RHS, APInt(32, 0));
+
+ EXPECT_TRUE(
+ ConstantRange(32, /*isFullSet=*/false).getEquivalentICmp(Pred, RHS));
+ EXPECT_EQ(Pred, CmpInst::ICMP_ULT);
+ EXPECT_EQ(RHS, APInt(32, 0));
+
+ EXPECT_FALSE(ConstantRange(APInt(32, 100), APInt(32, 200))
+ .getEquivalentICmp(Pred, RHS));
+
+ EXPECT_FALSE(ConstantRange(APInt::getSignedMinValue(32) - APInt(32, 100),
+ APInt::getSignedMinValue(32) + APInt(32, 100))
+ .getEquivalentICmp(Pred, RHS));
+
+ EXPECT_FALSE(ConstantRange(APInt::getMinValue(32) - APInt(32, 100),
+ APInt::getMinValue(32) + APInt(32, 100))
+ .getEquivalentICmp(Pred, RHS));
+}
+
} // anonymous namespace