[llvm-branch-commits] [BOLT] Add tests for pre-aggregated parsing (PR #193843)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Apr 24 22:51:43 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Amir Ayupov (aaupov)
<details>
<summary>Changes</summary>
Extends e2e coverage of pre-aggregated profile parsing to match the
unit-test coverage added in #<!-- -->192390:
- R (Return) records, including the branch=0 fallback path that
rewrites to the FT_EXTERNAL_RETURN sentinel.
- r (FT_EXTERNAL_RETURN) records.
- B and T records using the negative -1 hex form (#<!-- -->192391),
which is parsed as the BR_ONLY/FT_ONLY sentinel.
- Error paths: invalid record type letter and malformed hex address
(perf2bolt is expected to exit non-zero with a parser error).
The two error-path inputs are tiny raw files under Inputs/ since they
contain intentionally malformed records that link_fdata doesn't process.
Test Plan:
added bolt/test/X86/pre-aggregated-records.s
---
Full diff: https://github.com/llvm/llvm-project/pull/193843.diff
3 Files Affected:
- (added) bolt/test/X86/Inputs/pre-aggregated-bad-hex.txt (+1)
- (added) bolt/test/X86/Inputs/pre-aggregated-bad-type.txt (+1)
- (added) bolt/test/X86/pre-aggregated-records.s (+60)
``````````diff
diff --git a/bolt/test/X86/Inputs/pre-aggregated-bad-hex.txt b/bolt/test/X86/Inputs/pre-aggregated-bad-hex.txt
new file mode 100644
index 0000000000000..6039fec8af02d
--- /dev/null
+++ b/bolt/test/X86/Inputs/pre-aggregated-bad-hex.txt
@@ -0,0 +1 @@
+B notahex 200 1 0
diff --git a/bolt/test/X86/Inputs/pre-aggregated-bad-type.txt b/bolt/test/X86/Inputs/pre-aggregated-bad-type.txt
new file mode 100644
index 0000000000000..00af6f4763a5b
--- /dev/null
+++ b/bolt/test/X86/Inputs/pre-aggregated-bad-type.txt
@@ -0,0 +1 @@
+Z 100 200 1 0
diff --git a/bolt/test/X86/pre-aggregated-records.s b/bolt/test/X86/pre-aggregated-records.s
new file mode 100644
index 0000000000000..98fcf08c677fd
--- /dev/null
+++ b/bolt/test/X86/pre-aggregated-records.s
@@ -0,0 +1,60 @@
+## Test parsing of R (Return), r (FT_EXTERNAL_RETURN), and -1 hex (BR_ONLY)
+## records in pre-aggregated profiles, plus error paths for invalid record
+## types and malformed hex addresses. Closes e2e gaps that were previously
+## only exercised by unit tests.
+
+# REQUIRES: system-linux
+
+# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
+# RUN: ld.lld %t.o -o %t
+# RUN: link_fdata %s %t %t.preagg PREAGG
+
+## Parse R, r, B-with-neg1, T-with-neg1, plus a regular F as a sanity check.
+# RUN: perf2bolt %t -p %t.preagg --pa -o %t.fdata 2>&1 \
+# RUN: | FileCheck %s --check-prefix=CHECK-PARSE
+# CHECK-PARSE: read 6 aggregated brstack entries
+
+## Error path: invalid record type letter.
+# RUN: not perf2bolt %t -o %t.bad.fdata --pa \
+# RUN: -p %p/Inputs/pre-aggregated-bad-type.txt 2>&1 \
+# RUN: | FileCheck %s --check-prefix=CHECK-BAD-TYPE
+# CHECK-BAD-TYPE: expected T, R, S, E, B, F, f or r
+
+## Error path: malformed hex address.
+# RUN: not perf2bolt %t -o %t.bad.fdata --pa \
+# RUN: -p %p/Inputs/pre-aggregated-bad-hex.txt 2>&1 \
+# RUN: | FileCheck %s --check-prefix=CHECK-BAD-HEX
+# CHECK-BAD-HEX: expected hexadecimal number
+
+ .text
+ .globl main
+ .type main, @function
+main:
+ pushq %rbp
+ movq %rsp, %rbp
+ cmpl $0, %edi
+Lbr:
+ je Lfalse
+Ltrue:
+ movl $1, %eax
+ jmp Lret
+Lfalse:
+ xorl %eax, %eax
+Lret:
+ popq %rbp
+Lretins:
+ retq
+ .size main, .-main
+
+## R: Return - branch in main returning to caller's continuation.
+# PREAGG: R #Lretins# #Lretins# #Lbr# 5
+## R with branch=0: falls back to FT_EXTERNAL_RETURN sentinel.
+# PREAGG: R 0 #Lretins# #Lbr# 2
+## r: fall-through after an external return.
+# PREAGG: r #Lbr# #Ltrue# 7
+## B with -1 (HEAD commit feature): parsed as BR_ONLY (overwritten anyway).
+# PREAGG: B #Lbr# -1 1 0
+## T with -1 as fall-through end: BR_ONLY sentinel preserved.
+# PREAGG: T #Lbr# #Ltrue# -1 4
+## F: regular fall-through sanity check.
+# PREAGG: F #Ltrue# #Lret# 3
``````````
</details>
https://github.com/llvm/llvm-project/pull/193843
More information about the llvm-branch-commits
mailing list