[llvm-commits] CVS: llvm/lib/Analysis/ScalarEvolution.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Apr 14 16:12:01 PDT 2004
Changes in directory llvm/lib/Analysis:
ScalarEvolution.cpp updated: 1.7 -> 1.8
---
Log message:
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.
---
Diffs of the changes: (+11 -6)
Index: llvm/lib/Analysis/ScalarEvolution.cpp
diff -u llvm/lib/Analysis/ScalarEvolution.cpp:1.7 llvm/lib/Analysis/ScalarEvolution.cpp:1.8
--- llvm/lib/Analysis/ScalarEvolution.cpp:1.7 Wed Apr 7 11:16:11 2004
+++ llvm/lib/Analysis/ScalarEvolution.cpp Wed Apr 14 16:11:25 2004
@@ -1465,14 +1465,19 @@
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;
+ 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?");
- Constant *One = Ty->isFloatingPoint() ?(Constant*)ConstantFP::get(Ty, 1.0)
- :(Constant*)ConstantInt::get(Ty, 1);
+ // 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())
More information about the llvm-commits
mailing list