public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/42995]  New: [4.3 regression] inline-small-functions does not inline simple delegation calls
@ 2010-02-07 23:01 matt at use dot net
  2010-02-07 23:04 ` [Bug middle-end/42995] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: matt at use dot net @ 2010-02-07 23:01 UTC (permalink / raw)
  To: gcc-bugs

Using gcc 4.4.1 under Ubuntu 9.10 on amd64:

main.c:

#include "database.h"

int main()
{
  int my_id = 0;
  int result_for_my_id = get_data_for(my_id);

  switch (result_for_my_id)
  {
    case 0:
      return 666;
    default:
      return -1;
  }
}

database.h:
#include <stdlib.h>

int get_data_for(int id)
{
  return rand();
}

Compiling with:
gcc -O2 main.c -o n

produces this code:
0000000000400380 <main>:
  400380:       48 83 ec 08             sub    rsp,0x8
  400384:       31 ff                   xor    edi,edi
  400386:       e8 e5 ff ff ff          call   400370 <get_data_for>
  40038b:       83 f8 01                cmp    eax,0x1
  40038e:       19 c0                   sbb    eax,eax
  400390:       48 83 c4 08             add    rsp,0x8
  400394:       25 9b 02 00 00          and    eax,0x29b
  400399:       83 e8 01                sub    eax,0x1
  40039c:       c3                      ret
  40039d:       0f 1f 00                nop    DWORD PTR [rax]

Note the 3 bytes of padding after the return. I'm confused why
inline-small-functions does not inline get_data_for. I tried this experiment:
gcc -O2 -finline-functions --param max-inline-insns-auto=20 main.c -o n

which produces this code:
0000000000400380 <main>:
  400380:       48 83 ec 08             sub    rsp,0x8
  400384:       e8 27 02 00 00          call   4005b0 <rand@plt>
  400389:       83 f8 01                cmp    eax,0x1
  40038c:       19 c0                   sbb    eax,eax
  40038e:       48 83 c4 08             add    rsp,0x8
  400392:       25 9b 02 00 00          and    eax,0x29b
  400397:       83 e8 01                sub    eax,0x1
  40039a:       c3                      ret
  40039b:       0f 1f 44 00 00          nop    DWORD PTR [rax+rax*1+0x0]

The padding got larger, but the code is actually smaller. Shouldn't the
heuristic used for inline-small-functions have caused get_data_for() to be
inlined?

This does not appear to be a problem in GCC 4.5.20091228 or 4.3.4.


-- 
           Summary: [4.3 regression] inline-small-functions does not inline
                    simple delegation calls
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: matt at use dot net
 GCC build triplet: x86_64-linux-unknown
  GCC host triplet: x86_64-linux-unknown
GCC target triplet: x86_64-linux-unknown


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42995


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

end of thread, other threads:[~2010-02-08 14:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-07 23:01 [Bug middle-end/42995] New: [4.3 regression] inline-small-functions does not inline simple delegation calls matt at use dot net
2010-02-07 23:04 ` [Bug middle-end/42995] " pinskia at gcc dot gnu dot org
2010-02-08 10:19 ` [Bug middle-end/42995] [4.4 Regression] " rguenth at gcc dot gnu dot org
2010-02-08 10:41 ` rguenth at gcc dot gnu dot org
2010-02-08 14:11 ` rguenth at gcc dot gnu dot org
2010-02-08 14:11 ` rguenth at gcc dot gnu dot 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).