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

--- Comment #4 from Jan Hubicka <hubicka at gcc dot gnu.org> 2010-10-19 
03:20:48 UTC ---
It is caused by fact that the main() function is optimized for size except for
code in loops because we know it will be executed once.
Inliner thinks that it is not good idea to inline printf.

The code size grows because we align the functions.
This is handled by the new ipa profile pass that recognizes the functions as
executed once.  With current mainline I get
0000000000400520 <main>:
  400520:       48 83 ec 08             sub    $0x8,%rsp
  400524:       bf 80 05 40 00          mov    $0x400580,%edi
  400529:       e8 12 00 00 00          callq  400540 <print>
  40052e:       bf 70 05 40 00          mov    $0x400570,%edi
  400533:       e8 08 00 00 00          callq  400540 <print>
  400538:       31 c0                   xor    %eax,%eax
  40053a:       48 83 c4 08             add    $0x8,%rsp
  40053e:       c3                      retq   
  40053f:       90                      nop

0000000000400540 <print>:
  400540:       53                      push   %rbx
  400541:       48 89 fb                mov    %rdi,%rbx
  400544:       ff d7                   callq  *%rdi
  400546:       bf 84 06 40 00          mov    $0x400684,%edi
  40054b:       0f b6 f0                movzbl %al,%esi
  40054e:       31 c0                   xor    %eax,%eax
  400550:       e8 bb fe ff ff          callq  400410 <pri...@plt>
  400555:       ff d3                   callq  *%rbx
  400557:       5b                      pop    %rbx
  400558:       0f b6 f0                movzbl %al,%esi
  40055b:       bf 80 06 40 00          mov    $0x400680,%edi
  400560:       31 c0                   xor    %eax,%eax
  400562:       83 c6 01                add    $0x1,%esi
  400565:       e9 a6 fe ff ff          jmpq   400410 <pri...@plt>
  40056a:       66 0f 1f 44 00 00       nopw   0x0(%rax,%rax,1)

0000000000400570 <two>:
  400570:       b8 02 00 00 00          mov    $0x2,%eax
  400575:       c3                      retq   
  400576:       66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
  40057d:       00 00 00 

0000000000400580 <one>:
  400580:       b8 01 00 00 00          mov    $0x1,%eax
  400585:       c3                      retq   
  400586:       90                      nop
  400587:       90                      nop
  400588:       90                      nop
  400589:       90                      nop
  40058a:       90                      nop
  40058b:       90                      nop
  40058c:       90                      nop
  40058d:       90                      nop
  40058e:       90                      nop
  40058f:       90                      nop

this is smaller (if I am counting right, original is 98 bytes, the code in
comment1 is 110 bytes and this code is 95 bytes including the alignment at the
end of section.)

Reply via email to