public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51680] New: g++ 4.7 fails to inline trivial template stuff
@ 2011-12-27  9:32 miles at gnu dot org
  2011-12-27 11:15 ` [Bug c++/51680] " paolo.carlini at oracle dot com
                   ` (21 more replies)
  0 siblings, 22 replies; 23+ messages in thread
From: miles at gnu dot org @ 2011-12-27  9:32 UTC (permalink / raw)
  To: gcc-bugs

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


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

end of thread, other threads:[~2015-06-22 14:25 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-27  9:32 [Bug c++/51680] New: g++ 4.7 fails to inline trivial template stuff miles at gnu dot org
2011-12-27 11:15 ` [Bug c++/51680] " paolo.carlini at oracle dot com
2011-12-27 14:15 ` miles at gnu dot org
2011-12-27 15:04 ` paolo.carlini at oracle dot com
2011-12-27 20:18 ` jakub at gcc dot gnu.org
2011-12-28  1:04 ` redi at gcc dot gnu.org
2011-12-28  2:44 ` miles at gnu dot org
2011-12-28 15:53 ` marc.glisse at normalesup dot org
2011-12-28 20:25 ` redi at gcc dot gnu.org
2011-12-30 23:43 ` [Bug tree-optimization/51680] [4.7 Regression] " pinskia at gcc dot gnu.org
2012-01-02 10:43 ` rguenth at gcc dot gnu.org
2012-01-07 16:13 ` hubicka at gcc dot gnu.org
2012-01-07 17:31 ` hubicka at gcc dot gnu.org
2012-01-07 23:36 ` hubicka at gcc dot gnu.org
2012-01-08 16:39 ` hubicka at gcc dot gnu.org
2012-01-08 16:44 ` [Bug tree-optimization/51680] " hubicka at gcc dot gnu.org
2012-01-09  9:59 ` rguenth at gcc dot gnu.org
2012-01-09 15:18 ` hubicka at ucw dot cz
2013-01-09  5:36 ` miles at gnu dot org
2013-03-22 14:47 ` jakub at gcc dot gnu.org
2013-05-31 11:00 ` jakub at gcc dot gnu.org
2013-10-16  9:51 ` jakub at gcc dot gnu.org
2015-06-22 14:26 ` rguenth 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).