From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29619 invoked by alias); 5 May 2010 14:38:54 -0000 Received: (qmail 29510 invoked by uid 48); 5 May 2010 14:38:25 -0000 Date: Wed, 05 May 2010 14:38:00 -0000 Subject: [Bug other/43992] New: Suboptimal x86 pre/postamble emitted X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "hv at crypt dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-05/txt/msg00440.txt.bz2 zen% /opt/gcc-4.5.0/bin/gcc -v Using built-in specs. COLLECT_GCC=/opt/gcc-4.5.0/bin/gcc COLLECT_LTO_WRAPPER=/opt/gcc-4.5.0/libexec/gcc/i686-pc-linux-gnu/4.5.0/lto-wrapper Target: i686-pc-linux-gnu Configured with: /src/package/lang/other/gcc-4.5.0/configure --prefix=/opt/gcc-4.5.0 --with-gmp=/opt/gmp-4.2.2 --with-mpfr=/opt/mpfr-2.4.1 --with-mpc=/opt/mpc-0.8.1 Thread model: posix gcc version 4.5.0 (GCC) zen% Compiling with an appropriate LD_LIBRARY_PATH and "/opt/gcc-4.5.0/bin/gcc -o gcctest.s -S -O3 gcctest.c", the assembler produced for the following C code includes unnecessary stack manipulation instructions. I suspect this is x86-specific preamble/postamble generation being confused by the tail-call optimization. zen% cat gcctest.c typedef int (f2_t)(int pi1, int pi2); typedef int (f3_t)(f2_t* pf2, int pi1, int pi2); typedef struct { f2_t* sf2; f3_t* sf3; } cmp_t; int* gip; int f2(int pi1, int pi2) { return 0; } int f3(f2_t* pf2, int pi1, int pi2) { return pf2(gip[pi1], gip[pi2]); } int main(void) { cmp_t ct = { &f2, &f3 }; return ct.sf3(ct.sf2, 0, 0); } zen% The assembler emitted for f3() is: .p2align 4,,15 .globl f3 .type f3, @function f3: pushl %ebp movl %esp, %ebp pushl %ebx subl $4, %esp ; this is not needed movl gip, %eax movl 16(%ebp), %ebx movl 12(%ebp), %ecx movl 8(%ebp), %edx movl (%eax,%ebx,4), %ebx movl %ebx, 12(%ebp) movl (%eax,%ecx,4), %eax movl %eax, 8(%ebp) addl $4, %esp ; this is not needed popl %ebx popl %ebp jmp *%edx .size f3, .-f3 I spotted this initially with gcc-4.4.3, and have just verified that the same code is emitted for 4.5.0. Given that in similar code without a tail-call the stack manipulation is completely elided, this could maybe be classed as a bug. However, the code as generated is not incorrect. -- Summary: Suboptimal x86 pre/postamble emitted Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: other AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hv at crypt dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43992