diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-04-15 20:26:22 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-04-15 20:26:22 +0000 | 
| commit | d7a559e353a2ba5b8f51573f96ce3f06ad34f4cb (patch) | |
| tree | 1e484a65833cf493e70f4420dd2a52a872cee4ad /llvm/lib/Transforms | |
| parent | 5bee0f3068f6020f848dc3ca24ec184e125b953e (diff) | |
| download | bcm5719-llvm-d7a559e353a2ba5b8f51573f96ce3f06ad34f4cb.tar.gz bcm5719-llvm-d7a559e353a2ba5b8f51573f96ce3f06ad34f4cb.zip | |
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.
llvm-svn: 12968
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 30 | 
1 files changed, 23 insertions, 7 deletions
| diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 728e20e0cff..8462945a742 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -209,13 +209,29 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L, SCEV *IterationCount,    if (Instruction *Cond = dyn_cast<Instruction>(BI->getCondition()))      InstructionsToDelete.insert(Cond); -  // 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); -  SCEVHandle TripCount=SCEVAddExpr::get(IterationCount, SCEVUnknown::get(OneC)); - -  Value *IndVar = L->getCanonicalInductionVariableIncrement(); +  // If the exiting block is not the same as the backedge block, we must compare +  // against the preincremented value, otherwise we prefer to compare against +  // the post-incremented value. +  BasicBlock *Header = L->getHeader(); +  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?"); + +  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.    BasicBlock *Preheader = L->getLoopPreheader(); | 

