[PATCH] D119266: [SimplifyCFG] Do not merge landingpads for invokes with deopt state.

Denis Antrushin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 8 10:55:12 PST 2022


dantrushin created this revision.
dantrushin added reviewers: skatkov, anna.
Herald added a subscriber: hiraditya.
dantrushin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Invokes with deopt states on them must have unique landingpads
for gc.relocate placement (see RewriteStatepointsForGC.cpp)

Disable landingpad merging for invokes with deopt states in SimplifyCFG,
to avoid need of undoing this optimization later.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119266

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/duplicate-landingpad.ll


Index: llvm/test/Transforms/SimplifyCFG/duplicate-landingpad.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/duplicate-landingpad.ll
+++ llvm/test/Transforms/SimplifyCFG/duplicate-landingpad.ll
@@ -147,3 +147,52 @@
   call void @fn()
   ret void
 }
+
+; Should not trigger when invokes have deopt bundles
+; CHECK-LABEL: @neg3(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    invoke void @fn()
+; CHECK-NEXT:    to label [[INVOKE2:%.*]] unwind label [[LPAD1:%.*]]
+; CHECK:       invoke2:
+; CHECK-NEXT:    invoke void @fn()
+; CHECK-NEXT:    to label [[COMMON_RET:%.*]] unwind label [[LPAD2:%.*]]
+; CHECK:       common.ret:
+; CHECK-NEXT:    ret void
+; CHECK:       lpad1:
+; CHECK-NEXT:    [[EXN:%.*]] = landingpad { i8*, i32 }
+; CHECK-NEXT:    cleanup
+; CHECK-NEXT:    br label [[SHARED_RESUME:%.*]]
+; CHECK:       lpad2:
+; CHECK-NEXT:    [[EXN2:%.*]] = landingpad { i8*, i32 }
+; CHECK-NEXT:    cleanup
+; CHECK-NEXT:    br label [[SHARED_RESUME]]
+; CHECK:       shared_resume:
+; CHECK-NEXT:    call void @fn()
+; CHECK-NEXT:    br label [[COMMON_RET]]
+;
+define void @neg3() gc "statepoint-example" personality i32 (...)* @__gxx_personality_v0 {
+entry:
+  invoke void @fn() [ "deopt"() ]
+  to label %invoke2 unwind label %lpad1
+
+invoke2:
+  invoke void @fn() [ "deopt"() ]
+  to label %invoke.cont unwind label %lpad2
+
+invoke.cont:
+  ret void
+
+lpad1:
+  %exn = landingpad {i8*, i32}
+  cleanup
+  br label %shared_resume
+
+lpad2:
+  %exn2 = landingpad {i8*, i32}
+  cleanup
+  br label %shared_resume
+
+shared_resume:
+  call void @fn()
+  ret void
+}
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6652,6 +6652,15 @@
 /// merged.  In some cases, this could result in removal of the PHI entirely.
 static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
                                  BasicBlock *BB, DomTreeUpdater *DTU) {
+
+  // Invokes with deopt bundles must have unique landingpads
+  // (See RewriteStatepointsForGC.cpp). Prohibit landingpad merging
+  // for such invokes.
+  BasicBlock *Pred = *pred_begin(BB);
+  if (auto *Invoke = dyn_cast<InvokeInst>(Pred->getTerminator()))
+    if (Invoke->getOperandBundle(LLVMContext::OB_deopt))
+      return false;
+
   auto Succ = BB->getUniqueSuccessor();
   assert(Succ);
   // If there's a phi in the successor block, we'd likely have to introduce


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119266.406898.patch
Type: text/x-patch
Size: 2565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220208/ec6131a6/attachment.bin>


More information about the llvm-commits mailing list