mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-01 00:33:09 +00:00
Fix a bug in the previous checkin: if the exit block is not the same as
the back-edge block, we must check the preincremented value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12968 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b75a316758
commit
d244057a48
@ -209,13 +209,29 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L, SCEV *IterationCount,
|
|||||||
if (Instruction *Cond = dyn_cast<Instruction>(BI->getCondition()))
|
if (Instruction *Cond = dyn_cast<Instruction>(BI->getCondition()))
|
||||||
InstructionsToDelete.insert(Cond);
|
InstructionsToDelete.insert(Cond);
|
||||||
|
|
||||||
// The IterationCount expression contains the number of times that the
|
// If the exiting block is not the same as the backedge block, we must compare
|
||||||
// backedge actually branches to the loop header. This is one less than the
|
// against the preincremented value, otherwise we prefer to compare against
|
||||||
// number of times the loop executes, so add one to it.
|
// the post-incremented value.
|
||||||
Constant *OneC = ConstantInt::get(IterationCount->getType(), 1);
|
BasicBlock *Header = L->getHeader();
|
||||||
SCEVHandle TripCount=SCEVAddExpr::get(IterationCount, SCEVUnknown::get(OneC));
|
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?");
|
||||||
|
|
||||||
Value *IndVar = L->getCanonicalInductionVariableIncrement();
|
SCEVHandle TripCount = IterationCount;
|
||||||
|
Value *IndVar;
|
||||||
|
if (*HPI == ExitingBlock) {
|
||||||
|
// The IterationCount expression contains the number of times that the
|
||||||
|
// backedge actually branches to the loop header. This is one less than the
|
||||||
|
// number of times the loop executes, so add one to it.
|
||||||
|
Constant *OneC = ConstantInt::get(IterationCount->getType(), 1);
|
||||||
|
TripCount = SCEVAddExpr::get(IterationCount, SCEVUnknown::get(OneC));
|
||||||
|
IndVar = L->getCanonicalInductionVariableIncrement();
|
||||||
|
} else {
|
||||||
|
// We have to use the preincremented value...
|
||||||
|
IndVar = L->getCanonicalInductionVariable();
|
||||||
|
}
|
||||||
|
|
||||||
// Expand the code for the iteration count into the preheader of the loop.
|
// Expand the code for the iteration count into the preheader of the loop.
|
||||||
BasicBlock *Preheader = L->getLoopPreheader();
|
BasicBlock *Preheader = L->getLoopPreheader();
|
||||||
|
Loading…
Reference in New Issue
Block a user