79 lines · plain
1; RUN: opt < %s -passes='require<profile-summary>,cgscc(inline)' -S -inline-threshold=50 | FileCheck %s2 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 now13; 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) = 10016; Remaining count of e = C3 - 100 = 500 - 100 = 40017; Remaining count of c = C4 - C1 - C5 = 500 - 200 - 300 = 018 19@data = external global i3220 21define i32 @a(i32 %a1) !prof !1 {22 %a2 = call i32 @c(i32 %a1, i32 1)23 ret i32 %a224}25 26define i32 @b(i32 %b1) !prof !2 {27 %b2 = call i32 @c(i32 %b1, i32 %b1)28 ret i32 %b229}30 31declare void @ext();32 33; CHECK: @c(i32 %c1, i32 %c100) !prof [[COUNT1:![0-9]+]]34define i32 @c(i32 %c1, i32 %c100) !prof !3 {35 call void @ext()36 %cond = icmp sle i32 %c1, 137 br i1 %cond, label %cond_true, label %cond_false38 39cond_false:40 ret i32 041 42cond_true:43 %c11 = call i32 @e(i32 %c100)44 ret i32 %c1145}46 47 48; CHECK: @e(i32 %c1) !prof [[COUNT2:![0-9]+]]49define i32 @e(i32 %c1) !prof !4 {50 %cond = icmp sle i32 %c1, 151 br i1 %cond, label %cond_true, label %cond_false52 53cond_false:54 call void @ext()55 %c2 = load i32, ptr @data, align 456 %c3 = add i32 %c1, %c257 %c4 = mul i32 %c3, %c258 %c5 = add i32 %c4, %c259 %c6 = mul i32 %c5, %c260 %c7 = add i32 %c6, %c261 %c8 = mul i32 %c7, %c262 %c9 = add i32 %c8, %c263 %c10 = mul i32 %c9, %c264 ret i32 %c1065 66cond_true:67 ret i32 068}69 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}78 79