xref: /aosp_15_r20/external/llvm/test/Transforms/SampleProfile/offset.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/offset.prof | opt -analyze -branch-prob | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/offset.prof | opt -analyze -branch-prob | FileCheck %s
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker; Original C++ code for this test case:
5*9880d681SAndroid Build Coastguard Worker;
6*9880d681SAndroid Build Coastguard Worker; a.cc:
7*9880d681SAndroid Build Coastguard Worker; #1
8*9880d681SAndroid Build Coastguard Worker; #2
9*9880d681SAndroid Build Coastguard Worker; #3
10*9880d681SAndroid Build Coastguard Worker; #4
11*9880d681SAndroid Build Coastguard Worker; #5 int foo(int a) {
12*9880d681SAndroid Build Coastguard Worker; #6 #include "a.b"
13*9880d681SAndroid Build Coastguard Worker; #7}
14*9880d681SAndroid Build Coastguard Worker;
15*9880d681SAndroid Build Coastguard Worker; a.b:
16*9880d681SAndroid Build Coastguard Worker; #1 if (a > 0) {
17*9880d681SAndroid Build Coastguard Worker; #2   return 10;
18*9880d681SAndroid Build Coastguard Worker; #3 } else {
19*9880d681SAndroid Build Coastguard Worker; #4   return 20;
20*9880d681SAndroid Build Coastguard Worker; #5 }
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable
23*9880d681SAndroid Build Coastguard Workerdefine i32 @_Z3fooi(i32 %a) #0 !dbg !4 {
24*9880d681SAndroid Build Coastguard Workerentry:
25*9880d681SAndroid Build Coastguard Worker  %retval = alloca i32, align 4
26*9880d681SAndroid Build Coastguard Worker  %a.addr = alloca i32, align 4
27*9880d681SAndroid Build Coastguard Worker  store i32 %a, i32* %a.addr, align 4
28*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !11, metadata !12), !dbg !13
29*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* %a.addr, align 4, !dbg !14
30*9880d681SAndroid Build Coastguard Worker  %cmp = icmp sgt i32 %0, 0, !dbg !18
31*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %if.then, label %if.else, !dbg !19
32*9880d681SAndroid Build Coastguard Worker; CHECK: edge entry -> if.then probability is 0x0147ae14 / 0x80000000 = 1.00%
33*9880d681SAndroid Build Coastguard Worker; CHECK: edge entry -> if.else probability is 0x7eb851ec / 0x80000000 = 99.00% [HOT edge]
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Workerif.then:                                          ; preds = %entry
36*9880d681SAndroid Build Coastguard Worker  store i32 10, i32* %retval, align 4, !dbg !20
37*9880d681SAndroid Build Coastguard Worker  br label %return, !dbg !20
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Workerif.else:                                          ; preds = %entry
40*9880d681SAndroid Build Coastguard Worker  store i32 20, i32* %retval, align 4, !dbg !22
41*9880d681SAndroid Build Coastguard Worker  br label %return, !dbg !22
42*9880d681SAndroid Build Coastguard Worker
43*9880d681SAndroid Build Coastguard Workerreturn:                                           ; preds = %if.else, %if.then
44*9880d681SAndroid Build Coastguard Worker  %1 = load i32, i32* %retval, align 4, !dbg !24
45*9880d681SAndroid Build Coastguard Worker  ret i32 %1, !dbg !24
46*9880d681SAndroid Build Coastguard Worker}
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone
49*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.dbg.declare(metadata, metadata, metadata) #1
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" }
52*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind readnone }
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0}
55*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!8, !9}
56*9880d681SAndroid Build Coastguard Worker!llvm.ident = !{!10}
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Worker!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)
59*9880d681SAndroid Build Coastguard Worker!1 = !DIFile(filename: "a.cc", directory: "/tmp")
60*9880d681SAndroid Build Coastguard Worker!2 = !{}
61*9880d681SAndroid Build Coastguard Worker!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, variables: !2)
62*9880d681SAndroid Build Coastguard Worker!5 = !DISubroutineType(types: !6)
63*9880d681SAndroid Build Coastguard Worker!6 = !{!7, !7}
64*9880d681SAndroid Build Coastguard Worker!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
65*9880d681SAndroid Build Coastguard Worker!8 = !{i32 2, !"Dwarf Version", i32 4}
66*9880d681SAndroid Build Coastguard Worker!9 = !{i32 2, !"Debug Info Version", i32 3}
67*9880d681SAndroid Build Coastguard Worker!10 = !{!"clang version 3.8.0 (trunk 250750)"}
68*9880d681SAndroid Build Coastguard Worker!11 = !DILocalVariable(name: "a", arg: 1, scope: !4, file: !1, line: 5, type: !7)
69*9880d681SAndroid Build Coastguard Worker!12 = !DIExpression()
70*9880d681SAndroid Build Coastguard Worker!13 = !DILocation(line: 5, column: 13, scope: !4)
71*9880d681SAndroid Build Coastguard Worker!14 = !DILocation(line: 1, column: 5, scope: !15)
72*9880d681SAndroid Build Coastguard Worker!15 = distinct !DILexicalBlock(scope: !17, file: !16, line: 1, column: 5)
73*9880d681SAndroid Build Coastguard Worker!16 = !DIFile(filename: "./a.b", directory: "/tmp")
74*9880d681SAndroid Build Coastguard Worker!17 = !DILexicalBlockFile(scope: !4, file: !16, discriminator: 0)
75*9880d681SAndroid Build Coastguard Worker!18 = !DILocation(line: 1, column: 7, scope: !15)
76*9880d681SAndroid Build Coastguard Worker!19 = !DILocation(line: 1, column: 5, scope: !17)
77*9880d681SAndroid Build Coastguard Worker!20 = !DILocation(line: 2, column: 3, scope: !21)
78*9880d681SAndroid Build Coastguard Worker!21 = distinct !DILexicalBlock(scope: !15, file: !16, line: 1, column: 12)
79*9880d681SAndroid Build Coastguard Worker!22 = !DILocation(line: 4, column: 3, scope: !23)
80*9880d681SAndroid Build Coastguard Worker!23 = distinct !DILexicalBlock(scope: !15, file: !16, line: 3, column: 8)
81*9880d681SAndroid Build Coastguard Worker!24 = !DILocation(line: 7, column: 1, scope: !25)
82*9880d681SAndroid Build Coastguard Worker!25 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 0)
83