97 lines · plain
1; Ensure that profile counters that overflow are handled correctly.2; This can happen when the sum of all counters exceeds the max size of uint32_t3 4; RUN: llvm-profdata merge %S/Inputs/misexpect-branch-overflow.proftext -o %t.profdata5; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -unlikely-branch-weight=2147483648 -likely-branch-weight=2147483648 -S 2>&1 | FileCheck %s --check-prefix=OVERFLOW6 7; OVERFLOW-NOT: warning: misexpect-branch.c:22:0: 50.00%8; OVERFLOW-NOT: remark: misexpect-branch.c:22:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 50.00% (2147483648 / 4294967296) of profiled executions.9 10; ModuleID = 'misexpect-branch.c'11source_filename = "misexpect-branch.c"12target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"13target triple = "x86_64-unknown-linux-gnu"14 15@inner_loop = constant i32 100, align 416@outer_loop = constant i32 2000, align 417 18; Function Attrs: nounwind19define i32 @bar() !dbg !6 {20entry:21 %rando = alloca i32, align 422 %x = alloca i32, align 423 call void @llvm.lifetime.start.p0(ptr %rando), !dbg !924 %call = call i32 (...) @buzz(), !dbg !925 store i32 %call, ptr %rando, align 4, !dbg !9, !tbaa !1026 call void @llvm.lifetime.start.p0(ptr %x), !dbg !1427 store i32 0, ptr %x, align 4, !dbg !14, !tbaa !1028 %0 = load i32, ptr %rando, align 4, !dbg !15, !tbaa !1029 %rem = srem i32 %0, 200000, !dbg !1530 %cmp = icmp eq i32 %rem, 0, !dbg !1531 %lnot = xor i1 %cmp, true, !dbg !1532 %lnot1 = xor i1 %lnot, true, !dbg !1533 %lnot.ext = zext i1 %lnot1 to i32, !dbg !1534 %conv = sext i32 %lnot.ext to i64, !dbg !1535 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1), !dbg !1536 %tobool = icmp ne i64 %expval, 0, !dbg !1537 br i1 %tobool, label %if.then, label %if.else, !dbg !1538 39if.then: ; preds = %entry40 %1 = load i32, ptr %rando, align 4, !dbg !16, !tbaa !1041 %call2 = call i32 @baz(i32 %1), !dbg !1642 store i32 %call2, ptr %x, align 4, !dbg !16, !tbaa !1043 br label %if.end, !dbg !1744 45if.else: ; preds = %entry46 %call3 = call i32 @foo(i32 50), !dbg !1847 store i32 %call3, ptr %x, align 4, !dbg !18, !tbaa !1048 br label %if.end49 50if.end: ; preds = %if.else, %if.then51 %2 = load i32, ptr %x, align 4, !dbg !19, !tbaa !1052 call void @llvm.lifetime.end.p0(ptr %x), !dbg !2053 call void @llvm.lifetime.end.p0(ptr %rando), !dbg !2054 ret i32 %2, !dbg !1955}56 57; Function Attrs: argmemonly nounwind willreturn58declare void @llvm.lifetime.start.p0(ptr nocapture)59 60declare i32 @buzz(...)61 62; Function Attrs: nounwind readnone willreturn63declare i64 @llvm.expect.i64(i64, i64)64 65declare i32 @baz(i32)66 67declare i32 @foo(i32)68 69; Function Attrs: argmemonly nounwind willreturn70declare void @llvm.lifetime.end.p0(ptr nocapture)71 72!llvm.dbg.cu = !{!0}73!llvm.module.flags = !{!3, !4}74!llvm.ident = !{!5}75 76!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)77!1 = !DIFile(filename: "<stdin>", directory: ".")78!2 = !{}79!3 = !{i32 2, !"Debug Info Version", i32 3}80!4 = !{i32 1, !"wchar_size", i32 4}81!5 = !{!"clang version 10.0.0 (trunk c20270bfffc9d6965219de339d66c61e9fe7d82d)"}82!6 = distinct !DISubprogram(name: "bar", scope: !7, file: !7, line: 19, type: !8, scopeLine: 19, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)83!7 = !DIFile(filename: "misexpect-branch.c", directory: ".")84!8 = !DISubroutineType(types: !2)85!9 = !DILocation(line: 20, scope: !6)86!10 = !{!11, !11, i64 0}87!11 = !{!"int", !12, i64 0}88!12 = !{!"omnipotent char", !13, i64 0}89!13 = !{!"Simple C/C++ TBAA"}90!14 = !DILocation(line: 21, scope: !6)91!15 = !DILocation(line: 22, scope: !6)92!16 = !DILocation(line: 23, scope: !6)93!17 = !DILocation(line: 24, scope: !6)94!18 = !DILocation(line: 25, scope: !6)95!19 = !DILocation(line: 27, scope: !6)96!20 = !DILocation(line: 28, scope: !6)97