[llvm] [BOLT][AArch64] Support FEAT_CMPBR branch instructions. (PR #174972)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 3 03:54:50 PST 2026


paschalis-mpeis wrote:

Hey Alexandros,

Thanks for the improvements. I think that, at a higher level, we need to clearly specify what will be supported after this initial patch. See the two points below.

### Regarding disallowing LongJmp:
> To do this we will need BinaryFunction::hasShortRangeBranchBeyondFragment() as shown in https://github.com/llvm/llvm-project/pull/174546. We'd have to call it from LongJmpPass::tentativeLayout() and abort execution when !opts::CompactCodeModel. Lemme know if you would want this.

I think we can do this as follows instead:

```cpp
static bool mayNeedStub(const BinaryContext &BC, const MCInst &Inst) {
  if (BC.isAArch64() && BC.MIB->isCompAndBranch(Inst)) {
    BC.errs() << .. // unsupported, printing the instruction, suggesting to use compact-code flag
    exit(1);
  }
  ...
}
```

You may need to expose `isCompAndBranch` in MIB.
This should cleanly exit in all cases:
1. the current test, where introducing `large_function` causes those branches to need a stub.
2. when the code is smaller (no `large_function`) and stubs are not needed.

If we want to be more explicit in the code, we can exit from `relax` instead.

Note that if we wanted to support LongJmp, a simple approach could be to conservatively create a stub for CB.cc, at all times.
In other words, if `needsStubs` sees this branch type and the target is not a stub, create one.


### Clarifying what is supported
We could amend the commit message to clearly state what support this patch adds, and also cover this with tests, including unsupported cases. We could split tests to multiple files as needed.

Some cases to cover:
- with compact-mode
  - with <1 MB branch distance
  - with >1 MB branch distance
  - with a >128MB distance (needs relaxation, currently unsupported)
  - block reordering that goes out of range, requiring >1MiB distance within the same fragment (unsupported)

- with LongJmp: show that this pass is disallowed (at least for now)
  - when it does not need stubs (<1 MB branch distance)
  - when it needs stubs, as in the current test (>1 MB branch distance)
  - with a >128MB distance (requires relaxation)


https://github.com/llvm/llvm-project/pull/174972


More information about the llvm-commits mailing list