[BOLT][AArch64] Support block reordering beyond 1KB for FEAT_CMPBR. (#185443)

Currently LongJmpPass::relaxLocalBranches bails early if the estimated
size of a binary function is less than 32KB assuming that the shortest
branches are 16 bits. Therefore the fixup value for the cold branch
target may go out of range if the function is larger than 1KB.

I am decreasing ShortestJumpSpan from 32KB to 1KB, since FEAT_CMPBR
branches are 11 bits.
This commit is contained in:
Alexandros Lamprineas 2026-03-12 11:01:15 +00:00 committed by GitHub
parent 753db4b457
commit 3a8eabeb3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 7 deletions

View File

@ -64,7 +64,7 @@ class LongJmpPass : public BinaryFunctionPass {
uint32_t NumSharedStubs{0};
/// The shortest distance for any branch instruction on AArch64.
static constexpr size_t ShortestJumpBits = 16;
static constexpr size_t ShortestJumpBits = 11;
static constexpr size_t ShortestJumpSpan = 1ULL << (ShortestJumpBits - 1);
/// The longest single-instruction branch.

View File

@ -10,8 +10,8 @@
# RUN: %clang %cflags -march=armv9-a+cmpbr -Wl,-q %s -o %t -DNUM_NOPS=256
# RUN: link_fdata --no-lbr %s %t %t.fdata
# RUN: not llvm-bolt %t -o %t.bolt --data %t.fdata --reorder-blocks=ext-tsp --compact-code-model --keep-nops 2>&1 \
# RUN: | FileCheck %s --check-prefix=FIXUP_OUT_OF_RANGE
# RUN: llvm-bolt %t -o %t.bolt --data %t.fdata --reorder-blocks=ext-tsp --compact-code-model --keep-nops
# RUN: llvm-objdump -d %t.bolt | FileCheck %s --check-prefix=BEYOND-1KB
.globl reorder_blocks
.type reorder_blocks, %function
@ -31,15 +31,15 @@ reorder_blocks:
.rept NUM_NOPS
nop
.endr
mov x0, #2
ret
mov x0, #2
ret
## Force relocation mode.
.reloc 0, R_AARCH64_NONE
# CHECK: Disassembly of section .text:
# CHECK: <reorder_blocks>:
# CHECK: <reorder_blocks>:
# CHECK-NEXT: {{.*}} cbgt x0, #0x0, 0x[[ADDR:[0-9a-f]+]] <{{.*}}>
# CHECK: <.hot_exit>:
# CHECK-NEXT: {{.*}} mov x0, #0x2 // =2
@ -48,4 +48,15 @@ reorder_blocks:
# CHECK-NEXT: [[ADDR]]: {{.*}} mov x0, #0x1 // =1
# CHECK-NEXT: {{.*}} ret
# FIXUP_OUT_OF_RANGE: error: fixup value out of range
# BEYOND-1KB: Disassembly of section .text:
# BEYOND-1KB: <reorder_blocks>:
# BEYOND-1KB-NEXT: {{.*}} cblt x0, #0x1, 0x[[ADDR0:[0-9a-f]+]] <{{.*}}>
# BEYOND-1KB-NEXT: {{.*}} b 0x[[ADDR1:[0-9a-f]+]] <{{.*}}>
# BEYOND-1KB: <.hot_exit>:
# BEYOND-1KB-NEXT: [[ADDR0]]: {{.*}} nop
# BEYOND-1KB: {{.*}} mov x0, #0x2 // =2
# BEYOND-1KB-NEXT: {{.*}} ret
# BEYOND-1KB: <.cold_exit>:
# BEYOND-1KB-NEXT: [[ADDR1]]: {{.*}} mov x0, #0x1 // =1
# BEYOND-1KB-NEXT: {{.*}} ret