On 2/23/26 12:26 AM, Oleg Endo wrote:
Hi,
In order to move the SH backend over to LRA there is one more missing piece.
On SH we have two fp constant load insns "fldi0" and "fldi1". However, they
are bound to single-precision fp mode. We were hitting some cases where LRA
wants to substitute constant loads, which have been emitted differently
originally, and picks up those "fldi0" / "fldi1" insns but doesn't check
whether they are valid for the current fp mode.
Eventually LRA should be taught to check that any substitution is valid for
any mode, not just fp mode. But for now, the quick solution is to add a
cannot_substitute_const_equiv_p target hook.
Bootsrapped on x86_64. OK to apply?
gcc/ChangeLog:
PR target/117182
* target.def (cannot_substitute_const_equiv_p): New target hook.
* doc/tm.texi.in: Add it.
* lra-constraints.cc (get_equiv): Use it.
* config/sh/sh.cc (sh_cannot_substitute_const_equiv_p): Override
it.
* doc/tm.texi: Re-generate.
I spent last Friday solving the problem. I tried several approaches,
including one used by reload that prevents equiv substitution into
insns with USE of hard regs although I believe this is too conservative
and results in missing a lot of optimization opportunities. The code
implementing these approaches looks worse, is larger, and appears
artificial.
After some reflection, I came to the conclusion that the proposed approach
is minimal and targeted: in other words, the best one even though it
introduces a new hook and I generally prefer to avoid such solutions.
The patch is OK with me. You can commit it to the trunk. Sorry,
it took so long on my side to approve your fix.