This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.

> 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
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]