This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Question: Virtual call ellimination with GCC.


Dear Sirs,

    Here is a simple test file, compiled by GCC Cygwin-b20 and Watcom 11
C/C++.
The resulting files show the Watcom generated code is faster than Gcc, in
this case.
I think, the reasons behind the difference is in the difference of virtual
function handling. ( In other cases, code generated by GCC is better.)
Does GCC have some option for virtual call optimization?

TIA:    Kelemen Csaba ( SoftCad Ltd)

//    ----- Test.c

struct A
{
virtual void f() =0;
};
struct B : public A
{
void f() {}
};
inline void g( A & a)
{
a.f();
}
void h()
{
B b;
g( b);
}

//    ----- End of Test.c

Test.c was first time compiled whit "wpp386 -ox test" command.
The result:

0000                          void near h():
0000    C3                        ret

0000                          void near B::f():
0000    C3                        ret

Test.c was second time compiled whit "gcc -S -Winline -O3 -x c++  test.c -o
tmp.txt" command.
The result:

_h__Fv:
pushl %ebp
movl %esp,%ebp
subl $16,%esp
movl $__vt$1B,-16(%ebp)
movswl __vt$1B+8,%eax
leal -16(%eax,%ebp),%eax
pushl %eax
movl __vt$1B+12,%eax
call *%eax
movl %ebp,%esp
popl %ebp
ret
_f__1B:
pushl %ebp
movl %esp,%ebp
movl %ebp,%esp
popl %ebp
ret






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]