Elimination of function call

negit@dela-grante.net negit@dela-grante.net
Wed Oct 20 13:07:00 GMT 2004


Hello, everyone.

I compiled the following sample source code, and then checked the generated executable code:

//----- sample source code -----
void foo(...) { }
inline void foo2(...) { }
static void foo3(...) { }
static inline void foo4(...) { }

int main()
{
    foo("test");
    foo2("test");
    foo3("test");
    foo4("test");
    return 0;
}
//----- end of the code -----

prompt% g++ --version
g++-3.4.2 (GCC) 3.4.2
prompt% g++ -O2 test.cc -g && objdump -S ./a.out

Here is the result.

int main()
{
 80483b0:   55                      push   %ebp
 80483b1:   89 e5                   mov    %esp,%ebp
 80483b3:   83 ec 08                sub    $0x8,%esp
 80483b6:   83 e4 f0                and    $0xfffffff0,%esp
 80483b9:   83 ec 10                sub    $0x10,%esp
    foo("test");
    foo2("test");
 80483bc:   c7 04 24 e8 84 04 08    movl   $0x80484e8,(%esp)
 80483c3:   e8 08 00 00 00          call   80483d0 <_Z4foo2z>
    foo3("test");
    foo4("test");
    return 0;
}
 80483c8:   c9                      leave
 80483c9:   31 c0                   xor    %eax,%eax
 80483cb:   c3                      ret
 80483cc:   90                      nop
 80483cd:   90                      nop
 80483ce:   90                      nop
 80483cf:   90                      nop

Although the function calls of foo(), foo3(), and foo4() are eliminated
by the optimization of the compiler (-O2 option),
the call of func2() is not eliminated.

I do not know whether this is an optimization bug or not,
but, if possible, I hope to fix this problem.

Thanks.



More information about the Gcc mailing list