Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/branch.prof | opt -analyze -branch-prob | FileCheck %s |
| 2 | |
| 3 | ; Original C++ code for this test case: |
| 4 | ; |
| 5 | ; #include <stdio.h> |
| 6 | ; #include <stdlib.h> |
| 7 | ; |
| 8 | ; int main(int argc, char *argv[]) { |
| 9 | ; if (argc < 2) |
| 10 | ; return 1; |
| 11 | ; double result; |
| 12 | ; int limit = atoi(argv[1]); |
| 13 | ; if (limit > 100) { |
| 14 | ; double s = 23.041968; |
| 15 | ; for (int u = 0; u < limit; u++) { |
| 16 | ; double x = s; |
| 17 | ; s = x + 3.049 + (double)u; |
| 18 | ; s -= s + 3.94 / x * 0.32; |
| 19 | ; } |
| 20 | ; result = s; |
| 21 | ; } else { |
| 22 | ; result = 0; |
| 23 | ; } |
| 24 | ; printf("result is %lf\n", result); |
| 25 | ; return 0; |
| 26 | ; } |
| 27 | |
| 28 | @.str = private unnamed_addr constant [15 x i8] c"result is %lf\0A\00", align 1 |
| 29 | |
| 30 | ; Function Attrs: nounwind uwtable |
| 31 | define i32 @main(i32 %argc, i8** nocapture readonly %argv) #0 { |
| 32 | ; CHECK: Printing analysis 'Branch Probability Analysis' for function 'main': |
| 33 | |
| 34 | entry: |
Duncan P. N. Exon Smith | 166121a | 2015-03-15 01:21:30 +0000 | [diff] [blame] | 35 | tail call void @llvm.dbg.value(metadata i32 %argc, i64 0, metadata !13, metadata !MDExpression()), !dbg !27 |
| 36 | tail call void @llvm.dbg.value(metadata i8** %argv, i64 0, metadata !14, metadata !MDExpression()), !dbg !27 |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 37 | %cmp = icmp slt i32 %argc, 2, !dbg !28 |
| 38 | br i1 %cmp, label %return, label %if.end, !dbg !28 |
| 39 | ; CHECK: edge entry -> return probability is 1 / 2 = 50% |
| 40 | ; CHECK: edge entry -> if.end probability is 1 / 2 = 50% |
| 41 | |
| 42 | if.end: ; preds = %entry |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 43 | %arrayidx = getelementptr inbounds i8*, i8** %argv, i64 1, !dbg !30 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 44 | %0 = load i8*, i8** %arrayidx, align 8, !dbg !30, !tbaa !31 |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 45 | %call = tail call i32 @atoi(i8* %0) #4, !dbg !30 |
Duncan P. N. Exon Smith | 166121a | 2015-03-15 01:21:30 +0000 | [diff] [blame] | 46 | tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !17, metadata !MDExpression()), !dbg !30 |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 47 | %cmp1 = icmp sgt i32 %call, 100, !dbg !35 |
| 48 | br i1 %cmp1, label %for.body, label %if.end6, !dbg !35 |
Diego Novillo | 0accb3d | 2014-01-10 23:23:46 +0000 | [diff] [blame] | 49 | ; CHECK: edge if.end -> for.body probability is 1 / 2 = 50% |
| 50 | ; CHECK: edge if.end -> if.end6 probability is 1 / 2 = 50% |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 51 | |
| 52 | for.body: ; preds = %if.end, %for.body |
| 53 | %u.016 = phi i32 [ %inc, %for.body ], [ 0, %if.end ] |
| 54 | %s.015 = phi double [ %sub, %for.body ], [ 0x40370ABE6A337A81, %if.end ] |
| 55 | %add = fadd double %s.015, 3.049000e+00, !dbg !36 |
| 56 | %conv = sitofp i32 %u.016 to double, !dbg !36 |
| 57 | %add4 = fadd double %add, %conv, !dbg !36 |
Duncan P. N. Exon Smith | 166121a | 2015-03-15 01:21:30 +0000 | [diff] [blame] | 58 | tail call void @llvm.dbg.value(metadata double %add4, i64 0, metadata !18, metadata !MDExpression()), !dbg !36 |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 59 | %div = fdiv double 3.940000e+00, %s.015, !dbg !37 |
| 60 | %mul = fmul double %div, 3.200000e-01, !dbg !37 |
| 61 | %add5 = fadd double %add4, %mul, !dbg !37 |
| 62 | %sub = fsub double %add4, %add5, !dbg !37 |
Duncan P. N. Exon Smith | 166121a | 2015-03-15 01:21:30 +0000 | [diff] [blame] | 63 | tail call void @llvm.dbg.value(metadata double %sub, i64 0, metadata !18, metadata !MDExpression()), !dbg !37 |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 64 | %inc = add nsw i32 %u.016, 1, !dbg !38 |
Duncan P. N. Exon Smith | 166121a | 2015-03-15 01:21:30 +0000 | [diff] [blame] | 65 | tail call void @llvm.dbg.value(metadata i32 %inc, i64 0, metadata !21, metadata !MDExpression()), !dbg !38 |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 66 | %exitcond = icmp eq i32 %inc, %call, !dbg !38 |
| 67 | br i1 %exitcond, label %if.end6, label %for.body, !dbg !38 |
Diego Novillo | 0accb3d | 2014-01-10 23:23:46 +0000 | [diff] [blame] | 68 | ; CHECK: edge for.body -> if.end6 probability is 1 / 10227 = 0.00977804 |
| 69 | ; CHECK: edge for.body -> for.body probability is 10226 / 10227 = 99.9902% [HOT edge] |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 70 | |
| 71 | if.end6: ; preds = %for.body, %if.end |
| 72 | %result.0 = phi double [ 0.000000e+00, %if.end ], [ %sub, %for.body ] |
David Blaikie | f72d05b | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 73 | %call7 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %result.0), !dbg !39 |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 74 | br label %return, !dbg !40 |
| 75 | ; CHECK: edge if.end6 -> return probability is 16 / 16 = 100% [HOT edge] |
| 76 | |
| 77 | return: ; preds = %entry, %if.end6 |
| 78 | %retval.0 = phi i32 [ 0, %if.end6 ], [ 1, %entry ] |
| 79 | ret i32 %retval.0, !dbg !41 |
| 80 | } |
| 81 | |
| 82 | ; Function Attrs: nounwind readonly |
| 83 | declare i32 @atoi(i8* nocapture) #1 |
| 84 | |
| 85 | ; Function Attrs: nounwind |
| 86 | declare i32 @printf(i8* nocapture readonly, ...) #2 |
| 87 | |
| 88 | ; Function Attrs: nounwind readnone |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 89 | declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #3 |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 90 | |
| 91 | attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 92 | attributes #1 = { nounwind readonly "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 93 | attributes #2 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 94 | attributes #3 = { nounwind readnone } |
| 95 | attributes #4 = { nounwind readonly } |
| 96 | |
| 97 | !llvm.dbg.cu = !{!0} |
Manman Ren | 409558f | 2013-11-22 21:49:45 +0000 | [diff] [blame] | 98 | !llvm.module.flags = !{!25, !42} |
Diego Novillo | 8d6568b | 2013-11-13 12:22:21 +0000 | [diff] [blame] | 99 | !llvm.ident = !{!26} |
| 100 | |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 101 | !0 = !MDCompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.4 (trunk 192896) (llvm/trunk 192895)", isOptimized: true, emissionKind: 0, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2) |
| 102 | !1 = !MDFile(filename: "branch.cc", directory: ".") |
Duncan P. N. Exon Smith | 988a7f8 | 2015-03-27 20:46:33 +0000 | [diff] [blame^] | 103 | !2 = !{} |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 104 | !3 = !{!4} |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 105 | !4 = !MDSubprogram(name: "main", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 4, file: !1, scope: !5, type: !6, function: i32 (i32, i8**)* @main, variables: !12) |
| 106 | !5 = !MDFile(filename: "branch.cc", directory: ".") |
| 107 | !6 = !MDSubroutineType(types: !7) |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 108 | !7 = !{!8, !8, !9} |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 109 | !8 = !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) |
| 110 | !9 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !10) |
| 111 | !10 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !11) |
| 112 | !11 = !MDBasicType(tag: DW_TAG_base_type, name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 113 | !12 = !{!13, !14, !15, !17, !18, !21, !23} |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 114 | !13 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "argc", line: 4, arg: 1, scope: !4, file: !5, type: !8) |
| 115 | !14 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "argv", line: 4, arg: 2, scope: !4, file: !5, type: !9) |
| 116 | !15 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "result", line: 7, scope: !4, file: !5, type: !16) |
| 117 | !16 = !MDBasicType(tag: DW_TAG_base_type, name: "double", size: 64, align: 64, encoding: DW_ATE_float) |
| 118 | !17 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "limit", line: 8, scope: !4, file: !5, type: !8) |
| 119 | !18 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "s", line: 10, scope: !19, file: !5, type: !16) |
| 120 | !19 = distinct !MDLexicalBlock(line: 9, column: 0, file: !1, scope: !20) |
| 121 | !20 = distinct !MDLexicalBlock(line: 9, column: 0, file: !1, scope: !4) |
| 122 | !21 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "u", line: 11, scope: !22, file: !5, type: !8) |
| 123 | !22 = distinct !MDLexicalBlock(line: 11, column: 0, file: !1, scope: !19) |
| 124 | !23 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "x", line: 12, scope: !24, file: !5, type: !16) |
| 125 | !24 = distinct !MDLexicalBlock(line: 11, column: 0, file: !1, scope: !22) |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 126 | !25 = !{i32 2, !"Dwarf Version", i32 4} |
| 127 | !26 = !{!"clang version 3.4 (trunk 192896) (llvm/trunk 192895)"} |
Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 128 | !27 = !MDLocation(line: 4, scope: !4) |
| 129 | !28 = !MDLocation(line: 5, scope: !29) |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 130 | !29 = distinct !MDLexicalBlock(line: 5, column: 0, file: !1, scope: !4) |
Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 131 | !30 = !MDLocation(line: 8, scope: !4) |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 132 | !31 = !{!32, !32, i64 0} |
| 133 | !32 = !{!"any pointer", !33, i64 0} |
| 134 | !33 = !{!"omnipotent char", !34, i64 0} |
| 135 | !34 = !{!"Simple C/C++ TBAA"} |
Duncan P. N. Exon Smith | 9885469 | 2015-01-14 22:27:36 +0000 | [diff] [blame] | 136 | !35 = !MDLocation(line: 9, scope: !20) |
| 137 | !36 = !MDLocation(line: 13, scope: !24) |
| 138 | !37 = !MDLocation(line: 14, scope: !24) |
| 139 | !38 = !MDLocation(line: 11, scope: !22) |
| 140 | !39 = !MDLocation(line: 20, scope: !4) |
| 141 | !40 = !MDLocation(line: 21, scope: !4) |
| 142 | !41 = !MDLocation(line: 22, scope: !4) |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 143 | !42 = !{i32 1, !"Debug Info Version", i32 3} |