xref: /llvm-project/llvm/test/Transforms/SampleProfile/warm-inline-instance.ll (revision 0271ae65a66367d802fa6866599d11e35f68450f)
1; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/warm-inline-instance.prof -S | FileCheck %s
2
3@.str = private unnamed_addr constant [11 x i8] c"sum is %d\0A\00", align 1
4
5; Function Attrs: nounwind uwtable
6define i32 @foo(i32 %x, i32 %y) #0 !dbg !4 {
7entry:
8  %x.addr = alloca i32, align 4
9  %y.addr = alloca i32, align 4
10  store i32 %x, ptr %x.addr, align 4
11  store i32 %y, ptr %y.addr, align 4
12  %t0 = load i32, ptr %x.addr, align 4, !dbg !11
13  %t1 = load i32, ptr %y.addr, align 4, !dbg !11
14  %add = add nsw i32 %t0, %t1, !dbg !11
15  ret i32 %add, !dbg !11
16}
17
18define i32 @goo(i32 %x, i32 %y) #0 {
19entry:
20  %x.addr = alloca i32, align 4
21  %y.addr = alloca i32, align 4
22  store i32 %x, ptr %x.addr, align 4
23  store i32 %y, ptr %y.addr, align 4
24  %t0 = load i32, ptr %x.addr, align 4, !dbg !11
25  %t1 = load i32, ptr %y.addr, align 4, !dbg !11
26  %add = add nsw i32 %t0, %t1, !dbg !11
27  ret i32 %add, !dbg !11
28}
29
30; Function Attrs: uwtable
31define i32 @main() #0 !dbg !7 {
32entry:
33  %retval = alloca i32, align 4
34  %s = alloca i32, align 4
35  %i = alloca i32, align 4
36  store i32 0, ptr %retval
37  store i32 0, ptr %i, align 4, !dbg !12
38  br label %while.cond, !dbg !13
39
40while.cond:                                       ; preds = %if.end, %entry
41  %t0 = load i32, ptr %i, align 4, !dbg !14
42  %inc = add nsw i32 %t0, 1, !dbg !14
43  store i32 %inc, ptr %i, align 4, !dbg !14
44  %cmp = icmp slt i32 %t0, 400000000, !dbg !14
45  br i1 %cmp, label %while.body, label %while.end, !dbg !14
46
47while.body:                                       ; preds = %while.cond
48  %t1 = load i32, ptr %i, align 4, !dbg !16
49  %cmp1 = icmp ne i32 %t1, 100, !dbg !16
50  br i1 %cmp1, label %if.then, label %if.else, !dbg !16
51
52if.then:                                          ; preds = %while.body
53  %t2 = load i32, ptr %i, align 4, !dbg !18
54  %t3 = load i32, ptr %s, align 4, !dbg !18
55; Although the ratio of total samples of @foo vs total samples of @main is
56; small, since the total samples count is larger than hot cutoff computed by
57; ProfileSummaryInfo, we will still regard the callsite of foo as hot and
58; early inlining will inline it.
59; CHECK-LABEL: @main(
60; CHECK-NOT: call i32 @foo(i32 %t2, i32 %t3)
61  %call1 = call i32 @foo(i32 %t2, i32 %t3), !dbg !18
62  store i32 %call1, ptr %s, align 4, !dbg !18
63  br label %if.end, !dbg !18
64
65if.else:                                          ; preds = %while.body
66; call @goo 's basicblock doesn't get any sample, so no profile will be annotated.
67; CHECK: call i32 @goo(i32 2, i32 3), !dbg !{{[0-9]+}}
68; CHECK-NOT: !prof
69; CHECK-SAME: {{$}}
70  %call2 = call i32 @goo(i32 2, i32 3), !dbg !26
71  store i32 %call2, ptr %s, align 4, !dbg !20
72  br label %if.end
73
74if.end:                                           ; preds = %if.else, %if.then
75  br label %while.cond, !dbg !22
76
77while.end:                                        ; preds = %while.cond
78  %t4 = load i32, ptr %s, align 4, !dbg !24
79  %call3 = call i32 (ptr, ...) @printf(ptr @.str, i32 %t4), !dbg !24
80  ret i32 0, !dbg !25
81}
82
83declare i32 @printf(ptr, ...) #2
84
85attributes #0 = { "use-sample-profile" }
86
87!llvm.dbg.cu = !{!0}
88!llvm.module.flags = !{!8, !9}
89!llvm.ident = !{!10}
90
91!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: NoDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
92!1 = !DIFile(filename: "calls.cc", directory: ".")
93!2 = !{}
94!4 = distinct !DISubprogram(name: "foo", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2)
95!5 = !DIFile(filename: "calls.cc", directory: ".")
96!6 = !DISubroutineType(types: !2)
97!7 = distinct !DISubprogram(name: "main", line: 7, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 7, file: !1, scope: !5, type: !6, retainedNodes: !2)
98!8 = !{i32 2, !"Dwarf Version", i32 4}
99!9 = !{i32 1, !"Debug Info Version", i32 3}
100!10 = !{!"clang version 3.5 "}
101!11 = !DILocation(line: 4, scope: !4)
102!12 = !DILocation(line: 8, scope: !7)
103!13 = !DILocation(line: 9, scope: !7)
104!14 = !DILocation(line: 9, scope: !15)
105!15 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !7)
106!16 = !DILocation(line: 10, scope: !17)
107!17 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !7)
108!18 = !DILocation(line: 10, scope: !19)
109!19 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !17)
110!20 = !DILocation(line: 10, scope: !21)
111!21 = !DILexicalBlockFile(discriminator: 4, file: !1, scope: !17)
112!22 = !DILocation(line: 10, scope: !23)
113!23 = !DILexicalBlockFile(discriminator: 6, file: !1, scope: !17)
114!24 = !DILocation(line: 11, scope: !7)
115!25 = !DILocation(line: 12, scope: !7)
116!26 = !DILocation(line: 11, scope: !19)
117