* [new-ra] GCC-3.3.2/x86: some suspicious behaviour
@ 2004-07-07 22:06 Denis Zaitsev
2004-07-08 14:46 ` Michael Matz
0 siblings, 1 reply; 5+ messages in thread
From: Denis Zaitsev @ 2004-07-07 22:06 UTC (permalink / raw)
To: gcc; +Cc: linux-gcc
This source
extern inline
void *i(void *d, void *s, int n)
{
__asm__ __volatile__ ( ""
:"+&c"(n), "+&D"(d), "+&S"(s)
);
}
void *o(void *d, void *s, int n)
{
return i(d, s, n);
}
is compiled into that assembler:
o:
pushl %edi
pushl %esi
movl 12(%esp), %edi
movl 16(%esp), %esi
movl 20(%esp), %ecx
popl %esi
popl %edi
ret
Everything looks ok. But the source modified slightly
extern inline
void *i(void *d, void *s, int n)
{
__asm__ __volatile__ ( ""
:"+&c"(n), "+&D"(d), "+&S"(s)
);
__asm__ __volatile__ ( ""
:"+&c"(n), "+&D"(d), "+&S"(s)
);
}
void *o(void *d, void *s, int n)
{
return i(d, s, n);
}
is compiled into that assembler:
o:
pushl %edi
pushl %esi
movl 12(%esp), %edi
movl 20(%esp), %ecx
movl 16(%esp), %esi
movl %ecx, 16(%esp)
movl %esi, 20(%esp)
popl %esi
popl %edi
ret
So, what does these two commands mean:
movl %ecx, 16(%esp)
movl %esi, 20(%esp)
? The options for the compiler are:
-O2 -fomit-frame-pointer -fnew-ra
The result is the same for any -O >0 and for -Os. And the presence of
these suspicious commands are not affected by the frame-pointer
option.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [new-ra] GCC-3.3.2/x86: some suspicious behaviour
2004-07-07 22:06 [new-ra] GCC-3.3.2/x86: some suspicious behaviour Denis Zaitsev
@ 2004-07-08 14:46 ` Michael Matz
2004-07-08 16:31 ` Denis Zaitsev
0 siblings, 1 reply; 5+ messages in thread
From: Michael Matz @ 2004-07-08 14:46 UTC (permalink / raw)
To: Denis Zaitsev; +Cc: gcc, linux-gcc
Hi,
On Thu, 8 Jul 2004, Denis Zaitsev wrote:
> So, what does these two commands mean:
>
>
> movl %ecx, 16(%esp)
> movl %esi, 20(%esp)
It means that the compiler wasn't able to optimize them away. They do no
harm. FWIW gcc 3.4 or the new-regalloc-branch don't have this problem.
> The result is the same for any -O >0 and for -Os. And the presence of
> these suspicious commands are not affected by the frame-pointer option.
Ciao,
Michael.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [new-ra] GCC-3.3.2/x86: some suspicious behaviour
2004-07-08 14:46 ` Michael Matz
@ 2004-07-08 16:31 ` Denis Zaitsev
2004-07-08 16:52 ` Paul Brook
0 siblings, 1 reply; 5+ messages in thread
From: Denis Zaitsev @ 2004-07-08 16:31 UTC (permalink / raw)
To: Michael Matz; +Cc: gcc, linux-gcc
On Thu, Jul 08, 2004 at 04:46:33PM +0200, Michael Matz wrote:
> Hi,
>
> On Thu, 8 Jul 2004, Denis Zaitsev wrote:
>
> > So, what does these two commands mean:
> >
> >
> > movl %ecx, 16(%esp)
> > movl %esi, 20(%esp)
>
> It means that the compiler wasn't able to optimize them away. They do no
> harm. FWIW gcc 3.4 or the new-regalloc-branch don't have this problem.
They don't harm. But to optimize _what_? So, what is the initial
meaning of these assignments? And why they appear only for the double
asm statement?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [new-ra] GCC-3.3.2/x86: some suspicious behaviour
2004-07-08 16:31 ` Denis Zaitsev
@ 2004-07-08 16:52 ` Paul Brook
2004-07-08 17:18 ` Denis Zaitsev
0 siblings, 1 reply; 5+ messages in thread
From: Paul Brook @ 2004-07-08 16:52 UTC (permalink / raw)
To: gcc; +Cc: Denis Zaitsev, Michael Matz, linux-gcc
On Thursday 08 July 2004 17:31, Denis Zaitsev wrote:
> On Thu, Jul 08, 2004 at 04:46:33PM +0200, Michael Matz wrote:
> > Hi,
> >
> > On Thu, 8 Jul 2004, Denis Zaitsev wrote:
> > > So, what does these two commands mean:
> > >
> > >
> > > movl %ecx, 16(%esp)
> > > movl %esi, 20(%esp)
> >
> > It means that the compiler wasn't able to optimize them away. They do no
> > harm. FWIW gcc 3.4 or the new-regalloc-branch don't have this problem.
>
> They don't harm. But to optimize _what_? So, what is the initial
> meaning of these assignments? And why they appear only for the double
> asm statement?
They're storing the modified values of s and d back into their stack slots
after the first asm. The compiler wasn't able to determine that these were
dead stores.
Remove the "extern inline" and compile with -O0. This will show you
approximately what the code looks like before optimization.
Paul
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [new-ra] GCC-3.3.2/x86: some suspicious behaviour
2004-07-08 16:52 ` Paul Brook
@ 2004-07-08 17:18 ` Denis Zaitsev
0 siblings, 0 replies; 5+ messages in thread
From: Denis Zaitsev @ 2004-07-08 17:18 UTC (permalink / raw)
To: Paul Brook; +Cc: gcc, Michael Matz, linux-gcc
On Thu, Jul 08, 2004 at 05:52:57PM +0100, Paul Brook wrote:
> On Thursday 08 July 2004 17:31, Denis Zaitsev wrote:
> > On Thu, Jul 08, 2004 at 04:46:33PM +0200, Michael Matz wrote:
> > > Hi,
> > >
> > > On Thu, 8 Jul 2004, Denis Zaitsev wrote:
> > > > So, what does these two commands mean:
> > > >
> > > >
> > > > movl %ecx, 16(%esp)
> > > > movl %esi, 20(%esp)
> > >
> > > It means that the compiler wasn't able to optimize them away. They do no
> > > harm. FWIW gcc 3.4 or the new-regalloc-branch don't have this problem.
> >
> > They don't harm. But to optimize _what_? So, what is the initial
> > meaning of these assignments? And why they appear only for the double
> > asm statement?
>
> They're storing the modified values of s and d back into their stack slots
> after the first asm. The compiler wasn't able to determine that these were
> dead stores.
>
> Remove the "extern inline" and compile with -O0. This will show you
> approximately what the code looks like before optimization.
Yes, this way the variables are really just stored back into their
stack locations. But in my case:
movl 20(%esp), %ecx
movl 16(%esp), %esi
movl %ecx, 16(%esp)
movl %esi, 20(%esp)
So, the stack slots seem to be swapped. Why?
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-07-08 17:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-07 22:06 [new-ra] GCC-3.3.2/x86: some suspicious behaviour Denis Zaitsev
2004-07-08 14:46 ` Michael Matz
2004-07-08 16:31 ` Denis Zaitsev
2004-07-08 16:52 ` Paul Brook
2004-07-08 17:18 ` Denis Zaitsev
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 NNTP newsgroup(s).