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

ivopts: Accurately estimate register pressure using hard registers

Register pressure estimation in ivopts now counts hard registers, improving accuracy for targets with wider register requirements.

The ivopts pass has been updated to more accurately estimate register pressure by counting hard registers rather than just values. Previously, the register pressure calculation could significantly underestimate needs on targets where a single logical value, like a 64-bit pointer on a 32-bit architecture, required multiple physical registers. This led to incorrect decisions about spilling and loop optimizations. The change introduces weights based on targetm.class_max_nregs to account for multi-register values, ensuring more precise pressure estimates and better optimization choices, especially on architectures like GCN or 32-bit systems handling 64-bit data.

In Details

This commit revises ivopts_estimate_reg_pressure to correctly account for hard register usage when estimating loop register pressure. The previous implementation summed the number of live values (invariants, candidates, etc.) and compared this against target_avail_regs. This failed on targets like GCN (where SGPRs are 32-bit and 64-bit pointers require two) or 32-bit targets needing to hold 64-bit integers, leading to underestimation. The fix introduces a weighting mechanism: values requiring multiple registers (e.g., SImode pointers on GCN) are assigned a weight based on `targetm.class…

For Context
ivopts
Invariant Optimization. A set of compiler optimizations focused on identifying and hoisting loop-invariant computations out of loops to improve performance.
register pressure
A measure of how many registers are simultaneously needed by a program at a given point. High register pressure can lead to performance degradation due to register spilling.
hard registers
Physical registers available on the CPU architecture.
values
In this context, refers to live variables or intermediate results within a loop that occupy registers.
SImode
A GCC internal machine mode representing a signed 32-bit integer. It's often used for pointer types on 32-bit architectures.
SGPR
Scalar General-Purpose Register. A type of register found on some architectures like AMD's GCN (Graphics Core Next), often used for scalar values and pointers.
GENERAL_REGS
A target-specific macro or constant representing the general-purpose integer registers available on the architecture.
spilling
The process of storing the value of a register into memory (usually the stack) when there are not enough available registers to hold all live values.
loop-invariant computation
An expression or calculation within a loop whose result does not change from one iteration to the next. These can often be moved outside the loop for efficiency.
Filed Under: optimizationregister allocationperformanceivopts