diff options
| author | Paul Kirth <paulkirth@google.com> | 2024-08-22 00:19:55 +0000 |
|---|---|---|
| committer | Paul Kirth <paulkirth@google.com> | 2024-08-22 00:19:55 +0000 |
| commit | bdebd8ee20d048ed5e485e957deb3c897023090a (patch) | |
| tree | f84e38c00fa9efc4ef1205e1f9b20dac31689e3b | |
| parent | ba7ccf3d2a684ef32f17f40216f942967214f9b1 (diff) | |
| parent | 02cf37f0f6bdc8c8badaedde62f6d46ec80923f7 (diff) | |
Created using spr 1.3.4
| -rw-r--r-- | clang/test/Profile/Inputs/missing-annotation.proftext | 18 | ||||
| -rw-r--r-- | clang/test/Profile/Inputs/missing-annotations-branch.proftext | 17 | ||||
| -rw-r--r-- | clang/test/Profile/missing-annotation.c | 35 | ||||
| -rw-r--r-- | clang/test/Profile/missing-annotations-branch.c | 62 | ||||
| -rw-r--r-- | clang/test/Profile/missing-annotations-switch.c | 74 | ||||
| -rw-r--r-- | clang/test/Profile/missing-annotations.c | 44 |
6 files changed, 136 insertions, 114 deletions
diff --git a/clang/test/Profile/Inputs/missing-annotation.proftext b/clang/test/Profile/Inputs/missing-annotation.proftext deleted file mode 100644 index 0bf7158702e2..000000000000 --- a/clang/test/Profile/Inputs/missing-annotation.proftext +++ /dev/null @@ -1,18 +0,0 @@ -bar -# Func Hash: -11262309464 -# Num Counters: -2 -# Counter Values: -200000 -1 - -fizz -# Func Hash: -11262309464 -# Num Counters: -2 -# Counter Values: -200000 -1 - diff --git a/clang/test/Profile/Inputs/missing-annotations-branch.proftext b/clang/test/Profile/Inputs/missing-annotations-branch.proftext deleted file mode 100644 index 81c857b9a84f..000000000000 --- a/clang/test/Profile/Inputs/missing-annotations-branch.proftext +++ /dev/null @@ -1,17 +0,0 @@ -bar -# Func Hash: -11262309464 -# Num Counters: -2 -# Counter Values: -20000000 -0 - -fizz -# Func Hash: -11262309464 -# Num Counters: -2 -# Counter Values: -0 -10000000000 diff --git a/clang/test/Profile/missing-annotation.c b/clang/test/Profile/missing-annotation.c deleted file mode 100644 index 5cf2a87a94c8..000000000000 --- a/clang/test/Profile/missing-annotation.c +++ /dev/null @@ -1,35 +0,0 @@ -/// Test that missing annotation diagnostics are suggested for hot branches - -// note test diagnostics are issued when profiling data mis-matches annotations -// RUN: llvm-profdata merge %S/Inputs/missing-annotation.proftext -o %t.profdata -// RUN: %clang %s -O2 -c -S -emit-llvm -o - -fprofile-instr-use=%t.profdata -Xclang -verify=exact -fdiagnostics-missing-annotations -debug-info-kind=line-tables-only -Rpass=missing-annotations - -// foo-no-diagnostics - -int foo(int); -int baz(int); -int buzz(); - -const int inner_loop = 100; -const int outer_loop = 2000; -int bar() { - int rando = buzz(); - int x = 0; - if (rando % (outer_loop * inner_loop) == 0) { // exact-remark {{Extremely hot condition. Consider adding llvm.expect intrinsic}} - x = baz(rando); - } else { - x = foo(50); - } - return x; -} - -int fizz() { - int rando = buzz(); - int x = 0; - if (rando % (outer_loop * inner_loop) == 0) { // exact-remark {{Extremely hot condition. Consider adding llvm.expect intrinsic}} - x = baz(rando); - } else { - x = foo(50); - } - return x; -} diff --git a/clang/test/Profile/missing-annotations-branch.c b/clang/test/Profile/missing-annotations-branch.c new file mode 100644 index 000000000000..fa764d9238c8 --- /dev/null +++ b/clang/test/Profile/missing-annotations-branch.c @@ -0,0 +1,62 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: split-file %s %t + +/// Test that missing-annotations detects branches that are hot, but not annotated. +// RUN: llvm-profdata merge %t/a.proftext -o %t/profdata +// RUN: %clang_cc1 %t/a.c -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t/profdata -verify -mllvm -pgo-missing-annotations -Rpass=missing-annotations -fdiagnostics-misexpect-tolerance=10 + +/// Test that we don't report any diagnostics, if the threshold isn't exceeded. +// RUN: %clang_cc1 %t/a.c -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t/profdata -mllvm -pgo-missing-annotations -Rpass=missing-annotations 2>&1 | FileCheck -implicit-check-not=remark %s + +//--- a.c +// foo-no-diagnostics +#define UNLIKELY(x) __builtin_expect(!!(x), 0) + +int foo(int); +int baz(int); +int buzz(void); + +const int inner_loop = 100; +const int outer_loop = 2000; + +int bar(void) { // imprecise-remark-re {{Extremely hot condition. Consider adding llvm.expect intrinsic{{.*}}}} + int a = buzz(); + int x = 0; + if (a % (outer_loop * inner_loop) == 0) { // expected-remark {{Extremely hot condition. Consider adding llvm.expect intrinsic}} + x = baz(a); + } else { + x = foo(50); + } + return x; +} + +int fizz(void) { + int a = buzz(); + int x = 0; + if ((a % (outer_loop * inner_loop) == 0)) { // expected-remark-re {{Extremely hot condition. Consider adding llvm.expect intrinsic{{.*}}}}} + x = baz(a); + } else { + x = foo(50); + } + return x; +} + +//--- a.proftext +bar +# Func Hash: +11262309464 +# Num Counters: +2 +# Counter Values: +1901 +99 + +fizz +# Func Hash: +11262309464 +# Num Counters: +2 +# Counter Values: +1901 +99 + diff --git a/clang/test/Profile/missing-annotations-switch.c b/clang/test/Profile/missing-annotations-switch.c new file mode 100644 index 000000000000..585ba27888fc --- /dev/null +++ b/clang/test/Profile/missing-annotations-switch.c @@ -0,0 +1,74 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: split-file %s %t + +/// Test that missing-annotations detects switch conditions that are hot, but not annotated. +// RUN: llvm-profdata merge %t/a.proftext -o %t/profdata +// RUN: %clang_cc1 %t/a.c -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t/profdata -verify \ +// RUN: -mllvm -pgo-missing-annotations -Rpass=missing-annotations -fdiagnostics-misexpect-tolerance=10 +// RUN: %clang %t/a.c -O2 -c -o - -emit-llvm -fprofile-instr-use=%t/profdata -Xclang -verify \ +// RUN: -fdiagnostics-missing-annotations -Rpass=missing-annotations -fdiagnostics-misexpect-tolerance=10 \ +// RUN: -debug-info-kind=line-tables-only + +/// Test that we don't report any diagnostics, if the threshold isn't exceeded. +// RUN: %clang_cc1 %t/a.c -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t/profdata \ +// RUN: -mllvm -pgo-missing-annotations -Rpass=missing-annotations 2>&1 | \ +// RUN: FileCheck -implicit-check-not=remark %s +// RUN: %clang %t/a.c -O2 -c -o - -emit-llvm -fprofile-instr-use=%t/profdata \ +// RUN: -Xclang -fdiagnostics-missing-annotations -Rpass=missing-annotations \ +// RUN: -debug-info-kind=line-tables-only 2>&1 | \ +// RUN: FileCheck -implicit-check-not=remark %s + +//--- a.c +#define inner_loop 1000 +#define outer_loop 20 +#define arry_size 25 + +int arry[arry_size] = {0}; + +int rand(void); +int sum(int *buff, int size); +int random_sample(int *buff, int size); + +int main(void) { + int val = 0; + + int j, k; + for (j = 0; j < outer_loop; ++j) { + for (k = 0; k < inner_loop; ++k) { + unsigned condition = rand() % 10000; + switch (condition) { // expected-remark {{Extremely hot condition. Consider adding llvm.expect intrinsic}} + + case 0: + val += sum(arry, arry_size); + break; + case 1: + case 2: + case 3: + break; + default: + val += random_sample(arry, arry_size); + break; + } // end switch + } // end inner_loop + } // end outer_loop + + return val; +} + +//--- a.proftext +main +# Func Hash: +872687477373597607 +# Num Counters: +9 +# Counter Values: +2 +9 +2 +2 +3 +3 +1 +999 +18001 + diff --git a/clang/test/Profile/missing-annotations.c b/clang/test/Profile/missing-annotations.c deleted file mode 100644 index ee6c120b210a..000000000000 --- a/clang/test/Profile/missing-annotations.c +++ /dev/null @@ -1,44 +0,0 @@ -// Test that missing-annotations detects branches that are hot, but not annotated - -// test diagnostics are issued when profiling data mis-matches annotations -// RUN: llvm-profdata merge %S/Inputs/missing-annotations-branch.proftext -o %t.profdata -// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -mllvm -pgo-missing-annotations -Rpass=missing-annotations - -// Ensure we emit an error when we don't use pgo with tolerance threshold -// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fdiagnostics-misexpect-tolerance=10 -mllvm -pgo-missing-annotations -debug-info-kind=line-tables-only 2>&1 | FileCheck -check-prefix=NOPGO %s - -// Test -fdiagnostics-misexpect-tolerance= requires pgo profile -// NOPGO: '-fdiagnostics-misexpect-tolerance=' requires profile-guided optimization information - -// foo-no-diagnostics -#define UNLIKELY(x) __builtin_expect(!!(x), 0) - -int foo(int); -int baz(int); -int buzz(void); - -const int inner_loop = 100; -const int outer_loop = 2000; - -int bar(void) { // imprecise-remark-re {{Extremely hot condition. Consider adding llvm.expect intrinsic{{.*}}}} - - int rando = buzz(); - int x = 0; - if (rando % (outer_loop * inner_loop) == 0) { // expected-remark {{Extremely hot condition. Consider adding llvm.expect intrinsic}} - x = baz(rando); - } else { - x = foo(50); - } - return x; -} - -int fizz(void) { // - int rando = buzz(); - int x = 0; - if ((rando % (outer_loop * inner_loop) == 0)) { // expected-remark-re {{Extremely hot condition. Consider adding llvm.expect intrinsic{{.*}}}}} - x = baz(rando); - } else { - x = foo(50); - } - return x; -} |
