Type-based alias analysis and alias sets

Richard Guenther rguenther@suse.de
Fri Oct 23 14:04:00 GMT 2009


On Fri, 23 Oct 2009, Eric Botcazou wrote:

> Hi Richard,
> 
> I just (re-)discovered that the new TBAA machinery is quite aggressive and 
> breaks cases that used to work in Ada (-O2 testcase for SPARC64 attached).
> 
> The problem boils down to this:
> 
>   D.1416_1 = (struct p__rec &) &r.F;
>   r.F = ...
>   ... = D.1416_1->d;
> 
> DSE computes that the store to r.F is dead and eliminates it at -O2 because 
> ultimately nonaliasing_component_refs_p returns false:
> 
>   /* If we have two type access paths B1.path1 and B2.path2 they may
>      only alias if either B1 is in B2.path2 or B2 is in B1.path1.  */
>   return false;
> 
> [Shouldn't nonaliasing_component_refs_p be named aliasing_component_refs_p or 
> component_refs_may_alias_p instead]?

Err, yes ;)  I named it after the RTL variant in alias.c.

> Yes, it's a blatant type-punning case but all the structure types are given 
> the same alias set (struct p__rec, type of r, type of F) and 'd' is not 
> addressable so all the memory accesses are done with the same alias set.
> 
> The root of the problem is that same_type_for_tbaa never returns true since 
> the types don't have the same TYPE_CANONICAL (rightfully so, they are not 
> equivalent) so we fall back to the final return of nonaliasing_c_r_p.
> 
> Shouldn't this final return be 'true' instead of 'false', like the final 
> return in indirect_ref_may_alias_decl_p, so that the ultimate fallback is the 
> comparison of alias sets like it used to be?

I changed this default to false somewhen in the past.  There was a
big fat comment there on the alias-improvements branch (where I
wondered if returning false would be a safe thing to do).

I didn't find (or could construct) a single C or C++ testcase that
wasn't fine with the new default, so I switched it (IIRC the default
is disambiguating the most cases).

I'm fine with switching it back though, this time with a comment
explaining why it is not safe (instead of just speculating) and
a testcase (I guess you now indeed have one).  Care to prepare
a patch?

Thanks,
Richard.



More information about the Gcc mailing list