public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steffen Hirschmann <steffen.hirschmann@ipvs.uni-stuttgart.de>
To: gcc-help@gcc.gnu.org
Subject: Unnecessary stores with std::optional?
Date: Tue, 26 May 2020 15:07:10 +0200	[thread overview]
Message-ID: <20200526130710.GB362962@lapsgs17> (raw)

Dear GCC community,

I was testing std::optional when I noticed that gcc produces stores that
don't seem to be required.

Code:
--------
#include <optional>
std::optional<long> foo();
long bar()
{
    auto r = foo();
    if (r)
        return *r;
    else
        return 0L;
}
--------

What gcc 10.1 with -std=c++17 -O3 produces is:
bar():
        sub     rsp, 24
        call    foo()
        mov     QWORD PTR [rsp+8], rdx
        cmp     BYTE PTR [rsp+8], 0
        mov     QWORD PTR [rsp], rax
        mov     rax, QWORD PTR [rsp]
        jne     .L1
        xor     eax, eax
.L1:
        add     rsp, 24
        ret

(see: https://godbolt.org/z/uHE6QB)

I don't understand the stores (and loads) after the call to foo. They
don't seem necessary to me. Can anyone explain them to me?

Greetings,
Steffen


             reply	other threads:[~2020-05-26 13:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26 13:07 Steffen Hirschmann [this message]
2020-05-28 15:00 ` Marc Glisse
2020-05-29  8:45   ` Steffen Hirschmann

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=20200526130710.GB362962@lapsgs17 \
    --to=steffen.hirschmann@ipvs.uni-stuttgart.de \
    --cc=gcc-help@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).