public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/95783] New: Inefficient use of the stack when a function takes the address of its argument
@ 2020-06-20  6:34 josephcsible at gmail dot com
  2020-06-20 12:12 ` [Bug target/95783] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: josephcsible at gmail dot com @ 2020-06-20  6:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95783
           Summary: Inefficient use of the stack when a function takes the
                    address of its argument
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: josephcsible at gmail dot com
  Target Milestone: ---
            Target: x86_64-linux-gnu

Consider this C code:

void g(long *);
long f(long x) {
    g(&x);
    return x;
}

At either "-O3" or "-Os", it results in this assembly:

f:
        subq    $24, %rsp
        movq    %rdi, 8(%rsp)
        leaq    8(%rsp), %rdi
        call    g
        movq    8(%rsp), %rax
        addq    $24, %rsp
        ret

There are two problems with this: it's unnecessarily complicated with extra
instructions, and it wastes 16 bytes of stack space. I'd rather see this
assembly instead:

f:
        pushq   %rdi
        movq    %rsp, %rdi
        call    g
        popq    %rax
        ret

https://godbolt.org/z/PuNB6Y

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

* [Bug target/95783] Inefficient use of the stack when a function takes the address of its argument
  2020-06-20  6:34 [Bug target/95783] New: Inefficient use of the stack when a function takes the address of its argument josephcsible at gmail dot com
@ 2020-06-20 12:12 ` pinskia at gcc dot gnu.org
  2020-06-20 13:28 ` schwab@linux-m68k.org
  2020-06-22  7:57 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-06-20 12:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the stack is required to be 16 byte aligned so you need one more push.

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

* [Bug target/95783] Inefficient use of the stack when a function takes the address of its argument
  2020-06-20  6:34 [Bug target/95783] New: Inefficient use of the stack when a function takes the address of its argument josephcsible at gmail dot com
  2020-06-20 12:12 ` [Bug target/95783] " pinskia at gcc dot gnu.org
@ 2020-06-20 13:28 ` schwab@linux-m68k.org
  2020-06-22  7:57 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: schwab@linux-m68k.org @ 2020-06-20 13:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> ---
That is already handled through the return address push.

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

* [Bug target/95783] Inefficient use of the stack when a function takes the address of its argument
  2020-06-20  6:34 [Bug target/95783] New: Inefficient use of the stack when a function takes the address of its argument josephcsible at gmail dot com
  2020-06-20 12:12 ` [Bug target/95783] " pinskia at gcc dot gnu.org
  2020-06-20 13:28 ` schwab@linux-m68k.org
@ 2020-06-22  7:57 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-22  7:57 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-06-22
             Status|UNCONFIRMED                 |NEW

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2020-06-22  7:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-20  6:34 [Bug target/95783] New: Inefficient use of the stack when a function takes the address of its argument josephcsible at gmail dot com
2020-06-20 12:12 ` [Bug target/95783] " pinskia at gcc dot gnu.org
2020-06-20 13:28 ` schwab@linux-m68k.org
2020-06-22  7:57 ` rguenth 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).