forked from OSchip/llvm-project
fix corner case in ConstantRange::intersectWith().
this fixes the missed optimization I was seeing in the CorrelatedValuePropagation pass llvm-svn: 157032
This commit is contained in:
parent
badd100c26
commit
63afc08ca7
|
@ -288,7 +288,7 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
|
||||||
if (CR.Upper.ult(Upper))
|
if (CR.Upper.ult(Upper))
|
||||||
return CR;
|
return CR;
|
||||||
|
|
||||||
if (CR.Upper.ult(Lower))
|
if (CR.Upper.ule(Lower))
|
||||||
return ConstantRange(CR.Lower, Upper);
|
return ConstantRange(CR.Lower, Upper);
|
||||||
|
|
||||||
if (getSetSize().ult(CR.getSetSize()))
|
if (getSetSize().ult(CR.getSetSize()))
|
||||||
|
|
|
@ -232,6 +232,11 @@ TEST_F(ConstantRangeTest, IntersectWith) {
|
||||||
ConstantRange LHS(APInt(16, 4), APInt(16, 2));
|
ConstantRange LHS(APInt(16, 4), APInt(16, 2));
|
||||||
ConstantRange RHS(APInt(16, 6), APInt(16, 5));
|
ConstantRange RHS(APInt(16, 6), APInt(16, 5));
|
||||||
EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
|
EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
|
||||||
|
|
||||||
|
// previous bug: intersection of [min, 3) and [2, max) should be 2
|
||||||
|
LHS = ConstantRange(APInt(32, -2147483648), APInt(32, 3));
|
||||||
|
RHS = ConstantRange(APInt(32, 2), APInt(32, 2147483648));
|
||||||
|
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ConstantRangeTest, UnionWith) {
|
TEST_F(ConstantRangeTest, UnionWith) {
|
||||||
|
|
Loading…
Reference in New Issue