From 4fea22c63b5300fd1499bd6e8c445a9579c0d287 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. llvm-svn: 193035 --- llvm/lib/Transforms/Utils/Local.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 82b8da3a107..78217c8efa3 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/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.2.3