Hello!
I would like to backport PR115568 and PR119689 to release branches.
Author: Richard Biener <[email protected]>
Date: Wed Apr 9 14:36:19 2025 +0200
rtl-optimization/119689 - compare-debug failure with LRA
The previous change to fix LRA rematerialization broke compare-debug
for i586 bootstrap. Fixed by using prev_nonnote_nondebug_insn
instead of prev_nonnote_insn.
PR rtl-optimization/119689
PR rtl-optimization/115568
* lra-remat.cc (create_cands): Use prev_nonnote_nondebug_insn
to check whether insn2 is directly before insn.
* g++.target/i386/pr119689.C: New testcase.
(cherry picked from commit 088887de7717a22b1503760e9b79dfbe22a0f428)
Author: Vladimir N. Makarov <[email protected]>
Date: Wed Feb 5 14:23:23 2025 -0500
[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.
OK for branches?
Uros.
diff --git a/gcc/lra-remat.cc b/gcc/lra-remat.cc
index c84bf3c9938..6e553030f22 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_nondebug_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/g++.target/i386/pr119689.C
b/gcc/testsuite/g++.target/i386/pr119689.C
new file mode 100644
index 00000000000..cdc6d2dade5
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr119689.C
@@ -0,0 +1,44 @@
+// { dg-do compile }
+// { dg-options "-O2 -fcompare-debug" }
+// { dg-additional-options "-march=i586 -mtune=generic" { target ia32 } }
+// { dg-additional-options "-fPIC" { target { fpic } } }
+
+enum gimple_code { GIMPLE_ASSIGN, GIMPLE_RETURN };
+bool is_gimple_call();
+int m_sig, m_exp, sreal_new_exp;
+struct sreal {
+ sreal(long long sig) {
+ long long __trans_tmp_6 = sig >= 0 ? sig : -(unsigned long long)sig;
+ sig = __trans_tmp_6 <<= sreal_new_exp -= m_exp = __trans_tmp_6;
+ m_sig = sig;
+ }
+ void operator/(sreal);
+};
+struct ipa_predicate {
+ ipa_predicate(bool = true);
+ void operator&=(ipa_predicate);
+ void operator&(ipa_predicate);
+};
+void add_condition();
+gimple_code eliminated_by_inlining_prob_code;
+static int eliminated_by_inlining_prob() {
+ switch (eliminated_by_inlining_prob_code) {
+ case GIMPLE_RETURN:
+ return 2;
+ case GIMPLE_ASSIGN:
+ return 1;
+ }
+ return 0;
+}
+void fp_expression_p() {
+ ipa_predicate bb_predicate;
+ for (;;) {
+ int prob = eliminated_by_inlining_prob();
+ ipa_predicate sra_predicate;
+ sra_predicate &= add_condition;
+ if (is_gimple_call())
+ sreal(prob) / 2;
+ if (prob != 2)
+ bb_predicate & sra_predicate;
+ }
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr115568.c
b/gcc/testsuite/gcc.target/i386/pr115568.c
new file mode 100644
index 00000000000..cedc7ac3843
--- /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;
+}