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