public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101326] New: std::optional returns forced through stack
@ 2021-07-05 16:37 tnfchris at gcc dot gnu.org
  2021-07-05 16:45 ` [Bug middle-end/101326] " tnfchris at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2021-07-05 16:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101326

            Bug ID: 101326
           Summary: std::optional returns forced through stack
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tnfchris at gcc dot gnu.org
  Target Milestone: ---

The simple example

#include <optional>

std::optional<long> foo() {
    return 0;
}

shows suboptimal codegen at -O3 -std=c++17.

The values seem to be forced through the stack.  On AArch64 we get

foo():
        sub     sp, sp, #16
        mov     w0, 1
        strb    w0, [sp, 8]
        mov     x0, 0
        ldr     x1, [sp, 8]
        add     sp, sp, 16
        ret

instead of (what clang gives)

foo():                                // @foo()
        mov     w1, #1
        mov     x0, xzr
        ret

On x86 it's the same:

foo():
        mov     QWORD PTR [rsp-24], 0
        mov     rax, QWORD PTR [rsp-24]
        mov     BYTE PTR [rsp-16], 1
        mov     rdx, QWORD PTR [rsp-16]
        ret

vs

foo():                                // @foo()
        mov     w1, #1
        mov     x0, xzr
        ret

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

end of thread, other threads:[~2023-07-12 21:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-05 16:37 [Bug c++/101326] New: std::optional returns forced through stack tnfchris at gcc dot gnu.org
2021-07-05 16:45 ` [Bug middle-end/101326] " tnfchris at gcc dot gnu.org
2021-07-05 17:07 ` pinskia at gcc dot gnu.org
2021-07-06  6:38 ` rguenth at gcc dot gnu.org
2021-07-06  7:40 ` pinskia at gcc dot gnu.org
2023-04-26  9:46 ` pinskia at gcc dot gnu.org
2023-07-12 21:35 ` pinskia at gcc dot gnu.org

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