public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "eric-bugs at omnifarious dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/113527] New: Missed optimization [[assume]] attribute Date: Sun, 21 Jan 2024 02:55:47 +0000 [thread overview] Message-ID: <bug-113527-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113527 Bug ID: 113527 Summary: Missed optimization [[assume]] attribute Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: eric-bugs at omnifarious dot org Target Milestone: --- This code https://godbolt.org/z/jeYGcr5sv still generates all the exception handling code. It treats the assume attribute more like 'likely' than 'assume'. It's supposed to be undefined behavior for the assumption to be false. Here is the code replicated here: #include <variant> struct Potato { explicit Potato(int); Potato(const Potato & other) noexcept; }; using V = std::variant<Potato, int, double>; template <class... Ts_> struct overloaded : Ts_... { using Ts_::operator()...; }; auto f(const V & v) -> int { [[assume(! v.valueless_by_exception())]]; return visit(overloaded{ [](int) { return 144; }, [](double) { return 27; }, [](const Potato &) { return 50; } }, v); } You can make the exception handling code go away by simply using "if (v.valueless_by_exception())" and returning some random value in the false case. But, if the spirit of the keyword is to be observed, you should be fine just doing a straight up table lookup and using the result without even checking the type tag at all.
next reply other threads:[~2024-01-21 2:55 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-01-21 2:55 eric-bugs at omnifarious dot org [this message] 2024-01-21 2:57 ` [Bug tree-optimization/113527] " pinskia at gcc dot gnu.org 2024-01-21 3:00 ` [Bug ipa/113527] " pinskia 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-113527-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).