From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25838 invoked by alias); 29 Nov 2004 03:26:45 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 25662 invoked from network); 29 Nov 2004 03:26:40 -0000 Received: from unknown (HELO nile.gnat.com) (205.232.38.5) by sourceware.org with SMTP; 29 Nov 2004 03:26:40 -0000 Received: from localhost (localhost [127.0.0.1]) by filtered-nile.gnat.com (Postfix) with ESMTP id 7F9F69661; Sun, 28 Nov 2004 22:26:40 -0500 (EST) Received: from nile.gnat.com ([127.0.0.1]) by localhost (nile.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 23929-01-6; Sun, 28 Nov 2004 22:26:40 -0500 (EST) Received: from [127.0.0.1] (taconic.gnat.com [205.232.38.103]) by nile.gnat.com (Postfix) with ESMTP id 45A71965C; Sun, 28 Nov 2004 22:26:40 -0500 (EST) Message-ID: <41AA96F0.1070707@gnat.com> Date: Mon, 29 Nov 2004 04:25:00 -0000 From: Robert Dewar User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) MIME-Version: 1.0 To: Sam Lauber Cc: gcc@gcc.gnu.org Subject: Re: Useless assembly References: <20041128212717.4590B2B2B86@ws5-7.us4.outblaze.com> In-Reply-To: <20041128212717.4590B2B2B86@ws5-7.us4.outblaze.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at nile.gnat.com X-SW-Source: 2004-11/txt/msg01105.txt.bz2 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).