summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-07-06 06:36:11 +0000
committerChris Lattner <sabre@nondot.org>2004-07-06 06:36:11 +0000
commit520df8464bd0e2d54b2189705596be86e8069aef (patch)
tree8cd9a3235db3c0a2e5840ffa0069c3941fd1dfd1 /llvm
parent987e503e2e6a07b6a4f69b90c1ef76db781f8c8c (diff)
downloadbcm5719-llvm-520df8464bd0e2d54b2189705596be86e8069aef.tar.gz
bcm5719-llvm-520df8464bd0e2d54b2189705596be86e8069aef.zip
Fix a bug in the unreachable block elim pass. Dropping all references on a
basic block clear()'s all of the operands lists, including phis. This caused removePredecessor to get confused later. Because of this, we just nuke (without prejudice) PHI nodes in unreachable blocks. llvm-svn: 14635
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/CodeGen/UnreachableBlockElim.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/UnreachableBlockElim.cpp b/llvm/lib/CodeGen/UnreachableBlockElim.cpp
index bcc124538d3..1b59ac4a666 100644
--- a/llvm/lib/CodeGen/UnreachableBlockElim.cpp
+++ b/llvm/lib/CodeGen/UnreachableBlockElim.cpp
@@ -21,6 +21,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/Passes.h"
+#include "llvm/iPHINode.h"
+#include "llvm/Constant.h"
#include "llvm/Function.h"
#include "llvm/Pass.h"
#include "llvm/Support/CFG.h"
@@ -52,10 +54,15 @@ bool UnreachableBlockElim::runOnFunction(Function &F) {
std::vector<BasicBlock*> DeadBlocks;
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
if (!Reachable.count(I)) {
- DeadBlocks.push_back(I);
- for (succ_iterator SI = succ_begin(&*I), E = succ_end(&*I); SI != E; ++SI)
- (*SI)->removePredecessor(I);
- I->dropAllReferences();
+ BasicBlock *BB = I;
+ DeadBlocks.push_back(BB);
+ while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
+ PN->replaceAllUsesWith(Constant::getNullValue(PN->getType()));
+ BB->getInstList().pop_front();
+ }
+ for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)
+ (*SI)->removePredecessor(BB);
+ BB->dropAllReferences();
}
if (DeadBlocks.empty()) return false;
OpenPOWER on IntegriCloud