From 4dfc6bcabb5a040417e60cb8072e562e25974917 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 13 Dec 2023 09:05:59 +0100 Subject: [PATCH] Avoid losing MEM_REF offset in MEM_EXPR adjustment for stack slot sharing When investigating PR111591 with respect to TBAA and stack slot sharing I noticed we're eventually scrapping a [TARGET_]MEM_REF offset when rewriting the VAR_DECL base of the MEM_EXPR to use a pointer to the partition instead. The following makes sure to preserve that. * emit-rtl.cc (set_mem_attributes_minus_bitpos): Preserve the offset when rewriting an exising MEM_REF base for stack slot sharing. --- gcc/emit-rtl.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gcc/emit-rtl.cc b/gcc/emit-rtl.cc index 84b6833225e..4a7e420e7c0 100644 --- a/gcc/emit-rtl.cc +++ b/gcc/emit-rtl.cc @@ -2128,9 +2128,15 @@ set_mem_attributes_minus_bitpos (rtx ref, tree t, int objectp, tree *orig_base = &attrs.expr; while (handled_component_p (*orig_base)) orig_base = &TREE_OPERAND (*orig_base, 0); - tree aptrt = reference_alias_ptr_type (*orig_base); - *orig_base = build2 (MEM_REF, TREE_TYPE (*orig_base), *namep, - build_int_cst (aptrt, 0)); + if (TREE_CODE (*orig_base) == MEM_REF + || TREE_CODE (*orig_base) == TARGET_MEM_REF) + TREE_OPERAND (*orig_base, 0) = *namep; + else + { + tree aptrt = reference_alias_ptr_type (*orig_base); + *orig_base = build2 (MEM_REF, TREE_TYPE (*orig_base), + *namep, build_int_cst (aptrt, 0)); + } } } -- 2.11.4.GIT