aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-08-03 00:59:12 +0000
committerChris Lattner <sabre@nondot.org>2005-08-03 00:59:12 +0000
commit1aad921c18edbc17fdc7167b6081ba49c4ea39f9 (patch)
tree70f03cc591feeae6c9e3f47adcbc05bf5ba7e809 /lib/Transforms/Utils/SimplifyCFG.cpp
parent969c88e817246ba7d8f3b77363ec40d8d16fa4f6 (diff)
Finally, add the required constraint checks to fix Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll
the right way git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22615 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 5f368bc786..742efe6184 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -98,8 +98,35 @@ static bool CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
}
}
}
-
- return true;
+
+ // Finally, if BB has PHI nodes that are used by things other than the PHIs in
+ // Succ and Succ has predecessors that are not Succ and not Pred, we cannot
+ // fold these blocks, as we don't know whether BB dominates Succ or not to
+ // update the PHI nodes correctly.
+ if (!isa<PHINode>(BB->begin()) || Succ->getSinglePredecessor()) return true;
+
+ // If the predecessors of Succ are only BB and Succ itself, we can handle this.
+ bool IsSafe = true;
+ for (pred_iterator PI = pred_begin(Succ), E = pred_end(Succ); PI != E; ++PI)
+ if (*PI != Succ && *PI != BB) {
+ IsSafe = false;
+ break;
+ }
+ if (IsSafe) return true;
+
+ // If the PHI nodes in BB are only used by instructions in Succ, we are ok.
+ IsSafe = true;
+ for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I) && IsSafe; ++I) {
+ PHINode *PN = cast<PHINode>(I);
+ for (Value::use_iterator UI = PN->use_begin(), E = PN->use_end(); UI != E;
+ ++UI)
+ if (cast<Instruction>(*UI)->getParent() != Succ) {
+ IsSafe = false;
+ break;
+ }
+ }
+
+ return IsSafe;
}
/// TryToSimplifyUncondBranchFromEmptyBlock - BB contains an unconditional