From 9cd11fd48509234e18122036bf504981f5a91b9a Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Thu, 31 Aug 2023 11:59:56 +0100 Subject: [PATCH] lra: Avoid unfolded plus-0 To: gcc-patches@gcc.gnu.org While backporting another patch to an earlier release, I hit a situation in which lra_eliminate_regs_1 would eliminate an address to: (plus (reg:P R) (const_int 0)) This address compared not-equal to plain: (reg:P R) which caused an ICE in a later peephole2. (The ICE showed up in gfortran.fortran-torture/compile/pr80464.f90 on the branch but seems to be latent on trunk.) These unfolded PLUSes shouldn't occur in the insn stream, and later code in the same function tried to avoid them. gcc/ * lra-eliminations.cc (lra_eliminate_regs_1): Use simplify_gen_binary rather than gen_rtx_PLUS. --- gcc/lra-eliminations.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/lra-eliminations.c b/gcc/lra-eliminations.c index 993da861cf9..a3daf443caf 100644 --- a/gcc/lra-eliminations.c +++ b/gcc/lra-eliminations.c @@ -391,8 +391,8 @@ lra_eliminate_regs_1 (rtx_insn *insn, rtx x, machine_mode mem_mode, rtx to = subst_p ? ep->to_rtx : ep->from_rtx; if (! update_p && ! full_p) - return gen_rtx_PLUS (Pmode, to, XEXP (x, 1)); - + return simplify_gen_binary (PLUS, Pmode, to, XEXP (x, 1)); + if (update_sp_offset != 0) offset = ep->to_rtx == stack_pointer_rtx ? update_sp_offset : 0; else -- 2.35.3