Optimize unsigned conditional subtraction using SUBS/CSEL.
Improves AArch64 code generation for unsigned conditional subtractions.
This commit optimizes the generation of code for unsigned conditional subtractions on AArch64. Previously, expressions like x - (x >= q ? q : 0) were not recognized by the backend and resulted in separate compare, conditional move, and subtraction instructions. The patch introduces a new define_insn_and_split pattern that combines these operations into a more efficient sequence using the SUBS instruction (which updates condition flags) followed by a CSEL (conditional select), leading to improved instruction scheduling and potentially better performance.
In Details
The AArch64 backend now includes a new pattern aarch64_conditional_subtract<mode> in aarch64.md. This pattern targets RTL generated for expressions equivalent to x - (x >= q ? q : 0) where the subtraction is unsigned. It splits into a SUBS instruction (which sets flags) and a CSEL instruction that uses those flags, effectively replacing a less optimal sequence of CMP, CSEL, and SUB instructions. This optimization is specifically for unsigned comparisons and subtractions.
- AArch64
- The 64-bit ARM architecture instruction set.
- RTL
- Register Transfer Language, an intermediate representation used within GCC to describe operations on hardware registers.
- SUBS
- An AArch64 instruction that performs subtraction and sets the condition flags based on the result.
- CSEL
- An AArch64 instruction that conditionally selects one of two values based on the condition flags.