i386: Fix up replacement of registers in certain peephole2s [PR108832]
As mentioned in the PR, replace_rtx has 2 modes, one that only replaces
x == from with to, the other which i386.md uses which also replaces
REGNO (x) == REGNO (from) with to if both are REGs, but assert they have
the same mode. This is reasonable behavior if one replaces from with
some other expression, say constant etc., but ICEs whenever the register
appears in a different mode, which happens e.g. on the following testcase,
where from/to has DImode but inside of the operands we have SImode of
the from register. replace_rtx also does some limited simplifications
(though far less than simplify_replace_fn_rtx), which is needed if
from a REG is replaced say with CONST_INT, but the peephole2s that use
this only replace one REG with another one.
The following patch introduces a new backend function for this, avoids doing
any simplifications and just replaces the REGs, for safety on a copy of
the expression if any changes will be needed.
2023-02-18 Jakub Jelinek <jakub@redhat.com>
PR target/108832
* config/i386/i386-protos.h (ix86_replace_reg_with_reg): Declare.
* config/i386/i386-expand.cc (ix86_replace_reg_with_reg): New
function.
* config/i386/i386.md: Replace replace_rtx calls in all peephole2s
with ix86_replace_reg_with_reg.
* gcc.target/i386/pr108832.c: New test.