Implement SimplifyCFG/BrUnwind.ll
authorChris Lattner <sabre@nondot.org>
Tue, 20 Jul 2004 01:17:38 +0000 (01:17 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 20 Jul 2004 01:17:38 +0000 (01:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15022 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp

index cc28e54c37469083c35fe71520d64c9a6fad654c..2cf4ab9cded8ca5e8db6655489c46e5c7c2f4f34 100644 (file)
@@ -764,12 +764,19 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
   } else if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->begin())) {
     // Check to see if the first instruction in this block is just an unwind.
     // If so, replace any invoke instructions which use this as an exception
-    // destination with call instructions.
+    // destination with call instructions, and any unconditional branch
+    // predecessor with an unwind.
     //
     std::vector<BasicBlock*> Preds(pred_begin(BB), pred_end(BB));
     while (!Preds.empty()) {
       BasicBlock *Pred = Preds.back();
-      if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
+      if (BranchInst *BI = dyn_cast<BranchInst>(Pred->getTerminator())) {
+        if (BI->isUnconditional()) {
+          Pred->getInstList().pop_back();  // nuke uncond branch
+          new UnwindInst(Pred);            // Use unwind.
+          Changed = true;
+        }
+      } 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...