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 | 4059f43b744b88592a5a80add99e3f33954ec96e (patch) | |
| tree | cb690f6b9c8db05daf5a8203e757e5e41360938a /llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp | |
| parent | 5dfbfcd80d3a41fb6017914a8d5cb85a205d1884 (diff) | |
| download | bcm5719-llvm-4059f43b744b88592a5a80add99e3f33954ec96e.tar.gz bcm5719-llvm-4059f43b744b88592a5a80add99e3f33954ec96e.zip | |
defensive patch: if CGP is merging a block with the entry block, make sure
it ends up being the entry block.
llvm-svn: 60180
Diffstat (limited to 'llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp b/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp index caf60c8c7af..9bf39911b6c 100644 --- a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/llvm/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; } |

