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

* [Bug c/63597] Generate useless trampoline for some nested function
  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 ` patrick.pelissier at gmail dot com
  2014-10-19 21:42 ` [Bug middle-end/63597] " pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: patrick.pelissier at gmail dot com @ 2014-10-19 19:49 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Pelissier <patrick.pelissier at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|4.9.2                       |4.9.1

--- Comment #1 from Patrick Pelissier <patrick.pelissier at gmail dot com> ---
-O option shall be used to compile the code.


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

* [Bug middle-end/63597] Generate useless trampoline for some nested function
  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 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-10-19 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |RESOLVED
          Component|c                           |middle-end
         Resolution|---                         |INVALID

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Well this code is undefined anyways.
Plus we don't find out that we don't need the chain until it is too late (RTL
expand time).

I am going to close this as invalid as &x-&a and &y-&a is undefined and does
not mean the location will be fixed for the whole time as only a should be
considered as being escaping.


^ 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).