public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marc Glisse <marc.glisse@inria.fr>
To: Steffen Hirschmann <steffen.hirschmann@ipvs.uni-stuttgart.de>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Unnecessary stores with std::optional?
Date: Thu, 28 May 2020 17:00:18 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2005281658550.6869@stedding.saclay.inria.fr> (raw)
In-Reply-To: <20200526130710.GB362962@lapsgs17>

On Tue, 26 May 2020, Steffen Hirschmann wrote:

> 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?

One of them seems to be a tuning choice (it disappears with some 
-march/-mtune flags), but not the other. Could you file an issue in gcc's 
bugzilla please?

-- 
Marc Glisse

  reply	other threads:[~2020-05-28 15:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26 13:07 Steffen Hirschmann
2020-05-28 15:00 ` Marc Glisse [this message]
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=alpine.DEB.2.22.394.2005281658550.6869@stedding.saclay.inria.fr \
    --to=marc.glisse@inria.fr \
    --cc=gcc-help@gcc.gnu.org \
    --cc=steffen.hirschmann@ipvs.uni-stuttgart.de \
    /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).