diff options
author | Chris Lattner <sabre@nondot.org> | 2003-01-23 02:12:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-01-23 02:12:18 +0000 |
commit | 6fa1629c47daa770ca0bd161519b0789e425c29a (patch) | |
tree | 4017f9a6cf015879ac8833bc17483a43dbac7d00 /llvm/lib/Transforms | |
parent | 924a162072e7ae914865249dd7940c2bf02b2c79 (diff) | |
download | bcm5719-llvm-6fa1629c47daa770ca0bd161519b0789e425c29a.tar.gz bcm5719-llvm-6fa1629c47daa770ca0bd161519b0789e425c29a.zip |
Fix bug: ADCE/2003-01-22-PredecessorProblem.ll
llvm-svn: 5405
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/ADCE.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/ADCE.cpp b/llvm/lib/Transforms/Scalar/ADCE.cpp index e2e9e86216c..24ccee60344 100644 --- a/llvm/lib/Transforms/Scalar/ADCE.cpp +++ b/llvm/lib/Transforms/Scalar/ADCE.cpp @@ -331,10 +331,17 @@ bool ADCE::doADCE() { } } - // Loop over all of the basic blocks in the function, dropping references of - // the dead basic blocks + // We make changes if there are any dead blocks in the function... + if (unsigned NumDeadBlocks = Func->size() - AliveBlocks.size()) { + MadeChanges = true; + NumBlockRemoved += NumDeadBlocks; + } + + // Loop over all of the basic blocks in the function, removing control flow + // edges to live blocks (also eliminating any entries in PHI functions in + // referenced blocks). // - for (Function::iterator BB = Func->begin(), E = Func->end(); BB != E; ++BB) { + for (Function::iterator BB = Func->begin(), E = Func->end(); BB != E; ++BB) if (!AliveBlocks.count(BB)) { // Remove all outgoing edges from this basic block and convert the // terminator into a return instruction. @@ -354,12 +361,16 @@ bool ADCE::doADCE() { BB->getInstList().push_back(new ReturnInst(RetTy != Type::VoidTy ? Constant::getNullValue(RetTy) : 0)); } + } + + // Loop over all of the basic blocks in the function, dropping references of + // the dead basic blocks. We must do this after the previous step to avoid + // dropping references to PHIs which still have entries... + // + for (Function::iterator BB = Func->begin(), E = Func->end(); BB != E; ++BB) + if (!AliveBlocks.count(BB)) BB->dropAllReferences(); - ++NumBlockRemoved; - MadeChanges = true; - } - } // 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 |