mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-13 21:10:39 +00:00
[ConstantRange] Make getEquivalentICmp smarter
This change teaches getEquivalentICmp to be smarter about generating ICMP_NE and ICMP_EQ predicates. llvm-svn: 283057
This commit is contained in:
parent
6b37e26252
commit
2915cf67fe
@ -147,6 +147,14 @@ bool ConstantRange::getEquivalentICmp(CmpInst::Predicate &Pred,
|
|||||||
Pred = isEmptySet() ? CmpInst::ICMP_ULT : CmpInst::ICMP_UGE;
|
Pred = isEmptySet() ? CmpInst::ICMP_ULT : CmpInst::ICMP_UGE;
|
||||||
RHS = APInt(getBitWidth(), 0);
|
RHS = APInt(getBitWidth(), 0);
|
||||||
Success = true;
|
Success = true;
|
||||||
|
} else if (auto *OnlyElt = getSingleElement()) {
|
||||||
|
Pred = CmpInst::ICMP_EQ;
|
||||||
|
RHS = *OnlyElt;
|
||||||
|
Success = true;
|
||||||
|
} else if (auto *OnlyMissingElt = inverse().getSingleElement()) {
|
||||||
|
Pred = CmpInst::ICMP_NE;
|
||||||
|
RHS = *OnlyMissingElt;
|
||||||
|
Success = true;
|
||||||
} else if (getLower().isMinSignedValue() || getLower().isMinValue()) {
|
} else if (getLower().isMinSignedValue() || getLower().isMinValue()) {
|
||||||
Pred =
|
Pred =
|
||||||
getLower().isMinSignedValue() ? CmpInst::ICMP_SLT : CmpInst::ICMP_ULT;
|
getLower().isMinSignedValue() ? CmpInst::ICMP_SLT : CmpInst::ICMP_ULT;
|
||||||
|
@ -760,6 +760,37 @@ TEST(ConstantRange, GetEquivalentICmp) {
|
|||||||
EXPECT_FALSE(ConstantRange(APInt::getMinValue(32) - APInt(32, 100),
|
EXPECT_FALSE(ConstantRange(APInt::getMinValue(32) - APInt(32, 100),
|
||||||
APInt::getMinValue(32) + APInt(32, 100))
|
APInt::getMinValue(32) + APInt(32, 100))
|
||||||
.getEquivalentICmp(Pred, RHS));
|
.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
|
} // anonymous namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user