public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "drepper.fsp+rhbz at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109045] New: assume attribute and std::optional do not mix Date: Mon, 06 Mar 2023 19:32:14 +0000 [thread overview] Message-ID: <bug-109045-4@http.gcc.gnu.org/bugzilla/> (raw) 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).
next reply other threads:[~2023-03-06 19:32 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-06 19:32 drepper.fsp+rhbz at gmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-109045-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).