[llvm] [BOLT][AArch64] Relax compare-and-branch outside compact code model (PR #219930)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 03:03:06 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Adam Bzowski (adam-bzowski-arm)
<details>
<summary>Changes</summary>
This removes the unconditional rejection of AArch64 compare-and-branch instructions in the non-compact LongJmp path. The existing range check and stub insertion can relax these instructions correctly. A synthetic LIT test verifies relaxation of an out-of-range `CBGT`.
---
Full diff: https://github.com/llvm/llvm-project/pull/219930.diff
4 Files Affected:
- (modified) bolt/include/bolt/Core/MCPlusBuilder.h (+2-1)
- (modified) bolt/lib/Passes/LongJmp.cpp (-7)
- (added) bolt/test/AArch64/compare-and-branch-non-compact.S (+46)
- (removed) bolt/test/AArch64/compare-and-branch-unsupported.S (-51)
``````````diff
diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h
index be0d58af14fc4..86f969bac1168 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -1751,7 +1751,8 @@ class MCPlusBuilder {
return false;
}
- /// AArch64 uses this to perform diagnostics in the LongJmp pass.
+ /// Return true if \p Inst has a particularly short branch range and may
+ /// require branch liveness information during relaxation.
virtual bool isShortRangeBranch(const MCInst &Inst) const {
llvm_unreachable("not implemented");
return false;
diff --git a/bolt/lib/Passes/LongJmp.cpp b/bolt/lib/Passes/LongJmp.cpp
index 30ff9dc4ddc71..6c30287b6b99f 100644
--- a/bolt/lib/Passes/LongJmp.cpp
+++ b/bolt/lib/Passes/LongJmp.cpp
@@ -83,13 +83,6 @@ static BinaryBasicBlock *getBBAtHotColdSplitPoint(BinaryFunction &Func) {
}
static bool mayNeedStub(const BinaryContext &BC, const MCInst &Inst) {
- if (BC.isAArch64() && BC.MIB->isShortRangeBranch(Inst) &&
- !opts::CompactCodeModel) {
- BC.errs() << "BOLT-ERROR: short range branch not supported"
- << " outside compact code model\n";
- BC.printInstruction(BC.errs(), Inst);
- exit(1);
- }
return (BC.MIB->isBranch(Inst) || BC.MIB->isCall(Inst)) &&
!BC.MIB->isIndirectBranch(Inst) && !BC.MIB->isIndirectCall(Inst);
}
diff --git a/bolt/test/AArch64/compare-and-branch-non-compact.S b/bolt/test/AArch64/compare-and-branch-non-compact.S
new file mode 100644
index 0000000000000..eea19e333303c
--- /dev/null
+++ b/bolt/test/AArch64/compare-and-branch-non-compact.S
@@ -0,0 +1,46 @@
+# This test checks that the non-compact LongJmp path inserts a stub when a
+# compare-and-branch target is moved beyond its +/-1KB range.
+
+# REQUIRES: system-linux
+
+# RUN: %clang %cflags -march=armv9-a+cmpbr -Wl,-q %s -o %t
+# RUN: link_fdata --no-lbr %s %t %t.fdata
+# RUN: llvm-strip --strip-unneeded %t
+# RUN: llvm-bolt %t -o %t.bolt --data %t.fdata --split-functions --keep-nops
+# RUN: llvm-objdump --no-show-raw-insn -d %t.bolt | FileCheck %s
+
+ .globl foo
+ .type foo, %function
+foo:
+.entry_foo:
+# FDATA: 1 foo #.entry_foo# 10
+ cbgt x0, #0, .Lcold_foo
+ mov x0, #1
+.Lcold_foo:
+ ret
+
+ .globl large_function
+ .type large_function, %function
+large_function:
+.entry_large_function:
+# FDATA: 1 large_function #.entry_large_function# 10
+ .rept 256
+ nop
+ .endr
+ ret
+
+## Force relocation mode.
+.reloc 0, R_AARCH64_NONE
+
+# CHECK: Disassembly of section .text:
+
+# CHECK: <foo>:
+# CHECK-NEXT: {{.*}} cblt x0, #0x1, 0x[[STUB:[0-9a-f]+]] <{{.*}}>
+# CHECK-NEXT: {{.*}} b 0x[[TARGET:[0-9a-f]+]] <{{.*}}>
+# CHECK-NEXT: [[STUB]]: b 0x[[FALLTHROUGH:[0-9a-f]+]] <{{.*}}>
+
+# CHECK: Disassembly of section .text.cold:
+
+# CHECK: <foo.cold.0>:
+# CHECK-NEXT: [[FALLTHROUGH]]: mov x0, #0x1
+# CHECK-NEXT: [[TARGET]]: ret
diff --git a/bolt/test/AArch64/compare-and-branch-unsupported.S b/bolt/test/AArch64/compare-and-branch-unsupported.S
deleted file mode 100644
index b0384cee06181..0000000000000
--- a/bolt/test/AArch64/compare-and-branch-unsupported.S
+++ /dev/null
@@ -1,51 +0,0 @@
-# This test checks that splitting functions which contain short range
-# conditional branches does not work outside compact code model.
-
-# REQUIRES: system-linux, asserts
-
-# RUN: %clang %cflags -march=armv9-a+cmpbr -Wl,-q %s -o %t -DNUM_NOPS=0 -DRESERVE_SPACE=0
-# RUN: link_fdata --no-lbr %s %t %t.fdata
-# RUN: llvm-strip --strip-unneeded %t
-# RUN: not llvm-bolt %t -o %t.bolt --data %t.fdata -split-functions 2>&1 \
-# RUN: | FileCheck %s
-
-# RUN: %clang %cflags -march=armv9-a+cmpbr -Wl,-q %s -o %t -DNUM_NOPS=256 -DRESERVE_SPACE=0
-# RUN: link_fdata --no-lbr %s %t %t.fdata
-# RUN: llvm-strip --strip-unneeded %t
-# RUN: not llvm-bolt %t -o %t.bolt --data %t.fdata -split-functions --keep-nops 2>&1 \
-# RUN: | FileCheck %s
-
-# RUN: %clang %cflags -march=armv9-a+cmpbr -Wl,-q %s -o %t -DNUM_NOPS=0 -DRESERVE_SPACE=1
-# RUN: link_fdata --no-lbr %s %t %t.fdata
-# RUN: llvm-strip --strip-unneeded %t
-# RUN: not llvm-bolt %t -o %t.bolt --data %t.fdata -split-functions 2>&1 \
-# RUN: | FileCheck %s
-
- .globl foo
- .type foo, %function
-foo:
-.entry_foo:
-# FDATA: 1 foo #.entry_foo# 10
- cbgt x0, #0, .Lcold_foo
- mov x0, #1
-.Lcold_foo:
- ret
-
- .globl large_function
- .type large_function, %function
-large_function:
-.entry_large_function:
-# FDATA: 1 large_function #.entry_large_function# 10
- .rept NUM_NOPS
- nop
- .endr
- ret
-
-.if RESERVE_SPACE
-.space 0x8000000
-.endif
-
-## Force relocation mode.
-.reloc 0, R_AARCH64_NONE
-
-# CHECK: BOLT-ERROR: short range branch not supported outside compact code model
``````````
</details>
https://github.com/llvm/llvm-project/pull/219930
More information about the llvm-commits
mailing list