This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Useless assembly


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]