GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc Performance Win

Process operand NO_REGS class for register cost calculation

Fixes register cost calculation for operands with the NO_REGS class, potentially changing generated code.

This commit fixes an issue in GCC’s intermediate representation (IRA) where the cost of instructions was not being accurately calculated when operands had the NO_REGS class. The record_reg_classes function lacked special processing for this case, leading to potentially inflated instruction cost estimates. This correction can lead to changes in generated code as the register allocator now has a more accurate picture of instruction costs.

In Details

In GCC's IRA, the record_reg_classes function determines the set of register classes available for each operand in an instruction. Operands with the NO_REGS class represent values that do not reside in registers. The original code lacked specific handling for NO_REGS, causing potentially high cost assignments to these operands. This commit updates ira-costs.cc to correctly handle NO_REGS operands, leading to more accurate cost calculations during register allocation and potentially influencing generated code.

For Context

Before generating machine code, a compiler transforms the source code into an intermediate representation (IR). One step in this process is register allocation: deciding which values should live in registers for fast access. The Intermediate Representation Allocator (IRA) within GCC is responsible for this. This commit fixes a bug in how IRA calculates the "cost" of using registers for certain values. Specifically, when a value doesn't need a register at all, the cost calculation was incorrect, potentially leading to suboptimal code generation. This change improves the accuracy of register allocation, which can lead to faster and more efficient programs.

Filed Under: gccIRAregister allocationoptimization