114 lines · plain
1; Test that misexpect diagnostics are emtted when profile branch weights are2; below the branch weights added by llvm.expect intrinsics3 4; RUN: llvm-profdata merge %S/Inputs/misexpect-branch.proftext -o %t.profdata5 6; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING7; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK8; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH9; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED10; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -misexpect-tolerance=81 -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=THRESHOLD11 12; WARNING-DAG: warning: misexpect-branch.c:22:0: 19.98%13; WARNING-NOT: remark: misexpect-branch.c:22:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions.14 15; REMARK-NOT: warning: misexpect-branch.c:22:0: 19.98%16; REMARK-DAG: remark: misexpect-branch.c:22:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions.17 18; BOTH-DAG: warning: misexpect-branch.c:22:0: 19.98%19; BOTH-DAG: remark: misexpect-branch.c:22:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions.20 21; DISABLED-NOT: warning: misexpect-branch.c:22:0: 19.98%22; DISABLED-NOT: remark: misexpect-branch.c:22:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions.23 24; THRESHOLD-NOT: warning: misexpect-branch.c:22:0: 19.98%25; THRESHOLD-NOT: remark: misexpect-branch.c:22:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions.26 27; ModuleID = 'misexpect-branch.c'28source_filename = "misexpect-branch.c"29target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"30target triple = "x86_64-unknown-linux-gnu"31 32@inner_loop = constant i32 100, align 433@outer_loop = constant i32 2000, align 434 35; Function Attrs: nounwind36define i32 @bar() !dbg !6 {37entry:38 %rando = alloca i32, align 439 %x = alloca i32, align 440 call void @llvm.lifetime.start.p0(ptr %rando), !dbg !941 %call = call i32 (...) @buzz(), !dbg !942 store i32 %call, ptr %rando, align 4, !dbg !9, !tbaa !1043 call void @llvm.lifetime.start.p0(ptr %x), !dbg !1444 store i32 0, ptr %x, align 4, !dbg !14, !tbaa !1045 %0 = load i32, ptr %rando, align 4, !dbg !15, !tbaa !1046 %rem = srem i32 %0, 200000, !dbg !1547 %cmp = icmp eq i32 %rem, 0, !dbg !1548 %lnot = xor i1 %cmp, true, !dbg !1549 %lnot1 = xor i1 %lnot, true, !dbg !1550 %lnot.ext = zext i1 %lnot1 to i32, !dbg !1551 %conv = sext i32 %lnot.ext to i64, !dbg !1552 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1), !dbg !1553 %tobool = icmp ne i64 %expval, 0, !dbg !1554 br i1 %tobool, label %if.then, label %if.else, !dbg !1555 56if.then: ; preds = %entry57 %1 = load i32, ptr %rando, align 4, !dbg !16, !tbaa !1058 %call2 = call i32 @baz(i32 %1), !dbg !1659 store i32 %call2, ptr %x, align 4, !dbg !16, !tbaa !1060 br label %if.end, !dbg !1761 62if.else: ; preds = %entry63 %call3 = call i32 @foo(i32 50), !dbg !1864 store i32 %call3, ptr %x, align 4, !dbg !18, !tbaa !1065 br label %if.end66 67if.end: ; preds = %if.else, %if.then68 %2 = load i32, ptr %x, align 4, !dbg !19, !tbaa !1069 call void @llvm.lifetime.end.p0(ptr %x), !dbg !2070 call void @llvm.lifetime.end.p0(ptr %rando), !dbg !2071 ret i32 %2, !dbg !1972}73 74; Function Attrs: argmemonly nounwind willreturn75declare void @llvm.lifetime.start.p0(ptr nocapture)76 77declare i32 @buzz(...)78 79; Function Attrs: nounwind readnone willreturn80declare i64 @llvm.expect.i64(i64, i64)81 82declare i32 @baz(i32)83 84declare i32 @foo(i32)85 86; Function Attrs: argmemonly nounwind willreturn87declare void @llvm.lifetime.end.p0(ptr nocapture)88 89!llvm.dbg.cu = !{!0}90!llvm.module.flags = !{!3, !4}91!llvm.ident = !{!5}92 93!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (trunk c20270bfffc9d6965219de339d66c61e9fe7d82d)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, nameTableKind: None)94!1 = !DIFile(filename: "<stdin>", directory: ".")95!2 = !{}96!3 = !{i32 2, !"Debug Info Version", i32 3}97!4 = !{i32 1, !"wchar_size", i32 4}98!5 = !{!"clang version 10.0.0 (trunk c20270bfffc9d6965219de339d66c61e9fe7d82d)"}99!6 = distinct !DISubprogram(name: "bar", scope: !7, file: !7, line: 19, type: !8, scopeLine: 19, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)100!7 = !DIFile(filename: "misexpect-branch.c", directory: ".")101!8 = !DISubroutineType(types: !2)102!9 = !DILocation(line: 20, scope: !6)103!10 = !{!11, !11, i64 0}104!11 = !{!"int", !12, i64 0}105!12 = !{!"omnipotent char", !13, i64 0}106!13 = !{!"Simple C/C++ TBAA"}107!14 = !DILocation(line: 21, scope: !6)108!15 = !DILocation(line: 22, scope: !6)109!16 = !DILocation(line: 23, scope: !6)110!17 = !DILocation(line: 24, scope: !6)111!18 = !DILocation(line: 25, scope: !6)112!19 = !DILocation(line: 27, scope: !6)113!20 = !DILocation(line: 28, scope: !6)114