summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-06-15 21:29:31 +0000
committerChris Lattner <sabre@nondot.org>2005-06-15 21:29:31 +0000
commitdf81539278b238151e5b0b48290acdd7776d1aea (patch)
tree98438f8b02603e1fa0dafd7bf138fd77a355ded5 /llvm/lib/Transforms
parent478158a4c55ab890ed2fca763521ec26c869c304 (diff)
downloadbcm5719-llvm-df81539278b238151e5b0b48290acdd7776d1aea.tar.gz
bcm5719-llvm-df81539278b238151e5b0b48290acdd7776d1aea.zip
Fix PR582. The rewriter can move casts around, which invalidated the
BB iterator. This fixes Transforms/IndVarsSimplify/2005-06-15-InstMoveCrash.ll llvm-svn: 22221
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/IndVarSimplify.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 88ad6d206af..5b7e4e1fd9e 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -551,7 +551,7 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
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 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
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 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
// 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);
OpenPOWER on IntegriCloud