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

RISC-V: Generalize LDINDEXED macro-fusion for loads

GCC enhances LDINDEXED fusion on RISC-V to include ADD instructions for address calculation.

The LDINDEXED macro-fusion recognition in GCC for RISC-V has been generalized to allow ADD, ADDW, or ADD.UW instructions to precede an undisplaced scalar integer load. This enables the load instruction to use the result of the ADD-type instruction as its memory address, even if the destination register of the load overwrites the address register. This change shares structural matching logic with the ADD_ST fusion, making the ADD classifier more versatile by optionally reporting wordness for fusion rules.

In Details

This commit refines the RISCV_FUSE_LDINDEXED macro-fusion pattern in GCC's RISC-V backend. It now allows ADD, ADDW, or ADD.UW instructions to be recognized as the address-generating component before a scalar integer load. The previous limitation of requiring the load's destination to be distinct from the ADD's result has been removed, allowing for address register reuse. Crucially, this implementation shares the common 'add-plus-memory' structural matching with the ADD_ST fusion, and the ADD classifier has been enhanced to optionally report wordness (e.g., for ADDW), facilitating fusion rules…

For Context
LDINDEXED
A pattern recognized by the compiler for macro-fusion, typically involving a load instruction that uses an address computed by a preceding instruction.
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 load
A memory operation that reads a single integer value from a specific memory address into a register.
RISC-V
An open-standard instruction set architecture (ISA) based on modularity, extensibility, and simplicity, gaining traction in embedded systems and high-performance computing.
Filed Under: risc-voptimizationcompiler