summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-21 19:52:49 +0000
committerChris Lattner <sabre@nondot.org>2002-05-21 19:52:49 +0000
commit87a09b10f8e03182e9edcb6e9ee8386f4a5d8dae (patch)
treeda27372cee70dfc4b6e23082f3dc735b047632b2 /lib
parent4a4e39d647d4eb451be15ab2b7d3279e26bb94d7 (diff)
downloadexternal_llvm-87a09b10f8e03182e9edcb6e9ee8386f4a5d8dae.zip
external_llvm-87a09b10f8e03182e9edcb6e9ee8386f4a5d8dae.tar.gz
external_llvm-87a09b10f8e03182e9edcb6e9ee8386f4a5d8dae.tar.bz2
Fix bug: test/Regression/Transforms/CFGSimplify/2002-05-21-PHIElimination.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2694 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/BasicBlock.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index a3fdb28..9a6301e 100644
--- a/lib/VMCore/BasicBlock.cpp
+++ b/lib/VMCore/BasicBlock.cpp
@@ -100,8 +100,26 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
for (max_idx = 0; PI != EI && max_idx < 3; ++PI, ++max_idx) /*empty*/;
// If there are exactly two predecessors, then we want to nuke the PHI nodes
- // altogether.
+ // altogether. We cannot do this, however if this in this case however:
+ //
+ // Loop:
+ // %x = phi [X, Loop]
+ // %x2 = add %x, 1 ;; This would become %x2 = add %x2, 1
+ // br Loop ;; %x2 does not dominate all uses
+ //
+ // This is because the PHI node input is actually taken from the predecessor
+ // basic block. The only case this can happen is with a self loop, so we
+ // check for this case explicitly now.
+ //
assert(max_idx != 0 && "PHI Node in block with 0 predecessors!?!?!");
+ if (max_idx == 2) {
+ PI = pred_begin(this);
+ BasicBlock *Other = *PI == Pred ? *++PI : *PI;
+
+ // Disable PHI elimination!
+ if (this == Other) max_idx = 3;
+ }
+
if (max_idx <= 2) { // <= Two predecessors BEFORE I remove one?
// Yup, loop through and nuke the PHI nodes
while (PHINode *PN = dyn_cast<PHINode>(front())) {
@@ -118,9 +136,8 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
} else {
// Okay, now we know that we need to remove predecessor #pred_idx from all
// PHI nodes. Iterate over each PHI node fixing them up
- iterator II(begin());
- for (; isa<PHINode>(*II); ++II)
- cast<PHINode>(*II)->removeIncomingValue(Pred);
+ for (iterator II = begin(); PHINode *PN = dyn_cast<PHINode>(*II); ++II)
+ PN->removeIncomingValue(Pred);
}
}