[llvm-commits] [llvm] r117224 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/2010-10-24-OnlyUnwindInEntry.ll

Duncan Sands baldrick at free.fr
Sun Oct 24 05:23:30 PDT 2010


Author: baldrick
Date: Sun Oct 24 07:23:30 2010
New Revision: 117224

URL: http://llvm.org/viewvc/llvm-project?rev=117224&view=rev
Log:
Fix PR8445: a block with no predecessors may be the entry block, in which case
it isn't unreachable and should not be zapped.  The check for the entry block
was missing in one case: a block containing a unwind instruction.  While there,
do some small cleanups: "M" is not a great name for a Function* (it would be
more appropriate for a Module*), change it to "Fn"; use Fn in more places.

Added:
    llvm/trunk/test/Transforms/SimplifyCFG/2010-10-24-OnlyUnwindInEntry.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=117224&r1=117223&r2=117224&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sun Oct 24 07:23:30 2010
@@ -1720,15 +1720,14 @@
 
 bool SimplifyCFGOpt::run(BasicBlock *BB) {
   bool Changed = false;
-  Function *M = BB->getParent();
+  Function *Fn = BB->getParent();
 
-  assert(BB && BB->getParent() && "Block not embedded in function!");
+  assert(BB && Fn && "Block not embedded in function!");
   assert(BB->getTerminator() && "Degenerate basic block encountered!");
 
   // Remove basic blocks that have no predecessors (except the entry block)...
   // or that just have themself as a predecessor.  These are unreachable.
-  if ((pred_begin(BB) == pred_end(BB) &&
-       &BB->getParent()->getEntryBlock() != BB) ||
+  if ((pred_begin(BB) == pred_end(BB) && BB != &Fn->getEntryBlock()) ||
       BB->getSinglePredecessor() == BB) {
     DEBUG(dbgs() << "Removing BB: \n" << *BB);
     DeleteDeadBlock(BB);
@@ -1798,7 +1797,7 @@
         // If we eliminated all predecessors of the block, delete the block now.
         if (pred_begin(BB) == pred_end(BB))
           // We know there are no successors, so just nuke the block.
-          M->getBasicBlockList().erase(BB);
+          Fn->getBasicBlockList().erase(BB);
 
         return true;
       }
@@ -1847,10 +1846,10 @@
       Preds.pop_back();
     }
 
-    // If this block is now dead, remove it.
-    if (pred_begin(BB) == pred_end(BB)) {
+    // If this block is now dead (and isn't the entry block), remove it.
+    if (pred_begin(BB) == pred_end(BB) && BB != &Fn->getEntryBlock()) {
       // We know there are no successors, so just nuke the block.
-      M->getBasicBlockList().erase(BB);
+      Fn->getBasicBlockList().erase(BB);
       return true;
     }
 
@@ -1880,7 +1879,7 @@
       while (isa<DbgInfoIntrinsic>(BBI))
         ++BBI;
       if (BBI->isTerminator()) // Terminator is the only non-phi instruction!
-        if (BB != &BB->getParent()->getEntryBlock())
+        if (BB != &Fn->getEntryBlock())
           if (TryToSimplifyUncondBranchFromEmptyBlock(BB))
             return true;
       
@@ -2050,10 +2049,9 @@
       }
 
       // If this block is now dead, remove it.
-      if (pred_begin(BB) == pred_end(BB) &&
-          BB != &BB->getParent()->getEntryBlock()) {
+      if (pred_begin(BB) == pred_end(BB) && BB != &Fn->getEntryBlock()) {
         // We know there are no successors, so just nuke the block.
-        M->getBasicBlockList().erase(BB);
+        Fn->getBasicBlockList().erase(BB);
         return true;
       }
     }

Added: llvm/trunk/test/Transforms/SimplifyCFG/2010-10-24-OnlyUnwindInEntry.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/2010-10-24-OnlyUnwindInEntry.ll?rev=117224&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/2010-10-24-OnlyUnwindInEntry.ll (added)
+++ llvm/trunk/test/Transforms/SimplifyCFG/2010-10-24-OnlyUnwindInEntry.ll Sun Oct 24 07:23:30 2010
@@ -0,0 +1,6 @@
+; RUN: opt %s -simplifycfg -disable-output
+; PR8445
+
+define void @test() {
+      unwind
+}





More information about the llvm-commits mailing list