http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46507
Summary: std::tuple missed optimization Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: mi...@gnu.org My understanding is that std::tuple should offer largely the same optimization opportunities as std::pair (while being more flexible). However gcc-4.6 seems to miss some optimizations with std::tuple that it doesn't with pair. E.g. the following code ("tp.cc"): ---- start ---- #include <tuple> #include <utility> struct A { virtual void f () const; }; void arg_tuple_test (const std::tuple<A> &t) { std::get<0>(t).f (); } void extern_tuple_test () { extern const std::tuple<A> &t; std::get<0>(t).f (); } void arg_pair_test (const std::pair<A,A> &t) { t.first.f (); } ---- end ---- compiled with: g++-snapshot -std=c++0x -O2 -march=amdfam10 -S tp.cc results in the following assembly: arg_tuple_test(std::tuple<A> const&): movq (%rdi), %rax movq (%rax), %rax jmp *%rax extern_tuple_test(): movq t(%rip), %rdi movq (%rdi), %rax movq (%rax), %rax jmp *%rax arg_pair_test(std::pair<A, A> const&): jmp A::f() const .ident "GCC: (Debian 20101114-1) 4.6.0 20101114 (experimental) [trunk revision 166728]" It seems like all of these functions should use a direct jump to A::f, but the tuple versions do not. Note that when I tried this same test yesterday, on a different machine (but the same compiler version), "extern_tuple_test" (but not "arg_tuple_test") _did_ result in a direct jump to A::f! So maybe something funny is going on... Thanks, -Miles