public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113527] New: Missed optimization [[assume]] attribute
@ 2024-01-21  2:55 eric-bugs at omnifarious dot org
  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
  0 siblings, 2 replies; 3+ messages in thread
From: eric-bugs at omnifarious dot org @ 2024-01-21  2:55 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug tree-optimization/113527] Missed optimization [[assume]] attribute
  2024-01-21  2:55 [Bug c++/113527] New: Missed optimization [[assume]] attribute eric-bugs at omnifarious dot org
@ 2024-01-21  2:57 ` pinskia at gcc dot gnu.org
  2024-01-21  3:00 ` [Bug ipa/113527] " pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-21  2:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113527

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement
          Component|c++                         |tree-optimization

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug ipa/113527] Missed optimization [[assume]] attribute
  2024-01-21  2:55 [Bug c++/113527] New: Missed optimization [[assume]] attribute eric-bugs at omnifarious dot org
  2024-01-21  2:57 ` [Bug tree-optimization/113527] " pinskia at gcc dot gnu.org
@ 2024-01-21  3:00 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-21  3:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113527

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 109112, that is the problem is similar for many other things.

*** This bug has been marked as a duplicate of bug 109112 ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-21  3:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-21  2:55 [Bug c++/113527] New: Missed optimization [[assume]] attribute eric-bugs at omnifarious dot org
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

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).