xref: /llvm-project/llvm/test/Transforms/SampleProfile/offset.ll (revision bb6497ffa6a88d1b3a32101d9b6519094d75ef2a)
1; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/offset.prof | opt -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
2
3; Original C++ code for this test case:
4;
5; a.cc:
6; #1
7; #2
8; #3
9; #4
10; #5 int foo(int a) {
11; #6 #include "a.b"
12; #7}
13;
14; a.b:
15; #1 if (a > 0) {
16; #2   return 10;
17; #3 } else {
18; #4   return 20;
19; #5 }
20
21; Function Attrs: nounwind uwtable
22define i32 @_Z3fooi(i32 %a) #0 !dbg !4 {
23entry:
24  %retval = alloca i32, align 4
25  %a.addr = alloca i32, align 4
26  store i32 %a, ptr %a.addr, align 4
27  call void @llvm.dbg.declare(metadata ptr %a.addr, metadata !11, metadata !12), !dbg !13
28  %0 = load i32, ptr %a.addr, align 4, !dbg !14
29  %cmp = icmp sgt i32 %0, 0, !dbg !18
30  br i1 %cmp, label %if.then, label %if.else, !dbg !19
31; CHECK: edge %entry -> %if.then probability is 0x0167ba82 / 0x80000000 = 1.10%
32; CHECK: edge %entry -> %if.else probability is 0x7e98457e / 0x80000000 = 98.90% [HOT edge]
33
34if.then:                                          ; preds = %entry
35  store i32 10, ptr %retval, align 4, !dbg !20
36  br label %return, !dbg !20
37
38if.else:                                          ; preds = %entry
39  store i32 20, ptr %retval, align 4, !dbg !22
40  br label %return, !dbg !22
41
42return:                                           ; preds = %if.else, %if.then
43  %1 = load i32, ptr %retval, align 4, !dbg !24
44  ret i32 %1, !dbg !24
45}
46
47; Function Attrs: nounwind readnone
48declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
49
50attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" "use-sample-profile" }
51attributes #1 = { nounwind readnone }
52
53!llvm.dbg.cu = !{!0}
54!llvm.module.flags = !{!8, !9}
55!llvm.ident = !{!10}
56
57!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 250750)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2)
58!1 = !DIFile(filename: "a.cc", directory: "/tmp")
59!2 = !{}
60!4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !1, file: !1, line: 5, type: !5, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
61!5 = !DISubroutineType(types: !6)
62!6 = !{!7, !7}
63!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
64!8 = !{i32 2, !"Dwarf Version", i32 4}
65!9 = !{i32 2, !"Debug Info Version", i32 3}
66!10 = !{!"clang version 3.8.0 (trunk 250750)"}
67!11 = !DILocalVariable(name: "a", arg: 1, scope: !4, file: !1, line: 5, type: !7)
68!12 = !DIExpression()
69!13 = !DILocation(line: 5, column: 13, scope: !4)
70!14 = !DILocation(line: 1, column: 5, scope: !15)
71!15 = distinct !DILexicalBlock(scope: !17, file: !16, line: 1, column: 5)
72!16 = !DIFile(filename: "./a.b", directory: "/tmp")
73!17 = !DILexicalBlockFile(scope: !4, file: !16, discriminator: 0)
74!18 = !DILocation(line: 1, column: 7, scope: !15)
75!19 = !DILocation(line: 1, column: 5, scope: !17)
76!20 = !DILocation(line: 2, column: 3, scope: !21)
77!21 = distinct !DILexicalBlock(scope: !15, file: !16, line: 1, column: 12)
78!22 = !DILocation(line: 4, column: 3, scope: !23)
79!23 = distinct !DILexicalBlock(scope: !15, file: !16, line: 3, column: 8)
80!24 = !DILocation(line: 7, column: 1, scope: !25)
81!25 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 0)
82