summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Hahn <florian.hahn@arm.com>2018-06-27 12:57:51 +0000
committerFlorian Hahn <florian.hahn@arm.com>2018-06-27 12:57:51 +0000
commitf681413e67a4e2b7a7ba54caba674a0023b30d15 (patch)
tree2206ae16cf6ace5063e24021717427b4224df108
parentbb78eef6b682a62745c09892d47660fe44d8ac88 (diff)
downloadbcm5719-llvm-f681413e67a4e2b7a7ba54caba674a0023b30d15.tar.gz
bcm5719-llvm-f681413e67a4e2b7a7ba54caba674a0023b30d15.zip
[ValueLattice] Return false if value range did not change in mergeIn.
llvm-svn: 335729
-rw-r--r--llvm/include/llvm/Analysis/ValueLattice.h2
-rw-r--r--llvm/unittests/Analysis/ValueLatticeTest.cpp29
2 files changed, 23 insertions, 8 deletions
diff --git a/llvm/include/llvm/Analysis/ValueLattice.h b/llvm/include/llvm/Analysis/ValueLattice.h
index c943fd1e47d..0744ca617e4 100644
--- a/llvm/include/llvm/Analysis/ValueLattice.h
+++ b/llvm/include/llvm/Analysis/ValueLattice.h
@@ -275,6 +275,8 @@ public:
ConstantRange NewR = getConstantRange().unionWith(RHS.getConstantRange());
if (NewR.isFullSet())
markOverdefined();
+ else if (NewR == getConstantRange())
+ return false;
else
markConstantRange(std::move(NewR));
return true;
diff --git a/llvm/unittests/Analysis/ValueLatticeTest.cpp b/llvm/unittests/Analysis/ValueLatticeTest.cpp
index b3e86c48b55..b0b379760a5 100644
--- a/llvm/unittests/Analysis/ValueLatticeTest.cpp
+++ b/llvm/unittests/Analysis/ValueLatticeTest.cpp
@@ -50,20 +50,26 @@ TEST_F(ValueLatticeTest, MergeIn) {
// Merge to lattice values with equal integer constant.
auto LV1 = ValueLatticeElement::get(C1);
- LV1.mergeIn(ValueLatticeElement::get(C1), M.getDataLayout());
+ EXPECT_FALSE(LV1.mergeIn(ValueLatticeElement::get(C1), M.getDataLayout()));
EXPECT_TRUE(LV1.isConstantRange());
EXPECT_EQ(LV1.asConstantInteger().getValue().getLimitedValue(), 1U);
// Merge LV1 with different integer constant.
- LV1.mergeIn(ValueLatticeElement::get(ConstantInt::get(I32Ty, 99)),
- M.getDataLayout());
+ EXPECT_TRUE(LV1.mergeIn(ValueLatticeElement::get(ConstantInt::get(I32Ty, 99)),
+ M.getDataLayout()));
+ EXPECT_TRUE(LV1.isConstantRange());
+ EXPECT_EQ(LV1.getConstantRange().getLower().getLimitedValue(), 1U);
+ EXPECT_EQ(LV1.getConstantRange().getUpper().getLimitedValue(), 100U);
+
+ // Merge constant range with same constant range.
+ EXPECT_FALSE(LV1.mergeIn(LV1, M.getDataLayout()));
EXPECT_TRUE(LV1.isConstantRange());
EXPECT_EQ(LV1.getConstantRange().getLower().getLimitedValue(), 1U);
EXPECT_EQ(LV1.getConstantRange().getUpper().getLimitedValue(), 100U);
// Merge LV1 in undefined value.
ValueLatticeElement LV2;
- LV2.mergeIn(LV1, M.getDataLayout());
+ EXPECT_TRUE(LV2.mergeIn(LV1, M.getDataLayout()));
EXPECT_TRUE(LV1.isConstantRange());
EXPECT_EQ(LV1.getConstantRange().getLower().getLimitedValue(), 1U);
EXPECT_EQ(LV1.getConstantRange().getUpper().getLimitedValue(), 100U);
@@ -71,8 +77,14 @@ TEST_F(ValueLatticeTest, MergeIn) {
EXPECT_EQ(LV2.getConstantRange().getLower().getLimitedValue(), 1U);
EXPECT_EQ(LV2.getConstantRange().getUpper().getLimitedValue(), 100U);
- // Merge with overdefined.
- LV1.mergeIn(ValueLatticeElement::getOverdefined(), M.getDataLayout());
+ // Merge LV1 with overdefined.
+ EXPECT_TRUE(
+ LV1.mergeIn(ValueLatticeElement::getOverdefined(), M.getDataLayout()));
+ EXPECT_TRUE(LV1.isOverdefined());
+
+ // Merge overdefined with overdefined.
+ EXPECT_FALSE(
+ LV1.mergeIn(ValueLatticeElement::getOverdefined(), M.getDataLayout()));
EXPECT_TRUE(LV1.isOverdefined());
}
@@ -136,8 +148,9 @@ TEST_F(ValueLatticeTest, getCompareFloat) {
EXPECT_TRUE(LV1.getCompare(CmpInst::FCMP_OLT, I1Ty, LV2)->isZeroValue());
EXPECT_TRUE(LV1.getCompare(CmpInst::FCMP_OGT, I1Ty, LV2)->isZeroValue());
- LV1.mergeIn(ValueLatticeElement::get(ConstantFP::get(FloatTy, 2.2)),
- M.getDataLayout());
+ EXPECT_TRUE(
+ LV1.mergeIn(ValueLatticeElement::get(ConstantFP::get(FloatTy, 2.2)),
+ M.getDataLayout()));
EXPECT_EQ(LV1.getCompare(CmpInst::FCMP_OEQ, I1Ty, LV2), nullptr);
EXPECT_EQ(LV1.getCompare(CmpInst::FCMP_OGE, I1Ty, LV2), nullptr);
EXPECT_EQ(LV1.getCompare(CmpInst::FCMP_OLE, I1Ty, LV2), nullptr);
OpenPOWER on IntegriCloud