|
| 1 | +; Test that misexpect diagnostics are issued in sample profiling |
| 2 | +; RUN: opt < %s -passes="function(lower-expect),sample-profile" -sample-profile-file=%S/Inputs/misexpect.prof -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING |
| 3 | + |
| 4 | +; Test that if expect intrinsics are not lowered, then no diagnostics are issued |
| 5 | +; RUN: opt < %s -passes="sample-profile" -sample-profile-file=%S/Inputs/misexpect.prof -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=NONE |
| 6 | + |
| 7 | +; Original C++ code for this test case: |
| 8 | +; |
| 9 | +; #include <stdio.h> |
| 10 | +; #include <stdlib.h> |
| 11 | + |
| 12 | +; int main(int argc, char *argv[]) { |
| 13 | +; if (argc < 2) |
| 14 | +; return 1; |
| 15 | +; double result; |
| 16 | +; int limit = atoi(argv[1]); |
| 17 | +; if (limit > 100) { |
| 18 | +; double s = 23.041968 * atoi(argv[2]); |
| 19 | +; for (int u = 0; u < limit; u++) { |
| 20 | +; double x = s; |
| 21 | +; s = x + 3.049 + (double)u; |
| 22 | +; s -= s + 3.94 / x * 0.32; |
| 23 | +; } |
| 24 | +; result = s; |
| 25 | +; } else { |
| 26 | +; result = atoi(argv[2]); |
| 27 | +; } |
| 28 | +; printf("result is %lf\n", result); |
| 29 | +; return 0; |
| 30 | +; } |
| 31 | + |
| 32 | +; WARNING-DAG: warning: test.cc:9:14: 20.06% |
| 33 | +; WARNING-DAG: warning: test.cc:11:24: 92.74% |
| 34 | + |
| 35 | +; NONE-NOT: warning: test.cc:9:14: 20.06% |
| 36 | +; NONE-NOT: warning: test.cc:11:24: 92.74% |
| 37 | + |
| 38 | +@.str = private unnamed_addr constant [15 x i8] c"result is %lf\0A\00", align 1 |
| 39 | + |
| 40 | +; Function Attrs: uwtable |
| 41 | +define i32 @main(i32 %argc, i8** %argv) #0 !dbg !6 { |
| 42 | + |
| 43 | +entry: |
| 44 | + %retval = alloca i32, align 4 |
| 45 | + %argc.addr = alloca i32, align 4 |
| 46 | + %argv.addr = alloca i8**, align 8 |
| 47 | + %result = alloca double, align 8 |
| 48 | + %limit = alloca i32, align 4 |
| 49 | + %s = alloca double, align 8 |
| 50 | + %u = alloca i32, align 4 |
| 51 | + %x = alloca double, align 8 |
| 52 | + store i32 0, i32* %retval, align 4 |
| 53 | + store i32 %argc, i32* %argc.addr, align 4 |
| 54 | + call void @llvm.dbg.declare(metadata i32* %argc.addr, metadata !16, metadata !17), !dbg !18 |
| 55 | + store i8** %argv, i8*** %argv.addr, align 8 |
| 56 | + call void @llvm.dbg.declare(metadata i8*** %argv.addr, metadata !19, metadata !17), !dbg !20 |
| 57 | + %0 = load i32, i32* %argc.addr, align 4, !dbg !21 |
| 58 | + %cmp = icmp slt i32 %0, 2, !dbg !23 |
| 59 | + br i1 %cmp, label %if.then, label %if.end, !dbg !24 |
| 60 | + |
| 61 | +if.then: ; preds = %entry |
| 62 | + store i32 1, i32* %retval, align 4, !dbg !25 |
| 63 | + br label %return, !dbg !25 |
| 64 | + |
| 65 | +if.end: ; preds = %entry |
| 66 | + call void @llvm.dbg.declare(metadata double* %result, metadata !26, metadata !17), !dbg !27 |
| 67 | + call void @llvm.dbg.declare(metadata i32* %limit, metadata !28, metadata !17), !dbg !29 |
| 68 | + %1 = load i8**, i8*** %argv.addr, align 8, !dbg !30 |
| 69 | + %arrayidx = getelementptr inbounds i8*, i8** %1, i64 1, !dbg !30 |
| 70 | + %2 = load i8*, i8** %arrayidx, align 8, !dbg !30 |
| 71 | + %call = call i32 @atoi(i8* %2) #4, !dbg !31 |
| 72 | + store i32 %call, i32* %limit, align 4, !dbg !29 |
| 73 | + %3 = load i32, i32* %limit, align 4, !dbg !32 |
| 74 | + %exp = call i32 @llvm.expect.i32(i32 %3, i32 0) |
| 75 | + %tobool = icmp ne i32 %exp, 0, !dbg !34 |
| 76 | + br i1 %tobool, label %if.then.2, label %if.else, !dbg !35 |
| 77 | + |
| 78 | +if.then.2: ; preds = %if.end |
| 79 | + call void @llvm.dbg.declare(metadata double* %s, metadata !36, metadata !17), !dbg !38 |
| 80 | + %4 = load i8**, i8*** %argv.addr, align 8, !dbg !39 |
| 81 | + %arrayidx3 = getelementptr inbounds i8*, i8** %4, i64 2, !dbg !39 |
| 82 | + %5 = load i8*, i8** %arrayidx3, align 8, !dbg !39 |
| 83 | + %call4 = call i32 @atoi(i8* %5) #4, !dbg !40 |
| 84 | + %conv = sitofp i32 %call4 to double, !dbg !40 |
| 85 | + %mul = fmul double 0x40370ABE6A337A81, %conv, !dbg !41 |
| 86 | + store double %mul, double* %s, align 8, !dbg !38 |
| 87 | + call void @llvm.dbg.declare(metadata i32* %u, metadata !42, metadata !17), !dbg !44 |
| 88 | + store i32 0, i32* %u, align 4, !dbg !44 |
| 89 | + br label %for.cond, !dbg !45 |
| 90 | + |
| 91 | +for.cond: ; preds = %for.inc, %if.then.2 |
| 92 | + %6 = load i32, i32* %u, align 4, !dbg !46 |
| 93 | + %7 = load i32, i32* %limit, align 4, !dbg !48 |
| 94 | + %expval = call i32 @llvm.expect.i32(i32 %6, i32 1) |
| 95 | + %cmp5 = icmp ne i32 %expval, 0, !dbg !49 |
| 96 | + br i1 %cmp5, label %for.body, label %for.end, !dbg !50 |
| 97 | + |
| 98 | +for.body: ; preds = %for.cond |
| 99 | + call void @llvm.dbg.declare(metadata double* %x, metadata !51, metadata !17), !dbg !53 |
| 100 | + %8 = load double, double* %s, align 8, !dbg !54 |
| 101 | + store double %8, double* %x, align 8, !dbg !53 |
| 102 | + %9 = load double, double* %x, align 8, !dbg !55 |
| 103 | + %add = fadd double %9, 3.049000e+00, !dbg !56 |
| 104 | + %10 = load i32, i32* %u, align 4, !dbg !57 |
| 105 | + %conv6 = sitofp i32 %10 to double, !dbg !57 |
| 106 | + %add7 = fadd double %add, %conv6, !dbg !58 |
| 107 | + store double %add7, double* %s, align 8, !dbg !59 |
| 108 | + %11 = load double, double* %s, align 8, !dbg !60 |
| 109 | + %12 = load double, double* %x, align 8, !dbg !61 |
| 110 | + %div = fdiv double 3.940000e+00, %12, !dbg !62 |
| 111 | + %mul8 = fmul double %div, 3.200000e-01, !dbg !63 |
| 112 | + %add9 = fadd double %11, %mul8, !dbg !64 |
| 113 | + %13 = load double, double* %s, align 8, !dbg !65 |
| 114 | + %sub = fsub double %13, %add9, !dbg !65 |
| 115 | + store double %sub, double* %s, align 8, !dbg !65 |
| 116 | + br label %for.inc, !dbg !66 |
| 117 | + |
| 118 | +for.inc: ; preds = %for.body |
| 119 | + %14 = load i32, i32* %u, align 4, !dbg !67 |
| 120 | + %inc = add nsw i32 %14, 1, !dbg !67 |
| 121 | + store i32 %inc, i32* %u, align 4, !dbg !67 |
| 122 | + br label %for.cond, !dbg !68 |
| 123 | + |
| 124 | +for.end: ; preds = %for.cond |
| 125 | + %15 = load double, double* %s, align 8, !dbg !69 |
| 126 | + store double %15, double* %result, align 8, !dbg !70 |
| 127 | + br label %if.end.13, !dbg !71 |
| 128 | + |
| 129 | +if.else: ; preds = %if.end |
| 130 | + %16 = load i8**, i8*** %argv.addr, align 8, !dbg !72 |
| 131 | + %arrayidx10 = getelementptr inbounds i8*, i8** %16, i64 2, !dbg !72 |
| 132 | + %17 = load i8*, i8** %arrayidx10, align 8, !dbg !72 |
| 133 | + %call11 = call i32 @atoi(i8* %17) #4, !dbg !74 |
| 134 | + %conv12 = sitofp i32 %call11 to double, !dbg !74 |
| 135 | + store double %conv12, double* %result, align 8, !dbg !75 |
| 136 | + br label %if.end.13 |
| 137 | + |
| 138 | +if.end.13: ; preds = %if.else, %for.end |
| 139 | + %18 = load double, double* %result, align 8, !dbg !76 |
| 140 | + %call14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0), double %18), !dbg !77 |
| 141 | + store i32 0, i32* %retval, align 4, !dbg !78 |
| 142 | + br label %return, !dbg !78 |
| 143 | + |
| 144 | +return: ; preds = %if.end.13, %if.then |
| 145 | + %19 = load i32, i32* %retval, align 4, !dbg !79 |
| 146 | + ret i32 %19, !dbg !79 |
| 147 | +} |
| 148 | + |
| 149 | +; Function Attrs: nounwind readnone |
| 150 | +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 |
| 151 | + |
| 152 | +; Function Attrs: nounwind readonly |
| 153 | +declare i32 @atoi(i8*) #2 |
| 154 | + |
| 155 | +declare i32 @printf(i8*, ...) #3 |
| 156 | + |
| 157 | +; Function Attrs: nounwind readnone willreturn |
| 158 | +declare i32 @llvm.expect.i32(i32, i32) #5 |
| 159 | + |
| 160 | + |
| 161 | +attributes #0 = { 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"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" "use-sample-profile" } |
| 162 | +attributes #1 = { nounwind readnone } |
| 163 | +attributes #2 = { nounwind readonly "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"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 164 | +attributes #3 = { "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"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 165 | +attributes #4 = { nounwind readonly } |
| 166 | +attributes #5 = { nounwind readnone willreturn } |
| 167 | + |
| 168 | +!llvm.dbg.cu = !{!0} |
| 169 | +!llvm.module.flags = !{!13, !14} |
| 170 | +!llvm.ident = !{!15} |
| 171 | + |
| 172 | +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 248211) (llvm/trunk 248217)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2, retainedTypes: !3) |
| 173 | +!1 = !DIFile(filename: "test.cc", directory: "/ssd/llvm_commit") |
| 174 | +!2 = !{} |
| 175 | +!3 = !{!4} |
| 176 | +!4 = !DIBasicType(name: "double", size: 64, align: 64, encoding: DW_ATE_float) |
| 177 | +!6 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !7, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2) |
| 178 | +!7 = !DISubroutineType(types: !8) |
| 179 | +!8 = !{!9, !9, !10} |
| 180 | +!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) |
| 181 | +!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64, align: 64) |
| 182 | +!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, align: 64) |
| 183 | +!12 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) |
| 184 | +!13 = !{i32 2, !"Dwarf Version", i32 4} |
| 185 | +!14 = !{i32 2, !"Debug Info Version", i32 3} |
| 186 | +!15 = !{!"clang version 3.8.0 (trunk 248211) (llvm/trunk 248217)"} |
| 187 | +!16 = !DILocalVariable(name: "argc", arg: 1, scope: !6, file: !1, line: 4, type: !9) |
| 188 | +!17 = !DIExpression() |
| 189 | +!18 = !DILocation(line: 4, column: 15, scope: !6) |
| 190 | +!19 = !DILocalVariable(name: "argv", arg: 2, scope: !6, file: !1, line: 4, type: !10) |
| 191 | +!20 = !DILocation(line: 4, column: 27, scope: !6) |
| 192 | +!21 = !DILocation(line: 5, column: 8, scope: !22) |
| 193 | +!22 = distinct !DILexicalBlock(scope: !6, file: !1, line: 5, column: 8) |
| 194 | +!23 = !DILocation(line: 5, column: 13, scope: !22) |
| 195 | +!24 = !DILocation(line: 5, column: 8, scope: !6) |
| 196 | +!25 = !DILocation(line: 6, column: 6, scope: !22) |
| 197 | +!26 = !DILocalVariable(name: "result", scope: !6, file: !1, line: 7, type: !4) |
| 198 | +!27 = !DILocation(line: 7, column: 11, scope: !6) |
| 199 | +!28 = !DILocalVariable(name: "limit", scope: !6, file: !1, line: 8, type: !9) |
| 200 | +!29 = !DILocation(line: 8, column: 8, scope: !6) |
| 201 | +!30 = !DILocation(line: 8, column: 21, scope: !6) |
| 202 | +!31 = !DILocation(line: 8, column: 16, scope: !6) |
| 203 | +!32 = !DILocation(line: 9, column: 8, scope: !33) |
| 204 | +!33 = distinct !DILexicalBlock(scope: !6, file: !1, line: 9, column: 8) |
| 205 | +!34 = !DILocation(line: 9, column: 14, scope: !33) |
| 206 | +!35 = !DILocation(line: 9, column: 8, scope: !6) |
| 207 | +!36 = !DILocalVariable(name: "s", scope: !37, file: !1, line: 10, type: !4) |
| 208 | +!37 = distinct !DILexicalBlock(scope: !33, file: !1, line: 9, column: 21) |
| 209 | +!38 = !DILocation(line: 10, column: 13, scope: !37) |
| 210 | +!39 = !DILocation(line: 10, column: 34, scope: !37) |
| 211 | +!40 = !DILocation(line: 10, column: 29, scope: !37) |
| 212 | +!41 = !DILocation(line: 10, column: 27, scope: !37) |
| 213 | +!42 = !DILocalVariable(name: "u", scope: !43, file: !1, line: 11, type: !9) |
| 214 | +!43 = distinct !DILexicalBlock(scope: !37, file: !1, line: 11, column: 6) |
| 215 | +!44 = !DILocation(line: 11, column: 15, scope: !43) |
| 216 | +!45 = !DILocation(line: 11, column: 11, scope: !43) |
| 217 | +!46 = !DILocation(line: 11, column: 22, scope: !47) |
| 218 | +!47 = distinct !DILexicalBlock(scope: !43, file: !1, line: 11, column: 6) |
| 219 | +!48 = !DILocation(line: 11, column: 26, scope: !47) |
| 220 | +!49 = !DILocation(line: 11, column: 24, scope: !47) |
| 221 | +!50 = !DILocation(line: 11, column: 6, scope: !43) |
| 222 | +!51 = !DILocalVariable(name: "x", scope: !52, file: !1, line: 12, type: !4) |
| 223 | +!52 = distinct !DILexicalBlock(scope: !47, file: !1, line: 11, column: 38) |
| 224 | +!53 = !DILocation(line: 12, column: 15, scope: !52) |
| 225 | +!54 = !DILocation(line: 12, column: 19, scope: !52) |
| 226 | +!55 = !DILocation(line: 13, column: 12, scope: !52) |
| 227 | +!56 = !DILocation(line: 13, column: 14, scope: !52) |
| 228 | +!57 = !DILocation(line: 13, column: 32, scope: !52) |
| 229 | +!58 = !DILocation(line: 13, column: 22, scope: !52) |
| 230 | +!59 = !DILocation(line: 13, column: 10, scope: !52) |
| 231 | +!60 = !DILocation(line: 14, column: 13, scope: !52) |
| 232 | +!61 = !DILocation(line: 14, column: 24, scope: !52) |
| 233 | +!62 = !DILocation(line: 14, column: 22, scope: !52) |
| 234 | +!63 = !DILocation(line: 14, column: 26, scope: !52) |
| 235 | +!64 = !DILocation(line: 14, column: 15, scope: !52) |
| 236 | +!65 = !DILocation(line: 14, column: 10, scope: !52) |
| 237 | +!66 = !DILocation(line: 15, column: 6, scope: !52) |
| 238 | +!67 = !DILocation(line: 11, column: 34, scope: !47) |
| 239 | +!68 = !DILocation(line: 11, column: 6, scope: !47) |
| 240 | +!69 = !DILocation(line: 16, column: 15, scope: !37) |
| 241 | +!70 = !DILocation(line: 16, column: 13, scope: !37) |
| 242 | +!71 = !DILocation(line: 17, column: 4, scope: !37) |
| 243 | +!72 = !DILocation(line: 18, column: 20, scope: !73) |
| 244 | +!73 = distinct !DILexicalBlock(scope: !33, file: !1, line: 17, column: 11) |
| 245 | +!74 = !DILocation(line: 18, column: 15, scope: !73) |
| 246 | +!75 = !DILocation(line: 18, column: 13, scope: !73) |
| 247 | +!76 = !DILocation(line: 20, column: 30, scope: !6) |
| 248 | +!77 = !DILocation(line: 20, column: 4, scope: !6) |
| 249 | +!78 = !DILocation(line: 21, column: 4, scope: !6) |
| 250 | +!79 = !DILocation(line: 22, column: 2, scope: !6) |
0 commit comments