diff options
| author | Andrew Trick <atrick@apple.com> | 2011-10-13 17:31:47 +0000 |
|---|---|---|
| committer | Andrew Trick <atrick@apple.com> | 2011-10-13 17:31:47 +0000 |
| commit | e15d6e14e371b55168a0da0cb5edbae6322d9feb (patch) | |
| tree | 016f57165c7f2d83c0dc5f7b0597a9ba9de5f08c /llvm/lib/Analysis | |
| parent | 4072bfe71308427916cd085e53477c79bc6220f0 (diff) | |
| download | bcm5719-llvm-e15d6e14e371b55168a0da0cb5edbae6322d9feb.tar.gz bcm5719-llvm-e15d6e14e371b55168a0da0cb5edbae6322d9feb.zip | |
LSR: Reuse the post-inc expansion of expressions.
This avoids unnecessary expansion of expressions and allows the SCEV
expander to work on expression DAGs, not just trees.
Fixes PR11090.
llvm-svn: 141870
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index 81f4db1c7d2..e76b6b10cf9 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -1120,6 +1120,14 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) { BasicBlock *LatchBlock = L->getLoopLatch(); assert(LatchBlock && "PostInc mode requires a unique loop latch!"); Result = PN->getIncomingValueForBlock(LatchBlock); + + // For an expansion to use the postinc form, the client must call + // expandCodeFor with an InsertPoint that is either outside the PostIncLoop + // or dominated by IVIncInsertPos. + assert((!isa<Instruction>(Result) || + SE.DT->dominates(cast<Instruction>(Result), + Builder.GetInsertPoint())) && + "postinc expansion does not dominate use"); } // Re-apply any non-loop-dominating scale. @@ -1410,8 +1418,12 @@ Value *SCEVExpander::expand(const SCEV *S) { Value *V = visit(S); // Remember the expanded value for this SCEV at this location. - if (PostIncLoops.empty()) - InsertedExpressions[std::make_pair(S, InsertPt)] = V; + // + // This is independent of PostIncLoops. The mapped value simply materializes + // the expression at this insertion point. If the mapped value happened to be + // a postinc expansion, it could be reused by a non postinc user, but only if + // its insertion point was already at the head of the loop. + InsertedExpressions[std::make_pair(S, InsertPt)] = V; restoreInsertPoint(SaveInsertBB, SaveInsertPt); return V; |

