[llvm-commits] [llvm] r60179 - in /llvm/trunk: lib/Transforms/Scalar/JumpThreading.cpp test/Transforms/JumpThreading/2008-11-27-EntryMunge.ll

Chris Lattner sabre at nondot.org
Thu Nov 27 11:25:19 PST 2008


Author: lattner
Date: Thu Nov 27 13:25:19 2008
New Revision: 60179

URL: http://llvm.org/viewvc/llvm-project?rev=60179&view=rev
Log:
Fix PR3138: if we merge the entry block into another block, make sure to
move the other block back up into the entry position!


Added:
    llvm/trunk/test/Transforms/JumpThreading/2008-11-27-EntryMunge.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=60179&r1=60178&r2=60179&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Thu Nov 27 13:25:19 2008
@@ -165,7 +165,13 @@
   // 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;
     }
   

Added: llvm/trunk/test/Transforms/JumpThreading/2008-11-27-EntryMunge.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/2008-11-27-EntryMunge.ll?rev=60179&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/JumpThreading/2008-11-27-EntryMunge.ll (added)
+++ llvm/trunk/test/Transforms/JumpThreading/2008-11-27-EntryMunge.ll Thu Nov 27 13:25:19 2008
@@ -0,0 +1,13 @@
+; RUN: llvm-as < %s  | opt -jump-threading -simplifycfg | llvm-dis | grep {ret i32 0}
+; PR3138
+
+define i32 @jt() {
+entry:
+       br i1 true, label %bb3, label %bb
+
+bb:             ; preds = %entry
+       unreachable
+
+bb3:            ; preds = %entry
+       ret i32 0
+}





More information about the llvm-commits mailing list