Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 1 | ; The two profiles used in this test are the same but encoded in different |
| 2 | ; formats. This checks that we produce the same profile annotations regardless |
| 3 | ; of the profile format. |
| 4 | ; |
| 5 | ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.prof | opt -analyze -branch-prob | FileCheck %s |
| 6 | ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.binprof | opt -analyze -branch-prob | FileCheck %s |
| 7 | |
Xinliang David Li | d38392e | 2016-05-27 23:20:16 +0000 | [diff] [blame] | 8 | ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/fnptr.prof | opt -analyze -branch-prob | FileCheck %s |
| 9 | ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/fnptr.binprof | opt -analyze -branch-prob | FileCheck %s |
| 10 | |
Dehao Chen | 160fbc3 | 2016-09-21 16:26:51 +0000 | [diff] [blame] | 11 | ; CHECK: edge for.body3 -> if.then probability is 0x19f584f3 / 0x80000000 = 20.28% |
| 12 | ; CHECK: edge for.body3 -> if.else probability is 0x660a7b0d / 0x80000000 = 79.72% |
| 13 | ; CHECK: edge for.inc -> for.inc12 probability is 0x000f92fb / 0x80000000 = 0.05% |
| 14 | ; CHECK: edge for.inc -> for.body3 probability is 0x7ff06d05 / 0x80000000 = 99.95% |
Dehao Chen | 82667d0 | 2016-09-19 16:33:41 +0000 | [diff] [blame] | 15 | ; CHECK: edge for.inc12 -> for.end14 probability is 0x04000000 / 0x80000000 = 3.12% |
| 16 | ; CHECK: edge for.inc12 -> for.cond1.preheader probability is 0x7c000000 / 0x80000000 = 96.88% |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 17 | |
| 18 | ; Original C++ test case. |
| 19 | ; |
| 20 | ; #include <stdlib.h> |
| 21 | ; #include <math.h> |
| 22 | ; #include <stdio.h> |
| 23 | ; |
| 24 | ; #define N 10000 |
| 25 | ; #define M 6000 |
| 26 | ; |
| 27 | ; double foo(int x) { |
| 28 | ; return x * sin((double)x); |
| 29 | ; } |
| 30 | ; |
| 31 | ; double bar(int x) { |
| 32 | ; return x - cos((double)x); |
| 33 | ; } |
| 34 | ; |
| 35 | ; int main() { |
| 36 | ; double (*fptr)(int); |
| 37 | ; double S = 0; |
| 38 | ; for (int i = 0; i < N; i++) |
| 39 | ; for (int j = 0; j < M; j++) { |
| 40 | ; fptr = (rand() % 100 < 30) ? foo : bar; |
| 41 | ; if (rand() % 100 < 10) |
| 42 | ; S += (*fptr)(i + j * 300); |
| 43 | ; else |
| 44 | ; S += (*fptr)(i - j / 840); |
| 45 | ; } |
| 46 | ; printf("S = %lf\n", S); |
| 47 | ; return 0; |
| 48 | ; } |
| 49 | |
| 50 | @.str = private unnamed_addr constant [9 x i8] c"S = %lf\0A\00", align 1 |
| 51 | |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 52 | define double @_Z3fooi(i32 %x) #0 !dbg !3 { |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 53 | entry: |
| 54 | %conv = sitofp i32 %x to double, !dbg !2 |
| 55 | %call = tail call double @sin(double %conv) #3, !dbg !8 |
| 56 | %mul = fmul double %conv, %call, !dbg !8 |
| 57 | ret double %mul, !dbg !8 |
| 58 | } |
| 59 | |
| 60 | declare double @sin(double) #1 |
| 61 | |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 62 | define double @_Z3bari(i32 %x) #0 !dbg !10 { |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 63 | entry: |
| 64 | %conv = sitofp i32 %x to double, !dbg !9 |
| 65 | %call = tail call double @cos(double %conv) #3, !dbg !11 |
| 66 | %sub = fsub double %conv, %call, !dbg !11 |
| 67 | ret double %sub, !dbg !11 |
| 68 | } |
| 69 | |
| 70 | declare double @cos(double) #1 |
| 71 | |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 72 | define i32 @main() #2 !dbg !13 { |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 73 | entry: |
| 74 | br label %for.cond1.preheader, !dbg !12 |
| 75 | |
| 76 | for.cond1.preheader: ; preds = %for.inc12, %entry |
| 77 | %i.025 = phi i32 [ 0, %entry ], [ %inc13, %for.inc12 ] |
| 78 | %S.024 = phi double [ 0.000000e+00, %entry ], [ %S.2.lcssa, %for.inc12 ] |
| 79 | br label %for.body3, !dbg !14 |
| 80 | |
| 81 | for.body3: ; preds = %for.inc, %for.cond1.preheader |
| 82 | %j.023 = phi i32 [ 0, %for.cond1.preheader ], [ %inc, %for.inc ] |
| 83 | %S.122 = phi double [ %S.024, %for.cond1.preheader ], [ %S.2, %for.inc ] |
| 84 | %call = tail call i32 @rand() #3, !dbg !15 |
| 85 | %rem = srem i32 %call, 100, !dbg !15 |
| 86 | %cmp4 = icmp slt i32 %rem, 30, !dbg !15 |
| 87 | %_Z3fooi._Z3bari = select i1 %cmp4, double (i32)* @_Z3fooi, double (i32)* @_Z3bari, !dbg !15 |
| 88 | %call5 = tail call i32 @rand() #3, !dbg !16 |
| 89 | %rem6 = srem i32 %call5, 100, !dbg !16 |
| 90 | %cmp7 = icmp slt i32 %rem6, 10, !dbg !16 |
Dehao Chen | 82667d0 | 2016-09-19 16:33:41 +0000 | [diff] [blame] | 91 | br i1 %cmp7, label %if.then, label %if.else, !dbg !16 |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 92 | |
| 93 | if.then: ; preds = %for.body3 |
| 94 | %mul = mul nsw i32 %j.023, 300, !dbg !18 |
| 95 | %add = add nsw i32 %mul, %i.025, !dbg !18 |
| 96 | %call8 = tail call double %_Z3fooi._Z3bari(i32 %add), !dbg !18 |
| 97 | br label %for.inc, !dbg !18 |
| 98 | |
| 99 | if.else: ; preds = %for.body3 |
| 100 | %div = sdiv i32 %j.023, 840, !dbg !19 |
| 101 | %sub = sub nsw i32 %i.025, %div, !dbg !19 |
| 102 | %call10 = tail call double %_Z3fooi._Z3bari(i32 %sub), !dbg !19 |
| 103 | br label %for.inc |
| 104 | |
| 105 | for.inc: ; preds = %if.then, %if.else |
| 106 | %call8.pn = phi double [ %call8, %if.then ], [ %call10, %if.else ] |
| 107 | %S.2 = fadd double %S.122, %call8.pn, !dbg !18 |
| 108 | %inc = add nsw i32 %j.023, 1, !dbg !20 |
| 109 | %exitcond = icmp eq i32 %j.023, 5999, !dbg !14 |
Dehao Chen | 82667d0 | 2016-09-19 16:33:41 +0000 | [diff] [blame] | 110 | br i1 %exitcond, label %for.inc12, label %for.body3, !dbg !14 |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 111 | |
| 112 | for.inc12: ; preds = %for.inc |
| 113 | %S.2.lcssa = phi double [ %S.2, %for.inc ] |
| 114 | %inc13 = add nsw i32 %i.025, 1, !dbg !22 |
| 115 | %exitcond26 = icmp eq i32 %i.025, 9999, !dbg !12 |
Dehao Chen | 82667d0 | 2016-09-19 16:33:41 +0000 | [diff] [blame] | 116 | br i1 %exitcond26, label %for.end14, label %for.cond1.preheader, !dbg !12 |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 117 | |
| 118 | for.end14: ; preds = %for.inc12 |
| 119 | %S.2.lcssa.lcssa = phi double [ %S.2.lcssa, %for.inc12 ] |
David Blaikie | 23af648 | 2015-04-16 23:24:18 +0000 | [diff] [blame] | 120 | %call15 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %S.2.lcssa.lcssa), !dbg !24 |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 121 | ret i32 0, !dbg !25 |
| 122 | } |
| 123 | |
| 124 | ; Function Attrs: nounwind |
| 125 | declare i32 @rand() #1 |
| 126 | |
| 127 | ; Function Attrs: nounwind |
| 128 | declare i32 @printf(i8* nocapture readonly, ...) #1 |
| 129 | |
| 130 | !llvm.module.flags = !{!0} |
| 131 | !llvm.ident = !{!1} |
Davide Italiano | 7469644 | 2016-04-11 18:53:27 +0000 | [diff] [blame] | 132 | !llvm.dbg.cu = !{!26} |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 133 | |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 134 | !0 = !{i32 2, !"Debug Info Version", i32 3} |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 135 | !1 = !{!"clang version 3.6.0 "} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 136 | !2 = !DILocation(line: 9, column: 3, scope: !3) |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 137 | !3 = distinct !DISubprogram(name: "foo", line: 8, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, unit: !26, scopeLine: 8, file: !4, scope: !5, type: !6, variables: !7) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 138 | !4 = !DIFile(filename: "fnptr.cc", directory: ".") |
| 139 | !5 = !DIFile(filename: "fnptr.cc", directory: ".") |
| 140 | !6 = !DISubroutineType(types: !7) |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 141 | !7 = !{} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 142 | !8 = !DILocation(line: 9, column: 14, scope: !3) |
| 143 | !9 = !DILocation(line: 13, column: 3, scope: !10) |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 144 | !10 = distinct !DISubprogram(name: "bar", line: 12, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, unit: !26, scopeLine: 12, file: !4, scope: !5, type: !6, variables: !7) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 145 | !11 = !DILocation(line: 13, column: 14, scope: !10) |
| 146 | !12 = !DILocation(line: 19, column: 3, scope: !13) |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 147 | !13 = distinct !DISubprogram(name: "main", line: 16, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, unit: !26, scopeLine: 16, file: !4, scope: !5, type: !6, variables: !7) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 148 | !14 = !DILocation(line: 20, column: 5, scope: !13) |
| 149 | !15 = !DILocation(line: 21, column: 15, scope: !13) |
| 150 | !16 = !DILocation(line: 22, column: 11, scope: !13) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 151 | !18 = !DILocation(line: 23, column: 14, scope: !13) |
| 152 | !19 = !DILocation(line: 25, column: 14, scope: !13) |
| 153 | !20 = !DILocation(line: 20, column: 28, scope: !13) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 154 | !22 = !DILocation(line: 19, column: 26, scope: !13) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 155 | !24 = !DILocation(line: 27, column: 3, scope: !13) |
| 156 | !25 = !DILocation(line: 28, column: 3, scope: !13) |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 157 | !26 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: FullDebug, file: !4) |