bad code generation on x86

Ulrich Drepper drepper@cygnus.com
Sun May 30 16:04:00 GMT 1999


The current mainline egcs generates very bad/strange code for the
stack frame handling.  Use the following sources file

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int foo (int, int);

int bar (int a, int b, int c)
{
  return foo (a + b, c);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

and compile it using -O3.  To see the problem most clearly use

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drepper@myware cv$ gcc -O3 -c -Wa,-al u.c -fomit-frame-pointer -mregparm=3    
GAS LISTING /tmp/ccItjaaa.s                     page 1


   1                            .file   "u.c"
   2                            .version        "01.01"
   3                    gcc2_compiled.:
   4                    .text
   5                            .align 4
   6                    .globl bar
   7                            .type    bar,@function
   8                    bar:
   9 0000 83EC0C                subl $12,%esp
  10 0003 01D0                  addl %edx,%eax
  11 0005 89CA                  movl %ecx,%edx
  12 0007 E8FCFFFF              call foo
  12      FF
  13 000c 83C40C                addl $12,%esp
  14 000f C3                    ret
  15                    .Lfe1:
  16                            .size    bar,.Lfe1-bar
  17                            .ident  "GCC: (GNU) gcc-2.96 19990530 (experimental)"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The problem is of course the `subl $12,%esp'/`addl $12,%esp' pair.  It
also appears when you emit any of the options beside -O3.  I really
have no idea where the $12 can come from.  The number of bytes used
for the called funciton is only 8.  The number of bytes used for the
parameters of current function is 12 bytes but this should not have
any effect.

I don't know how the release branch compiler behaves since I don't
have this version handy.

-- 
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------


More information about the Gcc-bugs mailing list