This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/14703] Inadequate optimization of inline templated functions
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Mar 2006 10:29:18 -0000
- Subject: [Bug tree-optimization/14703] Inadequate optimization of inline templated functions
- References: <bug-14703-3016@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #7 from rguenth at gcc dot gnu dot org 2006-03-03 10:29 -------
Note that using functions as in fibconst is not really an efficient way to do
this. Still, with gcc 4.1.0 you now have the ability to use
template<unsigned long long L> inline __attribute__((flatten)) unsigned long
long fibconst()
{
return fibconst<L - 1>() + fibconst<L - 2>();
}
which will result in one call in main and a fibconst that returns the constant
requested. Of course for big numbers you'll hit interesting quadraticness in
time and memory required to build the program - so the limits in place actually
prevent you from running into this issue. It's like
rguenther@g148:/tmp> ~/bin/maxmem2.sh
/space/rguenther/install/gcc-4.1.0/bin/gcc -O2 -S t.C -DVAL=23
total: 149886 kB
rguenther@g148:/tmp> ~/bin/maxmem2.sh
/space/rguenther/install/gcc-4.1.0/bin/gcc -O2 -S t.C -DVAL=24
total: 238102 kB
rguenther@g148:/tmp> ~/bin/maxmem2.sh
/space/rguenther/install/gcc-4.1.0/bin/gcc -O2 -S t.C -DVAL=25
total: 385738 kB
rguenther@g148:/tmp> ~/bin/maxmem2.sh
/space/rguenther/install/gcc-4.1.0/bin/gcc -O2 -S t.C -DVAL=26
total: 623094 kB
so, an exponential growth in memory usage due to the way we're doing the
inlining.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14703