Use LoopInfo's getLoopLatch() instead of doing what it does manualy.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66467 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2009-03-09 21:14:16 +00:00
parent 53f2ae268a
commit 0daeed270b

View File

@ -1599,17 +1599,12 @@ static PHINode *InsertAffinePhi(SCEVHandle Start, SCEVHandle Step,
BasicBlock *Header = L->getHeader();
BasicBlock *Preheader = L->getLoopPreheader();
BasicBlock *LatchBlock = L->getLoopLatch();
PHINode *PN = PHINode::Create(Start->getType(), "lsr.iv", Header->begin());
PN->addIncoming(Rewriter.expandCodeFor(Start, Preheader->getTerminator()),
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?");
// If the stride is negative, insert a sub instead of an add for the
// increment.
bool isNegative = isNonConstantNegative(Step);
@ -1622,17 +1617,14 @@ static PHINode *InsertAffinePhi(SCEVHandle Start, SCEVHandle Step,
Value *StepV = Rewriter.expandCodeFor(IncAmount, Preheader->getTerminator());
if (isNegative) {
IncV = BinaryOperator::CreateSub(PN, StepV, "lsr.iv.next",
(*HPI)->getTerminator());
LatchBlock->getTerminator());
} else {
IncV = BinaryOperator::CreateAdd(PN, StepV, "lsr.iv.next",
(*HPI)->getTerminator());
LatchBlock->getTerminator());
}
if (!isa<ConstantInt>(StepV)) ++NumVariable;
pred_iterator PI = pred_begin(Header);
if (*PI == L->getLoopPreheader())
++PI;
PN->addIncoming(IncV, *PI);
PN->addIncoming(IncV, LatchBlock);
++NumInserted;
return PN;