From d5b7f2b62cdb3a14162c57e27c06a27dda9a78c4 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 19 Oct 2013 11:27:12 +0000 Subject: 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 --- lib/Transforms/Utils/Local.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib/Transforms') diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 82b8da3..78217c8 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(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(); @@ -513,6 +525,7 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB, Pass *P) { DT->eraseNode(PredBB); } } + // Nuke BB. PredBB->eraseFromParent(); } -- cgit v1.1