diff options
| author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-10-02 00:09:49 +0000 |
|---|---|---|
| committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-10-02 00:09:49 +0000 |
| commit | 6ef69d97f54cbeb7c1d6764feb125191ad03c413 (patch) | |
| tree | c8226380a0199de3b18b43b21712b86989188745 /llvm/unittests | |
| parent | 54e6a21dca76029753f4ad2dbade9d7595cae128 (diff) | |
| download | bcm5719-llvm-6ef69d97f54cbeb7c1d6764feb125191ad03c413.tar.gz bcm5719-llvm-6ef69d97f54cbeb7c1d6764feb125191ad03c413.zip | |
[ConstantRange] Make getEquivalentICmp smarter
This change teaches getEquivalentICmp to be smarter about generating
ICMP_NE and ICMP_EQ predicates.
llvm-svn: 283057
Diffstat (limited to 'llvm/unittests')
| -rw-r--r-- | llvm/unittests/IR/ConstantRangeTest.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp index f7a8a82043b..423f0627917 100644 --- a/llvm/unittests/IR/ConstantRangeTest.cpp +++ b/llvm/unittests/IR/ConstantRangeTest.cpp @@ -760,6 +760,37 @@ TEST(ConstantRange, GetEquivalentICmp) { EXPECT_FALSE(ConstantRange(APInt::getMinValue(32) - APInt(32, 100), APInt::getMinValue(32) + APInt(32, 100)) .getEquivalentICmp(Pred, RHS)); + + EXPECT_TRUE(ConstantRange(APInt(32, 100)).getEquivalentICmp(Pred, RHS)); + EXPECT_EQ(Pred, CmpInst::ICMP_EQ); + EXPECT_EQ(RHS, APInt(32, 100)); + + EXPECT_TRUE( + ConstantRange(APInt(32, 100)).inverse().getEquivalentICmp(Pred, RHS)); + EXPECT_EQ(Pred, CmpInst::ICMP_NE); + EXPECT_EQ(RHS, APInt(32, 100)); + + // NB! It would be correct for the following four calls to getEquivalentICmp + // to return ordered predicates like CmpInst::ICMP_ULT or CmpInst::ICMP_UGT. + // However, that's not the case today. + + EXPECT_TRUE(ConstantRange(APInt(32, 0)).getEquivalentICmp(Pred, RHS)); + EXPECT_EQ(Pred, CmpInst::ICMP_EQ); + EXPECT_EQ(RHS, APInt(32, 0)); + + EXPECT_TRUE( + ConstantRange(APInt(32, 0)).inverse().getEquivalentICmp(Pred, RHS)); + EXPECT_EQ(Pred, CmpInst::ICMP_NE); + EXPECT_EQ(RHS, APInt(32, 0)); + + EXPECT_TRUE(ConstantRange(APInt(32, -1)).getEquivalentICmp(Pred, RHS)); + EXPECT_EQ(Pred, CmpInst::ICMP_EQ); + EXPECT_EQ(RHS, APInt(32, -1)); + + EXPECT_TRUE( + ConstantRange(APInt(32, -1)).inverse().getEquivalentICmp(Pred, RHS)); + EXPECT_EQ(Pred, CmpInst::ICMP_NE); + EXPECT_EQ(RHS, APInt(32, -1)); } } // anonymous namespace |

