Skip to content

Commit e0db533

Browse files
committed
[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 llvm-svn: 329250
1 parent 70565e4 commit e0db533

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ static bool canSplitCallSite(CallSite CS, TargetTransformInfo &TTI) {
206206
isa<IndirectBrInst>(Preds[1]->getTerminator()))
207207
return false;
208208

209+
// Do not split a call-site in an exception handling block. This check
210+
// prevents triggering an assertion in SplitEdge used via
211+
// DuplicateInstructionsInSplitBetween.
212+
if (CallSiteBB->isEHPad())
213+
return false;
214+
209215
return CallSiteBB->canSplitPredecessors();
210216
}
211217

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: opt -S -callsite-splitting < %s | FileCheck %s
2+
;
3+
; Make sure that the callsite is not splitted by checking that there's only one
4+
; call to @callee.
5+
6+
; CHECK-LABEL: @caller
7+
; CHECK-LABEL: lpad
8+
; CHECK: call void @callee
9+
; CHECK-NOT: call void @callee
10+
11+
declare void @foo(i1* %p);
12+
declare void @bar(i1* %p);
13+
declare dso_local i32 @__gxx_personality_v0(...)
14+
15+
define void @caller(i1* %p) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
16+
entry:
17+
%0 = icmp eq i1* %p, null
18+
br i1 %0, label %bb1, label %bb2
19+
20+
bb1:
21+
invoke void @foo(i1* %p) to label %end1 unwind label %lpad
22+
23+
bb2:
24+
invoke void @bar(i1* %p) to label %end2 unwind label %lpad
25+
26+
lpad:
27+
%1 = landingpad { i8*, i32 } cleanup
28+
call void @callee(i1* %p)
29+
resume { i8*, i32 } %1
30+
31+
end1:
32+
ret void
33+
34+
end2:
35+
ret void
36+
}
37+
38+
define internal void @callee(i1* %p) {
39+
ret void
40+
}

0 commit comments

Comments
 (0)