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]
Other format: [Raw text]

Re: missed tail-optimization with templates



On Dec 29, 2003, at 15:48, Luca Padovani wrote:


Hi,

I'm using g++ (GCC) 3.3.3 20031206 (prerelease) (Debian). I don't fully
understand the behavior of the compiler -O2 with the C++ program (the
smallest I could produce showing the "problem") attached to this email.

The zero() function gets compiled and tail-optimized, fine. However, the
A::zero() and B::zero() static member functions, although they amount in
combination at the same code of zero(), are _not_ tail optimized. At
first I thought templates prevent the compiler from tail-optimizing, but
if I make A::zero() more trivial (turn the #if 1 into an #if 0) the tail
optimization shows up.


Is there anything that prevents tail optimization with #if 1? If not, is
this to be considered a possible improvement for gcc or it is just too
specific/hard to implement?

The problem is GCC does not remove dead code before trying to do the tail
optimization. On the tree-ssa branch these functions are optimized right because it
works on the tree level instead of the RTL level.


Thanks,
Andrew Pinski


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