On 05/24/2016 03:14 AM, Richard Biener wrote:
On Wed, 18 May 2016, Richard Biener wrote:


The following adjusts get_alias_set beahvior when applied to
union accesses to use the union alias-set rather than alias-set
zero.  This is in line with behavior from the alias oracle
which (bogously) circumvents alias-set zero with looking at
the alias-sets of the base object.  Thus for

union U { int i; float f; };

float
foo (union U *u, double *p)
{
  u->f = 1.;
  *p = 0;
  return u->f;
}

the langhooks ensured u->f has alias-set zero and thus disambiguation
against *p was not allowed.  Still the alias-oracle did the disambiguation
by using the alias set of the union here (I think optimizing the
return to return 1. is valid).

We have a good place in the middle-end to apply such rules which
is component_uses_parent_alias_set_from - this is where I move
the logic that is duplicated in various frontends.

The Java and Ada frontends do not allow union type punning (LTO does),
so this patch may eventually pessimize them.  I don't care anything
about Java but Ada folks might want to chime in.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Ok for trunk?

Ping.

Thanks,
Richard.

Thanks,
Richard.

2016-05-18  Richard Biener  <rguent...@suse.de>

        * alias.c (component_uses_parent_alias_set_from): Handle
        type punning through union accesses by using the union alias set.
        * gimple.c (gimple_get_alias_set): Remove union type punning case.

        c-family/
        * c-common.c (c_common_get_alias_set): Remove union type punning case.
        
        fortran/
        * f95-lang.c (LANG_HOOKS_GET_ALIAS_SET): Remove (un-)define.
        (gfc_get_alias_set): Remove.
You know the aliasing rules better than I. If you're confident using the union's alias set is safe, then it's OK with me.

My only worry is that if we get it wrong, it's likely to be a subtle bug that may take a long time to expose itself. But that in and of itself shouldn't stop us from going forward.


Jeff

Reply via email to