aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-12-03 18:25:58 +0000
committerChris Lattner <sabre@nondot.org>2005-12-03 18:25:58 +0000
commit8e75ee212f95861138f813d095d581828ca111cb (patch)
tree88159226f933135386a272b4eeb0ee04b98e9aa8 /lib/Transforms/Utils/SimplifyCFG.cpp
parent9e6924fc0f9cc866161bd88fa06c3d85e5628afa (diff)
Fix SimplifyCFG/2005-12-03-IncorrectPHIFold.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24581 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 6b5914365b..da8541659b 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -82,7 +82,7 @@ static bool CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
//
if (isa<PHINode>(Succ->front())) {
std::set<BasicBlock*> BBPreds(pred_begin(BB), pred_end(BB));
- for (pred_iterator PI = pred_begin(Succ), PE = pred_end(Succ);\
+ for (pred_iterator PI = pred_begin(Succ), PE = pred_end(Succ);
PI != PE; ++PI)
if (std::find(BBPreds.begin(), BBPreds.end(), *PI) != BBPreds.end()) {
// Loop over all of the PHI nodes checking to see if there are
@@ -115,19 +115,25 @@ static bool CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
}
if (IsSafe) return true;
- // If the PHI nodes in BB are only used by instructions in Succ, we are ok.
- IsSafe = true;
+ // If the PHI nodes in BB are only used by instructions in Succ, we are ok if
+ // BB and Succ have no common predecessors.
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;
- }
+ if (cast<Instruction>(*UI)->getParent() != Succ)
+ return false;
}
- return IsSafe;
+ // Scan the predecessor sets of BB and Succ, making sure there are no common
+ // predecessors. Common predecessors would cause us to build a phi node with
+ // differing incoming values, which is not legal.
+ std::set<BasicBlock*> BBPreds(pred_begin(BB), pred_end(BB));
+ for (pred_iterator PI = pred_begin(Succ), E = pred_end(Succ); PI != E; ++PI)
+ if (BBPreds.count(*PI))
+ return false;
+
+ return true;
}
/// TryToSimplifyUncondBranchFromEmptyBlock - BB contains an unconditional