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.
This commit is contained in:
Richard Biener 2023-12-13 09:05:59 +01:00
parent 93db32a414
commit 4dfc6bcabb

View file

@ -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));
}
}
}