aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-01-23 02:12:18 +0000
committerChris Lattner <sabre@nondot.org>2003-01-23 02:12:18 +0000
commitd7f268d4189c2945f4752e21e6f4c91d5d814649 (patch)
treeb16ffde56046902c90c903a1847bc06677a0df75 /lib/Transforms
parent56b6db8eb0ec30b074ac267a95829ec9e18e42f7 (diff)
Fix bug: ADCE/2003-01-22-PredecessorProblem.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5405 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/ADCE.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp
index e2e9e86216..24ccee6034 100644
--- a/lib/Transforms/Scalar/ADCE.cpp
+++ b/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