* 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
* Re: Unnecessary stores with std::optional?
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
0 siblings, 1 reply; 3+ messages in thread
From: Marc Glisse @ 2020-05-28 15:00 UTC (permalink / raw)
To: Steffen Hirschmann; +Cc: gcc-help
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Unnecessary stores with std::optional?
2020-05-28 15:00 ` Marc Glisse
@ 2020-05-29 8:45 ` Steffen Hirschmann
0 siblings, 0 replies; 3+ messages in thread
From: Steffen Hirschmann @ 2020-05-29 8:45 UTC (permalink / raw)
To: gcc-help
On 17:00 Thu 28 May , Marc Glisse wrote:
> 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?
thank you for the quick answer. I filed an issue:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95405
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).