[llvm-branch-commits] [clang] [misexpect] Support missing-annotations diagnostics from frontend profile data (PR #96524)
Paul Kirth via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Aug 21 17:19:39 PDT 2024
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/96524
>From 49aabf7bbc1cf30274c034b1cf2babc1fd851b31 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Thu, 22 Aug 2024 00:19:28 +0000
Subject: [PATCH] Use split-file in test, and add test for switch statements
Created using spr 1.3.4
---
.../missing-annotations-branch.proftext | 17 -----
.../test/Profile/missing-annotations-branch.c | 62 ++++++++++++++++++
.../test/Profile/missing-annotations-switch.c | 64 +++++++++++++++++++
clang/test/Profile/missing-annotations.c | 44 -------------
4 files changed, 126 insertions(+), 61 deletions(-)
delete mode 100644 clang/test/Profile/Inputs/missing-annotations-branch.proftext
create mode 100644 clang/test/Profile/missing-annotations-branch.c
create mode 100644 clang/test/Profile/missing-annotations-switch.c
delete mode 100644 clang/test/Profile/missing-annotations.c
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 81c857b9a84fb3..00000000000000
--- 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-annotations-branch.c b/clang/test/Profile/missing-annotations-branch.c
new file mode 100644
index 00000000000000..fa764d9238c8a7
--- /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 00000000000000..2d7ea0865ac8a1
--- /dev/null
+++ b/clang/test/Profile/missing-annotations-switch.c
@@ -0,0 +1,64 @@
+// 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 -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
+#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 ee6c120b210a07..00000000000000
--- 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;
-}
More information about the llvm-branch-commits
mailing list