1 2; RUN: llvm-profdata merge %S/Inputs/misexpect-branch.proftext -o %t.profdata 3 4 5; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING 6; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK 7; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH 8; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED 9 10; New PM 11; 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 12; 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 13; 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 14; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED 15 16 17 18; WARNING-DAG: warning: <unknown>:0:0: 19.98% 19; WARNING-NOT: remark: <unknown>:0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions. 20 21; REMARK-NOT: warning: <unknown>:0:0: 19.98% 22; REMARK-DAG: remark: <unknown>:0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions. 23 24; BOTH-DAG: warning: <unknown>:0:0: 19.98% 25; BOTH-DAG: remark: <unknown>:0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions. 26 27; DISABLED-NOT: warning: <unknown>:0:0: 19.98% 28; DISABLED-NOT: remark: <unknown>:0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions. 29 30; CHECK-DAG: !{!"misexpect", i64 1, i64 2000, i64 1} 31 32 33 34; ModuleID = 'misexpect-branch.c' 35source_filename = "misexpect-branch.c" 36target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 37target triple = "x86_64-unknown-linux-gnu" 38 39@inner_loop = constant i32 100, align 4 40@outer_loop = constant i32 2000, align 4 41 42; Function Attrs: nounwind 43define i32 @bar() #0 { 44entry: 45 %rando = alloca i32, align 4 46 %x = alloca i32, align 4 47 %0 = bitcast i32* %rando to i8* 48 call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #4 49 %call = call i32 (...) @buzz() 50 store i32 %call, i32* %rando, align 4, !tbaa !3 51 %1 = bitcast i32* %x to i8* 52 call void @llvm.lifetime.start.p0i8(i64 4, i8* %1) #4 53 store i32 0, i32* %x, align 4, !tbaa !3 54 %2 = load i32, i32* %rando, align 4, !tbaa !3 55 %rem = srem i32 %2, 200000 56 %cmp = icmp eq i32 %rem, 0 57 %lnot = xor i1 %cmp, true 58 %lnot1 = xor i1 %lnot, true 59 %lnot.ext = zext i1 %lnot1 to i32 60 %conv = sext i32 %lnot.ext to i64 61 %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1) 62 %tobool = icmp ne i64 %expval, 0 63 br i1 %tobool, label %if.then, label %if.else 64 65if.then: ; preds = %entry 66 %3 = load i32, i32* %rando, align 4, !tbaa !3 67 %call2 = call i32 @baz(i32 %3) 68 store i32 %call2, i32* %x, align 4, !tbaa !3 69 br label %if.end 70 71if.else: ; preds = %entry 72 %call3 = call i32 @foo(i32 50) 73 store i32 %call3, i32* %x, align 4, !tbaa !3 74 br label %if.end 75 76if.end: ; preds = %if.else, %if.then 77 %4 = load i32, i32* %x, align 4, !tbaa !3 78 %5 = bitcast i32* %x to i8* 79 call void @llvm.lifetime.end.p0i8(i64 4, i8* %5) #4 80 %6 = bitcast i32* %rando to i8* 81 call void @llvm.lifetime.end.p0i8(i64 4, i8* %6) #4 82 ret i32 %4 83} 84 85; Function Attrs: argmemonly nounwind willreturn 86declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1 87 88declare i32 @buzz(...) #2 89 90; Function Attrs: nounwind readnone willreturn 91declare i64 @llvm.expect.i64(i64, i64) #3 92 93declare i32 @baz(i32) #2 94 95declare i32 @foo(i32) #2 96 97; Function Attrs: argmemonly nounwind willreturn 98declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1 99 100attributes #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" } 101attributes #1 = { argmemonly nounwind willreturn } 102attributes #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" } 103attributes #3 = { nounwind readnone willreturn } 104attributes #4 = { nounwind } 105 106!llvm.module.flags = !{!0, !1} 107!llvm.ident = !{!2} 108 109!0 = !{i32 2, !"Debug Info Version", i32 3} 110!1 = !{i32 1, !"wchar_size", i32 4} 111!2 = !{!"clang version 10.0.0 (trunk c20270bfffc9d6965219de339d66c61e9fe7d82d)"} 112!3 = !{!4, !4, i64 0} 113!4 = !{!"int", !5, i64 0} 114!5 = !{!"omnipotent char", !6, i64 0} 115!6 = !{!"Simple C/C++ TBAA"} 116