blob: 17ca21d7a57ffffa64660b84e062e6dab4e7b2ce [file] [log] [blame]
Dehao Chen10042412015-10-21 01:22:27 +00001; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/offset.prof | opt -analyze -branch-prob | FileCheck %s
Xinliang David Lid38392e2016-05-27 23:20:16 +00002; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/offset.prof | opt -analyze -branch-prob | FileCheck %s
Dehao Chen10042412015-10-21 01:22:27 +00003
4; Original C++ code for this test case:
5;
6; a.cc:
7; #1
8; #2
9; #3
10; #4
11; #5 int foo(int a) {
12; #6 #include "a.b"
13; #7}
14;
15; a.b:
16; #1 if (a > 0) {
17; #2 return 10;
18; #3 } else {
19; #4 return 20;
20; #5 }
21
22; Function Attrs: nounwind uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +000023define i32 @_Z3fooi(i32 %a) #0 !dbg !4 {
Dehao Chen10042412015-10-21 01:22:27 +000024entry:
25 %retval = alloca i32, align 4
26 %a.addr = alloca i32, align 4
27 store i32 %a, i32* %a.addr, align 4
28 call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !11, metadata !12), !dbg !13
29 %0 = load i32, i32* %a.addr, align 4, !dbg !14
30 %cmp = icmp sgt i32 %0, 0, !dbg !18
31 br i1 %cmp, label %if.then, label %if.else, !dbg !19
Dehao Chenc0a1e432016-08-12 16:22:12 +000032; CHECK: edge entry -> if.then probability is 0x0167ba82 / 0x80000000 = 1.10%
33; CHECK: edge entry -> if.else probability is 0x7e98457e / 0x80000000 = 98.90% [HOT edge]
Dehao Chen10042412015-10-21 01:22:27 +000034
35if.then: ; preds = %entry
36 store i32 10, i32* %retval, align 4, !dbg !20
37 br label %return, !dbg !20
38
39if.else: ; preds = %entry
40 store i32 20, i32* %retval, align 4, !dbg !22
41 br label %return, !dbg !22
42
43return: ; preds = %if.else, %if.then
44 %1 = load i32, i32* %retval, align 4, !dbg !24
45 ret i32 %1, !dbg !24
46}
47
48; Function Attrs: nounwind readnone
49declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
50
51attributes #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" }
52attributes #1 = { nounwind readnone }
53
54!llvm.dbg.cu = !{!0}
55!llvm.module.flags = !{!8, !9}
56!llvm.ident = !{!10}
57
Adrian Prantl75819ae2016-04-15 15:57:41 +000058!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)
Dehao Chen10042412015-10-21 01:22:27 +000059!1 = !DIFile(filename: "a.cc", directory: "/tmp")
60!2 = !{}
Adrian Prantl75819ae2016-04-15 15:57:41 +000061!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)
Dehao Chen10042412015-10-21 01:22:27 +000062!5 = !DISubroutineType(types: !6)
63!6 = !{!7, !7}
64!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
65!8 = !{i32 2, !"Dwarf Version", i32 4}
66!9 = !{i32 2, !"Debug Info Version", i32 3}
67!10 = !{!"clang version 3.8.0 (trunk 250750)"}
68!11 = !DILocalVariable(name: "a", arg: 1, scope: !4, file: !1, line: 5, type: !7)
69!12 = !DIExpression()
70!13 = !DILocation(line: 5, column: 13, scope: !4)
71!14 = !DILocation(line: 1, column: 5, scope: !15)
72!15 = distinct !DILexicalBlock(scope: !17, file: !16, line: 1, column: 5)
73!16 = !DIFile(filename: "./a.b", directory: "/tmp")
74!17 = !DILexicalBlockFile(scope: !4, file: !16, discriminator: 0)
75!18 = !DILocation(line: 1, column: 7, scope: !15)
76!19 = !DILocation(line: 1, column: 5, scope: !17)
77!20 = !DILocation(line: 2, column: 3, scope: !21)
78!21 = distinct !DILexicalBlock(scope: !15, file: !16, line: 1, column: 12)
79!22 = !DILocation(line: 4, column: 3, scope: !23)
80!23 = distinct !DILexicalBlock(scope: !15, file: !16, line: 3, column: 8)
81!24 = !DILocation(line: 7, column: 1, scope: !25)
82!25 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 0)