xref: /llvm-project/llvm/test/Transforms/SampleProfile/remap-2.ll (revision 0271ae65a66367d802fa6866599d11e35f68450f)
1; RUN: opt %s -passes=sample-profile -sample-profile-file=%S/Inputs/remap-2.prof -sample-profile-remapping-file=%S/Inputs/remap.map -S | FileCheck %s
2; Check profile remapping works for searching inline instance, searching
3; indirect call promotion candidate and prevent recursive inline.
4
5@x.addr = common global i32 zeroinitializer, align 16
6@y.addr = common global i32 zeroinitializer, align 16
7
8define i32 @_ZN3foo3barERKN1M1XINS_6detail3quxEEE() #0 !dbg !9 {
9entry:
10  %t0 = load i32, ptr @x.addr, align 4
11  %t1 = load i32, ptr @y.addr, align 4
12  %add = add nsw i32 %t0, %t1
13  ret i32 %add
14}
15
16define i32 @_ZN1M1XE() #0 !dbg !10 {
17entry:
18  %t0 = load i32, ptr @x.addr, align 4
19  %t1 = load i32, ptr @y.addr, align 4
20  %sub = sub nsw i32 %t0, %t1
21  ret i32 %sub
22}
23
24define void @test(ptr) #0 !dbg !4 {
25  %t2 = alloca ptr
26  store ptr %0, ptr %t2
27  %t3 = load ptr, ptr %t2
28; Check call i32 %t3 has been indirect call promoted and call i32 @_ZN1M1XE
29; has been inlined.
30; CHECK-LABEL: @test(
31; CHECK: icmp eq ptr %t3, @_ZN3foo3barERKN1M1XINS_6detail3quxEEE
32; CHECK-NOT: call i32 @_ZN1M1XE
33  %t4 = call i32 %t3(), !dbg !7
34  %t5 = call i32 @_ZN1M1XE(), !dbg !8
35  ret void
36}
37
38define void @_ZN1M1X1YE(ptr) #0 !dbg !11 {
39  %t2 = alloca ptr
40  store ptr %0, ptr %t2
41  %t3 = load ptr, ptr %t2
42; Check call i32 %t3 has got its profile but is not indirect call promoted
43; because the promotion candidate is a recursive call to the current function.
44; CHECK-LABEL: @_ZN1M1X1YE(
45; CHECK: call i32 %t3(), {{.*}} !prof ![[PROFID:[0-9]+]]
46; CHECK-NOT: icmp eq ptr %t3, @_ZN1M1X1YE
47  %t4 = call i32 %t3(), !dbg !12
48  ret void
49}
50
51; CHECK: ![[PROFID]] = !{!"VP", i32 0, i64 3000
52
53attributes #0 = { "use-sample-profile" }
54
55!llvm.dbg.cu = !{!0}
56!llvm.module.flags = !{!13, !14}
57!llvm.ident = !{!15}
58
59!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
60!1 = !DIFile(filename: "calls.cc", directory: ".")
61!2 = !{}
62!4 = distinct !DISubprogram(name: "test", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2)
63!5 = !DIFile(filename: "calls.cc", directory: ".")
64!6 = !DISubroutineType(types: !2)
65!7 = !DILocation(line: 8, scope: !4)
66!8 = !DILocation(line: 9, scope: !4)
67!9 = distinct !DISubprogram(name: "_ZN3foo3barERKN1M1XINS_6detail3quxEEE", line: 15, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2)
68!10 = distinct !DISubprogram(name: "_ZN1M1XE", line: 20, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2)
69!11 = distinct !DISubprogram(name: "_ZN1M1X1YE", line: 25, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2)
70!12 = !DILocation(line: 30, scope: !11)
71!13 = !{i32 2, !"Dwarf Version", i32 4}
72!14 = !{i32 1, !"Debug Info Version", i32 3}
73!15 = !{!"clang version 3.5 "}
74
75