[llvm] [AArch64] Lower an equality branch against a logical immediate to EOR + CBZ/CBNZ (PR #223123)

Andrew Gaul via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 12 00:18:36 PDT 2026


gaul wrote:

> Note depening on the micro-arch, eor/cbnz might be worse than mov/cmp/bne. Even though eor/cbnz is smaller.
> The reason is because the mov might be resolved in the renamer and not need to be issued and the cmp/bne are merged into one macro-op. While eor takes up an issue slot and so does cbnz. So 2 issue slots vs a possibility of 1. Note most micro-arch will merge cmp/bne while the mov improvement is only on some.

Agree that some hardware handles `mov` in the renamer and most bigger cores (~A7x onward) fuse `cmp`/`bne`.  There isn't a model for this so we cannot gate on the property.  So in the general case this PR is not a clear win.

But I think we could narrow this to the dominant case in my measurements, 11,262 of the 13,019 sites in libxul: `x == INT64_MIN` is `cmp xzr, x0 ; b.vs` (0 - x overflows only for `INT64_MIN`). Two instructions, still a fusable compare-and-branch, no scratch register, no materialization. Same for `0x80000000` in the W form.

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


More information about the llvm-commits mailing list