llvm.org GIT mirror llvm / 6cd2a99
[PartialInliner] Skip call sites where inlining fails. Summary: InlineFunction can fail, for example when trying to inline vararg fuctions. In those cases, we do not want to bump partial inlining counters or set AnyInlined to true, because this could leave an unused function hanging around. Reviewers: davidxl, davide, gyiu Reviewed By: davide Subscribers: llvm-commits, eraman Differential Revision: https://reviews.llvm.org/D39581 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317314 91177308-0d34-0410-b5e6-96231b3b80d8 Florian Hahn 1 year, 10 months ago
2 changed file(s) with 54 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
930930 if (!shouldPartialInline(CS, Cloner, WeightedRcost, ORE))
931931 continue;
932932
933 ORE.emit([&]() {
934 return OptimizationRemark(DEBUG_TYPE, "PartiallyInlined",
935 CS.getInstruction())
936 << ore::NV("Callee", Cloner.OrigFunc) << " partially inlined into "
937 << ore::NV("Caller", CS.getCaller());
938 });
933 // Construct remark before doing the inlining, as after successful inlining
934 // the callsite is removed.
935 OptimizationRemark OR(DEBUG_TYPE, "PartiallyInlined", CS.getInstruction());
936 OR << ore::NV("Callee", Cloner.OrigFunc) << " partially inlined into "
937 << ore::NV("Caller", CS.getCaller());
939938
940939 InlineFunctionInfo IFI(nullptr, GetAssumptionCache, PSI);
941 InlineFunction(CS, IFI);
940 if (!InlineFunction(CS, IFI))
941 continue;
942
943 ORE.emit(OR);
942944
943945 // Now update the entry count:
944946 if (CalleeEntryCountV && CallSiteToProfCountMap.count(User)) {
0 ; RUN: opt < %s -partial-inliner -S -stats -pass-remarks=partial-inlining 2>&1 | FileCheck %s
1 ; RUN: opt < %s -passes=partial-inliner -S -stats -pass-remarks=partial-inlining 2>&1 | FileCheck %s
2
3 @stat = external global i32, align 4
4
5 define i32 @inline_fail(i32 %count, ...) {
6 entry:
7 %vargs = alloca i8*, align 8
8 %vargs1 = bitcast i8** %vargs to i8*
9 call void @llvm.va_start(i8* %vargs1)
10 %stat1 = load i32, i32* @stat, align 4
11 %cmp = icmp slt i32 %stat1, 0
12 br i1 %cmp, label %bb2, label %bb1
13
14 bb1: ; preds = %entry
15 %vg1 = add nsw i32 %stat1, 1
16 store i32 %vg1, i32* @stat, align 4
17 %va1 = va_arg i8** %vargs, i32
18 call void @foo(i32 %count, i32 %va1) #2
19 br label %bb2
20
21 bb2: ; preds = %bb1, %entry
22 %res = phi i32 [ 1, %bb1 ], [ 0, %entry ]
23 call void @llvm.va_end(i8* %vargs1)
24 ret i32 %res
25 }
26
27 define i32 @caller(i32 %arg) {
28 bb:
29 %res = tail call i32 (i32, ...) @inline_fail(i32 %arg, i32 %arg)
30 ret i32 %res
31 }
32
33 declare void @foo(i32, i32)
34 declare void @llvm.va_start(i8*)
35 declare void @llvm.va_end(i8*)
36
37 ; Check that no remarks have been emitted, inline_fail has not been partial
38 ; inlined, no code has been extracted and the partial-inlining counter
39 ; has not been incremented.
40
41 ; CHECK-NOT: remark
42 ; CHECK: tail call i32 (i32, ...) @inline_fail(i32 %arg, i32 %arg)
43 ; CHECK-NOT: inline_fail.1_bb1
44 ; CHECK-NOT: partial-inlining