summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Analysis
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2016-02-21 17:42:10 +0000
committerTobias Grosser <tobias@grosser.es>2016-02-21 17:42:10 +0000
commit11332e5ec5b8f1e50bdc4e8f3b08b8c35510586f (patch)
tree510fc63ab8bd3d974f4a05f889a11c854148f917 /llvm/unittests/Analysis
parent2440130437320c9671f842a933548a57dbaf5184 (diff)
downloadbcm5719-llvm-11332e5ec5b8f1e50bdc4e8f3b08b8c35510586f.tar.gz
bcm5719-llvm-11332e5ec5b8f1e50bdc4e8f3b08b8c35510586f.zip
ScalarEvolution: Do not keep temporary PHI values in ValueExprMap
Before this patch simplified SCEV expressions for PHI nodes were only returned the very first time getSCEV() was called, but later calls to getSCEV always returned the non-simplified value, which had "temporarily" been stored in the ValueExprMap, but was never removed and consequently blocked the caching of the simplified PHI expression. llvm-svn: 261485
Diffstat (limited to 'llvm/unittests/Analysis')
-rw-r--r--llvm/unittests/Analysis/ScalarEvolutionTest.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
index 938dafe6038..4089e5dce56 100644
--- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
+++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
@@ -237,5 +237,31 @@ TEST_F(ScalarEvolutionsTest, SCEVMultiplyAddRecs) {
EXPECT_EQ(Product->getOperand(8), SE.getAddExpr(Sum));
}
+TEST_F(ScalarEvolutionsTest, SimplifiedPHI) {
+ FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context),
+ std::vector<Type *>(), false);
+ Function *F = cast<Function>(M.getOrInsertFunction("f", FTy));
+ BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F);
+ BasicBlock *LoopBB = BasicBlock::Create(Context, "loop", F);
+ BasicBlock *ExitBB = BasicBlock::Create(Context, "exit", F);
+ BranchInst::Create(LoopBB, EntryBB);
+ BranchInst::Create(LoopBB, ExitBB, UndefValue::get(Type::getInt1Ty(Context)),
+ LoopBB);
+ ReturnInst::Create(Context, nullptr, ExitBB);
+ auto *Ty = Type::getInt32Ty(Context);
+ auto *PN = PHINode::Create(Ty, 2, "", &*LoopBB->begin());
+ PN->addIncoming(Constant::getNullValue(Ty), EntryBB);
+ PN->addIncoming(UndefValue::get(Ty), LoopBB);
+ ScalarEvolution SE = buildSE(*F);
+ auto *S1 = SE.getSCEV(PN);
+ auto *S2 = SE.getSCEV(PN);
+ assert(isa<SCEVConstant>(S1) && "Expected a SCEV Constant");
+
+ // At some point, only the first call to getSCEV returned the simplified
+ // SCEVConstant and later calls just returned a SCEVUnknown referencing the
+ // PHI node.
+ assert(S1 == S2 && "Expected identical SCEV values");
+}
+
} // end anonymous namespace
} // end namespace llvm
OpenPOWER on IntegriCloud