summaryrefslogtreecommitdiffstats
path: root/lib/Analysis/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-02-12 10:34:29 +0000
committerDan Gohman <gohman@apple.com>2010-02-12 10:34:29 +0000
commit572645cf84060c0fc25cb91d38cb9079918b3a88 (patch)
tree0571ce42ea03d210844a627baea045fa36f16df5 /lib/Analysis/ScalarEvolutionExpander.cpp
parent5cef638855c9f2bb23a9c181cc47ddace8551f50 (diff)
downloadexternal_llvm-572645cf84060c0fc25cb91d38cb9079918b3a88.zip
external_llvm-572645cf84060c0fc25cb91d38cb9079918b3a88.tar.gz
external_llvm-572645cf84060c0fc25cb91d38cb9079918b3a88.tar.bz2
Reapply the new LoopStrengthReduction code, with compile time and
bug fixes, and with improved heuristics for analyzing foreign-loop addrecs. This change also flattens IVUsers, eliminating the stride-oriented groupings, which makes it easier to work with. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95975 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index 4310e3c..9439d08 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -641,8 +641,24 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
// Reuse a previously-inserted PHI, if present.
for (BasicBlock::iterator I = L->getHeader()->begin();
PHINode *PN = dyn_cast<PHINode>(I); ++I)
- if (isInsertedInstruction(PN) && SE.getSCEV(PN) == Normalized)
- return PN;
+ if (SE.isSCEVable(PN->getType()) &&
+ (SE.getEffectiveSCEVType(PN->getType()) ==
+ SE.getEffectiveSCEVType(Normalized->getType())) &&
+ SE.getSCEV(PN) == Normalized)
+ if (BasicBlock *LatchBlock = L->getLoopLatch()) {
+ // Remember this PHI, even in post-inc mode.
+ InsertedValues.insert(PN);
+ // Remember the increment.
+ Instruction *IncV =
+ cast<Instruction>(PN->getIncomingValueForBlock(LatchBlock)
+ ->stripPointerCasts());
+ rememberInstruction(IncV);
+ // Make sure the increment is where we want it. But don't move it
+ // down past a potential existing post-inc user.
+ if (L == IVIncInsertLoop && !SE.DT->dominates(IncV, IVIncInsertPos))
+ IncV->moveBefore(IVIncInsertPos);
+ return PN;
+ }
// Save the original insertion point so we can restore it when we're done.
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();