public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/109370] New: Missed optimization for std::optional branchless unwrapping
@ 2023-04-01 16:52 andre.schackier at gmail dot com
  2023-04-01 16:53 ` [Bug middle-end/109370] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: andre.schackier at gmail dot com @ 2023-04-01 16:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109370
           Summary: Missed optimization for std::optional branchless
                    unwrapping
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andre.schackier at gmail dot com
  Target Milestone: ---

Given the following source code godbolt: https://godbolt.org/z/vW6ebqafK

#include <optional>

int f(std::optional<int>&& o) {
    if (!o) return -1;

    return *o;
}

gcc with '-O3' generates:
f(std::optional<int>&&):
        cmp     BYTE PTR [rdi+4], 0
        je      .L3
        mov     eax, DWORD PTR [rdi]
        ret
.L3:
        mov     eax, -1
        ret

while clang generates:
f(std::optional<int>&&):                    # @f(std::optional<int>&&)
        xor     eax, eax
        cmp     byte ptr [rdi + 4], 1
        sbb     eax, eax
        or      eax, dword ptr [rdi]
        ret

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

end of thread, other threads:[~2023-04-11 11:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-01 16:52 [Bug middle-end/109370] New: Missed optimization for std::optional branchless unwrapping andre.schackier at gmail dot com
2023-04-01 16:53 ` [Bug middle-end/109370] " pinskia at gcc dot gnu.org
2023-04-01 16:59 ` pinskia at gcc dot gnu.org
2023-04-11 11:59 ` [Bug rtl-optimization/109370] " rguenth 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).