TUESDAY, SEPTEMBER 22, 2026
gcc/lra
LRA: Implement fallback to memory for memory and reg constraint
Fixes the LRA register allocator to correctly handle 'g' constraints when a register cannot hold the mode value.
The Local Register Allocation (LRA) pass in GCC had a bug where it would fail for ‘g’ constraints when a suitable register could not hold the required mode value. This commit adjusts LRA to ignore such registers, falling back to memory, and includes a new test case for this scenario.
In Details
In GCC's LRA, the 'g' constraint handling for the process_alt_operands function in lra-constraints.cc failed when a hard register could not accommodate the operand's mode, even if the constraint itself was technically satisfiable. This patch introduces a fallback mechanism to memory for such cases, addressing PR127326.
For Context
- LRA
- Local Register Allocation, a GCC optimization pass that attempts to allocate machine registers to variables and temporaries within a function's basic blocks.
- constraint
- In GCC's instruction selection, a constraint specifies the type of operand that an instruction can accept, such as a specific register, any register, or memory.
- mode
- A machine-dependent representation of a data type's size and type, used internally by GCC.
- rm constraint
- A GCC constraint that allows either a register or memory operand.
- g constraint
- A GCC constraint that allows general-purpose registers.