[PATCH] D104849: [SimplifyCFG] Tail-merging all blocks with `resume` terminator

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 24 05:16:54 PDT 2021


lebedev.ri created this revision.
lebedev.ri added reviewers: rnk, fhahn, spatel, dmgreen.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.
lebedev.ri requested review of this revision.

Similar to what we already do for `ret` terminators.
As noted by @rnk, clang seems to already generate a single `ret`/`resume`,
so this isn't likely to cause widespread changes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104849

Files:
  llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
  llvm/test/Transforms/SimplifyCFG/tail-merge-resume.ll


Index: llvm/test/Transforms/SimplifyCFG/tail-merge-resume.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/tail-merge-resume.ll
+++ llvm/test/Transforms/SimplifyCFG/tail-merge-resume.ll
@@ -24,17 +24,20 @@
 ; CHECK-NEXT:    cleanup
 ; CHECK-NEXT:    call void @baz()
 ; CHECK-NEXT:    br i1 [[COND:%.*]], label [[RESUME0:%.*]], label [[RESUME1:%.*]]
+; CHECK:       common.resume:
+; CHECK-NEXT:    [[COMMON_RESUME_OP:%.*]] = phi { i8*, i32 } [ [[LP2:%.*]], [[LPAD2]] ], [ [[LP]], [[RESUME0]] ], [ [[LP]], [[RESUME1]] ]
+; CHECK-NEXT:    resume { i8*, i32 } [[COMMON_RESUME_OP]]
 ; CHECK:       lpad2:
-; CHECK-NEXT:    [[LP2:%.*]] = landingpad { i8*, i32 }
+; CHECK-NEXT:    [[LP2]] = landingpad { i8*, i32 }
 ; CHECK-NEXT:    cleanup
 ; CHECK-NEXT:    call void @quuz()
-; CHECK-NEXT:    resume { i8*, i32 } [[LP2]]
+; CHECK-NEXT:    br label [[COMMON_RESUME:%.*]]
 ; CHECK:       resume0:
 ; CHECK-NEXT:    call void @qux()
-; CHECK-NEXT:    resume { i8*, i32 } [[LP]]
+; CHECK-NEXT:    br label [[COMMON_RESUME]]
 ; CHECK:       resume1:
 ; CHECK-NEXT:    call void @quux()
-; CHECK-NEXT:    resume { i8*, i32 } [[LP]]
+; CHECK-NEXT:    br label [[COMMON_RESUME]]
 ;
   invoke void @foo() to label %invoke.cont unwind label %lpad
 
Index: llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -94,10 +94,15 @@
 
     auto *Term = BB.getTerminator();
 
-    // Fow now only support `ret` function terminators.
+    // Fow now only support `ret`/`resume` function terminators.
     // FIXME: lift this restriction.
-    if (Term->getOpcode() != Instruction::Ret)
+    switch (Term->getOpcode()) {
+    case Instruction::Ret:
+    case Instruction::Resume:
+      break;
+    default:
       continue;
+    }
 
     // We can't tail-merge block that contains a musttail call.
     if (BB.getTerminatingMustTailCall())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104849.354219.patch
Type: text/x-patch
Size: 2044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210624/4c2128d0/attachment.bin>


More information about the llvm-commits mailing list