https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118924

--- Comment #14 from Martin Jambor <jamborm at gcc dot gnu.org> ---
So something like the following - which is completely untested, the
type test may be a wrong one, I'd like to think this through a little
more before actually proposing this, but any comments still welcome:

diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc
index c26559edc66..88b350800ce 100644
--- a/gcc/tree-sra.cc
+++ b/gcc/tree-sra.cc
@@ -979,6 +979,7 @@ create_access (tree expr, gimple *stmt, bool write)
   access->type = TREE_TYPE (expr);
   access->write = write;
   access->grp_unscalarizable_region = unscalarizable_region;
+  access->grp_same_access_path = true;
   access->stmt = stmt;
   access->reverse = reverse;

@@ -1522,6 +1523,10 @@ build_accesses_from_assign (gimple *stmt)
   racc = build_access_from_expr_1 (rhs, stmt, false);
   lacc = build_access_from_expr_1 (lhs, stmt, true);

+  bool tbaa_hazard
+    = (TYPE_MAIN_VARIANT (TREE_TYPE (lhs))
+       == TYPE_MAIN_VARIANT (TREE_TYPE (rhs)));
+
   if (lacc)
     {
       lacc->grp_assignment_write = 1;
@@ -1536,6 +1541,8 @@ build_accesses_from_assign (gimple *stmt)
            bitmap_set_bit (cannot_scalarize_away_bitmap,
                            DECL_UID (lacc->base));
        }
+      if (tbaa_hazard)
+       lacc->grp_same_access_path = false;
     }

   if (racc)
@@ -1555,6 +1562,8 @@ build_accesses_from_assign (gimple *stmt)
        }
       if (storage_order_barrier_p (lhs))
        racc->grp_unscalarizable_region = 1;
+      if (tbaa_hazard)
+       racc->grp_same_access_path = false;
     }

   if (lacc && racc
@@ -2396,7 +2405,7 @@ sort_and_splice_var_accesses (tree var)
       bool grp_partial_lhs = access->grp_partial_lhs;
       bool first_scalar = is_gimple_reg_type (access->type);
       bool unscalarizable_region = access->grp_unscalarizable_region;
-      bool grp_same_access_path = true;
+      bool grp_same_access_path = access->grp_same_access_path;
       bool bf_non_full_precision
        = (INTEGRAL_TYPE_P (access->type)
           && TYPE_PRECISION (access->type) != access->size
@@ -2432,7 +2441,8 @@ sort_and_splice_var_accesses (tree var)
          return NULL;
        }

-      grp_same_access_path = path_comparable_for_same_access (access->expr);
+      if (grp_same_access_path)
+       grp_same_access_path = path_comparable_for_same_access (access->expr);

       j = i + 1;
       while (j < access_count)

Reply via email to