This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: aggregate alias anomaly
- From: Jeff Sturm <jsturm at one-point dot com>
- To: Dan Nicolaescu <dann at godzilla dot ics dot uci dot edu>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 25 Feb 2004 08:48:00 -0500 (EST)
- Subject: Re: aggregate alias anomaly
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