[PR115568][LRA]: Use more strict output reload check in rematerialization

In this PR case LRA rematerialized a value from inheritance insn
instead of output reload one.  This resulted in considering a
rematerilization candidate value available when it was actually
not.  As a consequence an insn after rematerliazation used the
unexpected value and this use resulted in fp exception.  The patch
fixes this bug.

gcc/ChangeLog:

	PR rtl-optimization/115568
	* lra-remat.cc (create_cands): Check that output reload insn is
	adjacent to given insn.  Update a comment.

gcc/testsuite/ChangeLog:

	PR rtl-optimization/115568
	* gcc.target/i386/pr115568.c: New.
This commit is contained in:
Vladimir N. Makarov 2025-02-05 14:23:23 -05:00
parent 0006c07b7a
commit 9854544130
2 changed files with 44 additions and 4 deletions

View file

@ -459,7 +459,8 @@ create_cands (void)
if (insn2 != NULL
&& dst_regno >= FIRST_PSEUDO_REGISTER
&& reg_renumber[dst_regno] < 0
&& BLOCK_FOR_INSN (insn2) == BLOCK_FOR_INSN (insn))
&& BLOCK_FOR_INSN (insn2) == BLOCK_FOR_INSN (insn)
&& insn2 == prev_nonnote_insn (insn))
{
create_cand (insn2, regno_potential_cand[src_regno].nop,
dst_regno, insn);
@ -473,9 +474,10 @@ create_cands (void)
gcc_assert (REG_P (*id->operand_loc[nop]));
int regno = REGNO (*id->operand_loc[nop]);
gcc_assert (regno >= FIRST_PSEUDO_REGISTER);
/* If we're setting an unrenumbered pseudo, make a candidate immediately.
If it's an output reload register, save it for later; the code above
looks for output reload insns later on. */
/* If we're setting an unrenumbered pseudo, make a candidate
immediately. If it's a potential output reload register, save
it for later; the code above looks for output reload insns later
on. */
if (reg_renumber[regno] < 0)
create_cand (insn, nop, regno);
else if (regno >= lra_constraint_new_regno_start)

View file

@ -0,0 +1,38 @@
/* { dg-do run } */
/* { dg-options "-O2 -fno-tree-sink -fno-tree-ter -fschedule-insns" } */
int a, c, d = 1, e, f = 1, h, i, j;
unsigned b = 1, g;
int main() {
for (; h < 2; h++) {
int k = ~(b || 0), l = ((~e - j) ^ a % b) % k, m = (b ^ -1) + e;
unsigned o = ~a % ~1;
if (f) {
l = d;
m = 10;
i = e;
d = -(~e + b);
g = o % m;
e = -1;
n:
a = a % ~i;
b = ~k;
if (!g) {
b = e + o % -1;
continue;
}
if (!l)
break;
}
int q = (~d + g) << ~e, p = (~d - q) & a >> b;
unsigned s = ~((g & e) + (p | (b ^ (d + k))));
int r = (e & s) + p, u = d | ~a,
t = ((~(q + (~a + (s + e)))) & u) | (-g & (c << d ^ p));
if (t)
if (!r)
goto n;
g = m;
e = i;
}
return 0;
}