mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 22:28:18 +00:00
Fix PR582. The rewriter can move casts around, which invalidated the
BB iterator. This fixes Transforms/IndVarsSimplify/2005-06-15-InstMoveCrash.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22221 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -551,7 +551,7 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
|
|||||||
for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i)
|
for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i)
|
||||||
if (LI->getLoopFor(L->getBlocks()[i]) == L) { // Not in a subloop...
|
if (LI->getLoopFor(L->getBlocks()[i]) == L) { // Not in a subloop...
|
||||||
BasicBlock *BB = L->getBlocks()[i];
|
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
|
if (I->getType()->isInteger()) { // Is an integer instruction
|
||||||
SCEVHandle SH = SE->getSCEV(I);
|
SCEVHandle SH = SE->getSCEV(I);
|
||||||
if (SH->hasComputableLoopEvolution(L) || // Varies predictably
|
if (SH->hasComputableLoopEvolution(L) || // Varies predictably
|
||||||
@@ -571,6 +571,10 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
|
|||||||
if (!isa<SCEVCouldNotCompute>(ExitValue)) {
|
if (!isa<SCEVCouldNotCompute>(ExitValue)) {
|
||||||
Changed = true;
|
Changed = true;
|
||||||
++NumReplaced;
|
++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,
|
Value *NewVal = Rewriter.expandCodeFor(ExitValue, InsertPt,
|
||||||
I->getType());
|
I->getType());
|
||||||
|
|
||||||
@@ -582,10 +586,16 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
|
|||||||
// If this instruction is dead now, schedule it to be removed.
|
// If this instruction is dead now, schedule it to be removed.
|
||||||
if (I->use_empty())
|
if (I->use_empty())
|
||||||
InstructionsToDelete.insert(I);
|
InstructionsToDelete.insert(I);
|
||||||
|
I = NextI;
|
||||||
|
continue; // Skip the ++I
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next instruction. Continue instruction skips this.
|
||||||
|
++I;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteTriviallyDeadInstructions(InstructionsToDelete);
|
DeleteTriviallyDeadInstructions(InstructionsToDelete);
|
||||||
|
Reference in New Issue
Block a user