When attempting to bootstrap arm-linux-gnueabihf with
{BOOT_C,T}FLAGS='-g -O2 -fnon-call-exceptions
-fstack-clash-protection', gmp fails to build in stage2: gen-fac's
mpz_and gets miscompiled.

A pseudo is initialized before a loop and used in a PRE_INC load
inside a loop.  It gets spilled just as the fp2sp elimination is
disabled, and only the initialization gets adjusted with elimination
offsets.  The unadjusted stack slot within the PRE_INC load ends up
reloaded later, but only when the FP offset has already missed its
chance to be adjusted.

Arrange for lra_eliminate_regs_1 to adjust autoinc addresses that are
MEMs themselves.

Regstrapped on x86_64-linux-gnu, bootstrapped on arm-linux-gnueabihf
(arm and thumb modes), also tested with gcc-14 on arm-vx7r2 and
arm-linux-gnueabihf.  Ok to install?


for  gcc/ChangeLog

        PR rtl-optimization/120424
        * lra_eliminations.cc (lra_eliminate_regs_1): Adjust autoinc
        addresses that are MEMs.
---
 gcc/lra-eliminations.cc |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/lra-eliminations.cc b/gcc/lra-eliminations.cc
index 5713a96805233..9cdd0c5ff53a2 100644
--- a/gcc/lra-eliminations.cc
+++ b/gcc/lra-eliminations.cc
@@ -571,6 +571,9 @@ lra_eliminate_regs_1 (rtx_insn *insn, rtx x, machine_mode 
mem_mode,
     case POST_INC:
     case PRE_DEC:
     case POST_DEC:
+      /* Recurse to adjust elimination offsets in a spilled pseudo.  */
+      if (GET_CODE (XEXP (x, 0)) == MEM)
+       break;
       /* We do not support elimination of a register that is modified.
         elimination_effects has already make sure that this does not
         happen.  */
@@ -578,6 +581,9 @@ lra_eliminate_regs_1 (rtx_insn *insn, rtx x, machine_mode 
mem_mode,
 
     case PRE_MODIFY:
     case POST_MODIFY:
+      /* Recurse to adjust elimination offsets in a spilled pseudo.  */
+      if (GET_CODE (XEXP (x, 0)) == MEM)
+       break;
       /* We do not support elimination of a hard register that is
         modified.  LRA has already make sure that this does not
         happen. The only remaining case we need to consider here is

-- 
Alexandre Oliva, happy hacker            https://blog.lx.oliva.nom.br/
Free Software Activist     FSFLA co-founder     GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity.
Excluding neuro-others for not behaving ""normal"" is *not* inclusive!

Reply via email to