public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Unnecessary stores with std::optional?
@ 2020-05-26 13:07 Steffen Hirschmann
  2020-05-28 15:00 ` Marc Glisse
  0 siblings, 1 reply; 3+ messages in thread
From: Steffen Hirschmann @ 2020-05-26 13:07 UTC (permalink / raw)
  To: gcc-help

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


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

end of thread, other threads:[~2020-05-29  8:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 13:07 Unnecessary stores with std::optional? Steffen Hirschmann
2020-05-28 15:00 ` Marc Glisse
2020-05-29  8:45   ` Steffen Hirschmann

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