Skip to content

Commit 7578243

Browse files
vnmakarovubizjak
authored andcommitted
[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. (cherry picked from commit 9854544)
1 parent 26919c4 commit 7578243

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

gcc/lra-remat.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ create_cands (void)
459459
if (insn2 != NULL
460460
&& dst_regno >= FIRST_PSEUDO_REGISTER
461461
&& reg_renumber[dst_regno] < 0
462-
&& BLOCK_FOR_INSN (insn2) == BLOCK_FOR_INSN (insn))
462+
&& BLOCK_FOR_INSN (insn2) == BLOCK_FOR_INSN (insn)
463+
&& insn2 == prev_nonnote_insn (insn))
463464
{
464465
create_cand (insn2, regno_potential_cand[src_regno].nop,
465466
dst_regno, insn);
@@ -473,9 +474,10 @@ create_cands (void)
473474
gcc_assert (REG_P (*id->operand_loc[nop]));
474475
int regno = REGNO (*id->operand_loc[nop]);
475476
gcc_assert (regno >= FIRST_PSEUDO_REGISTER);
476-
/* If we're setting an unrenumbered pseudo, make a candidate immediately.
477-
If it's an output reload register, save it for later; the code above
478-
looks for output reload insns later on. */
477+
/* If we're setting an unrenumbered pseudo, make a candidate
478+
immediately. If it's a potential output reload register, save
479+
it for later; the code above looks for output reload insns later
480+
on. */
479481
if (reg_renumber[regno] < 0)
480482
create_cand (insn, nop, regno);
481483
else if (regno >= lra_constraint_new_regno_start)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* { dg-do run } */
2+
/* { dg-options "-O2 -fno-tree-sink -fno-tree-ter -fschedule-insns" } */
3+
4+
int a, c, d = 1, e, f = 1, h, i, j;
5+
unsigned b = 1, g;
6+
int main() {
7+
for (; h < 2; h++) {
8+
int k = ~(b || 0), l = ((~e - j) ^ a % b) % k, m = (b ^ -1) + e;
9+
unsigned o = ~a % ~1;
10+
if (f) {
11+
l = d;
12+
m = 10;
13+
i = e;
14+
d = -(~e + b);
15+
g = o % m;
16+
e = -1;
17+
n:
18+
a = a % ~i;
19+
b = ~k;
20+
if (!g) {
21+
b = e + o % -1;
22+
continue;
23+
}
24+
if (!l)
25+
break;
26+
}
27+
int q = (~d + g) << ~e, p = (~d - q) & a >> b;
28+
unsigned s = ~((g & e) + (p | (b ^ (d + k))));
29+
int r = (e & s) + p, u = d | ~a,
30+
t = ((~(q + (~a + (s + e)))) & u) | (-g & (c << d ^ p));
31+
if (t)
32+
if (!r)
33+
goto n;
34+
g = m;
35+
e = i;
36+
}
37+
return 0;
38+
}

0 commit comments

Comments
 (0)