GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
aarch64 Performance Win

AArch64 BFI instructions recognized with any-or-plus, costing one insn

AArch64 BFI instructions using OR or ADD operations are now recognized and costed as a single instruction, improving code generation efficiency.

This change enables the AArch64 backend to recognize bit-field insert (BFI) instructions that are formed using bitwise OR (IOR) or addition (PLUS) operations, especially when operands have disjoint non-zero bits. Previously, the compiler would generate multiple AND, AND, and ORR/ADD instructions, leading to inefficient code. By using any_or_plus in pattern matching and updating the cost model, these operations are now correctly identified and emitted as a single BFI instruction, resolving performance regressions and test failures.

In Details

This commit enhances the AArch64 backend's recognition and cost-modeling of the bfi instruction. It modifies six aarch64_bfi patterns to use any_or_plus instead of only ior, allowing them to match cases where the operands are combined with PLUS. Additionally, aarch64_bfi_rtx_p and aarch64_rtx_costs are updated to assign a cost of one instruction for these IOR and PLUS forms. This directly addresses the issue where combine would reject the bfi pattern in favor of a multi-instruction sequence for operations like (x & ~0xffff) | ((y << 8) & 0xffff). The change also impact…

For Context
BFI
Bit Field Insert. An instruction that inserts a specified number of bits from a source register into a destination register at a specified bit position, overwriting existing bits in the destination.
any-or-plus
A pattern matching construct in GCC that matches either a bitwise OR (IOR) or an addition (PLUS) operation, used here to generalize the recognition of bit manipulation instructions.
IOR
Bitwise Inclusive OR. A logical operation that combines two bits; the result is 1 if at least one of the input bits is 1.
rtx_costs
A component of the GCC backend responsible for estimating the performance cost (latency, throughput) of various machine instructions, used by the optimizer to select the most efficient code sequences.
any_or_plus
A pattern matching construct in GCC that matches either a bitwise OR (IOR) or an addition (PLUS) operation, used here to generalize the recognition of bit manipulation instructions.
Filed Under: aarch64optimizationinstruction selectionperformance