On Tue, 14 Apr 2020, Jan Hubicka wrote:

> > 
> > Note that now, looking again, the TYPE_STRUCTURAL_EQUALITY_P in my patch
> > doesn't match that of get_alias_set.  Since we're looking at the alias
> > sets of type1 and type2 anyway we could resort to alias_sets_conflict_p
> > for the two POINTER_TYPE_P case and return -1 then.  Not sure about
> > returning 1 - they are not the same as in, one cannot replace a
> > *(void *) access with a *(T *) access since the latter behaves differently
> > wrt a *(U *) access not visible to the call.
> > 
> > But the semantics of same_type_for_tbaa are not entirely clear
> > (ISTR you suggested to use it for ICF-like compares).
> 
> I think it is clear.
> 
> 0 means that accesspath ending by one type can not continue by access path 
> starting by the other type.
> 1 means that they can continue.
> -1 means that we do not know (or are too lazy to decide).
> 
> In this partiuclar case we have the continuation path trivial and we
> only want to check if one continues the other, so 1 should work.

But we're using it in indirect_ref_may_alias_decl_p as

      /* If second reference is view-converted, give up now.  */
      if (same_type_for_tbaa (TREE_TYPE (dbase2), TREE_TYPE (ptrtype2)) != 
1)
        return true;

and clearly if TREE_TYPE (ptrtype2) is void * while TREE_TYPE (dbase2)
is T * we've "view-converted" things.

Not sure what the consequence is when we fall through here since those
checks may be redundant now(?)  But given we're late for GCC 10 I'd
rather be safe than sorry ;)

> For ICF checking we need to be more careful anyway (in particular we do
> not want all those -1s on arrays), so I would worry about that next
> stage1.
> 
> With 1 we will probably save some work since the code will not continue
> looking for must aliases.

I think we have still quite some cleanup to do for the path-based
disambiguations.

Richard.

> Honza
> 
> > 
> > So, like the following.
> > 
> > Richard.
> > 
> > 
> > middle-end/94539 - void * aliases every other pointer
> > 
> > This makes same_type_for_tbaa_p conservative in the same way
> > get_alias_set is about void * which we allow to alias all other
> > pointers.
> > 
> > 2020-04-14  Richard Biener  <rguent...@suse.de>
> > 
> >     PR middle-end/94539
> >     * tree-ssa-alias.c (same_type_for_tbaa): Defer to
> >     alias_sets_conflict_p for pointers.
> > 
> >     * gcc.dg/alias-14.c: Make dg-do run.
> > ---
> >  gcc/testsuite/gcc.dg/alias-14.c |  2 +-
> >  gcc/tree-ssa-alias.c            | 11 ++++++++++-
> >  2 files changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/gcc/testsuite/gcc.dg/alias-14.c 
> > b/gcc/testsuite/gcc.dg/alias-14.c
> > index 1ca1c09d5e3..24f0d1c1168 100644
> > --- a/gcc/testsuite/gcc.dg/alias-14.c
> > +++ b/gcc/testsuite/gcc.dg/alias-14.c
> > @@ -1,4 +1,4 @@
> > -/* { dg-do compile } */
> > +/* { dg-do run } */
> >  /* { dg-options "-O2" } */
> >  #include <stddef.h>
> >  void *a;
> > diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
> > index df9ba0de0d6..ede4f198342 100644
> > --- a/gcc/tree-ssa-alias.c
> > +++ b/gcc/tree-ssa-alias.c
> > @@ -839,7 +839,16 @@ same_type_for_tbaa (tree type1, tree type2)
> >       would mean that conversions between them are useless, whereas they are
> >       not (e.g. type and subtypes can have different modes).  So, in the 
> > end,
> >       they are only guaranteed to have the same alias set.  */
> > -  if (get_alias_set (type1) == get_alias_set (type2))
> > +  alias_set_type set1 = get_alias_set (type1);
> > +  alias_set_type set2 = get_alias_set (type2);
> > +  if (set1 == set2)
> > +    return -1;
> > +
> > +  /* Pointers to void are considered compatible with all other pointers,
> > +     so for two pointers see what the alias set resolution thinks.  */
> > +  if (POINTER_TYPE_P (type1)
> > +      && POINTER_TYPE_P (type2)
> > +      && alias_sets_conflict_p (set1, set2))
> >      return -1;
> >  
> >    /* The types are known to be not equal.  */
> > -- 
> > 2.13.7
> > 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

Reply via email to