diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-27 19:29:14 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-27 19:29:14 +0000 |
commit | 9918fb5631974f2201a640384b7ebe672c749e43 (patch) | |
tree | 3699563820d30ccf9b3f6c8eb8b5de5c3cb014c2 /lib/Transforms | |
parent | 3d86d242c69a26ba2e6102f32b00b04884c4c9b1 (diff) |
defensive patch: if CGP is merging a block with the entry block, make sure
it ends up being the entry block.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60180 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/CodeGenPrepare.cpp | 9 |
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; } |