* 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
* Re: Is this correct behaviour?
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
0 siblings, 1 reply; 4+ messages in thread
From: Richard Guenther @ 2011-09-06 15:42 UTC (permalink / raw)
To: Bingfeng Mei; +Cc: gcc
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
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Is this correct behaviour?
2011-09-06 15:42 ` Richard Guenther
@ 2011-09-06 15:54 ` Bingfeng Mei
2011-09-06 22:30 ` Ian Lance Taylor
0 siblings, 1 reply; 4+ messages in thread
From: Bingfeng Mei @ 2011-09-06 15:54 UTC (permalink / raw)
To: Richard Guenther; +Cc: gcc
> -----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
> >
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Is this correct behaviour?
2011-09-06 15:54 ` Bingfeng Mei
@ 2011-09-06 22:30 ` Ian Lance Taylor
0 siblings, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2011-09-06 22:30 UTC (permalink / raw)
To: Bingfeng Mei; +Cc: Richard Guenther, gcc
"Bingfeng Mei" <bmei@broadcom.com> writes:
> 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++;
>> > }
How about
int a;
int P[100];
void foo (int * restrict p)
{
foo1 (p, P, &a);
}
void foo1 (int * restrict p, int * restrict pp, int * restrict pa)
{
pp[0] = *p;
a++;
pp[1] = *p;
a++;
pp[2] = *p;
a++;
}
Ian
^ 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).