[llvm-commits] [llvm] r48099 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/unwindto.ll

Nick Lewycky nicholas at mxc.ca
Sat Mar 8 23:50:37 PST 2008


Author: nicholas
Date: Sun Mar  9 01:50:37 2008
New Revision: 48099

URL: http://llvm.org/viewvc/llvm-project?rev=48099&view=rev
Log:
Firstly, having a BranchInst isn't exclusive with having an unwind_to.
Secondly, we have to check whether the branch is actually pointing to the block
with the unwind in it. We could have gotten here because of the unwind_to alone.

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/trunk/test/Transforms/SimplifyCFG/unwindto.ll

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=48099&r1=48098&r2=48099&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sun Mar  9 01:50:37 2008
@@ -1364,13 +1364,19 @@
     SmallVector<BasicBlock*, 8> Preds(pred_begin(BB), pred_end(BB));
     while (!Preds.empty()) {
       BasicBlock *Pred = Preds.back();
+
+      if (Pred->getUnwindDest() == BB) {
+        Pred->setUnwindDest(NULL);
+        Changed = true;
+      }
+
       if (BranchInst *BI = dyn_cast<BranchInst>(Pred->getTerminator())) {
-        if (BI->isUnconditional()) {
+        if (BI->isUnconditional() && BI->getSuccessor(0) == BB) {
           Pred->getInstList().pop_back();  // nuke uncond branch
           new UnwindInst(Pred);            // Use unwind.
           Changed = true;
         }
-      } else if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator())) {
+      } else if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
         if (II->getUnwindDest() == BB) {
           // Insert a new branch instruction before the invoke, because this
           // is now a fall through...
@@ -1388,9 +1394,6 @@
           delete II;
           Changed = true;
         }
-      } else if (Pred->getUnwindDest() == BB) {
-        Pred->setUnwindDest(NULL);
-      }
 
       Preds.pop_back();
     }

Modified: llvm/trunk/test/Transforms/SimplifyCFG/unwindto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/unwindto.ll?rev=48099&r1=48098&r2=48099&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/unwindto.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/unwindto.ll Sun Mar  9 01:50:37 2008
@@ -41,3 +41,21 @@
 cleanup:
   unwind
 }
+
+define i32 @f4() {
+entry: unwind_to %cleanup
+  call void @g(i32 0)
+  br label %cleanup
+cleanup:
+  unwind
+}
+
+define i32 @f5() {
+entry: unwind_to %cleanup
+  call void @g(i32 0)
+  br label %other
+other:
+  ret i32 0
+cleanup:
+  unwind
+}





More information about the llvm-commits mailing list