]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid losing MEM_REF offset in MEM_EXPR adjustment for stack slot sharing
authorRichard Biener <rguenther@suse.de>
Wed, 13 Dec 2023 08:05:59 +0000 (09:05 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 13 Dec 2023 09:06:30 +0000 (10:06 +0100)
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

index 84b6833225e627f36361bc5de095065e808a02ba..4a7e420e7c0590b2d1855f2313f363dc8cd3076a 100644 (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));
+               }
            }
        }