public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug tree-optimization/109045] New: assume attribute and std::optional do not mix @ 2023-03-06 19:32 drepper.fsp+rhbz at gmail dot com 2023-03-06 19:33 ` [Bug tree-optimization/109045] " pinskia at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: drepper.fsp+rhbz at gmail dot com @ 2023-03-06 19:32 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109045 Bug ID: 109045 Summary: assume attribute and std::optional do not mix Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: drepper.fsp+rhbz at gmail dot com Target Milestone: --- The assume attribute is meant to help expressing more complex assumptions which involve function calls. Given that interfaces should use std::optional when the semantics matches this should mean code like this should be optimized: #include <optional> std::optional<long> g(long); long f(long a) { auto r = g(a); [[assume(!r || *r > 0)]]; return r.value_or(0) / 2; } The generated code should use the unsigned divide by two method but it does not. With today's gcc trunk version: 0000000000000000 <_Z1fl>: 0: 48 83 ec 18 sub $0x18,%rsp 4: e8 00 00 00 00 call 9 <_Z1fl+0x9> 9: 48 89 04 24 mov %rax,(%rsp) d: 48 89 54 24 08 mov %rdx,0x8(%rsp) 12: 31 c0 xor %eax,%eax 14: 80 7c 24 08 00 cmpb $0x0,0x8(%rsp) 19: 74 11 je 2c <_Z1fl+0x2c> 1b: 48 8b 14 24 mov (%rsp),%rdx 1f: 48 89 d0 mov %rdx,%rax 22: 48 c1 e8 3f shr $0x3f,%rax 26: 48 01 d0 add %rdx,%rax 29: 48 d1 f8 sar %rax 2c: 48 83 c4 18 add $0x18,%rsp 30: c3 ret The instructions from 1f to 28 including are not needed (and the initial load at 1b adjusted). ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/109045] assume attribute and std::optional do not mix 2023-03-06 19:32 [Bug tree-optimization/109045] New: assume attribute and std::optional do not mix drepper.fsp+rhbz at gmail dot com @ 2023-03-06 19:33 ` pinskia at gcc dot gnu.org 2023-03-06 19:35 ` [Bug tree-optimization/109045] assume attribute does not always optimize std::optional cases pinskia at gcc dot gnu.org 2023-03-07 9:11 ` rguenth at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-03-06 19:33 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109045 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 tree-optimization/109045] assume attribute does not always optimize std::optional cases 2023-03-06 19:32 [Bug tree-optimization/109045] New: assume attribute and std::optional do not mix drepper.fsp+rhbz at gmail dot com 2023-03-06 19:33 ` [Bug tree-optimization/109045] " pinskia at gcc dot gnu.org @ 2023-03-06 19:35 ` pinskia at gcc dot gnu.org 2023-03-07 9:11 ` rguenth at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-03-06 19:35 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109045 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- GCC does optimize much dealing with assume and function calls really so this is not really shocking. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/109045] assume attribute does not always optimize std::optional cases 2023-03-06 19:32 [Bug tree-optimization/109045] New: assume attribute and std::optional do not mix drepper.fsp+rhbz at gmail dot com 2023-03-06 19:33 ` [Bug tree-optimization/109045] " pinskia at gcc dot gnu.org 2023-03-06 19:35 ` [Bug tree-optimization/109045] assume attribute does not always optimize std::optional cases pinskia at gcc dot gnu.org @ 2023-03-07 9:11 ` rguenth at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: rguenth at gcc dot gnu.org @ 2023-03-07 9:11 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109045 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed| |2023-03-07 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-07 9:11 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-03-06 19:32 [Bug tree-optimization/109045] New: assume attribute and std::optional do not mix drepper.fsp+rhbz at gmail dot com 2023-03-06 19:33 ` [Bug tree-optimization/109045] " pinskia at gcc dot gnu.org 2023-03-06 19:35 ` [Bug tree-optimization/109045] assume attribute does not always optimize std::optional cases pinskia at gcc dot gnu.org 2023-03-07 9:11 ` 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).