summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-28 21:38:16 +0000
committerChris Lattner <sabre@nondot.org>2002-05-28 21:38:16 +0000
commit84369b323e51ced9070659cadb15e2aacb5d0ea5 (patch)
tree49af4fa87ad5a4130a314b0b53f057d0984297de /lib
parent5454f82af22bb42a30dd4227aebae423426785fe (diff)
downloadexternal_llvm-84369b323e51ced9070659cadb15e2aacb5d0ea5.zip
external_llvm-84369b323e51ced9070659cadb15e2aacb5d0ea5.tar.gz
external_llvm-84369b323e51ced9070659cadb15e2aacb5d0ea5.tar.bz2
Avoid deleting individual instructions until AFTER dead blocks have dropped
their references. This fixes bug: test/Regression/Transforms/ADCE/2002-05-28-Crash*.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2753 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/ADCE.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp
index ffd16e1..862ec5a 100644
--- a/lib/Transforms/Scalar/ADCE.cpp
+++ b/lib/Transforms/Scalar/ADCE.cpp
@@ -264,22 +264,12 @@ bool ADCE::doADCE() {
}
}
- // Loop over all of the basic blocks in the function, removing dead
- // instructions from alive blocks, and dropping references of the dead blocks
+ // Loop over all of the basic blocks in the function, dropping references of
+ // the dead basic blocks
//
for (Function::iterator I = Func->begin(), E = Func->end(); I != E; ++I) {
BasicBlock *BB = *I;
- if (AliveBlocks.count(BB)) {
- for (BasicBlock::iterator II = BB->begin(); II != BB->end()-1; )
- if (!LiveSet.count(*II)) { // Is this instruction alive?
- // Nope... remove the instruction from it's basic block...
- delete BB->getInstList().remove(II);
- ++NumInstRemoved;
- MadeChanges = true;
- } else {
- ++II;
- }
- } else {
+ if (!AliveBlocks.count(BB)) {
// Remove all outgoing edges from this basic block and convert the
// terminator into a return instruction.
vector<BasicBlock*> Succs(succ_begin(BB), succ_end(BB));
@@ -306,15 +296,28 @@ bool ADCE::doADCE() {
}
}
- // Now loop through all of the blocks and delete them. We can safely do this
- // now because we know that there are no references to dead blocks (because
- // they have dropped all of their references...
+ // Now loop through all of the blocks and delete the dead ones. We can safely
+ // do this now because we know that there are no references to dead blocks
+ // (because they have dropped all of their references... we also remove dead
+ // instructions from alive blocks.
//
for (Function::iterator BI = Func->begin(); BI != Func->end(); )
if (!AliveBlocks.count(*BI))
delete Func->getBasicBlocks().remove(BI);
- else
+ else {
+ BasicBlock *BB = *BI;
+ for (BasicBlock::iterator II = BB->begin(); II != BB->end()-1; )
+ if (!LiveSet.count(*II)) { // Is this instruction alive?
+ // Nope... remove the instruction from it's basic block...
+ delete BB->getInstList().remove(II);
+ ++NumInstRemoved;
+ MadeChanges = true;
+ } else {
+ ++II;
+ }
+
++BI; // Increment iterator...
+ }
return MadeChanges;
}