[llvm-commits] [llvm] r82905 - /llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
Dan Gohman
gohman at apple.com
Sun Sep 27 10:46:40 PDT 2009
Author: djg
Date: Sun Sep 27 12:46:40 2009
New Revision: 82905
URL: http://llvm.org/viewvc/llvm-project?rev=82905&view=rev
Log:
Fix SCEVExpander's canonical addrec expansion code to work on loops that
aren't in canonical loop-simplify form, since it doesn't itself depend
on LoopSimplify. This means handling loops without preheaders and loops
with multiple backedges.
Modified:
llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=82905&r1=82904&r2=82905&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Sun Sep 27 12:46:40 2009
@@ -680,29 +680,22 @@
// Create and insert the PHI node for the induction variable in the
// specified loop.
BasicBlock *Header = L->getHeader();
- BasicBlock *Preheader = L->getLoopPreheader();
PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin());
InsertedValues.insert(PN);
- PN->addIncoming(Constant::getNullValue(Ty), Preheader);
- pred_iterator HPI = pred_begin(Header);
- assert(HPI != pred_end(Header) && "Loop with zero preds???");
- if (!L->contains(*HPI)) ++HPI;
- assert(HPI != pred_end(Header) && L->contains(*HPI) &&
- "No backedge in loop?");
-
- // Insert a unit add instruction right before the terminator corresponding
- // to the back-edge.
Constant *One = ConstantInt::get(Ty, 1);
- Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next",
- (*HPI)->getTerminator());
- InsertedValues.insert(Add);
-
- pred_iterator PI = pred_begin(Header);
- if (*PI == Preheader)
- ++PI;
- PN->addIncoming(Add, *PI);
- return PN;
+ for (pred_iterator HPI = pred_begin(Header), HPE = pred_end(Header);
+ HPI != HPE; ++HPI)
+ if (L->contains(*HPI)) {
+ // Insert a unit add instruction right before the terminator corresponding
+ // to the back-edge.
+ Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next",
+ (*HPI)->getTerminator());
+ InsertedValues.insert(Add);
+ PN->addIncoming(Add, *HPI);
+ } else {
+ PN->addIncoming(Constant::getNullValue(Ty), *HPI);
+ }
}
// {0,+,F} --> {0,+,1} * F
More information about the llvm-commits
mailing list