diff options
author | Jingyue Wu <jingyue@google.com> | 2015-10-01 03:51:44 +0000 |
---|---|---|
committer | Jingyue Wu <jingyue@google.com> | 2015-10-01 03:51:44 +0000 |
commit | df1a1b113b557d99d828c38d2f0b2c72313fbd66 (patch) | |
tree | 3dc9fa976a874fcd048abdf0077b82da3e31177e /llvm/lib/Transforms/Scalar | |
parent | 551c814e48d162634efaa31c7849059c62b53ecd (diff) | |
download | bcm5719-llvm-df1a1b113b557d99d828c38d2f0b2c72313fbd66.tar.gz bcm5719-llvm-df1a1b113b557d99d828c38d2f0b2c72313fbd66.zip |
[NaryReassociate] SeenExprs records WeakVH
Summary:
The instructions SeenExprs records may be deleted during rewriting.
FindClosestMatchingDominator should ignore these deleted instructions.
Fixes PR24301.
Reviewers: grosser
Subscribers: grosser, llvm-commits
Differential Revision: http://reviews.llvm.org/D13315
llvm-svn: 248983
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r-- | llvm/lib/Transforms/Scalar/NaryReassociate.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp index c6cb12f77fa..972bd335c85 100644 --- a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp +++ b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp @@ -188,7 +188,7 @@ private: // foo(a + b); // if (p2) // bar(a + b); - DenseMap<const SCEV *, SmallVector<Instruction *, 2>> SeenExprs; + DenseMap<const SCEV *, SmallVector<WeakVH, 2>> SeenExprs; }; } // anonymous namespace @@ -252,13 +252,15 @@ bool NaryReassociate::doOneIteration(Function &F) { Changed = true; SE->forgetValue(I); I->replaceAllUsesWith(NewI); + // If SeenExprs constains I's WeakVH, that entry will be replaced with + // nullptr. RecursivelyDeleteTriviallyDeadInstructions(I, TLI); I = NewI; } // Add the rewritten instruction to SeenExprs; the original instruction // is deleted. const SCEV *NewSCEV = SE->getSCEV(I); - SeenExprs[NewSCEV].push_back(I); + SeenExprs[NewSCEV].push_back(WeakVH(I)); // Ideally, NewSCEV should equal OldSCEV because tryReassociate(I) // is equivalent to I. However, ScalarEvolution::getSCEV may // weaken nsw causing NewSCEV not to equal OldSCEV. For example, suppose @@ -278,7 +280,7 @@ bool NaryReassociate::doOneIteration(Function &F) { // // This improvement is exercised in @reassociate_gep_nsw in nary-gep.ll. if (NewSCEV != OldSCEV) - SeenExprs[OldSCEV].push_back(I); + SeenExprs[OldSCEV].push_back(WeakVH(I)); } } } @@ -562,9 +564,13 @@ NaryReassociate::findClosestMatchingDominator(const SCEV *CandidateExpr, // future instruction either. Therefore, we pop it out of the stack. This // optimization makes the algorithm O(n). while (!Candidates.empty()) { - Instruction *Candidate = Candidates.back(); - if (DT->dominates(Candidate, Dominatee)) - return Candidate; + // Candidates stores WeakVHs, so a candidate can be nullptr if it's removed + // during rewriting. + if (Value *Candidate = Candidates.back()) { + Instruction *CandidateInstruction = cast<Instruction>(Candidate); + if (DT->dominates(CandidateInstruction, Dominatee)) + return CandidateInstruction; + } Candidates.pop_back(); } return nullptr; |