Revised patch that cures the lra related -m32 -Os regression too. The code that I'm patching here is changing a REG_EQUAL note to REG_EQUIV, ie. asserting that the value of the reg is always the value set by the current instruction. Which is not always true when the insn is in a loop and the use of the reg happens before the def. Of course that implies the value of the reg is initially undefined, so it's not unreasonable to make the initial reg value the same. Except when the code setting the initial value may trap, as it does in the testcase.
Bootstrap and regression test on x86_64-linux in progress. OK assuming no regressions? I also took a look at gcc/*.o to see whether there were any code quality regressions. No differences found except the expected change in ira.o. PR rtl-optimization/79286 * ira.c (update_equiv_regs): Do not create an equivalence for mems that may trap. testsuite/ * gcc.c-torture/execute/pr79286.c: New. diff --git a/gcc/ira.c b/gcc/ira.c index 96b4b62..8e79929 100644 --- a/gcc/ira.c +++ b/gcc/ira.c @@ -3500,7 +3500,9 @@ update_equiv_regs (void) /* If this register is known to be equal to a constant, record that it is always equivalent to the constant. */ if (DF_REG_DEF_COUNT (regno) == 1 - && note && ! rtx_varies_p (XEXP (note, 0), 0)) + && note + && !rtx_varies_p (XEXP (note, 0), 0) + && !may_trap_p (XEXP (note, 0))) { rtx note_value = XEXP (note, 0); remove_note (insn, note); diff --git a/gcc/testsuite/gcc.c-torture/execute/pr79286.c b/gcc/testsuite/gcc.c-torture/execute/pr79286.c new file mode 100644 index 0000000..e6d0e93 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr79286.c @@ -0,0 +1,15 @@ +int a = 0, c = 0; +static int d[][8] = {}; + +int main () +{ + int e; + for (int b = 0; b < 4; b++) + { + __builtin_printf ("%d\n", b, e); + while (a && c++) + e = d[300000000000000000][0]; + } + + return 0; +} -- Alan Modra Australia Development Lab, IBM