RISC-V: Enable ADD-ST macro-fusion for stores
GCC can now fuse ADD instructions with subsequent store operations on RISC-V, improving code efficiency.
GCC now recognizes and fuses ADD, ADDW, or ADD.UW instructions with a subsequent undisplaced scalar integer store operation on RISC-V when the store uses the add result as its memory address. This optimization aims to streamline address calculation and store operations. The fusion logic carefully checks for overlapping registers between the ADD result and the store data to prevent incorrect behavior. This new fusion capability is disabled by default and is verified with new test cases.
In Details
This commit introduces the RISCV_FUSE_ADD_ST macro-fusion pattern to GCC's RISC-V backend. It targets sequences where an ADD-type instruction (ADD, ADDW, ADD.UW) computes an address that is then used by a subsequent scalar integer store instruction. The fusion is enabled when the store is undisplaced and directly uses the result of the ADD-type instruction as its address. A critical aspect is the careful checking for register overlap between the ADD result and the store's data operand, including specific handling for RV32 Zilsd stores, to maintain correctness. This fusion is disabled by defau…
- 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.
- ADDW
- A RISC-V instruction that performs word-sized addition between two source registers.
- ADD.UW
- A RISC-V instruction that performs unsigned word-sized addition.
- scalar integer store
- A memory operation that writes a single integer value from a register to a specific memory address.
- RISC-V
- An open-standard instruction set architecture (ISA) based on modularity, extensibility, and simplicity, gaining traction in embedded systems and high-performance computing.