public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "josephcsible at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/95783] New: Inefficient use of the stack when a function takes the address of its argument
Date: Sat, 20 Jun 2020 06:34:56 +0000	[thread overview]
Message-ID: <bug-95783-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2020-06-20  6:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-20  6:34 josephcsible at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-95783-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).