summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2013-10-19 11:27:12 +0000
committerBill Wendling <isanbard@gmail.com>2013-10-19 11:27:12 +0000
commitd5b7f2b62cdb3a14162c57e27c06a27dda9a78c4 (patch)
tree0bd1a02066e426eebb49c415b1d758b3a4f1d832 /lib/Transforms/Utils
parent4805bf59b9e41a95336c066ec58194ff6801694a (diff)
downloadllvm-d5b7f2b62cdb3a14162c57e27c06a27dda9a78c4.tar.gz
llvm-d5b7f2b62cdb3a14162c57e27c06a27dda9a78c4.tar.bz2
llvm-d5b7f2b62cdb3a14162c57e27c06a27dda9a78c4.tar.xz
Perform an intelligent splice of the predecessor with the single successor.
If the predecessor's being spliced into a landing pad, then we need the PHIs to come first and the rest of the predecessor's code to come *after* the landing pad instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193035 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r--lib/Transforms/Utils/Local.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 82b8da3a10..78217c8efa 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -503,7 +503,19 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB, Pass *P) {
// Splice all the instructions from PredBB to DestBB.
PredBB->getTerminator()->eraseFromParent();
- DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList());
+
+ // First splice over the PHI nodes.
+ BasicBlock::iterator PI = PredBB->begin();
+ while (isa<PHINode>(PI))
+ ++PI;
+
+ if (PI != PredBB->begin())
+ DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList(),
+ PredBB->begin(), PI);
+
+ // Now splice over the rest of the instructions.
+ DestBB->getInstList().splice(DestBB->getFirstInsertionPt(),
+ PredBB->getInstList(), PI, PredBB->end());
if (P) {
DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>();
@@ -513,6 +525,7 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB, Pass *P) {
DT->eraseNode(PredBB);
}
}
+
// Nuke BB.
PredBB->eraseFromParent();
}