Middle-end: Improve bitreverse RTL expansion with AOP
New optab improves bitwise operations by allowing backends to choose optimal instructions.
This patch enhances the RTL expansion for bitreverse and store_fixed_bitfield operations by introducing a new aop_optab. This aop_optab allows target backends to precisely choose between bitwise OR, XOR, or addition instructions, leading to better code generation on various architectures like x86, RISC-V, and AVR. Previously, the expansion relied on a generic PLUS or IOR that might not be optimal. This change provides finer control, yielding more efficient code, as demonstrated by an improved x86_64 expansion for a struct assignment.
In Details
This commit introduces an aop_optab (any_or_plus) to the middle-end's operation table. This new optab allows target backends to define their preferred instruction for bitwise operations that can be implemented using bitwise OR, XOR, or addition (e.g., bitreverse, store_fixed_bitfield). The goal is to let backends select the most efficient instruction based on their specific instruction set, moving beyond the previous, less flexible reliance on PLUS or IOR alone. This is crucial for targets without shift-add instructions or where certain bitwise operations map better to IOR/XOR t…
- RTL
- Register Transfer Language. An intermediate representation used by GCC to represent code before it is optimized and translated to machine code.
- optab
- Operation table. A data structure within GCC that maps generic operations to specific machine instructions or RTL patterns for a given target.
- bitreverse
- An operation that reverses the order of bits within a machine word.
- store_fixed_bitfield
- An operation that stores a value into a specific, fixed-size field within a larger data type (e.g., a bitfield in a C struct).
- x86_64
- A 64-bit extension of the x86 instruction set architecture, commonly used in modern desktop and server processors.
- AVR
- A family of microcontrollers developed by Atmel, often programmed using C.
- IOR
- Bitwise Inclusive OR operation.
- XOR
- Bitwise Exclusive OR operation.
- PLUS
- Addition operation.