[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Profile / misexpect-branch.c
blobce46b46880611d55c3d27266558ba0c5708b15d4
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
18 // foo-no-diagnostics
19 #define likely(x) __builtin_expect(!!(x), 1)
20 #define unlikely(x) __builtin_expect(!!(x), 0)
22 int foo(int);
23 int baz(int);
24 int buzz();
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.}}
30 int rando = buzz();
31 int x = 0;
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.}}
33 x = baz(rando);
34 } else {
35 x = foo(50);
37 return x;
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.}}
41 int rando = buzz();
42 int x = 0;
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.}}
44 x = baz(rando);
45 } else {
46 x = foo(50);
48 return x;