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
* [Bug middle-end/109370] Missed optimization for std::optional branchless unwrapping 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 ` 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 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-04-01 16:53 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109370 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement Keywords| |missed-optimization ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/109370] Missed optimization for std::optional branchless unwrapping 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 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-04-01 16:59 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109370 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- I am not so sure this is worse. Also I find LLVM code generataion depdedent on if the argument is a pointer vs a reference (rvalue or normal): ``` struct a { int b; bool c; }; int f(struct a &o) { if (!o.c) return -1; return o.b; } int f(struct a *o) { if (!o->c) return -1; return o->b; } ``` ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug rtl-optimization/109370] Missed optimization for std::optional branchless unwrapping 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 ` rguenth at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: rguenth at gcc dot gnu.org @ 2023-04-11 11:59 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109370 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Component|middle-end |rtl-optimization --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- Note we would need to know that dereferencing 'o' is OK (not sure if RTL knows this), and this if-conversion is certainly RTL territorry because of costing. On x86 I'd expect the branchy version to be faster. ^ 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).