aggregate alias anomaly

Jeff Sturm jsturm@one-point.com
Wed Feb 25 13:56:00 GMT 2004


On Wed, 18 Feb 2004, Dan Nicolaescu wrote:
> Jeff Sturm <jsturm@one-point.com> writes:
>
>   > Given:
> >
>   > struct X {int x;};
>   > struct Y {int y;};
> >
>   > int f(struct X *x, struct Y *y) {
>   >         x->x = 0;
>   >         y->y = 1;
>   >         return x->x;
>   > }
> >
>   > gcc -O2 -fomit-frame-pointer yields:
> >
>   > f:
>   >         movl    4(%esp), %eax
>   >         movl    8(%esp), %edx
>   >         movl    $0, (%eax)
>   >         movl    $1, (%edx)
>   >         movl    (%eax), %eax
>   >         ret
> >
>   > for every released compiler I tried, plus mainline.  Note the useless load
>   > of x->x, given that x and y cannot possibly have conflicting alias sets.
>
> I am not a language lawyer (nor have any desire to be one), but that
> is not necessarily correct for C. See DR257 (and also the "What is an
> object DR").

I see.  I may have unintentionally found a tree-ssa bug, then.  I'll file
a PR today.

> On the other hand, even if you change struct X and Y so that they
> don't have a common initial sequence:
> struct X {char c; int x;};
> struct Y {int y; short d;};
>
> your function still won't be optimized....
>
> I posted a patch some time ago that solved a problem
> related to this (or the same?):
>
> http://gcc.gnu.org/ml/gcc-patches/2002-03/msg00576.html
>
> This version even has a java example:
>
> http://gcc.gnu.org/ml/gcc-patches/2002-03/msg01869.html
>
> If there's interest I could revive that patch.

Nice.  My example was based on a Java example.

Given that merging tree-ssa appears imminent now, and tree-ssa does a far
better job than mainline of alias analysis for Java, it doesn't seem to be
worth reviving your patch unless it were considered suitable for 3.4
(unlikely).

Thanks,

Jeff



More information about the Gcc mailing list