[llvm] r329250 - [CallSiteSplitting] Do not perform callsite splitting inside landing pad

Taewook Oh via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 4 21:16:24 PDT 2018


Author: twoh
Date: Wed Apr  4 21:16:23 2018
New Revision: 329250

URL: http://llvm.org/viewvc/llvm-project?rev=329250&view=rev
Log:
[CallSiteSplitting] Do not perform callsite splitting inside landing pad

Summary:
If the callsite is inside landing pad, do not perform callsite splitting.

Callsite splitting uses utility function llvm::DuplicateInstructionsInSplitBetween, which eventually calls llvm::SplitEdge. llvm::SplitEdge calls llvm::SplitCriticalEdge with an assumption that the function returns nullptr only when the target edge is not a critical edge (and further assumes that if the return value was not nullptr, the predecessor of the original target edge always has a single successor because critical edge splitting was successful). However, this assumtion is not true because SplitCriticalEdge returns nullptr if the destination block is a landing pad. This invalid assumption results assertion failure.

Fundamental solution might be fixing llvm::SplitEdge to not to rely on the invalid assumption. However, it'll involve a lot of work because current API assumes that llvm::SplitEdge never fails. Instead, this patch makes callsite splitting to not to attempt splitting if the callsite is in a landing pad.

Attached test case will crash with assertion failure without the fix.

Reviewers: fhahn, junbuml, dberlin

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D45130

Added:
    llvm/trunk/test/Transforms/CallSiteSplitting/lpad.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp?rev=329250&r1=329249&r2=329250&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp Wed Apr  4 21:16:23 2018
@@ -206,6 +206,12 @@ static bool canSplitCallSite(CallSite CS
       isa<IndirectBrInst>(Preds[1]->getTerminator()))
     return false;
 
+  // Do not split a call-site in an exception handling block. This check
+  // prevents triggering an assertion in SplitEdge used via
+  // DuplicateInstructionsInSplitBetween. 
+  if (CallSiteBB->isEHPad())
+    return false;
+
   return CallSiteBB->canSplitPredecessors();
 }
 

Added: llvm/trunk/test/Transforms/CallSiteSplitting/lpad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CallSiteSplitting/lpad.ll?rev=329250&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/CallSiteSplitting/lpad.ll (added)
+++ llvm/trunk/test/Transforms/CallSiteSplitting/lpad.ll Wed Apr  4 21:16:23 2018
@@ -0,0 +1,40 @@
+; 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-LABEL: lpad
+; 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
+}




More information about the llvm-commits mailing list