1; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/entry_counts_cold.prof -S | FileCheck %s
2; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/entry_counts_cold.prof -S | FileCheck %s
3; ModuleID = 'temp.bc'
4source_filename = "temp.c"
5target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
6target triple = "x86_64-apple-macosx10.14.0"
7
8; Function Attrs: nounwind ssp uwtable
9; CHECK: define i32 @top({{.*}} !prof [[TOP:![0-9]+]]
10define i32 @top(i32* %p) #0 !dbg !8 {
11entry:
12  %p.addr = alloca i32*, align 8
13  store i32* %p, i32** %p.addr, align 8, !tbaa !15
14  call void @llvm.dbg.declare(metadata i32** %p.addr, metadata !14, metadata !DIExpression()), !dbg !19
15  %0 = load i32*, i32** %p.addr, align 8, !dbg !20, !tbaa !15
16  %call = call i32 @foo(i32* %0), !dbg !21
17; foo is inlined
18; CHECK-NOT: call i32 @foo
19; CHECK: call i32 @bar
20  %1 = load i32*, i32** %p.addr, align 8, !dbg !22, !tbaa !15
21  %2 = load i32, i32* %1, align 4, !dbg !24, !tbaa !25
22  %tobool = icmp ne i32 %2, 0, !dbg !24
23  br i1 %tobool, label %if.then, label %if.end, !dbg !27
24
25if.then:                                          ; preds = %entry
26  %3 = load i32*, i32** %p.addr, align 8, !dbg !28, !tbaa !15
27; bar is not inlined
28; CHECK: call i32 @bar
29  %call1 = call i32 @bar(i32* %3), !dbg !29
30  br label %if.end, !dbg !29
31
32if.end:                                           ; preds = %if.then, %entry
33  ret i32 0, !dbg !30
34}
35
36; Function Attrs: nounwind readnone speculatable
37declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
38
39; Function Attrs: nounwind ssp uwtable
40; CHECK: define i32 @foo({{.*}} !prof [[FOO:![0-9]+]]
41define i32 @foo(i32* %p) #0 !dbg !31 {
42entry:
43  %p.addr = alloca i32*, align 8
44  %a = alloca i32, align 4
45  store i32* %p, i32** %p.addr, align 8, !tbaa !15
46  call void @llvm.dbg.declare(metadata i32** %p.addr, metadata !33, metadata !DIExpression()), !dbg !35
47  %0 = bitcast i32* %a to i8*, !dbg !36
48  call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #4, !dbg !36
49  call void @llvm.dbg.declare(metadata i32* %a, metadata !34, metadata !DIExpression()), !dbg !37
50  %1 = load i32*, i32** %p.addr, align 8, !dbg !38, !tbaa !15
51  %arrayidx = getelementptr inbounds i32, i32* %1, i64 3, !dbg !38
52  %2 = load i32, i32* %arrayidx, align 4, !dbg !38, !tbaa !25
53  %3 = load i32*, i32** %p.addr, align 8, !dbg !39, !tbaa !15
54  %arrayidx1 = getelementptr inbounds i32, i32* %3, i64 2, !dbg !39
55  %4 = load i32, i32* %arrayidx1, align 4, !dbg !40, !tbaa !25
56  %add = add nsw i32 %4, %2, !dbg !40
57  store i32 %add, i32* %arrayidx1, align 4, !dbg !40, !tbaa !25
58  %5 = load i32*, i32** %p.addr, align 8, !dbg !41, !tbaa !15
59  %call = call i32 @bar(i32* %5), !dbg !42
60  store i32 %call, i32* %a, align 4, !dbg !43, !tbaa !25
61  %6 = load i32, i32* %a, align 4, !dbg !44, !tbaa !25
62  %add2 = add nsw i32 %6, 1, !dbg !45
63  %7 = bitcast i32* %a to i8*, !dbg !46
64  call void @llvm.lifetime.end.p0i8(i64 4, i8* %7) #4, !dbg !46
65  ret i32 %add2, !dbg !47
66}
67
68; Function Attrs: nounwind ssp uwtable
69; CHECK: define i32 @bar({{.*}} !prof [[BAR:![0-9]+]]
70define i32 @bar(i32* %p) #0 !dbg !48 {
71entry:
72  %p.addr = alloca i32*, align 8
73  store i32* %p, i32** %p.addr, align 8, !tbaa !15
74  call void @llvm.dbg.declare(metadata i32** %p.addr, metadata !50, metadata !DIExpression()), !dbg !51
75  ; CHECK: call void (...) @baz{{.*}} !prof [[BAZ:![0-9]+]]
76  call void (...) @baz(), !dbg !52
77  %0 = load i32*, i32** %p.addr, align 8, !dbg !53, !tbaa !15
78  %arrayidx = getelementptr inbounds i32, i32* %0, i64 2, !dbg !53
79  %1 = load i32, i32* %arrayidx, align 4, !dbg !53, !tbaa !25
80  %2 = load i32*, i32** %p.addr, align 8, !dbg !54, !tbaa !15
81  %arrayidx1 = getelementptr inbounds i32, i32* %2, i64 1, !dbg !54
82  %3 = load i32, i32* %arrayidx1, align 4, !dbg !55, !tbaa !25
83  %add = add nsw i32 %3, %1, !dbg !55
84  store i32 %add, i32* %arrayidx1, align 4, !dbg !55, !tbaa !25
85  %4 = load i32*, i32** %p.addr, align 8, !dbg !56, !tbaa !15
86  %arrayidx2 = getelementptr inbounds i32, i32* %4, i64 3, !dbg !56
87  %5 = load i32, i32* %arrayidx2, align 4, !dbg !56, !tbaa !25
88  ret i32 %5, !dbg !57
89}
90
91; Function Attrs: argmemonly nounwind
92declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #2
93
94; Function Attrs: argmemonly nounwind
95declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #2
96
97declare void @baz(...) #3
98
99attributes #0 = { nounwind ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="all" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" "use-sample-profile" }
100attributes #1 = { nounwind readnone speculatable }
101attributes #2 = { argmemonly nounwind }
102attributes #3 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
103attributes #4 = { nounwind }
104
105!llvm.dbg.cu = !{!0}
106!llvm.module.flags = !{!3, !4, !5, !6}
107!llvm.ident = !{!7}
108
109; CHECK: [[TOP]] = !{!"function_entry_count", i64 101}
110; CHECK: [[FOO]] = !{!"function_entry_count", i64 151}
111; CHECK: [[BAR]] = !{!"function_entry_count", i64 303}
112; CHECK: [[BAZ]] = !{!"branch_weights", i32 303}
113
114!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: GNU)
115!1 = !DIFile(filename: "temp.c", directory: "llvm/test/Transforms/SampleProfile")
116!2 = !{}
117!3 = !{i32 2, !"Dwarf Version", i32 4}
118!4 = !{i32 2, !"Debug Info Version", i32 3}
119!5 = !{i32 1, !"wchar_size", i32 4}
120!6 = !{i32 7, !"PIC Level", i32 2}
121!7 = !{!"clang version 8.0.0"}
122!8 = distinct !DISubprogram(name: "top", scope: !1, file: !1, line: 5, type: !9, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)
123!9 = !DISubroutineType(types: !10)
124!10 = !{!11, !12}
125!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
126!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
127!13 = !{!14}
128!14 = !DILocalVariable(name: "p", arg: 1, scope: !8, file: !1, line: 5, type: !12)
129!15 = !{!16, !16, i64 0}
130!16 = !{!"any pointer", !17, i64 0}
131!17 = !{!"omnipotent char", !18, i64 0}
132!18 = !{!"Simple C/C++ TBAA"}
133!19 = !DILocation(line: 5, column: 14, scope: !8)
134!20 = !DILocation(line: 6, column: 7, scope: !8)
135!21 = !DILocation(line: 6, column: 3, scope: !8)
136!22 = !DILocation(line: 7, column: 8, scope: !23)
137!23 = distinct !DILexicalBlock(scope: !8, file: !1, line: 7, column: 7)
138!24 = !DILocation(line: 7, column: 7, scope: !23)
139!25 = !{!26, !26, i64 0}
140!26 = !{!"int", !17, i64 0}
141!27 = !DILocation(line: 7, column: 7, scope: !8)
142!28 = !DILocation(line: 8, column: 9, scope: !23)
143!29 = !DILocation(line: 8, column: 5, scope: !23)
144!30 = !DILocation(line: 9, column: 3, scope: !8)
145!31 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 12, type: !9, scopeLine: 12, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !32)
146!32 = !{!33, !34}
147!33 = !DILocalVariable(name: "p", arg: 1, scope: !31, file: !1, line: 12, type: !12)
148!34 = !DILocalVariable(name: "a", scope: !31, file: !1, line: 13, type: !11)
149!35 = !DILocation(line: 12, column: 14, scope: !31)
150!36 = !DILocation(line: 13, column: 3, scope: !31)
151!37 = !DILocation(line: 13, column: 7, scope: !31)
152!38 = !DILocation(line: 14, column: 11, scope: !31)
153!39 = !DILocation(line: 14, column: 3, scope: !31)
154!40 = !DILocation(line: 14, column: 8, scope: !31)
155!41 = !DILocation(line: 15, column: 11, scope: !31)
156!42 = !DILocation(line: 15, column: 7, scope: !31)
157!43 = !DILocation(line: 15, column: 5, scope: !31)
158!44 = !DILocation(line: 16, column: 10, scope: !31)
159!45 = !DILocation(line: 16, column: 11, scope: !31)
160!46 = !DILocation(line: 17, column: 1, scope: !31)
161!47 = !DILocation(line: 16, column: 3, scope: !31)
162!48 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 19, type: !9, scopeLine: 19, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !49)
163!49 = !{!50}
164!50 = !DILocalVariable(name: "p", arg: 1, scope: !48, file: !1, line: 19, type: !12)
165!51 = !DILocation(line: 19, column: 15, scope: !48)
166!52 = !DILocation(line: 20, column: 3, scope: !48)
167!53 = !DILocation(line: 21, column: 11, scope: !48)
168!54 = !DILocation(line: 21, column: 3, scope: !48)
169!55 = !DILocation(line: 21, column: 8, scope: !48)
170!56 = !DILocation(line: 22, column: 10, scope: !48)
171!57 = !DILocation(line: 22, column: 3, scope: !48)
172