1; Let sample profile loader replay inlining of small/cold functions
2
3; Make sure we don't inline the cold call sites by default
4; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline-cold.prof -S | FileCheck -check-prefix=NOTINLINE %s
5; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-cold.prof -S | FileCheck -check-prefix=NOTINLINE %s
6
7; Make sure we inline code call sites for size if requested
8; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline-cold.prof -sample-profile-inline-size -S | FileCheck -check-prefix=INLINE %s
9
10; Make sure we re-inline everything if requested
11; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-cold.prof -sample-profile-inline-size -sample-profile-cold-inline-threshold=9999999 -S | FileCheck -check-prefix=INLINE %s
12
13; Make sure the separate size threshold for sample profile loader inlining works
14; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-cold.prof -sample-profile-inline-size -sample-profile-cold-inline-threshold=-500 -S | FileCheck -check-prefix=NOTINLINE %s
15
16@.str = private unnamed_addr constant [11 x i8] c"sum is %d\0A\00", align 1
17
18define i32 @_Z3sumii(i32 %x, i32 %y) #0 !dbg !6 {
19entry:
20  %x.addr = alloca i32, align 4
21  %y.addr = alloca i32, align 4
22  store i32 %x, i32* %x.addr, align 4
23  store i32 %y, i32* %y.addr, align 4
24  %tmp = load i32, i32* %x.addr, align 4, !dbg !8
25  %tmp1 = load i32, i32* %y.addr, align 4, !dbg !8
26  %add = add nsw i32 %tmp, %tmp1, !dbg !8
27  ret i32 %add, !dbg !8
28}
29
30define i32 @main() #0 !dbg !9 {
31entry:
32  %retval = alloca i32, align 4
33  %s = alloca i32, align 4
34  %i = alloca i32, align 4
35  store i32 0, i32* %retval
36  store i32 0, i32* %i, align 4, !dbg !10
37  br label %while.cond, !dbg !11
38
39while.cond:                                       ; preds = %if.end, %entry
40  %tmp = load i32, i32* %i, align 4, !dbg !12
41  %inc = add nsw i32 %tmp, 1, !dbg !12
42  store i32 %inc, i32* %i, align 4, !dbg !12
43  %cmp = icmp slt i32 %tmp, 400000000, !dbg !12
44  br i1 %cmp, label %while.body, label %while.end, !dbg !12
45
46while.body:                                       ; preds = %while.cond
47  %tmp1 = load i32, i32* %i, align 4, !dbg !14
48  %cmp1 = icmp ne i32 %tmp1, 100, !dbg !14
49  br i1 %cmp1, label %if.then, label %if.else, !dbg !14
50
51if.then:                                          ; preds = %while.body
52  %tmp2 = load i32, i32* %i, align 4, !dbg !16
53  %tmp3 = load i32, i32* %s, align 4, !dbg !16
54  %call = call i32 @_Z3sumii(i32 %tmp2, i32 %tmp3), !dbg !16
55; INLINE-NOT: call i32 @_Z3sumii
56; NOTINLINE: call i32 @_Z3sumii
57  store i32 %call, i32* %s, align 4, !dbg !16
58  br label %if.end, !dbg !16
59
60if.else:                                          ; preds = %while.body
61  store i32 30, i32* %s, align 4, !dbg !18
62  br label %if.end
63
64if.end:                                           ; preds = %if.else, %if.then
65  br label %while.cond, !dbg !20
66
67while.end:                                        ; preds = %while.cond
68  %tmp4 = load i32, i32* %s, align 4, !dbg !22
69  %call2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i32 %tmp4), !dbg !22
70  ret i32 0, !dbg !23
71}
72
73attributes #0 = { "use-sample-profile" }
74
75declare i32 @printf(i8*, ...)
76
77!llvm.dbg.cu = !{!0}
78!llvm.module.flags = !{!3, !4}
79!llvm.ident = !{!5}
80
81!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.5 ", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
82!1 = !DIFile(filename: "calls.cc", directory: ".")
83!2 = !{}
84!3 = !{i32 2, !"Dwarf Version", i32 4}
85!4 = !{i32 1, !"Debug Info Version", i32 3}
86!5 = !{!"clang version 3.5 "}
87!6 = distinct !DISubprogram(name: "sum", scope: !1, file: !1, line: 3, type: !7, scopeLine: 3, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
88!7 = !DISubroutineType(types: !2)
89!8 = !DILocation(line: 4, scope: !6)
90!9 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 7, type: !7, scopeLine: 7, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
91!10 = !DILocation(line: 8, scope: !9)
92!11 = !DILocation(line: 9, scope: !9)
93!12 = !DILocation(line: 9, scope: !13)
94!13 = !DILexicalBlockFile(scope: !9, file: !1, discriminator: 2)
95!14 = !DILocation(line: 10, scope: !15)
96!15 = distinct !DILexicalBlock(scope: !9, file: !1, line: 10)
97!16 = !DILocation(line: 10, scope: !17)
98!17 = !DILexicalBlockFile(scope: !15, file: !1, discriminator: 2)
99!18 = !DILocation(line: 10, scope: !19)
100!19 = !DILexicalBlockFile(scope: !15, file: !1, discriminator: 4)
101!20 = !DILocation(line: 10, scope: !21)
102!21 = !DILexicalBlockFile(scope: !15, file: !1, discriminator: 6)
103!22 = !DILocation(line: 11, scope: !9)
104!23 = !DILocation(line: 12, scope: !9)
105