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