diff options
author | Alex Coplan <alex.coplan@arm.com> | 2024-05-03 09:23:59 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2024-06-12 13:41:40 +0200 |
commit | 33663c0701a723846527f9bf2ea01d67d7033c0b (patch) | |
tree | 6e02c08fdcc0e1d7ce79d5a934c305b14669bd78 | |
parent | 959cef942508b818c7dcb8df0f3c7bf4968d406a (diff) | |
download | gcc-33663c0701a723846527f9bf2ea01d67d7033c0b.zip gcc-33663c0701a723846527f9bf2ea01d67d7033c0b.tar.gz gcc-33663c0701a723846527f9bf2ea01d67d7033c0b.tar.bz2 |
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.
(cherry picked from commit fe40d525619eee9c2821126390df75068df4773a)
-rw-r--r-- | gcc/cfgrtl.cc | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/cfgrtl.cc b/gcc/cfgrtl.cc index 8decf40..a8c95d8 100644 --- a/gcc/cfgrtl.cc +++ b/gcc/cfgrtl.cc @@ -4374,12 +4374,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 <rtx> (*iter), new_expr); + set_mem_expr (const_cast <rtx> (*iter), orig_new_expr); } } } |