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

--- Comment #15 from rguenther at suse dot de <rguenther at suse dot de> ---
On Mon, 3 Mar 2025, jamborm at gcc dot gnu.org wrote:

> 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:

There is refs_same_for_tbaa_p and I believe we have some other
compatibility function I can't find right now done by Honza for
path-based analysis which should be used by ICF and friends.

> 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)));
> +

I think you'd want to formulate this in a TBAA way instead.  Since
we constrain the base objects to be decls and the access path to
contain no V_C_Es it should be reasonable to do

  tbaa_hazard = !alias_sets_conflict_p (get_alias_set (lhs),
                                        get_alias_set (rhs));

which is a simplified form of what refs_same_for_tbaa_p checks
but which is not in any way flow-sensitive (refs_same_for_tbaa_p is).

If we then have a similar check when we process the access tree
of 'lhs' or 'rhs', that is, when we have two different typed
accesses to [0, 8] of lhs for example, then I think it should
be "complete".

>    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