[llvm-commits] [llvm] r60180 - /llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
Chris Lattner
sabre at nondot.org
Thu Nov 27 11:29:14 PST 2008
Author: lattner
Date: Thu Nov 27 13:29:14 2008
New Revision: 60180
URL: http://llvm.org/viewvc/llvm-project?rev=60180&view=rev
Log:
defensive patch: if CGP is merging a block with the entry block, make sure
it ends up being the entry block.
Modified:
llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=60180&r1=60179&r2=60180&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Thu Nov 27 13:29:14 2008
@@ -204,8 +204,15 @@
// 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;
}
More information about the llvm-commits
mailing list