mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
fix a off-by-one bug in intersectWith(), and add a bunch of tests
llvm-svn: 159319
This commit is contained in:
parent
0a5a8934ee
commit
fb9765fb80
@ -316,7 +316,7 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
|
||||
|
||||
return CR;
|
||||
}
|
||||
if (CR.Upper.ult(Lower)) {
|
||||
if (CR.Upper.ule(Lower)) {
|
||||
if (CR.Lower.ult(Lower))
|
||||
return *this;
|
||||
|
||||
|
@ -234,9 +234,39 @@ TEST_F(ConstantRangeTest, IntersectWith) {
|
||||
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));
|
||||
LHS = ConstantRange(APInt(32, -2147483646), APInt(32, 3));
|
||||
RHS = ConstantRange(APInt(32, 2), APInt(32, 2147483646));
|
||||
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 2)));
|
||||
|
||||
// [2, 0) /\ [4, 3) = [2, 0)
|
||||
LHS = ConstantRange(APInt(32, 2), APInt(32, 0));
|
||||
RHS = ConstantRange(APInt(32, 4), APInt(32, 3));
|
||||
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 2), APInt(32, 0)));
|
||||
|
||||
// [2, 0) /\ [4, 2) = [4, 0)
|
||||
LHS = ConstantRange(APInt(32, 2), APInt(32, 0));
|
||||
RHS = ConstantRange(APInt(32, 4), APInt(32, 2));
|
||||
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 4), APInt(32, 0)));
|
||||
|
||||
// [4, 2) /\ [5, 1) = [5, 1)
|
||||
LHS = ConstantRange(APInt(32, 4), APInt(32, 2));
|
||||
RHS = ConstantRange(APInt(32, 5), APInt(32, 1));
|
||||
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 5), APInt(32, 1)));
|
||||
|
||||
// [2, 0) /\ [7, 4) = [7, 4)
|
||||
LHS = ConstantRange(APInt(32, 2), APInt(32, 0));
|
||||
RHS = ConstantRange(APInt(32, 7), APInt(32, 4));
|
||||
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 7), APInt(32, 4)));
|
||||
|
||||
// [4, 2) /\ [1, 0) = [1, 0)
|
||||
LHS = ConstantRange(APInt(32, 4), APInt(32, 2));
|
||||
RHS = ConstantRange(APInt(32, 1), APInt(32, 0));
|
||||
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 4), APInt(32, 2)));
|
||||
|
||||
// [15, 0) /\ [7, 6) = [15, 0)
|
||||
LHS = ConstantRange(APInt(32, 15), APInt(32, 0));
|
||||
RHS = ConstantRange(APInt(32, 7), APInt(32, 6));
|
||||
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 15), APInt(32, 0)));
|
||||
}
|
||||
|
||||
TEST_F(ConstantRangeTest, UnionWith) {
|
||||
|
Loading…
Reference in New Issue
Block a user