Re: inlining callbacks question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Christopher Layne writes:
 > On Sun, Feb 11, 2007 at 03:56:39PM +0000, Andrew Haley wrote:
 > > With your unaltered source code, I get this at -O3:
 > > 
 > > main:
 > > .LFB28:
 > >         subl    $1, %edi
 > >         pushq   %rbx
 > > .LCFI1:
 > >         movl    $1, %eax
 > >         movq    %rsi, %rbx
 > >         jle     .L8
 > >         movl    $16, %edi
 > >         call    malloc
 > >         movq    8(%rbx), %rdx
 > >         movq    stdout(%rip), %rdi
 > >         movl    $.LC0, %esi
 > >         movq    $cbt_display, 8(%rax)
 > >         movq    %rdx, (%rax)
 > >         xorl    %eax, %eax
 > >         call    fprintf
 > >         xorl    %eax, %eax
 > > .L8:
 > >         popq    %rbx
 > >         ret
 > 
 > gcc 4.1.1. However, did you specify -DCB to gcc? Otherwise it's going to use
 > the direct call. :)

Oh yeah.  The reason you don't get the inlining is that the inlining
pass is done before the assignment has been propagated.

Here's the function just before inlining:


main (argc, argv)
{
  struct cbt * c;
  void (*<T870>) (struct cbt *) D.3712;
  char * D.3711;
  char * * D.3710;
  int D.3708;

<bb 2>:
  if (argc_2(D) <= 1) goto <L2>; else goto <L1>;

<L1>:;
  c_4 = cbt_new ();
  D.3710_7 = argv_6(D) + 8B;
  D.3711_8 = *D.3710_7;
  c_4->text = D.3711_8;
  D.3712_9 = c_4->display;
  D.3712_9 (c_4);

  # D.3708_1 = PHI <1(2), 0(3)>
<L2>:;
  return D.3708_1;

}


And here it is after inlining:


main (argc, argv)
{
  struct cbt * c;
  void * D.3781;
  struct cbt * D.3780;
  struct cbt * D.3780;
  struct cbt * c;
  void (*<T870>) (struct cbt *) D.3712;
  char * D.3711;
  char * * D.3710;
  int D.3708;

<bb 2>:
  if (argc_2(D) <= 1) goto <L2>; else goto <L3>;

<L3>:;
  D.3781_12 = malloc (16);
  c_13 = (struct cbt *) D.3781_12;
  c_13->text = 0B;
  c_13->display = cbt_display;
  D.3780_14 = c_13;
  c_4 = D.3780_14;
  D.3710_7 = argv_6(D) + 8B;
  D.3711_8 = *D.3710_7;
  c_4->text = D.3711_8;
  D.3712_9 = c_4->display;
  D.3712_9 (c_4);

  # D.3708_1 = PHI <1(2), 0(3)>
<L2>:;
  return D.3708_1;

}


In general, inlining early is a win, becasue it exposes many
opportunites that would otherwise be hidden.

This is one of the penalties of early inlining.  I suppose we could
attempt to inline again at the end of optimization, and maybe this
would reveal a few opportunities we'd missed, but in most cases it
wouldn't be worthwhile.

Andrew.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux