[PATCH] D45130: Do not perform callsite splitting inside landing pad

Taewook Oh via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 2 22:45:18 PDT 2018


twoh updated this revision to Diff 140739.
twoh added a comment.

Thanks @fhahn for the comments! I added comments about why we don't perform splitting for the callsites inside the landing pad. Please let me know if you think it is too verbose.


Repository:
  rL LLVM

https://reviews.llvm.org/D45130

Files:
  lib/Transforms/Scalar/CallSiteSplitting.cpp
  test/Transforms/CallSiteSplitting/lpad.ll


Index: test/Transforms/CallSiteSplitting/lpad.ll
===================================================================
--- /dev/null
+++ test/Transforms/CallSiteSplitting/lpad.ll
@@ -0,0 +1,39 @@
+; RUN: opt -S -callsite-splitting < %s | FileCheck %s
+;
+; Make sure that the callsite is not splitted by checking that there's only one
+; call to @callee.
+
+; CHECK-LABEL: @caller
+; CHECK: call void @callee
+; CHECK-NOT: call void @callee
+
+declare void @foo(i1* %p);
+declare void @bar(i1* %p);
+declare dso_local i32 @__gxx_personality_v0(...)
+
+define void @caller(i1* %p) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+entry:
+  %0 = icmp eq i1* %p, null
+  br i1 %0, label %bb1, label %bb2
+
+bb1:
+  invoke void @foo(i1* %p) to label %end1 unwind label %lpad
+
+bb2:
+  invoke void @bar(i1* %p) to label %end2 unwind label %lpad
+
+lpad:
+  %1 = landingpad { i8*, i32 } cleanup
+  call void @callee(i1* %p)
+  resume { i8*, i32 } %1
+
+end1:
+  ret void
+
+end2:
+  ret void
+}
+
+define internal void @callee(i1* %p) {
+  ret void
+}
Index: lib/Transforms/Scalar/CallSiteSplitting.cpp
===================================================================
--- lib/Transforms/Scalar/CallSiteSplitting.cpp
+++ lib/Transforms/Scalar/CallSiteSplitting.cpp
@@ -206,6 +206,17 @@
       isa<IndirectBrInst>(Preds[1]->getTerminator()))
     return false;
 
+  // Do not split a call-site in a landing pad to not to trigger the assertion
+  // failure from llvm::SplitEdge. This pass (CallSiteSplitting) uses
+  // llvm::DuplicateInstructionsInSplitBetween function, which eventually calls
+  // llvm::SplitEdge. Although llvm::SplitEdge assumes that critical edges are
+  // always splittable, the assumption is actually not true for critical edges
+  // whose destination is a landing pad. If we attempt to split the callsite
+  // inside a landing pad, this may trigger the assumption violation and
+  // crashes the compiler.
+  if (CallSiteBB->isEHPad())
+    return false;
+
   return CallSiteBB->canSplitPredecessors();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45130.140739.patch
Type: text/x-patch
Size: 2051 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180403/190d33af/attachment.bin>


More information about the llvm-commits mailing list