Skip to content

aarch64: Simplify and improve handling of conditionals#13315

Open
alexcrichton wants to merge 3 commits intobytecodealliance:mainfrom
alexcrichton:aarch64-refactor
Open

aarch64: Simplify and improve handling of conditionals#13315
alexcrichton wants to merge 3 commits intobytecodealliance:mainfrom
alexcrichton:aarch64-refactor

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This commit refactors the aarch64 backend to match the x64 backend with how it handles conditionals. Specifically there's now a "narrow waist" of a CondResult type which is used for trapnz, trapz, select, icmp, brif, and select_spectre_guard. This means that any lowering optimizations to handle conditionals are equally applied to all of these locations. Notably the smattering of optimizations and implementations across these instructions have all been deduplicated an unified. Codegen of trap{n,}z is much better than before, and minor optimizations such as testing if an 8-bit value is 0 are now improved across the board. Finally, jumping after comparing a less-than-64-bit value now will use a 32-bit comparison instruction instead of a 64-bit comparison instruction, sometimes eliding the need to extend a 32-bit value to a 64-bit value.

During this refactoring the method of comparing 128-bit integers was copied over from the x64 backend as well. This additionally significantly improves codegen over the previous iteration.

The end result is that it should be significantly easier to apply optimizations and bug fixes in the future. For example some float comparison orderings are not yet currently supported in the aarch64 backend, but are supported in the x64 backend, and this paves the way to make it much easier to add support for this feature as only one comparison-generation location need be updated and a small set of do-something-with-a-comparison locations will be specialized to the condition necessary.

This commit refactors the aarch64 backend to match the x64 backend with
how it handles conditionals. Specifically there's now a "narrow waist"
of a `CondResult` type which is used for `trapnz`, `trapz`, `select`,
`icmp`, `brif`, and `select_spectre_guard`. This means that any lowering
optimizations to handle conditionals are equally applied to all of these
locations. Notably the smattering of optimizations and implementations
across these instructions have all been deduplicated an unified. Codegen
of `trap{n,}z` is much better than before, and minor optimizations such
as testing if an 8-bit value is 0 are now improved across the board.
Finally, jumping after comparing a less-than-64-bit value now will use a
32-bit comparison instruction instead of a 64-bit comparison
instruction, sometimes eliding the need to extend a 32-bit value to a
64-bit value.

During this refactoring the method of comparing 128-bit integers was
copied over from the x64 backend as well. This additionally
significantly improves codegen over the previous iteration.

The end result is that it should be significantly easier to apply
optimizations and bug fixes in the future. For example some float
comparison orderings are not yet currently supported in the aarch64
backend, but are supported in the x64 backend, and this paves the way to
make it much easier to add support for this feature as only one
comparison-generation location need be updated and a small set of
do-something-with-a-comparison locations will be specialized to the
condition necessary.
@alexcrichton alexcrichton requested review from a team as code owners May 7, 2026 04:53
@alexcrichton alexcrichton requested review from cfallin and removed request for a team May 7, 2026 04:53
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:area:aarch64 Issues related to AArch64 backend. labels May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:aarch64 Issues related to AArch64 backend. cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant