1 // Test that misexpect detects mis-annotated branches
3 // test diagnostics are issued when profiling data mis-matches annotations
4 // RUN: llvm-profdata merge %S/Inputs/misexpect-branch.proftext -o %t.profdata
5 // RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify=imprecise -Wmisexpect
6 // RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify=exact -Wmisexpect -debug-info-kind=line-tables-only
8 // there should be no diagnostics when the tolerance is sufficiently high, or when -Wmisexpect is not requested
9 // RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify=foo -fdiagnostics-misexpect-tolerance=10 -Wmisexpect -debug-info-kind=line-tables-only
10 // RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify=foo
12 // Ensure we emit an error when we don't use pgo with tolerance threshold
13 // RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fdiagnostics-misexpect-tolerance=10 -Wmisexpect -debug-info-kind=line-tables-only 2>&1 | FileCheck -check-prefix=NO_PGO %s
15 // Test -fdiagnostics-misexpect-tolerance= requires pgo profile
16 // NO_PGO: '-fdiagnostics-misexpect-tolerance=' requires profile-guided optimization information
19 #define likely(x) __builtin_expect(!!(x), 1)
20 #define unlikely(x) __builtin_expect(!!(x), 0)
26 const int inner_loop
= 100;
27 const int outer_loop
= 2000;
29 int bar() { // imprecise-warning-re {{potential performance regression from use of __builtin_expect(): annotation was correct on {{.+}}% ({{[0-9]+ / [0-9]+}}) of profiled executions}}
32 if (likely(rando
% (outer_loop
* inner_loop
) == 0)) { // exact-warning-re {{potential performance regression from use of __builtin_expect(): annotation was correct on {{.+}}% ({{[0-9]+ / [0-9]+}}) of profiled executions}}
40 int fizz() { // imprecise-warning-re {{potential performance regression from use of __builtin_expect(): annotation was correct on {{.+}}% ({{[0-9]+ / [0-9]+}}) of profiled executions}}
43 if (unlikely(rando
% (outer_loop
* inner_loop
) == 0)) { // exact-warning-re {{potential performance regression from use of __builtin_expect(): annotation was correct on {{.+}}% ({{[0-9]+ / [0-9]+}}) of profiled executions}}