RISC-V: Add ANDI followed by ADD/ADDI fusion
GCC can now fuse ANDI with subsequent ADD/ADDI instructions on RISC-V, improving performance.
GCC gains the ability to recognize and fuse an ANDI instruction with a following ADD or ADDI instruction on RISC-V systems, provided the result register of the ANDI is used as a required dependency. This optimization also uses RTL to handle ADDIW before it might be optimized away by other passes. The new fusion is disabled by default and is accompanied by new test cases.
In Details
This commit introduces the RISCV_FUSE_ANDI_ADD macro-fusion pattern to GCC's RISC-V backend. It targets the specific sequence of an ANDI instruction followed by an ADD-type instruction (ADD, ADDI, ADDIW). The fusion is enabled when the destination register of the ANDI is a source operand for the ADD-type instruction. It leverages RTL to correctly identify ADDIW instructions, ensuring they are considered for fusion before potential earlier passes might transform them into ADDI. The fusion is disabled by default.
- 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.
- 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.
- 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.
- 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.