1bac6cd5bSPaul Kirth; Test that misexpect diagnostics are emtted when profile branch weights are 2bac6cd5bSPaul Kirth; below the branch weights added by llvm.expect intrinsics 3bac6cd5bSPaul Kirth 4bac6cd5bSPaul Kirth; RUN: llvm-profdata merge %S/Inputs/misexpect-branch.proftext -o %t.profdata 5bac6cd5bSPaul Kirth 6bac6cd5bSPaul Kirth; 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=WARNING 7bac6cd5bSPaul Kirth; 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=REMARK 8bac6cd5bSPaul Kirth; 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=BOTH 9bac6cd5bSPaul Kirth; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED 10bac6cd5bSPaul Kirth; 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=THRESHOLD 11bac6cd5bSPaul Kirth 12bac6cd5bSPaul Kirth; WARNING-DAG: warning: misexpect-branch.c:22:0: 19.98% 13bac6cd5bSPaul Kirth; 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. 14bac6cd5bSPaul Kirth 15bac6cd5bSPaul Kirth; REMARK-NOT: warning: misexpect-branch.c:22:0: 19.98% 16bac6cd5bSPaul Kirth; 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. 17bac6cd5bSPaul Kirth 18bac6cd5bSPaul Kirth; BOTH-DAG: warning: misexpect-branch.c:22:0: 19.98% 19bac6cd5bSPaul Kirth; 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. 20bac6cd5bSPaul Kirth 21bac6cd5bSPaul Kirth; DISABLED-NOT: warning: misexpect-branch.c:22:0: 19.98% 22bac6cd5bSPaul Kirth; 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. 23bac6cd5bSPaul Kirth 24bac6cd5bSPaul Kirth; THRESHOLD-NOT: warning: misexpect-branch.c:22:0: 19.98% 25bac6cd5bSPaul Kirth; 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. 26bac6cd5bSPaul Kirth 27bac6cd5bSPaul Kirth; ModuleID = 'misexpect-branch.c' 28bac6cd5bSPaul Kirthsource_filename = "misexpect-branch.c" 29bac6cd5bSPaul Kirthtarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 30bac6cd5bSPaul Kirthtarget triple = "x86_64-unknown-linux-gnu" 31bac6cd5bSPaul Kirth 32bac6cd5bSPaul Kirth@inner_loop = constant i32 100, align 4 33bac6cd5bSPaul Kirth@outer_loop = constant i32 2000, align 4 34bac6cd5bSPaul Kirth 35bac6cd5bSPaul Kirth; Function Attrs: nounwind 36bac6cd5bSPaul Kirthdefine i32 @bar() #0 !dbg !6 { 37bac6cd5bSPaul Kirthentry: 38bac6cd5bSPaul Kirth %rando = alloca i32, align 4 39bac6cd5bSPaul Kirth %x = alloca i32, align 4 40*9ff36df5SFangrui Song call void @llvm.lifetime.start.p0(i64 4, ptr %rando) #4, !dbg !9 41bac6cd5bSPaul Kirth %call = call i32 (...) @buzz(), !dbg !9 42*9ff36df5SFangrui Song store i32 %call, ptr %rando, align 4, !dbg !9, !tbaa !10 43*9ff36df5SFangrui Song call void @llvm.lifetime.start.p0(i64 4, ptr %x) #4, !dbg !14 44*9ff36df5SFangrui Song store i32 0, ptr %x, align 4, !dbg !14, !tbaa !10 45*9ff36df5SFangrui Song %0 = load i32, ptr %rando, align 4, !dbg !15, !tbaa !10 46*9ff36df5SFangrui Song %rem = srem i32 %0, 200000, !dbg !15 47bac6cd5bSPaul Kirth %cmp = icmp eq i32 %rem, 0, !dbg !15 48bac6cd5bSPaul Kirth %lnot = xor i1 %cmp, true, !dbg !15 49bac6cd5bSPaul Kirth %lnot1 = xor i1 %lnot, true, !dbg !15 50bac6cd5bSPaul Kirth %lnot.ext = zext i1 %lnot1 to i32, !dbg !15 51bac6cd5bSPaul Kirth %conv = sext i32 %lnot.ext to i64, !dbg !15 52bac6cd5bSPaul Kirth %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1), !dbg !15 53bac6cd5bSPaul Kirth %tobool = icmp ne i64 %expval, 0, !dbg !15 54bac6cd5bSPaul Kirth br i1 %tobool, label %if.then, label %if.else, !dbg !15 55bac6cd5bSPaul Kirth 56bac6cd5bSPaul Kirthif.then: ; preds = %entry 57*9ff36df5SFangrui Song %1 = load i32, ptr %rando, align 4, !dbg !16, !tbaa !10 58*9ff36df5SFangrui Song %call2 = call i32 @baz(i32 %1), !dbg !16 59*9ff36df5SFangrui Song store i32 %call2, ptr %x, align 4, !dbg !16, !tbaa !10 60bac6cd5bSPaul Kirth br label %if.end, !dbg !17 61bac6cd5bSPaul Kirth 62bac6cd5bSPaul Kirthif.else: ; preds = %entry 63bac6cd5bSPaul Kirth %call3 = call i32 @foo(i32 50), !dbg !18 64*9ff36df5SFangrui Song store i32 %call3, ptr %x, align 4, !dbg !18, !tbaa !10 65bac6cd5bSPaul Kirth br label %if.end 66bac6cd5bSPaul Kirth 67bac6cd5bSPaul Kirthif.end: ; preds = %if.else, %if.then 68*9ff36df5SFangrui Song %2 = load i32, ptr %x, align 4, !dbg !19, !tbaa !10 69*9ff36df5SFangrui Song call void @llvm.lifetime.end.p0(i64 4, ptr %x) #4, !dbg !20 70*9ff36df5SFangrui Song call void @llvm.lifetime.end.p0(i64 4, ptr %rando) #4, !dbg !20 71*9ff36df5SFangrui Song ret i32 %2, !dbg !19 72bac6cd5bSPaul Kirth} 73bac6cd5bSPaul Kirth 74bac6cd5bSPaul Kirth; Function Attrs: argmemonly nounwind willreturn 75*9ff36df5SFangrui Songdeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1 76bac6cd5bSPaul Kirth 77bac6cd5bSPaul Kirthdeclare i32 @buzz(...) #2 78bac6cd5bSPaul Kirth 79bac6cd5bSPaul Kirth; Function Attrs: nounwind readnone willreturn 80bac6cd5bSPaul Kirthdeclare i64 @llvm.expect.i64(i64, i64) #3 81bac6cd5bSPaul Kirth 82bac6cd5bSPaul Kirthdeclare i32 @baz(i32) #2 83bac6cd5bSPaul Kirth 84bac6cd5bSPaul Kirthdeclare i32 @foo(i32) #2 85bac6cd5bSPaul Kirth 86bac6cd5bSPaul Kirth; Function Attrs: argmemonly nounwind willreturn 87*9ff36df5SFangrui Songdeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1 88bac6cd5bSPaul Kirth 89bac6cd5bSPaul Kirthattributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } 90bac6cd5bSPaul Kirthattributes #1 = { argmemonly nounwind willreturn } 91bac6cd5bSPaul Kirthattributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } 92bac6cd5bSPaul Kirthattributes #3 = { nounwind readnone willreturn } 93bac6cd5bSPaul Kirthattributes #4 = { nounwind } 94bac6cd5bSPaul Kirth 95bac6cd5bSPaul Kirth!llvm.dbg.cu = !{!0} 96bac6cd5bSPaul Kirth!llvm.module.flags = !{!3, !4} 97bac6cd5bSPaul Kirth!llvm.ident = !{!5} 98bac6cd5bSPaul Kirth 99bac6cd5bSPaul Kirth!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) 100bac6cd5bSPaul Kirth!1 = !DIFile(filename: "<stdin>", directory: ".") 101bac6cd5bSPaul Kirth!2 = !{} 102bac6cd5bSPaul Kirth!3 = !{i32 2, !"Debug Info Version", i32 3} 103bac6cd5bSPaul Kirth!4 = !{i32 1, !"wchar_size", i32 4} 104bac6cd5bSPaul Kirth!5 = !{!"clang version 10.0.0 (trunk c20270bfffc9d6965219de339d66c61e9fe7d82d)"} 105bac6cd5bSPaul Kirth!6 = distinct !DISubprogram(name: "bar", scope: !7, file: !7, line: 19, type: !8, scopeLine: 19, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 106bac6cd5bSPaul Kirth!7 = !DIFile(filename: "misexpect-branch.c", directory: ".") 107bac6cd5bSPaul Kirth!8 = !DISubroutineType(types: !2) 108bac6cd5bSPaul Kirth!9 = !DILocation(line: 20, scope: !6) 109bac6cd5bSPaul Kirth!10 = !{!11, !11, i64 0} 110bac6cd5bSPaul Kirth!11 = !{!"int", !12, i64 0} 111bac6cd5bSPaul Kirth!12 = !{!"omnipotent char", !13, i64 0} 112bac6cd5bSPaul Kirth!13 = !{!"Simple C/C++ TBAA"} 113bac6cd5bSPaul Kirth!14 = !DILocation(line: 21, scope: !6) 114bac6cd5bSPaul Kirth!15 = !DILocation(line: 22, scope: !6) 115bac6cd5bSPaul Kirth!16 = !DILocation(line: 23, scope: !6) 116bac6cd5bSPaul Kirth!17 = !DILocation(line: 24, scope: !6) 117bac6cd5bSPaul Kirth!18 = !DILocation(line: 25, scope: !6) 118bac6cd5bSPaul Kirth!19 = !DILocation(line: 27, scope: !6) 119bac6cd5bSPaul Kirth!20 = !DILocation(line: 28, scope: !6) 120