brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · fb72250 Raw
50 lines · c
1// Test that misexpect detects mis-annotated branches2 3// test diagnostics are issued when profiling data mis-matches annotations4// RUN: llvm-profdata merge %S/Inputs/misexpect-branch.proftext -o %t.profdata5// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata -verify=imprecise -Wmisexpect6// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata -verify=exact -Wmisexpect -debug-info-kind=line-tables-only7 8// there should be no diagnostics when the tolerance is sufficiently high, or when -Wmisexpect is not requested9// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata -verify=foo -fdiagnostics-misexpect-tolerance=10 -Wmisexpect -debug-info-kind=line-tables-only10// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata -verify=foo11 12// Ensure we emit an error when we don't use pgo with tolerance threshold13// 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 %s14 15// Test -fdiagnostics-misexpect-tolerance=  requires pgo profile16// NO_PGO: '-fdiagnostics-misexpect-tolerance=' requires profile-guided optimization information17 18// foo-no-diagnostics19#define likely(x) __builtin_expect(!!(x), 1)20#define unlikely(x) __builtin_expect(!!(x), 0)21 22int foo(int);23int baz(int);24int buzz();25 26const int inner_loop = 100;27const int outer_loop = 2000;28 29int 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);36  }37  return x;38}39 40int 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);47  }48  return x;49}50