1; Test we lose details of not inlined profile without '-sample-profile-merge-inlinee'
2; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline-mergeprof.prof -S | FileCheck -check-prefix=SCALE %s
3; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-mergeprof.prof -S | FileCheck -check-prefix=SCALE %s
4
5; Test we properly merge not inlined profile properly with '-sample-profile-merge-inlinee'
6; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline-mergeprof.prof -sample-profile-merge-inlinee -S | FileCheck -check-prefix=MERGE %s
7; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-mergeprof.prof -sample-profile-merge-inlinee -S | FileCheck -check-prefix=MERGE  %s
8
9@.str = private unnamed_addr constant [11 x i8] c"sum is %d\0A\00", align 1
10
11define i32 @main() #0 !dbg !6 {
12entry:
13  %retval = alloca i32, align 4
14  %s = alloca i32, align 4
15  %i = alloca i32, align 4
16  %tmp = load i32, i32* %i, align 4, !dbg !8
17  %tmp1 = load i32, i32* %s, align 4, !dbg !8
18  %call = call i32 @_Z3sumii(i32 %tmp, i32 %tmp1), !dbg !8
19; SCALE: call i32 @_Z3sumii
20; MERGE: call i32 @_Z3sumii
21  store i32 %call, i32* %s, align 4, !dbg !8
22  ret i32 0, !dbg !11
23}
24
25define i32 @_Z3sumii(i32 %x, i32 %y) #0 !dbg !12 {
26entry:
27  %x.addr = alloca i32, align 4
28  %y.addr = alloca i32, align 4
29  store i32 %x, i32* %x.addr, align 4
30  store i32 %y, i32* %y.addr, align 4
31  %tmp = load i32, i32* %x.addr, align 4, !dbg !13
32  %tmp1 = load i32, i32* %y.addr, align 4, !dbg !13
33  %add = add nsw i32 %tmp, %tmp1, !dbg !13
34  %tmp2 = load i32, i32* %x.addr, align 4, !dbg !13
35  %tmp3 = load i32, i32* %y.addr, align 4, !dbg !13
36  %cmp1 = icmp ne i32 %tmp3, 100, !dbg !13
37  br i1 %cmp1, label %if.then, label %if.else, !dbg !13
38
39if.then:                                          ; preds = %entry
40  %call = call i32 @_Z3subii(i32 %tmp2, i32 %tmp3), !dbg !14
41  ret i32 %add, !dbg !14
42
43if.else:                                          ; preds = %entry
44  ret i32 %add, !dbg !15
45}
46
47define i32 @_Z3subii(i32 %x, i32 %y) #0 !dbg !16 {
48entry:
49  %x.addr = alloca i32, align 4
50  %y.addr = alloca i32, align 4
51  store i32 %x, i32* %x.addr, align 4
52  store i32 %y, i32* %y.addr, align 4
53  %tmp = load i32, i32* %x.addr, align 4, !dbg !17
54  %tmp1 = load i32, i32* %y.addr, align 4, !dbg !17
55  %add = sub nsw i32 %tmp, %tmp1, !dbg !17
56  ret i32 %add, !dbg !18
57}
58
59attributes #0 = { "use-sample-profile" }
60
61declare i32 @printf(i8*, ...)
62
63!llvm.dbg.cu = !{!0}
64!llvm.module.flags = !{!3, !4}
65!llvm.ident = !{!5}
66
67!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)
68!1 = !DIFile(filename: "calls.cc", directory: ".")
69!2 = !{}
70!3 = !{i32 2, !"Dwarf Version", i32 4}
71!4 = !{i32 1, !"Debug Info Version", i32 3}
72!5 = !{!"clang version 3.5 "}
73!6 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 7, type: !7, scopeLine: 7, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
74!7 = !DISubroutineType(types: !2)
75!8 = !DILocation(line: 10, scope: !9)
76!9 = !DILexicalBlockFile(scope: !10, file: !1, discriminator: 2)
77!10 = distinct !DILexicalBlock(scope: !6, file: !1, line: 10)
78!11 = !DILocation(line: 12, scope: !6)
79!12 = distinct !DISubprogram(name: "sum", scope: !1, file: !1, line: 3, type: !7, scopeLine: 3, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
80!13 = !DILocation(line: 4, scope: !12)
81!14 = !DILocation(line: 5, scope: !12)
82!15 = !DILocation(line: 6, scope: !12)
83!16 = distinct !DISubprogram(name: "sub", scope: !1, file: !1, line: 20, type: !7, scopeLine: 20, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
84!17 = !DILocation(line: 20, scope: !16)
85!18 = !DILocation(line: 21, scope: !16)
86
87; SCALE: name: "sum"
88; SCALE-NEXT: {!"function_entry_count", i64 46}
89; SCALE: !{!"branch_weights", i32 11, i32 2}
90; SCALE: !{!"branch_weights", i64 20}
91; SCALE: name: "sub"
92; SCALE-NEXT: {!"function_entry_count", i64 -1}
93
94; MERGE: name: "sum"
95; MERGE-NEXT: {!"function_entry_count", i64 46}
96; MERGE: !{!"branch_weights", i32 11, i32 23}
97; MERGE: !{!"branch_weights", i32 10}
98; MERGE: name: "sub"
99; MERGE-NEXT: {!"function_entry_count", i64 3}
100