[Bug c++/45221] missed optimization with multiple bases and casting

navin.kumar at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue May 17 15:49:00 GMT 2011


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

Navin Kumar <navin.kumar at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|4.5.0                       |4.6.0

--- Comment #11 from Navin Kumar <navin.kumar at gmail dot com> 2011-05-17 15:18:06 UTC ---
Bumping this to 4.6.0 since the problem still exists.

As a review (since this has been open and not updated for a while), the problem
is very slow performance when dealing with C++'s multiple-inheritance (even
under -O3).  In the example below, the 'simple' fooA function generates slow
code, whereas the equivalent code written with more steps in fooB generates
optimal code.

Base2* fooA(Derived* x)
{
    Base2& y = *x;
    return &y;
}
Base2* fooB(Derived* x) {
    Derived& x2 = *x;
    Base2& y = x2;
    return &y;
}

Both fooA and fooB are funtionally identical.

Yet the assembly generated for fooA is:
    leaq    4(%rdi), %rdx
    xorl    %eax, %eax
    testq   %rdi, %rdi
    cmovne  %rdx, %rax
    ret

and the assembly generated for fooB is:
    leaq    4(%rdi), %rax
    ret



More information about the Gcc-bugs mailing list