This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Useless assembly
- From: "Sam Lauber" <sam124 at operamail dot com>
- To: "Robert Dewar" <dewar at gnat dot com>, gcc at gcc dot gnu dot org
- Date: Tue, 30 Nov 2004 03:45:47 +0100
- Subject: Re: Useless assembly
What's the stack have to do with it? I thought I had a 32-bit i686. Why would we have to align the stack to a 16-bit boundry? And why would there have to be a stack at all?
----- Original Message -----
From: "Robert Dewar" <dewar@gnat.com>
To: "Sam Lauber" <sam124@operamail.com>
Subject: Re: Useless assembly
Date: Sun, 28 Nov 2004 22:26:40 -0500
>
> Sam Lauber wrote:
>
> > By hand-optimizing the assembly, I made this:
> >
> > .LC0:
> > .string "Hello World!\n"
> > .globl main
> > .type main, @function
> > main:
> > pushl %ebp
> > movl %esp, %ebp
> > movl $.LC0, (%esp)
> > call printf
> > leave
> >
> > It worked the exact same. Clearly a lot was unnessecary. Removing "call printf" or "movl $.LC0, (%esp)" caused it not to print "Hello World!". Removing ".globl main" caused the linker to fail with an undefined reference to main. Removing anything else caused it to print Hello World and then generate a segmentation fault. Optimizing it at -O3 (which I'm sure includes SSA, DCE, and CCP) just made the compilation take longer and generate more assembly then the first time. If someone could just automate removing that code in cc1, it would probably mean a lot of optimization. Also, when I just compiled a "return 0;", I would expect that to just generate main and the instruction "ret" (or is it "retn?"). Instead, it generated a lot of extra instructions, then finally "ret". Clearly this is unsatisfactory. It makes cc1, as, and ld slower because they have to compile, assemble, and link more instructions. Each extra instruction makes a compilation time penalty of -3 and a runtime
> penalty of -1. At least that could be put onto DCE. If extra code gets generated by cc1, as and ld can't optimize it.
> >
> > Samuel Lauber
>
> Yes, but you fail to establish 16-byte alignment for the
> stack, which is the normal default. If you don't want
> 16-byte alignment for the stack, supply an appropriate
> switch (e.g. -mpreferred-stack-boundary=2).
>
>
--
_____________________________________________________________
Web-based SMS services available at http://www.operamail.com.
From your mailbox to local or overseas cell phones.
Powered by Outblaze