public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/46507] New: std::tuple missed optimization
@ 2010-11-16 17:59 miles at gnu dot org
  2010-11-16 19:06 ` [Bug tree-optimization/46507] " paolo.carlini at oracle dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: miles at gnu dot org @ 2010-11-16 17:59 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: miles@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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-01-16 18:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-16 17:59 [Bug tree-optimization/46507] New: std::tuple missed optimization miles at gnu dot org
2010-11-16 19:06 ` [Bug tree-optimization/46507] " paolo.carlini at oracle dot com
2010-11-16 19:11 ` miles at gnu dot org
2010-11-16 19:53 ` redi at gcc dot gnu.org
2013-09-14 21:35 ` glisse at gcc dot gnu.org
2013-10-12 20:13 ` [Bug tree-optimization/46507] std::get and devirtualization on non-automatic variables glisse at gcc dot gnu.org
2013-11-08 14:41 ` jamborm at gcc dot gnu.org
2014-01-16  6:10 ` hubicka at gcc dot gnu.org
2014-01-16  6:18 ` hubicka at gcc dot gnu.org
2014-01-16  8:51 ` rguenther at suse dot de
2014-01-16 18:02 ` hubicka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).