diff options
author | Dan Gohman <gohman@apple.com> | 2009-06-26 22:53:46 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-06-26 22:53:46 +0000 |
commit | 667d787c0a21cf3f5dfcde03ca471162ba35b614 (patch) | |
tree | 717e8620e15b156cca07901a296ab52ea05ac3c5 /lib/Analysis | |
parent | acec7b35aa031a98dcd9ab9263445d1008ee60e5 (diff) | |
download | external_llvm-667d787c0a21cf3f5dfcde03ca471162ba35b614.zip external_llvm-667d787c0a21cf3f5dfcde03ca471162ba35b614.tar.gz external_llvm-667d787c0a21cf3f5dfcde03ca471162ba35b614.tar.bz2 |
Incorporate the insertion point into the key of SCEVExpander's CSE map.
This helps it avoid reusing an instruction that doesn't dominate all
of the users, in cases where the original instruction was inserted
before all of the users were known. This may result in redundant
expansions of sub-expressions that depend on loop-unpredictable values
in some cases, however this isn't very common, and it primarily impacts
IndVarSimplify, so GVN can be expected to clean these up.
This eliminates the need for IndVarSimplify's FixUsesBeforeDefs,
which fixes several bugs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/ScalarEvolutionExpander.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index 6d7abc0..4cc5ebc 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -468,13 +468,13 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) { const SCEV* Step = SE.getAnyExtendExpr(S->getStepRecurrence(SE), CanonicalIV->getType()); Value *V = expand(SE.getAddRecExpr(Start, Step, S->getLoop())); - BasicBlock::iterator SaveInsertPt = getInsertionPoint(); + BasicBlock::iterator SaveInsertPt = InsertPt; BasicBlock::iterator NewInsertPt = next(BasicBlock::iterator(cast<Instruction>(V))); while (isa<PHINode>(NewInsertPt)) ++NewInsertPt; V = expandCodeFor(SE.getTruncateExpr(SE.getUnknown(V), Ty), 0, NewInsertPt); - setInsertionPoint(SaveInsertPt); + InsertPt = SaveInsertPt; return V; } @@ -652,16 +652,10 @@ Value *SCEVExpander::expandCodeFor(const SCEV* SH, const Type *Ty) { } Value *SCEVExpander::expand(const SCEV *S) { - // Check to see if we already expanded this. - std::map<const SCEV*, AssertingVH<Value> >::iterator I = - InsertedExpressions.find(S); - if (I != InsertedExpressions.end()) - return I->second; + BasicBlock::iterator SaveInsertPt = InsertPt; // Compute an insertion point for this SCEV object. Hoist the instructions // as far out in the loop nest as possible. - BasicBlock::iterator InsertPt = getInsertionPoint(); - BasicBlock::iterator SaveInsertPt = InsertPt; for (Loop *L = SE.LI->getLoopFor(InsertPt->getParent()); ; L = L->getParentLoop()) if (S->isLoopInvariant(L)) { @@ -677,12 +671,23 @@ Value *SCEVExpander::expand(const SCEV *S) { while (isInsertedInstruction(InsertPt)) ++InsertPt; break; } - setInsertionPoint(InsertPt); + // Check to see if we already expanded this here. + std::map<std::pair<const SCEV *, Instruction *>, + AssertingVH<Value> >::iterator I = + InsertedExpressions.find(std::make_pair(S, InsertPt)); + if (I != InsertedExpressions.end()) { + InsertPt = SaveInsertPt; + return I->second; + } + + // Expand the expression into instructions. Value *V = visit(S); - setInsertionPoint(SaveInsertPt); - InsertedExpressions[S] = V; + // Remember the expanded value for this SCEV at this location. + InsertedExpressions[std::make_pair(S, InsertPt)] = V; + + InsertPt = SaveInsertPt; return V; } @@ -696,8 +701,8 @@ SCEVExpander::getOrInsertCanonicalInductionVariable(const Loop *L, assert(Ty->isInteger() && "Can only insert integer induction variables!"); const SCEV* H = SE.getAddRecExpr(SE.getIntegerSCEV(0, Ty), SE.getIntegerSCEV(1, Ty), L); - BasicBlock::iterator SaveInsertPt = getInsertionPoint(); + BasicBlock::iterator SaveInsertPt = InsertPt; Value *V = expandCodeFor(H, 0, L->getHeader()->begin()); - setInsertionPoint(SaveInsertPt); + InsertPt = SaveInsertPt; return V; } |