diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-04-14 21:11:25 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-04-14 21:11:25 +0000 |
| commit | 8a9fd94cfe2382b91b5e56fc6a867770dd8b3332 (patch) | |
| tree | 8818f795c60ca0e5856d6f0192e7712898096c7b /llvm/lib/Analysis | |
| parent | aec2bcd63bd46fafaf2b1079965056869c2b0a49 (diff) | |
| download | bcm5719-llvm-8a9fd94cfe2382b91b5e56fc6a867770dd8b3332.tar.gz bcm5719-llvm-8a9fd94cfe2382b91b5e56fc6a867770dd8b3332.zip | |
This is a trivial tweak to the addrec insertion code: insert the increment
at the bottom of the loop instead of the top. This reduces the number of
overlapping live ranges a lot, for example, eliminating a spill in an important
loop in 183.equake with linear scan.
I still need to make the exit comparison of the loop use the post-incremented
version of this variable, but this is an easy first step.
llvm-svn: 12952
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 70a7d04121c..62247e42ac4 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -1465,14 +1465,19 @@ Value *SCEVAddRecExpr::expandCodeFor(ScalarEvolutionRewriter &SER, PHINode *PN = new PHINode(Ty, "indvar", Header->begin()); PN->addIncoming(Constant::getNullValue(Ty), L->getLoopPreheader()); - // Insert a unit add instruction after the PHI nodes in the header block. - BasicBlock::iterator I = PN; - while (isa<PHINode>(I)) ++I; - - Constant *One = Ty->isFloatingPoint() ?(Constant*)ConstantFP::get(Ty, 1.0) - :(Constant*)ConstantInt::get(Ty, 1); + pred_iterator HPI = pred_begin(Header); + assert(HPI != pred_end(Header) && "Loop with zero preds???"); + if (!getLoop()->contains(*HPI)) ++HPI; + assert(HPI != pred_end(Header) && getLoop()->contains(*HPI) && + "No backedge in loop?"); + + // Insert a unit add instruction right before the terminator corresponding + // to the back-edge. + Constant *One = Ty->isFloatingPoint() ? (Constant*)ConstantFP::get(Ty, 1.0) + : (Constant*)ConstantInt::get(Ty, 1); Instruction *Add = BinaryOperator::create(Instruction::Add, PN, One, - "indvar.next", I); + "indvar.next", + (*HPI)->getTerminator()); pred_iterator PI = pred_begin(Header); if (*PI == L->getLoopPreheader()) |

