summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-03-07 18:13:41 +0000
committerChris Lattner <sabre@nondot.org>2003-03-07 18:13:41 +0000
commit569a57f9ff15c00e3eac9b302635cf722d13f723 (patch)
treecde21c1487039cdc8f74c1e863690bcfe9d952b4 /llvm/lib/Transforms
parent587cc42836c1ae0a0b3a374e395faae83b7b6ab8 (diff)
downloadbcm5719-llvm-569a57f9ff15c00e3eac9b302635cf722d13f723.tar.gz
bcm5719-llvm-569a57f9ff15c00e3eac9b302635cf722d13f723.zip
Fix bug: SimplifyCFG/2003-03-07-DominateProblem.ll
llvm-svn: 5722
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 3b658aacb40..25d835684b2 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -141,9 +141,11 @@ bool SimplifyCFG(BasicBlock *BB) {
//
if (!PropagatePredecessorsForPHIs(BB, Succ)) {
//cerr << "Killing Trivial BB: \n" << BB;
- BB->replaceAllUsesWith(Succ);
std::string OldName = BB->getName();
+ std::vector<BasicBlock*>
+ OldSuccPreds(pred_begin(Succ), pred_end(Succ));
+
// Move all PHI nodes in BB to Succ if they are alive, otherwise
// delete them.
while (PHINode *PN = dyn_cast<PHINode>(&BB->front()))
@@ -152,11 +154,26 @@ bool SimplifyCFG(BasicBlock *BB) {
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.
+ // now. Simply move it into Succ, because we know that BB
+ // strictly dominated Succ.
BB->getInstList().remove(BB->begin());
Succ->getInstList().push_front(PN);
+
+ // We need to add new entries for the PHI node to account for
+ // predecessors of Succ that the PHI node does not take into
+ // account. At this point, since we know that BB dominated succ,
+ // this means that we should any newly added incoming edges should
+ // use the PHI node as the value for these edges, because they are
+ // loop back edges.
+
+ for (unsigned i = 0, e = OldSuccPreds.size(); i != e; ++i)
+ if (OldSuccPreds[i] != BB)
+ PN->addIncoming(PN, OldSuccPreds[i]);
}
+ // Everything that jumped to BB now goes to Succ...
+ BB->replaceAllUsesWith(Succ);
+
// Delete the old basic block...
M->getBasicBlockList().erase(BB);
OpenPOWER on IntegriCloud