From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 20A6C3858C31; Sun, 21 Jan 2024 02:55:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20A6C3858C31 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705805748; bh=snfAF4tKD5Iyh11tDvs36BdbXyHzsGzb+CevhPkarII=; h=From:To:Subject:Date:From; b=K4saiWrgdyBH8BDmrysUuULepqkY+ZZqpieZ8k9wHYUCEQK94g19rultBImumnBh3 KQbr9+KeCuyknWF23TgTvgBOWEMztvFYyg+Zzqk5KYwH2+mwcSf9YogrcGcBFKy+oj 4pbOFgoQDwqEOuZkGLuDRa0lPWCRDBZjpOIz7D1o= From: "eric-bugs at omnifarious dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: eric-bugs at omnifarious dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113527 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 'assu= me'. It's supposed to be undefined behavior for the assumption to be false. Here is the code replicated here: #include struct Potato { explicit Potato(int); Potato(const Potato & other) noexcept; }; using V =3D std::variant; template 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 fi= ne just doing a straight up table lookup and using the result without even checking the type tag at all.=