This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51680] New: g++ 4.7 fails to inline trivial template stuff
- From: "miles at gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 27 Dec 2011 06:30:32 +0000
- Subject: [Bug c++/51680] New: g++ 4.7 fails to inline trivial template stuff
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51680
Bug #: 51680
Summary: g++ 4.7 fails to inline trivial template stuff
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: miles@gnu.org
Given the following source code (and options "-O2 -S"):
extern void process (float);
template<typename Fun, typename T>
void process_fun_at (const Fun &fun, T x)
{
process (fun (x));
}
static float add1 (float x)
{
return x + 1;
}
void test (float i)
{
process_fun_at (add1, i);
}
g++ 4.6 (and clang++ 3.0) produce the obvious output, inlining the template
function "process_fun_at", and the function "add1":
.globl test(float)
test(float):
addss .LC0(%rip), %xmm0
jmp process(float)
.LC0:
.long 1065353216
.ident "GCC: (Debian 4.6.2-9) 4.6.2"
However g++ 4.7 produces much more awkward code, inlining nothing:
add1(float):
addss .LC0(%rip), %xmm0
ret
void process_fun_at<float (float), float>(float ( const&)(float), float):
subq $8, %rsp
call *%rdi
addq $8, %rsp
jmp process(float)
.globl test(float)
test(float):
movl add1(float), %edi
jmp void process_fun_at<float (float), float>(float (
const&)(float), float)
.LC0:
.long 1065353216
.ident "GCC: (Debian 20111210-1) 4.7.0 20111210 (experimental)
[trunk revision 182188]"
If I add the keyword "inline" to the declaration of the "process_fun_at"
template function, then g++ 4.7 inlines everything and produces the same result
as 4.6.
However my impression is that given such very simple input, it should do this
inlining automatically.
g++ version is:
(Debian 20111210-1) 4.7.0 20111210 (experimental) [trunk revision 182188]
Thanks,
-miles