public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/43992]  New: Suboptimal x86 pre/postamble emitted
@ 2010-05-05 14:38 hv at crypt dot org
  2010-05-05 14:40 ` [Bug other/43992] " hv at crypt dot org
  2010-05-05 15:44 ` hjl dot tools at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: hv at crypt dot org @ 2010-05-05 14:38 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug other/43992] Suboptimal x86 pre/postamble emitted
  2010-05-05 14:38 [Bug other/43992] New: Suboptimal x86 pre/postamble emitted hv at crypt dot org
@ 2010-05-05 14:40 ` hv at crypt dot org
  2010-05-05 15:44 ` hjl dot tools at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: hv at crypt dot org @ 2010-05-05 14:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from hv at crypt dot org  2010-05-05 14:39 -------
Created an attachment (id=20562)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20562&action=view)
Example C source code


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43992


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

* [Bug other/43992] Suboptimal x86 pre/postamble emitted
  2010-05-05 14:38 [Bug other/43992] New: Suboptimal x86 pre/postamble emitted hv at crypt dot org
  2010-05-05 14:40 ` [Bug other/43992] " hv at crypt dot org
@ 2010-05-05 15:44 ` hjl dot tools at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: hjl dot tools at gmail dot com @ 2010-05-05 15:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from hjl dot tools at gmail dot com  2010-05-05 15:44 -------


*** This bug has been marked as a duplicate of 42778 ***


-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43992


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

end of thread, other threads:[~2010-05-05 15:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-05 14:38 [Bug other/43992] New: Suboptimal x86 pre/postamble emitted hv at crypt dot org
2010-05-05 14:40 ` [Bug other/43992] " hv at crypt dot org
2010-05-05 15:44 ` hjl dot tools at gmail dot com

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