public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/63597] New: Generate useless trampoline for some nested function
@ 2014-10-19 19:41 patrick.pelissier at gmail dot com
  2014-10-19 19:49 ` [Bug c/63597] " patrick.pelissier at gmail dot com
  2014-10-19 21:42 ` [Bug middle-end/63597] " pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: patrick.pelissier at gmail dot com @ 2014-10-19 19:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63597

            Bug ID: 63597
           Summary: Generate useless trampoline for some nested function
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick.pelissier at gmail dot com

In some cases, GCC generate a trampoline for nested functions whereas it is not
needed.

For example, for the code:

extern void h(void (*)(int*), int*);
int f(int x, int y) {
  int a;
  void g(int *ptr_a) {
    *ptr_a = ptr_a[&x-&a] + ptr_a[&y-&a];
  }
  h(g, &a);
  return a;
}

It generates a trampoline for function g:
    movl    $-17599, %eax
    movl    $-17847, %edx
    movl    %edi, 8(%rsp)
    movl    %esi, (%rsp)
    leaq    12(%rsp), %rdi
    leaq    4(%rsp), %rsi
    movw    %ax, 12(%rsp)
    movl    $g.1623, %eax
    movl    %eax, 2(%rdi)
    movq    %rsp, 8(%rdi)
    movw    %dx, 6(%rdi)
    movl    $-1864106167, 16(%rdi)
    call    h


whereas function g doesn't use this access and so doesn't need the trampoline:
g.1623:
.LFB1:
    .cfi_startproc
    movl    -4(%rdi), %eax
    addl    4(%rdi), %eax
    movl    %eax, (%rdi)
    ret

(no use of %r10).


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

end of thread, other threads:[~2014-10-19 21:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-19 19:41 [Bug c/63597] New: Generate useless trampoline for some nested function patrick.pelissier at gmail dot com
2014-10-19 19:49 ` [Bug c/63597] " patrick.pelissier at gmail dot com
2014-10-19 21:42 ` [Bug middle-end/63597] " pinskia 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).