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

             Bug #: 54360
           Summary: missed optimalization: unnecessary indirect call
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: nel...@seznam.cz


Consider following program:

void bar(int *x);
int x(){
  struct {
    void (*b)(int *);
    int a;
  } foo;
  foo.b=bar;
  foo.b(&(foo.a));
  foo.b(&(foo.a));
}
int y(){
    void (*b)(int *);
    int a;
    b=bar;
    b(&a);
    b(&a);
}

In function x gcc eliminaties first indirect call but not second. In y both
calls are eliminated.  

.file "s.c"
  .text
  .p2align 4,,15
  .globl  x
  .type x, @function
x:
.LFB0:
  .cfi_startproc
  subq  $24, %rsp
  .cfi_def_cfa_offset 32
  leaq  8(%rsp), %rdi
  movq  $bar, (%rsp)
  call  bar
  leaq  8(%rsp), %rdi
  call  *(%rsp)
  addq  $24, %rsp
  .cfi_def_cfa_offset 8
  ret
  .cfi_endproc
.LFE0:
  .size x, .-x
  .p2align 4,,15
  .globl  y
  .type y, @function
y:
.LFB1:
  .cfi_startproc
  subq  $24, %rsp
  .cfi_def_cfa_offset 32
  leaq  12(%rsp), %rdi
  call  bar
  leaq  12(%rsp), %rdi
  call  bar
  addq  $24, %rsp
  .cfi_def_cfa_offset 8
  ret
  .cfi_endproc
.LFE1:
  .size y, .-y
  .ident  "GCC: (Debian 20120820-1) 4.8.0 20120820 (experimental) [trunk
revision 190537]"
  .section  .note.GNU-stack,"",@progbits

Reply via email to