Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit a0883e0

Browse files
committed
[ValueLattice] Return false if value range did not change in mergeIn.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335729 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 16742ac commit a0883e0

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

include/llvm/Analysis/ValueLattice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ class ValueLatticeElement {
275275
ConstantRange NewR = getConstantRange().unionWith(RHS.getConstantRange());
276276
if (NewR.isFullSet())
277277
markOverdefined();
278+
else if (NewR == getConstantRange())
279+
return false;
278280
else
279281
markConstantRange(std::move(NewR));
280282
return true;

unittests/Analysis/ValueLatticeTest.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,41 @@ TEST_F(ValueLatticeTest, MergeIn) {
5050

5151
// Merge to lattice values with equal integer constant.
5252
auto LV1 = ValueLatticeElement::get(C1);
53-
LV1.mergeIn(ValueLatticeElement::get(C1), M.getDataLayout());
53+
EXPECT_FALSE(LV1.mergeIn(ValueLatticeElement::get(C1), M.getDataLayout()));
5454
EXPECT_TRUE(LV1.isConstantRange());
5555
EXPECT_EQ(LV1.asConstantInteger().getValue().getLimitedValue(), 1U);
5656

5757
// Merge LV1 with different integer constant.
58-
LV1.mergeIn(ValueLatticeElement::get(ConstantInt::get(I32Ty, 99)),
59-
M.getDataLayout());
58+
EXPECT_TRUE(LV1.mergeIn(ValueLatticeElement::get(ConstantInt::get(I32Ty, 99)),
59+
M.getDataLayout()));
60+
EXPECT_TRUE(LV1.isConstantRange());
61+
EXPECT_EQ(LV1.getConstantRange().getLower().getLimitedValue(), 1U);
62+
EXPECT_EQ(LV1.getConstantRange().getUpper().getLimitedValue(), 100U);
63+
64+
// Merge constant range with same constant range.
65+
EXPECT_FALSE(LV1.mergeIn(LV1, M.getDataLayout()));
6066
EXPECT_TRUE(LV1.isConstantRange());
6167
EXPECT_EQ(LV1.getConstantRange().getLower().getLimitedValue(), 1U);
6268
EXPECT_EQ(LV1.getConstantRange().getUpper().getLimitedValue(), 100U);
6369

6470
// Merge LV1 in undefined value.
6571
ValueLatticeElement LV2;
66-
LV2.mergeIn(LV1, M.getDataLayout());
72+
EXPECT_TRUE(LV2.mergeIn(LV1, M.getDataLayout()));
6773
EXPECT_TRUE(LV1.isConstantRange());
6874
EXPECT_EQ(LV1.getConstantRange().getLower().getLimitedValue(), 1U);
6975
EXPECT_EQ(LV1.getConstantRange().getUpper().getLimitedValue(), 100U);
7076
EXPECT_TRUE(LV2.isConstantRange());
7177
EXPECT_EQ(LV2.getConstantRange().getLower().getLimitedValue(), 1U);
7278
EXPECT_EQ(LV2.getConstantRange().getUpper().getLimitedValue(), 100U);
7379

74-
// Merge with overdefined.
75-
LV1.mergeIn(ValueLatticeElement::getOverdefined(), M.getDataLayout());
80+
// Merge LV1 with overdefined.
81+
EXPECT_TRUE(
82+
LV1.mergeIn(ValueLatticeElement::getOverdefined(), M.getDataLayout()));
83+
EXPECT_TRUE(LV1.isOverdefined());
84+
85+
// Merge overdefined with overdefined.
86+
EXPECT_FALSE(
87+
LV1.mergeIn(ValueLatticeElement::getOverdefined(), M.getDataLayout()));
7688
EXPECT_TRUE(LV1.isOverdefined());
7789
}
7890

@@ -136,8 +148,9 @@ TEST_F(ValueLatticeTest, getCompareFloat) {
136148
EXPECT_TRUE(LV1.getCompare(CmpInst::FCMP_OLT, I1Ty, LV2)->isZeroValue());
137149
EXPECT_TRUE(LV1.getCompare(CmpInst::FCMP_OGT, I1Ty, LV2)->isZeroValue());
138150

139-
LV1.mergeIn(ValueLatticeElement::get(ConstantFP::get(FloatTy, 2.2)),
140-
M.getDataLayout());
151+
EXPECT_TRUE(
152+
LV1.mergeIn(ValueLatticeElement::get(ConstantFP::get(FloatTy, 2.2)),
153+
M.getDataLayout()));
141154
EXPECT_EQ(LV1.getCompare(CmpInst::FCMP_OEQ, I1Ty, LV2), nullptr);
142155
EXPECT_EQ(LV1.getCompare(CmpInst::FCMP_OGE, I1Ty, LV2), nullptr);
143156
EXPECT_EQ(LV1.getCompare(CmpInst::FCMP_OLE, I1Ty, LV2), nullptr);

0 commit comments

Comments
 (0)