https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107206
--- Comment #5 from Martin Jambor <jamborm at gcc dot gnu.org> --- I believe this is fallout from the fix to PR 92706 where we started propagating accesses across assignments also from LHS to RHS and because everything is totally flow-insensitive, we have an access representing: MEM[(union _StorageD.10576 *)&D.11678]._M_valueD.10616 = 1; which gets propagated across: zD.11527.yD.11476.oD.11384 = D.11678; but this then triggers the LHS->RHS propagation across: MEM[(struct YD.10174 *)&zD.11527].oD.11384 = MEM[(const struct YD.10174 &)&D.11546].oD.11384; So another reason to re-invent SRA from scratch. Apart from that, I don't have a good solution except for adding another flag to mark accesses that are result of LHS->RHS propagation and ignore them if their base did not get totally scalarized because in the PR they were added basically to prevent bad total scalarization. But of course it is rather another band-aid than a real fix, but it seems to work for this case: diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc index 1a3e12f18cc..6cbeddfc548 100644 --- a/gcc/tree-sra.cc +++ b/gcc/tree-sra.cc @@ -260,6 +260,9 @@ struct access /* Should TREE_NO_WARNING of a replacement be set? */ unsigned grp_no_warning : 1; + + /* Result of propagation accross link from LHS to RHS. */ + unsigned grp_result_of_prop_from_lhs : 1; }; typedef struct access *access_p; @@ -2532,6 +2535,9 @@ analyze_access_subtree (struct access *root, struct access *parent, if (allow_replacements && expr_with_var_bounded_array_refs_p (root->expr)) allow_replacements = false; + if (!totally && root->grp_result_of_prop_from_lhs) + allow_replacements = false; + for (child = root->first_child; child; child = child->next_sibling) { hole |= covered_to < child->offset; @@ -2959,6 +2965,7 @@ propagate_subaccesses_from_lhs (struct access *lacc, struct access *racc) struct access *new_acc = create_artificial_child_access (racc, lchild, norm_offset, true, false); + new_acc->grp_result_of_prop_from_lhs = 1; propagate_subaccesses_from_lhs (lchild, new_acc); } else