[llvm-commits] CVS: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Jun 15 14:29:47 PDT 2005
Changes in directory llvm/lib/Transforms/Scalar:
IndVarSimplify.cpp updated: 1.77 -> 1.78
---
Log message:
Fix PR582: http://llvm.cs.uiuc.edu/PR582 . The rewriter can move casts around, which invalidated the
BB iterator. This fixes Transforms/IndVarsSimplify/2005-06-15-InstMoveCrash.ll
---
Diffs of the changes: (+11 -1)
IndVarSimplify.cpp | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletion(-)
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.77 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.78
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.77 Thu Apr 21 18:45:12 2005
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp Wed Jun 15 16:29:31 2005
@@ -551,7 +551,7 @@
for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i)
if (LI->getLoopFor(L->getBlocks()[i]) == L) { // Not in a subloop...
BasicBlock *BB = L->getBlocks()[i];
- for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
if (I->getType()->isInteger()) { // Is an integer instruction
SCEVHandle SH = SE->getSCEV(I);
if (SH->hasComputableLoopEvolution(L) || // Varies predictably
@@ -571,6 +571,10 @@
if (!isa<SCEVCouldNotCompute>(ExitValue)) {
Changed = true;
++NumReplaced;
+ // Remember the next instruction. The rewriter can move code
+ // around in some cases.
+ BasicBlock::iterator NextI = I; ++NextI;
+
Value *NewVal = Rewriter.expandCodeFor(ExitValue, InsertPt,
I->getType());
@@ -582,10 +586,16 @@
// If this instruction is dead now, schedule it to be removed.
if (I->use_empty())
InstructionsToDelete.insert(I);
+ I = NextI;
+ continue; // Skip the ++I
}
}
}
}
+
+ // Next instruction. Continue instruction skips this.
+ ++I;
+ }
}
DeleteTriviallyDeadInstructions(InstructionsToDelete);
More information about the llvm-commits
mailing list