Dear G++ developers, *PLATFORM*
GCC 4.2.3, Intel Core 1 (32 bit), Kubuntu 8.04-alpha (Debian-based). *DESCRIPTION OF THE PROBLEM* When using nested templates such as A<A<A<A<x,y>, z>, t>, u> the optimizer seems to give up some useful optimizations when the depth is greater than 17. I know that the C++ standard only requires the compiler to support depth<=17, but it still is very useful to be able to use deeper recursive templates. Also, that's what g++'s option -ftemplate-depth-N seems to control. Unfortunately, it doesn't seem to have any effect here. *TESTCASE* See attachment to this bug report (test.cpp). This is a very simple example of Expression Templates. $ g++ -O3 -DDEPTH17 test.cpp -o test $ time ./test real 0m1.810s $ g++ -O3 -DDEPTH18 test.cpp -o test $ time ./test real 1m9.941s $ g++ -O3 -DDEPTH18 -ftemplate-depth-20 test.cpp -o test $ time ./test real 1m10.751s *A MORE GENERAL QUESTION* I hit this bug while developing an expression-templates library for linear algebra. This bug might have little cousins. I have observed smaller performance issues in cases where the template depth was lower than 17, but where more complicated things were being done. In test.cpp, what really matters for performance is that g++ realizes that it needs not actually construct the objects of classes Sum and Int -- it only needs to emit the code of the value() method. My general question would be, is there a way to hint the g++ that a given class is a "small" "helper" class whose objects need not be actually constructed? Something like "inline" except it'd be for a class, not a function. g++ already does this "inlining" perfectly unless too complex things are being done. Is there some --param that I could try passing to g++ in order to make it handle more complex situations? -- Summary: Deep templates get 40x slower when depth goes from 17 to 18. Product: gcc Version: 4.2.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jacob at math dot jussieu dot fr http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35393