Optimize register allocation for spills in LRA.
Fixes the Local Register Allocator (LRA) to avoid unnecessary spilling of '+' operations when a register target is available.
This commit addresses a regression introduced by a previous fix (for PR128251) in the Local Register Allocator (LRA). The regression caused the + operation to be unnecessarily spilled to memory even when it could be reloaded into a register. By properly re-enabling the goal_alt guard, the allocator now correctly identifies opportunities to reuse registers. This optimization reduces code size, showing a 0.7% improvement on the SPEC2017 imagick benchmark.
In Details
The curr_insn_transform function within GCC's Local Register Allocator (LRA) in lra-constraints.cc has been fixed to correctly handle spilling of plus (addition) operations. A previous patch for PR128251 inadvertently disabled the goal_alt check, leading to suboptimal spilling: the plus operation was being spilled to memory when it could have been reloaded into a register. This commit re-introduces the goal_alt check, ensuring that spills to memory only occur when no register target is feasible. This improves code density and potentially performance, as evidenced by a 0.7% code si…
- Local Register Allocator (LRA)
- A phase in the GCC compiler that assigns program variables to physical machine registers within a single basic block or a small region of code. It aims to minimize memory accesses by keeping frequently used values in registers.
- spill
- The process of storing a value from a register into memory when there are no more available registers to hold all the live values. This is typically done when the compiler needs a register for another purpose.
- register target
- An instruction operand that is a physical CPU register. In register allocation, it means a value can be held or processed directly in a register.
- PR128251
- Patch Request number 128251, referring to a specific bug report or issue filed against the GCC project.