Skip to content

[BOLT][test] Add pseudo-probe-split-func.test #139305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aaupov
Copy link
Contributor

@aaupov aaupov commented May 9, 2025

Add a test checking if pseudo probes can be encoded and decoded with
function splitting in BOLT.

Test Plan: bin/llvm-lit -a tools/bolt/test/X86/pseudo-probe-split-func.test

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented May 9, 2025

@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)

Changes

Add a test checking if pseudo probes can be encoded and decoded with
function splitting in BOLT.

Test Plan: bin/llvm-lit -a tools/bolt/test/X86/pseudo-probe-split-func.test


Full diff: https://github.com/llvm/llvm-project/pull/139305.diff

2 Files Affected:

  • (added) bolt/test/X86/Inputs/pseudo-probe-split-func.c (+20)
  • (added) bolt/test/X86/pseudo-probe-split-func.test (+18)
diff --git a/bolt/test/X86/Inputs/pseudo-probe-split-func.c b/bolt/test/X86/Inputs/pseudo-probe-split-func.c
new file mode 100644
index 0000000000000..3f0edb3342178
--- /dev/null
+++ b/bolt/test/X86/Inputs/pseudo-probe-split-func.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+int bar(int x, int y) {
+  if (x % 3) {
+    return x - y;
+  }
+  return x + y;
+}
+
+void foo() {
+  int s, i = 0;
+  while (i++ < 4000 * 4000)
+    if (i % 91) s = bar(i, s); else s += 30;
+  printf("sum is %d\n", s);
+}
+
+int main() {
+  foo();
+  return 0;
+}
diff --git a/bolt/test/X86/pseudo-probe-split-func.test b/bolt/test/X86/pseudo-probe-split-func.test
new file mode 100644
index 0000000000000..0bce3eb82bb36
--- /dev/null
+++ b/bolt/test/X86/pseudo-probe-split-func.test
@@ -0,0 +1,18 @@
+## This test checks if pseudo probes are present in split fragments
+RUN: %clang %cflags %p/Inputs/pseudo-probe-split-func.c -o %t \
+RUN:   -O3 -fuse-ld=lld -fpseudo-probe-for-profiling -fno-omit-frame-pointer \
+RUN:   -mno-omit-leaf-frame-pointer -g -Wl,-q
+## Test pseudo probe encoding when hot fragments are emitted before cold
+RUN: llvm-bolt %t -o %t.out -split-functions --split-strategy=all -lite=0
+RUN: llvm-profgen --binary=%t.out --perfscript=1 --output=%t.null \
+RUN:   --show-disassembly-only --show-pseudo-probe | FileCheck %s
+## Test pseudo probe encoding when cold fragments are emitted before hot
+RUN: llvm-bolt %t -o %t.cold -split-functions --split-strategy=all -lite=0 \
+RUN:   --hot-functions-at-end
+RUN: llvm-profgen --binary=%t.cold --perfscript=1 --output=%t.null \
+RUN:   --show-disassembly-only --show-pseudo-probe | FileCheck %s
+CHECK: Disassembly of section .text.cold.3
+CHECK: <foo.cold.3>:
+CHECK: [Probe]:       FUNC: foo Index: 8  Type: Block
+CHECK: <main.cold.3>:
+CHECK: [Probe]:       FUNC: foo Index: 8  Type: Block  Inlined: @ main:2

Copy link

github-actions bot commented May 9, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions c -- bolt/test/X86/Inputs/pseudo-probe-split-func.c
View the diff from clang-format here.
diff --git a/bolt/test/X86/Inputs/pseudo-probe-split-func.c b/bolt/test/X86/Inputs/pseudo-probe-split-func.c
index 3f0edb334..8adf3bfc3 100644
--- a/bolt/test/X86/Inputs/pseudo-probe-split-func.c
+++ b/bolt/test/X86/Inputs/pseudo-probe-split-func.c
@@ -10,7 +10,10 @@ int bar(int x, int y) {
 void foo() {
   int s, i = 0;
   while (i++ < 4000 * 4000)
-    if (i % 91) s = bar(i, s); else s += 30;
+    if (i % 91)
+      s = bar(i, s);
+    else
+      s += 30;
   printf("sum is %d\n", s);
 }
 

Copy link
Contributor

@maksfb maksfb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the test under x86?

There are several implicit assumptions about the compiled code in the test, such as the function being inlined and not optimized away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants