This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Is this correct behaviour?
> -----Original Message-----
> From: Richard Guenther [mailto:richard.guenther@gmail.com]
> Sent: 06 September 2011 16:42
> To: Bingfeng Mei
> Cc: gcc@gcc.gnu.org
> Subject: Re: Is this correct behaviour?
>
> On Tue, Sep 6, 2011 at 5:30 PM, Bingfeng Mei <bmei@broadcom.com> wrote:
> > Hi,
> > I compile the following code with arm gcc 4.6 (x86 is the similar
> with one of 4.7 snapshot).
> > I noticed "a" is written to memory three times instead of being added
> by 3 and written at the
> > end. Doesn't restrict guarantee "a" won't be aliased to "p" so 3
> "a++" can be optimized?
>
> No it does not.
Then how do I tell compiler that "a" is not aliased if I have to use global variable?
>
> > Thanks,
> > Bingfeng Mei
> >
> > int a;
> > int P[100];
> > void foo (int * restrict p)
> > {
> > ?P[0] = *p;
> > ?a++;
> > ?P[1] = *p;
> > ?a++;
> > ?P[2] = *p;
> > ?a++;
> > }
> >
> > ~/work/install-arm/bin/arm-elf-gcc tst.c -O2 -S -std=c99
> >
> > foo:
> > ? ? ? ?@ args = 0, pretend = 0, frame = 0
> > ? ? ? ?@ frame_needed = 0, uses_anonymous_args = 0
> > ? ? ? ?@ link register save eliminated.
> > ? ? ? ?ldr ? ? r3, .L2
> > ? ? ? ?ldr ? ? r1, [r3, #0]
> > ? ? ? ?ldr ? ? ip, [r0, #0]
> > ? ? ? ?ldr ? ? r2, .L2+4
> > ? ? ? ?str ? ? r4, [sp, #-4]!
> > ? ? ? ?add ? ? r4, r1, #1
> > ? ? ? ?str ? ? r4, [r3, #0]
> > ? ? ? ?str ? ? ip, [r2, #0]
> > ? ? ? ?ldr ? ? ip, [r0, #0]
> > ? ? ? ?add ? ? r4, r1, #2
> > ? ? ? ?str ? ? r4, [r3, #0]
> > ? ? ? ?str ? ? ip, [r2, #4]
> > ? ? ? ?ldr ? ? r0, [r0, #0]
> > ? ? ? ?add ? ? r1, r1, #3
> > ? ? ? ?str ? ? r0, [r2, #8]
> > ? ? ? ?str ? ? r1, [r3, #0]
> > ? ? ? ?ldmfd ? sp!, {r4}
> > ? ? ? ?bx ? ? ?lr
> >
> >