public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Poor i386 code from egcs.
@ 1998-06-27  4:30 ak
  1998-06-27 10:03 ` Joern Rennecke
  0 siblings, 1 reply; 3+ messages in thread
From: ak @ 1998-06-27  4:30 UTC (permalink / raw)
  To: egcs

Hello,

Given this simple program:
(is it safe to use &tmp after the scope ends? Seems to do no harm in gcc)

#define NUMADDR(x) ({ typeof(x) tmp = (x); &tmp; })

f()
{
	f2(NUMADDR(1));
}

% egcc -v
Reading specs from /pkg/egcs-980605/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.34/specs
gcc version egcs-2.91.34 19980605 (gcc2 ss-980502 experimental)

% egcc -O2 -fomit-frame-pointer -S tcadr.c

Results in this assembler code:

.globl f
        .type    f,@function
f:
        subl $4,%esp
        movl $1,(%esp)
        movl %esp,%eax
        pushl %eax           <----- why can't it push %esp directly?
        call f2
        addl $4,%esp
        addl $4,%esp         <------ why not combine them in one addl?
        ret

Especially the double add looks bad on i386 (it would make sense on m68k,
but not on i386 I think) because it is probably a common occurence. It is
not dependent on the ({ }) block, but happens in an ANSI-C equivalent too.

Is it possible to fix it with a peephole optimizer rule?

I believe the push problem could be fixed by some "widening" of constraints
in i386.md, but my understanding is not good enough to do it myself. 


-Andi

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

* Re: Poor i386 code from egcs.
  1998-06-27  4:30 Poor i386 code from egcs ak
@ 1998-06-27 10:03 ` Joern Rennecke
  1998-06-27 12:05   ` ak
  0 siblings, 1 reply; 3+ messages in thread
From: Joern Rennecke @ 1998-06-27 10:03 UTC (permalink / raw)
  To: ak; +Cc: egcs

>         movl %esp,%eax
>         pushl %eax           <----- why can't it push %esp directly?

And what would that mean, then?  How do you know what value of esp is pushed?

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

* Re: Poor i386 code from egcs.
  1998-06-27 10:03 ` Joern Rennecke
@ 1998-06-27 12:05   ` ak
  0 siblings, 0 replies; 3+ messages in thread
From: ak @ 1998-06-27 12:05 UTC (permalink / raw)
  To: Joern Rennecke; +Cc: ak, egcs

On Sat, Jun 27, 1998 at 06:38:40PM +0200, Joern Rennecke wrote:
> >         movl %esp,%eax
> >         pushl %eax           <----- why can't it push %esp directly?
> 
> And what would that mean, then?  How do you know what value of esp is pushed?

To quote my Pentium Manual p25-253

"The PUSH ESP instruction pushes the value of the ESP register as it existed before the
instruction. This differs from the 8086, where the PUSH SP instruction pushes the new value
(decremented by 2).

Likewise, a PUSH-from-memory instruction, which uses the stack pointer (ESP) as a base
register, references memory before the PUSH. The base used is the value of the ESP before
the instruction executes."

GCC does not support the 8086 or 16bit code, so backward compatibility is no 
problem. 


-Andi

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

end of thread, other threads:[~1998-06-27 12:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-27  4:30 Poor i386 code from egcs ak
1998-06-27 10:03 ` Joern Rennecke
1998-06-27 12:05   ` ak

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