1 ; RUN: opt < %s -passes='require<profile-summary>,cgscc(inline)' -S -inline-threshold=50 | FileCheck %s
3 ; This tests that the function count of a function gets properly scaled after
4 ; inlining a call chain leading to the function.
5 ; Function a calls c with count 200 (C1)
6 ; Function c calls e with count 250 (C2)
7 ; Entry count of e is 500 (C3)
8 ; Entry count of c is 500 (C4)
9 ; Function b calls c with count 300 (C5)
10 ; c->e inlining does not happen since the cost exceeds threshold.
11 ; c then inlined into a.
12 ; e now gets inlined into a (through c) since the branch condition in e is now
13 ; known and hence the cost gets reduced.
14 ; Estimated count of a->e callsite = C2 * (C1 / C4)
15 ; Estimated count of a->e callsite = 250 * (200 / 500) = 100
16 ; Remaining count of e = C3 - 100 = 500 - 100 = 400
17 ; Remaining count of c = C4 - C1 - C5 = 500 - 200 - 300 = 0
19 @data = external global i32
21 define i32 @a(i32 %a1) !prof !1 {
22 %a2 = call i32 @c(i32 %a1, i32 1)
26 define i32 @b(i32 %b1) !prof !2 {
27 %b2 = call i32 @c(i32 %b1, i32 %b1)
33 ; CHECK: @c(i32 %c1, i32 %c100) !prof [[COUNT1:![0-9]+]]
34 define i32 @c(i32 %c1, i32 %c100) !prof !3 {
36 %cond = icmp sle i32 %c1, 1
37 br i1 %cond, label %cond_true, label %cond_false
43 %c11 = call i32 @e(i32 %c100)
48 ; CHECK: @e(i32 %c1) !prof [[COUNT2:![0-9]+]]
49 define i32 @e(i32 %c1) !prof !4 {
50 %cond = icmp sle i32 %c1, 1
51 br i1 %cond, label %cond_true, label %cond_false
55 %c2 = load i32, i32* @data, align 4
56 %c3 = add i32 %c1, %c2
57 %c4 = mul i32 %c3, %c2
58 %c5 = add i32 %c4, %c2
59 %c6 = mul i32 %c5, %c2
60 %c7 = add i32 %c6, %c2
61 %c8 = mul i32 %c7, %c2
62 %c9 = add i32 %c8, %c2
63 %c10 = mul i32 %c9, %c2
70 !llvm.module.flags = !{!0}
71 ; CHECK: [[COUNT1]] = !{!"function_entry_count", i64 0}
72 ; CHECK: [[COUNT2]] = !{!"function_entry_count", i64 400}
73 !0 = !{i32 1, !"MaxFunctionCount", i32 5000}
74 !1 = !{!"function_entry_count", i64 200}
75 !2 = !{!"function_entry_count", i64 300}
76 !3 = !{!"function_entry_count", i64 500}
77 !4 = !{!"function_entry_count", i64 500}