[llvm] r374703 - [Attributor][FIX] Avoid splitting blocks if possible

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 12 22:27:09 PDT 2019


Author: jdoerfert
Date: Sat Oct 12 22:27:09 2019
New Revision: 374703

URL: http://llvm.org/viewvc/llvm-project?rev=374703&view=rev
Log:
[Attributor][FIX] Avoid splitting blocks if possible

Before, we eagerly split blocks even if it was not necessary, e.g., they
had a single unreachable instruction and only a single predecessor.

Modified:
    llvm/trunk/lib/Transforms/IPO/Attributor.cpp
    llvm/trunk/test/Transforms/FunctionAttrs/liveness.ll
    llvm/trunk/test/Transforms/FunctionAttrs/noreturn_async.ll
    llvm/trunk/test/Transforms/FunctionAttrs/noreturn_sync.ll

Modified: llvm/trunk/lib/Transforms/IPO/Attributor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Attributor.cpp?rev=374703&r1=374702&r2=374703&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Attributor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Attributor.cpp Sat Oct 12 22:27:09 2019
@@ -2139,8 +2139,6 @@ struct AAIsDeadImpl : public AAIsDead {
       BasicBlock *BB = I->getParent();
       Instruction *SplitPos = I->getNextNode();
       // TODO: mark stuff before unreachable instructions as dead.
-      if (isa_and_nonnull<UnreachableInst>(SplitPos))
-        continue;
 
       if (auto *II = dyn_cast<InvokeInst>(I)) {
         // If we keep the invoke the split position is at the beginning of the
@@ -2183,15 +2181,23 @@ struct AAIsDeadImpl : public AAIsDead {
           //       also manifest.
           assert(!NormalDestBB->isLandingPad() &&
                  "Expected the normal destination not to be a landingpad!");
-          BasicBlock *SplitBB =
-              SplitBlockPredecessors(NormalDestBB, {BB}, ".dead");
-          // The split block is live even if it contains only an unreachable
-          // instruction at the end.
-          assumeLive(A, *SplitBB);
-          SplitPos = SplitBB->getTerminator();
+          if (NormalDestBB->getUniquePredecessor() == BB) {
+            assumeLive(A, *NormalDestBB);
+          } else {
+            BasicBlock *SplitBB =
+                SplitBlockPredecessors(NormalDestBB, {BB}, ".dead");
+            // The split block is live even if it contains only an unreachable
+            // instruction at the end.
+            assumeLive(A, *SplitBB);
+            SplitPos = SplitBB->getTerminator();
+            HasChanged = ChangeStatus::CHANGED;
+          }
         }
       }
 
+      if (isa_and_nonnull<UnreachableInst>(SplitPos))
+        continue;
+
       BB = SplitPos->getParent();
       SplitBlock(BB, SplitPos);
       changeToUnreachable(BB->getTerminator(), /* UseLLVMTrap */ false);

Modified: llvm/trunk/test/Transforms/FunctionAttrs/liveness.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/liveness.ll?rev=374703&r1=374702&r2=374703&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/liveness.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/liveness.ll Sat Oct 12 22:27:09 2019
@@ -177,7 +177,7 @@ cond.true:
   %call = invoke i32 @foo_noreturn() to label %continue
             unwind label %cleanup
   ; CHECK:      %call = invoke i32 @foo_noreturn()
-  ; CHECK-NEXT:         to label %continue.dead unwind label %cleanup
+  ; CHECK-NEXT:         to label %continue unwind label %cleanup
 
 cond.false:                                       ; preds = %entry
   call void @normal_call()
@@ -189,7 +189,7 @@ cond.end:
   ret i32 %cond
 
 continue:
-  ; CHECK:      continue.dead:
+  ; CHECK:      continue:
   ; CHECK-NEXT: unreachable
   br label %cond.end
 

Modified: llvm/trunk/test/Transforms/FunctionAttrs/noreturn_async.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/noreturn_async.ll?rev=374703&r1=374702&r2=374703&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/noreturn_async.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/noreturn_async.ll Sat Oct 12 22:27:09 2019
@@ -42,12 +42,12 @@ entry:
   %retval = alloca i32, align 4
   %__exception_code = alloca i32, align 4
 ; CHECK: invoke void @"?overflow@@YAXXZ"()
-; CHECK:          to label %invoke.cont.dead unwind label %catch.dispatch
+; CHECK:          to label %invoke.cont unwind label %catch.dispatch
   invoke void @"?overflow@@YAXXZ"()
           to label %invoke.cont unwind label %catch.dispatch
 
 invoke.cont:                                      ; preds = %entry
-; CHECK:      invoke.cont.dead:
+; CHECK:      invoke.cont:
 ; CHECK-NEXT: unreachable
   br label %invoke.cont1
 
@@ -101,12 +101,12 @@ entry:
   %retval = alloca i32, align 4
   %__exception_code = alloca i32, align 4
 ; CHECK: invoke void @"?overflow@@YAXXZ_may_throw"() 
-; CHECK:          to label %invoke.cont.dead unwind label %catch.dispatch
+; CHECK:          to label %invoke.cont unwind label %catch.dispatch
   invoke void @"?overflow@@YAXXZ_may_throw"() 
           to label %invoke.cont unwind label %catch.dispatch
 
 invoke.cont:                                      ; preds = %entry
-; CHECK:      invoke.cont.dead:
+; CHECK:      invoke.cont:
 ; CHECK-NEXT: unreachable
   br label %invoke.cont1
 

Modified: llvm/trunk/test/Transforms/FunctionAttrs/noreturn_sync.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/noreturn_sync.ll?rev=374703&r1=374702&r2=374703&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/noreturn_sync.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/noreturn_sync.ll Sat Oct 12 22:27:09 2019
@@ -97,12 +97,12 @@ entry:
   %retval = alloca i32, align 4
   %__exception_code = alloca i32, align 4
 ; CHECK: invoke void @"?overflow@@YAXXZ_may_throw"() 
-; CHECK:          to label %invoke.cont.dead unwind label %catch.dispatch
+; CHECK:          to label %invoke.cont unwind label %catch.dispatch
   invoke void @"?overflow@@YAXXZ_may_throw"() 
           to label %invoke.cont unwind label %catch.dispatch
 
 invoke.cont:                                      ; preds = %entry
-; CHECK:      invoke.cont.dead:
+; CHECK:      invoke.cont:
 ; CHECK-NEXT: unreachable
   br label %invoke.cont1
 




More information about the llvm-commits mailing list