RISC-V: Recognize ADD/ADDI followed by ANDI instruction fusion
GCC now fuses ADD/ADDI with subsequent ANDI instructions on RISC-V, optimizing code execution.
GCC has added support for macro-fusion of ADD/ADDI-type instructions followed by an ANDI instruction on RISC-V architectures. This optimization applies when the result of the ADD/ADDI instruction is a required dependency for the ANDI instruction. The implementation reuses RTL parsing logic for ANDI, allowing for shared code with existing B_ALUI fusion rules. This new fusion is disabled by default and is verified by new test cases.
In Details
This commit introduces the RISCV_FUSE_ADD_ANDI macro-fusion pattern into GCC's RISC-V backend. It recognizes sequences where an ADD or ADDI-type instruction is immediately followed by an ANDI instruction. The fusion is predicated on the destination register of the ADD/ADDI being a source operand for the ANDI. To enable code sharing, the ANDI classifier has been parameterized, allowing it to be reused by this new fusion rule as well as the existing B_ALUI fusion logic. This pattern is disabled by default.
- macro-fusion
- An optimization technique where the compiler combines two or more adjacent instructions into a single, more efficient instruction or sequence, provided specific conditions (like register dependencies) are met.
- ADD
- A RISC-V instruction that performs addition between two source registers, storing the result in a destination register.
- ADDI
- A RISC-V instruction that performs addition between a source register and an immediate value, storing the result in a destination register.
- ANDI
- A RISC-V instruction that performs a bitwise AND operation between a source register and an immediate value, storing the result in a destination register.
- RTL
- Register Transfer Language, an intermediate representation used by GCC to describe hardware operations before they are translated into machine code.
- RISC-V
- An open-standard instruction set architecture (ISA) based on modularity, extensibility, and simplicity, gaining traction in embedded systems and high-performance computing.