New target hook prevents unsafe constant load substitutions in LRA
A new target hook, `cannot_substitute_const_equiv_p`, is introduced to prevent the LRA from making incorrect floating-point constant load substitutions.
The Local Register Allocator (LRA) can now be prevented from substituting certain floating-point constant loads if a new target hook, cannot_substitute_const_equiv_p, returns true. This addresses issues like those on the SH architecture where specific instructions are mode-dependent and LRA lacked awareness of these constraints, potentially leading to incorrect code generation.
In Details
The cannot_substitute_const_equiv_p target hook is added to target.def and used by the LRA's get_equiv function. This hook allows target-specific code (like sh_cannot_substitute_const_equiv_p) to reject register allocation choices that would violate CPU/FPU mode constraints. Previously, passes after the mode-switching pass could make unsafe transformations because there was no general mechanism to validate instruction mode requirements against the current CPU state, as seen in SH's fldi0/fldi1 instructions.
- Local Register Allocator (LRA)
- A compiler pass responsible for assigning physical machine registers to virtual registers within a small, localized region of code (a basic block or a few). It optimizes register usage by making decisions based on local liveness information.
- Target Hook
- A mechanism in GCC that allows target-specific code to influence or provide implementations for a generic compiler behavior. It's a way for architecture-specific code to plug into the compiler's framework.
- SH architecture
- A family of 32-bit microprocessors developed by Hitachi (now Renesas Electronics). GCC has specific support for various SH processor cores and their features.
- Floating-point mode
- Refers to the operational mode of the floating-point unit (FPU) on a processor, which can affect the precision (e.g., single-precision or double-precision) and behavior of floating-point instructions.