aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir N. Makarov <vmakarov@redhat.com>2025-02-05 14:23:23 -0500
committerVladimir N. Makarov <vmakarov@redhat.com>2025-02-05 14:25:01 -0500
commit98545441308c2ae4d535f14b108ad6551fd927d5 (patch)
tree03c37c5e385d42830e2025f3636582d9d389e2f8
parent0006c07b7ac6594195d5db322e39907203be4c2a (diff)
downloadgcc-98545441308c2ae4d535f14b108ad6551fd927d5.zip
gcc-98545441308c2ae4d535f14b108ad6551fd927d5.tar.gz
gcc-98545441308c2ae4d535f14b108ad6551fd927d5.tar.bz2
[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.
-rw-r--r--gcc/lra-remat.cc10
-rw-r--r--gcc/testsuite/gcc.target/i386/pr115568.c38
2 files changed, 44 insertions, 4 deletions
diff --git a/gcc/lra-remat.cc b/gcc/lra-remat.cc
index bb13c61..2f3afff 100644
--- a/gcc/lra-remat.cc
+++ b/gcc/lra-remat.cc
@@ -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)
diff --git a/gcc/testsuite/gcc.target/i386/pr115568.c b/gcc/testsuite/gcc.target/i386/pr115568.c
new file mode 100644
index 0000000..cedc7ac
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115568.c
@@ -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;
+}