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

2010-08-06 Thread navin dot kumar at gmail dot com


--- Comment #3 from navin dot kumar at gmail dot com  2010-08-07 02:27 
---
The poor optimization does seem to stem from multiple-inheritance (and gcc
trying to preserve nulls across casts).  But it's not just upcast; even with
downcasts slow assembly is generated.  Take this example:


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:
leaq4(%rdi), %rdx
xorl%eax, %eax
testq   %rdi, %rdi
cmovne  %rdx, %rax
ret

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


-- 


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



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

2010-08-06 Thread pinskia at gcc dot gnu dot org


--- Comment #2 from pinskia at gcc dot gnu dot org  2010-08-07 01:33 ---
Confirmed, the issue has to do with multiple base classes and how NULL pointers
are handled during an upcast.


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

   Severity|normal  |enhancement
 Status|UNCONFIRMED |NEW
 Ever Confirmed|0   |1
   Keywords||missed-optimization
   Last reconfirmed|-00-00 00:00:00 |2010-08-07 01:33:06
   date||
Summary|missed optimization on  |missed optimization with
   |casting pointers even under |multiple bases and up
   |-O3 |casting and dereferencing


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