summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-08-02 03:24:05 +0000
committerChris Lattner <sabre@nondot.org>2005-08-02 03:24:05 +0000
commit1593ac259db20a5ed71b241c5e9c2796f5d34044 (patch)
tree4b4bcab3858ea1cfeb6faacc91250a683808f784 /lib/Transforms/Utils/SimplifyCFG.cpp
parent1bc0f735c935c286bfdfa2eaa482a54a29007398 (diff)
downloadllvm-1593ac259db20a5ed71b241c5e9c2796f5d34044.tar.gz
llvm-1593ac259db20a5ed71b241c5e9c2796f5d34044.tar.bz2
llvm-1593ac259db20a5ed71b241c5e9c2796f5d34044.tar.xz
This code was very close, but not quite right. It did not take into
consideration the case where a reference in an unreachable block could occur. This fixes Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll, something I ran into while bugpoint'ing another pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22584 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 6a3b803cbd..c060127e2c 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -894,9 +894,16 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
// Move all PHI nodes in BB to Succ if they are alive, otherwise
// delete them.
while (PHINode *PN = dyn_cast<PHINode>(&BB->front()))
- if (PN->use_empty())
- BB->getInstList().erase(BB->begin()); // Nuke instruction.
- else {
+ if (PN->use_empty() || Succ->getSinglePredecessor() == 0) {
+ // We can only move the PHI node into Succ if BB dominates Succ.
+ // Since BB only has a single successor (Succ), the PHI nodes
+ // will dominate Succ, unless Succ has multiple predecessors. In
+ // this case, the PHIs are either dead, or have references in dead
+ // blocks. In either case, we can just remove them.
+ if (!PN->use_empty()) // Uses in dead block?
+ PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
+ PN->eraseFromParent(); // Nuke instruction.
+ } else {
// The instruction is alive, so this means that Succ must have
// *ONLY* had BB as a predecessor, and the PHI node is still valid
// now. Simply move it into Succ, because we know that BB