From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7810) id ADDF4385E836; Fri, 3 May 2024 08:24:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADDF4385E836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714724672; bh=Zy6QizISvekJrCAwR6KPDNtNfqDIj9+xuwRdrgU/p8c=; h=From:To:Subject:Date:From; b=B5Ur4n/Z1lTOQrABQ3hsJgPKU9naHCcCTgoJMoWIjhxDV6IJtJbnLLNeUyOG+fvbQ MTzLx5Pu/CA+hOz9wsifAfFCKC2PU+RLPpajm5v17LDJ6W/FafIynunkSuFkpQQOsC OVBolCPMBD7/C18RZsy+kujHuhlrM2Sbc7USiwgY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Alex Coplan To: gcc-cvs@gcc.gnu.org Subject: [gcc r15-126] cfgrtl: Fix MEM_EXPR update in duplicate_insn_chain [PR114924] X-Act-Checkin: gcc X-Git-Author: Alex Coplan X-Git-Refname: refs/heads/master X-Git-Oldrev: 7117e1f6bf6de25c1ff26c4d7abcc79b407ca221 X-Git-Newrev: fe40d525619eee9c2821126390df75068df4773a Message-Id: <20240503082432.ADDF4385E836@sourceware.org> Date: Fri, 3 May 2024 08:24:32 +0000 (GMT) List-Id: https://gcc.gnu.org/g:fe40d525619eee9c2821126390df75068df4773a commit r15-126-gfe40d525619eee9c2821126390df75068df4773a Author: Alex Coplan Date: Fri May 3 09:23:59 2024 +0100 cfgrtl: Fix MEM_EXPR update in duplicate_insn_chain [PR114924] The PR shows that when cfgrtl.cc:duplicate_insn_chain attempts to update the MR_DEPENDENCE_CLIQUE information for a MEM_EXPR we can end up accidentally dropping (e.g.) an ARRAY_REF from the MEM_EXPR and end up replacing it with the underlying MEM_REF. This leads to an inconsistency in the MEM_EXPR information, and could lead to wrong code. While the walk down to the MEM_REF is necessary to update MR_DEPENDENCE_CLIQUE, we should use the outer tree expression for the MEM_EXPR. This patch does that. gcc/ChangeLog: PR rtl-optimization/114924 * cfgrtl.cc (duplicate_insn_chain): When updating MEM_EXPRs, don't strip (e.g.) ARRAY_REFs from the final MEM_EXPR. Diff: --- gcc/cfgrtl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/cfgrtl.cc b/gcc/cfgrtl.cc index 304c429c99b..a5dc3512159 100644 --- a/gcc/cfgrtl.cc +++ b/gcc/cfgrtl.cc @@ -4432,12 +4432,13 @@ duplicate_insn_chain (rtx_insn *from, rtx_insn *to, since MEM_EXPR is shared so make a copy and walk to the subtree again. */ tree new_expr = unshare_expr (MEM_EXPR (*iter)); + tree orig_new_expr = new_expr; if (TREE_CODE (new_expr) == WITH_SIZE_EXPR) new_expr = TREE_OPERAND (new_expr, 0); while (handled_component_p (new_expr)) new_expr = TREE_OPERAND (new_expr, 0); MR_DEPENDENCE_CLIQUE (new_expr) = newc; - set_mem_expr (const_cast (*iter), new_expr); + set_mem_expr (const_cast (*iter), orig_new_expr); } } }