change simplifycfg to not duplicate 'unwind' instructions. Hopefully
authorChris Lattner <sabre@nondot.org>
Tue, 13 Oct 2009 18:13:05 +0000 (18:13 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 13 Oct 2009 18:13:05 +0000 (18:13 +0000)
this will increase the likelihood of common code getting sunk towards
the unwind.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83996 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/invoke_unwind.ll

index 92b1335843d2aa9381a0a4f445686fc3538f1e78..6fd7d7bf9aeae2f6f682ff48b2f92f90aae04dcb 100644 (file)
@@ -1860,33 +1860,26 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
   } else if (isa<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, and any unconditional branch
-    // predecessor with an unwind.
+    // destination with call instructions.
     //
     SmallVector<BasicBlock*, 8> Preds(pred_begin(BB), pred_end(BB));
     while (!Preds.empty()) {
       BasicBlock *Pred = Preds.back();
-      if (BranchInst *BI = dyn_cast<BranchInst>(Pred->getTerminator())) {
-        if (BI->isUnconditional()) {
-          Pred->getInstList().pop_back();  // nuke uncond branch
-          new UnwindInst(Pred->getContext(), Pred);            // Use unwind.
-          Changed = true;
-        }
-      } else if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
+      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...
+          // is now a fall through.
           BranchInst *BI = BranchInst::Create(II->getNormalDest(), II);
           Pred->getInstList().remove(II);   // Take out of symbol table
 
-          // Insert the call now...
+          // Insert the call now.
           SmallVector<Value*,8> Args(II->op_begin()+3, II->op_end());
           CallInst *CI = CallInst::Create(II->getCalledValue(),
                                           Args.begin(), Args.end(),
                                           II->getName(), BI);
           CI->setCallingConv(II->getCallingConv());
           CI->setAttributes(II->getAttributes());
-          // If the invoke produced a value, the Call now does instead
+          // If the invoke produced a value, the Call now does instead.
           II->replaceAllUsesWith(CI);
           delete II;
           Changed = true;
index da6e3db2f8acf4b5370263798e011e575a22fa56..bbd779beb489d3f55b0f052e29608a8ef4c6d61e 100644 (file)
@@ -1,10 +1,9 @@
-; This testcase checks to see if the simplifycfg pass is converting invoke
-; instructions to call instructions if the handler just rethrows the exception.
-
 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
 
 declare void @bar()
 
+; This testcase checks to see if the simplifycfg pass is converting invoke
+; instructions to call instructions if the handler just rethrows the exception.
 define i32 @test1() {
 ; CHECK: @test1
 ; CHECK-NEXT: call void @bar()
@@ -16,3 +15,19 @@ Ok:             ; preds = %0
 Rethrow:                ; preds = %0
         unwind
 }
+
+
+; Verify that simplifycfg isn't duplicating 'unwind' instructions.  Doing this
+; is bad because it discourages commoning.
+define i32 @test2(i1 %c) {
+; CHECK: @test2
+; CHECK: T:
+; CHECK-NEXT: call void @bar()
+; CHECK-NEXT: br label %F
+  br i1 %c, label %T, label %F
+T:
+  call void @bar()
+  br label %F
+F:
+  unwind
+}