aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/CodeGenPrepare.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp
index caf60c8c7a..9bf39911b6 100644
--- a/lib/Transforms/Scalar/CodeGenPrepare.cpp
+++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp
@@ -204,8 +204,15 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) {
// If the destination block has a single pred, then this is a trivial edge,
// just collapse it.
- if (DestBB->getSinglePredecessor()) {
+ if (BasicBlock *SinglePred = DestBB->getSinglePredecessor()) {
+ // Remember if SinglePred was the entry block of the function. If so, we
+ // will need to move BB back to the entry position.
+ bool isEntry = SinglePred == &SinglePred->getParent()->getEntryBlock();
MergeBasicBlockIntoOnlyPred(DestBB);
+
+ if (isEntry && BB != &BB->getParent()->getEntryBlock())
+ BB->moveBefore(&BB->getParent()->getEntryBlock());
+
DOUT << "AFTER:\n" << *DestBB << "\n\n\n";
return;
}