xref: /llvm-project/llvm/test/Transforms/Inline/last-call-bonus.ll (revision e5369823bc0655806469724335d0ca5a4c17d8c7)
1; The goal of this test is checking if LastCallToStaticBonus is applied
2; correctly while deciding inline deferral. For the test code below, when
3; inliner evaluates the callsite of bar->baz, it checks if inlining of bar->baz
4; prevents ininling of foo->bar, even when foo->bar inlining is more beneficial
5; than bar->baz inlining. As LastCallToStaticBonus has a massive value, and
6; both baz and bar has only one caller, the cost of foo->bar inlining and
7; bar->baz inlining should be non-trivial for inliner to compute that bar->baz
8; inlining can actaully prevent foo->bar inlining. To make the cost of these
9; callsites big enough, loop unrolling pass with very high threshold is used to
10; preprocess the test.
11
12; RUN: opt < %s -passes='function(require<opt-remark-emit>,loop-unroll),require<profile-summary>,cgscc(inline)' -unroll-threshold=15000 -inline-threshold=250 -S | FileCheck %s
13; CHECK-LABEL: define internal i32 @bar()
14
15define internal i32 @baz() {
16entry:
17  br label %bb1
18
19bb1:
20  %ind = phi i32 [ 0, %entry ], [ %inc, %bb1 ]
21  call void @extern()
22  %inc = add nsw i32 %ind, 1
23  %cmp = icmp sgt i32 %inc, 510
24  br i1 %cmp, label %ret, label %bb1
25
26ret:
27  ret i32 0
28}
29
30define internal i32 @bar() {
31entry:
32  br label %bb1
33
34bb1:
35  %ind = phi i32 [ 0, %entry ], [ %inc, %bb1 ]
36  call void @extern()
37  %inc = add nsw i32 %ind, 1
38  %cmp = icmp sgt i32 %inc, 510
39  br i1 %cmp, label %ret, label %bb1
40
41ret:
42  call i32 @baz()
43  ret i32 0
44}
45
46define i32 @foo() {
47entry:
48  call i32 @bar()
49  ret i32 0
50}
51
52declare void @extern()
53