public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Is this correct behaviour?
@ 2011-09-06 15:31 Bingfeng Mei
  2011-09-06 15:42 ` Richard Guenther
  0 siblings, 1 reply; 4+ messages in thread
From: Bingfeng Mei @ 2011-09-06 15:31 UTC (permalink / raw)
  To: gcc

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?

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-06 22:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-06 15:31 Is this correct behaviour? Bingfeng Mei
2011-09-06 15:42 ` Richard Guenther
2011-09-06 15:54   ` Bingfeng Mei
2011-09-06 22:30     ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).