xref: /llvm-project/llvm/test/Transforms/SampleProfile/inline.ll (revision 0271ae65a66367d802fa6866599d11e35f68450f)
1cee313d2SEric Christopher; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline.prof -S | FileCheck %s
25740bb80SHongtao Yu; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-priority.prof -sample-profile-prioritized-inline=1 -S | FileCheck %s
3cee313d2SEric Christopher
4cee313d2SEric Christopher; Original C++ test case
5cee313d2SEric Christopher;
6cee313d2SEric Christopher; #include <stdio.h>
7cee313d2SEric Christopher;
8cee313d2SEric Christopher; int sum(int x, int y) {
9cee313d2SEric Christopher;   return x + y;
10cee313d2SEric Christopher; }
11cee313d2SEric Christopher;
12cee313d2SEric Christopher; int main() {
13cee313d2SEric Christopher;   int s, i = 0;
14cee313d2SEric Christopher;   while (i++ < 20000 * 20000)
15cee313d2SEric Christopher;     if (i != 100) s = sum(i, s); else s = 30;
16cee313d2SEric Christopher;   printf("sum is %d\n", s);
17cee313d2SEric Christopher;   return 0;
18cee313d2SEric Christopher; }
19cee313d2SEric Christopher;
20cee313d2SEric Christopher@.str = private unnamed_addr constant [11 x i8] c"sum is %d\0A\00", align 1
21cee313d2SEric Christopher
22cee313d2SEric Christopher; Function Attrs: nounwind uwtable
237a6c8942SWei Midefine i32 @_Z3sumii(i32 %x, i32 %y) #0 !dbg !4 {
24cee313d2SEric Christopherentry:
25cee313d2SEric Christopher  %x.addr = alloca i32, align 4
26cee313d2SEric Christopher  %y.addr = alloca i32, align 4
27*0271ae65SFangrui Song  store i32 %x, ptr %x.addr, align 4
28*0271ae65SFangrui Song  store i32 %y, ptr %y.addr, align 4
29*0271ae65SFangrui Song  %0 = load i32, ptr %x.addr, align 4, !dbg !11
30*0271ae65SFangrui Song  %1 = load i32, ptr %y.addr, align 4, !dbg !11
31cee313d2SEric Christopher  %add = add nsw i32 %0, %1, !dbg !11
32cee313d2SEric Christopher  ret i32 %add, !dbg !11
33cee313d2SEric Christopher}
34cee313d2SEric Christopher
35cee313d2SEric Christopher; Function Attrs: uwtable
367a6c8942SWei Midefine i32 @main() #0 !dbg !7 {
37cee313d2SEric Christopherentry:
38cee313d2SEric Christopher  %retval = alloca i32, align 4
39cee313d2SEric Christopher  %s = alloca i32, align 4
40cee313d2SEric Christopher  %i = alloca i32, align 4
41*0271ae65SFangrui Song  store i32 0, ptr %retval
42*0271ae65SFangrui Song  store i32 0, ptr %i, align 4, !dbg !12
43cee313d2SEric Christopher  br label %while.cond, !dbg !13
44cee313d2SEric Christopher
45cee313d2SEric Christopherwhile.cond:                                       ; preds = %if.end, %entry
46*0271ae65SFangrui Song  %0 = load i32, ptr %i, align 4, !dbg !14
47cee313d2SEric Christopher  %inc = add nsw i32 %0, 1, !dbg !14
48*0271ae65SFangrui Song  store i32 %inc, ptr %i, align 4, !dbg !14
49cee313d2SEric Christopher  %cmp = icmp slt i32 %0, 400000000, !dbg !14
50cee313d2SEric Christopher  br i1 %cmp, label %while.body, label %while.end, !dbg !14
51cee313d2SEric Christopher
52cee313d2SEric Christopherwhile.body:                                       ; preds = %while.cond
53*0271ae65SFangrui Song  %1 = load i32, ptr %i, align 4, !dbg !16
54cee313d2SEric Christopher  %cmp1 = icmp ne i32 %1, 100, !dbg !16
55cee313d2SEric Christopher  br i1 %cmp1, label %if.then, label %if.else, !dbg !16
56cee313d2SEric Christopher
57cee313d2SEric Christopher
58cee313d2SEric Christopherif.then:                                          ; preds = %while.body
59*0271ae65SFangrui Song  %2 = load i32, ptr %i, align 4, !dbg !18
60*0271ae65SFangrui Song  %3 = load i32, ptr %s, align 4, !dbg !18
61cee313d2SEric Christopher  %call = call i32 @_Z3sumii(i32 %2, i32 %3), !dbg !18
62cee313d2SEric Christopher; CHECK-NOT: call i32 @_Z3sumii
63*0271ae65SFangrui Song  store i32 %call, ptr %s, align 4, !dbg !18
64cee313d2SEric Christopher  br label %if.end, !dbg !18
65cee313d2SEric Christopher
66cee313d2SEric Christopherif.else:                                          ; preds = %while.body
67*0271ae65SFangrui Song  store i32 30, ptr %s, align 4, !dbg !20
68cee313d2SEric Christopher  br label %if.end
69cee313d2SEric Christopher
70cee313d2SEric Christopherif.end:                                           ; preds = %if.else, %if.then
71cee313d2SEric Christopher  br label %while.cond, !dbg !22
72cee313d2SEric Christopher
73cee313d2SEric Christopherwhile.end:                                        ; preds = %while.cond
74*0271ae65SFangrui Song  %4 = load i32, ptr %s, align 4, !dbg !24
75*0271ae65SFangrui Song  %call2 = call i32 (ptr, ...) @printf(ptr @.str, i32 %4), !dbg !24
76cee313d2SEric Christopher  ret i32 0, !dbg !25
77cee313d2SEric Christopher}
78cee313d2SEric Christopher
79*0271ae65SFangrui Songdeclare i32 @printf(ptr, ...) #2
80cee313d2SEric Christopher
817a6c8942SWei Miattributes #0 = { "use-sample-profile" }
827a6c8942SWei Mi
83cee313d2SEric Christopher!llvm.dbg.cu = !{!0}
84cee313d2SEric Christopher!llvm.module.flags = !{!8, !9}
85cee313d2SEric Christopher!llvm.ident = !{!10}
86cee313d2SEric Christopher
87cee313d2SEric Christopher!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)
88cee313d2SEric Christopher!1 = !DIFile(filename: "calls.cc", directory: ".")
89cee313d2SEric Christopher!2 = !{}
90cee313d2SEric Christopher!4 = distinct !DISubprogram(name: "sum", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2)
91cee313d2SEric Christopher!5 = !DIFile(filename: "calls.cc", directory: ".")
92cee313d2SEric Christopher!6 = !DISubroutineType(types: !2)
93cee313d2SEric Christopher!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)
94cee313d2SEric Christopher!8 = !{i32 2, !"Dwarf Version", i32 4}
95cee313d2SEric Christopher!9 = !{i32 1, !"Debug Info Version", i32 3}
96cee313d2SEric Christopher!10 = !{!"clang version 3.5 "}
97cee313d2SEric Christopher!11 = !DILocation(line: 4, scope: !4)
98cee313d2SEric Christopher!12 = !DILocation(line: 8, scope: !7)
99cee313d2SEric Christopher!13 = !DILocation(line: 9, scope: !7)
100cee313d2SEric Christopher!14 = !DILocation(line: 9, scope: !15)
101cee313d2SEric Christopher!15 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !7)
102cee313d2SEric Christopher!16 = !DILocation(line: 10, scope: !17)
103cee313d2SEric Christopher!17 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !7)
104cee313d2SEric Christopher!18 = !DILocation(line: 10, scope: !19)
105cee313d2SEric Christopher!19 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !17)
106cee313d2SEric Christopher!20 = !DILocation(line: 10, scope: !21)
107cee313d2SEric Christopher!21 = !DILexicalBlockFile(discriminator: 4, file: !1, scope: !17)
108cee313d2SEric Christopher!22 = !DILocation(line: 10, scope: !23)
109cee313d2SEric Christopher!23 = !DILexicalBlockFile(discriminator: 6, file: !1, scope: !17)
110cee313d2SEric Christopher!24 = !DILocation(line: 11, scope: !7)
111cee313d2SEric Christopher!25 = !DILocation(line: 12, scope: !7)
112