Fix PR3138: if we merge the entry block into another block, make sure to
[oota-llvm.git] / lib / Transforms / Scalar / JumpThreading.cpp
index ec35a891e05f9b3f124ee70253f84c78b567eb66..5de5fb3b776d18515f48d80b3cbcff29fe3f4ce8 100644 (file)
@@ -165,7 +165,13 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) {
   // predecessors of our predecessor block.
   if (BasicBlock *SinglePred = BB->getSinglePredecessor())
     if (SinglePred->getTerminator()->getNumSuccessors() == 1) {
+      // 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(BB);
+      
+      if (isEntry && BB != &BB->getParent()->getEntryBlock())
+        BB->moveBefore(&BB->getParent()->getEntryBlock());
       return true;
     }