public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/78113] std::variant and std::visit's current implementations do not get optimized out (compared to "recursive visitation")
       [not found] <bug-78113-4@http.gcc.gnu.org/bugzilla/>
@ 2021-05-12  9:52 ` redi at gcc dot gnu.org
  2021-10-01 19:38 ` cvs-commit at gcc dot gnu.org
  2021-10-01 19:54 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-12  9:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed in my fork (for visiting a single variant of up to 11 alternative types):
https://gitlab.com/jonathan-wakely/gcc/-/commit/f5de3d9055e47b73cd1c4d35c235ebaa3f93a5e6

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

* [Bug libstdc++/78113] std::variant and std::visit's current implementations do not get optimized out (compared to "recursive visitation")
       [not found] <bug-78113-4@http.gcc.gnu.org/bugzilla/>
  2021-05-12  9:52 ` [Bug libstdc++/78113] std::variant and std::visit's current implementations do not get optimized out (compared to "recursive visitation") redi at gcc dot gnu.org
@ 2021-10-01 19:38 ` cvs-commit at gcc dot gnu.org
  2021-10-01 19:54 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-01 19:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:cfb582f62791dfadc243d97d37f0b83ef77cf480

commit r12-4068-gcfb582f62791dfadc243d97d37f0b83ef77cf480
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue May 4 23:31:48 2021 +0100

    libstdc++: Optimize std::visit for the common case [PR 78113]

    GCC does not do a good job of optimizing the table of function pointers
    used for variant visitation. This avoids using the table for the common
    case of visiting a single variant with a small number of alternative
    types. Instead we use:

      switch(v.index())
      {
      case 0: return visitor(get<0>(v));
      case 1: return visitor(get<1>(v));
      ...
      }

    It's not quite that simple, because get<1>(v) is ill-formed if the
    variant only has one alternative, and similarly for each get<N>.  We
    need to ensure each case only applies the visitor if the index is in
    range for the actual type we're dealing with, and tell the compiler that
    the case is unreachable otherwise. We also need to invoke the visitor
    via the __gen_vtable_impl::__visit_invoke function, to handle the raw
    visitation cases used to implement std::variant assignments and
    comparisons.

    Because that gets quite verbose and repetitive, a macro is used to stamp
    out the cases.

    We also need to handle the valueless_by_exception case, but only for raw
    visitation, because std::visit already checks for it before calling
    __do_visit.

    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/78113
            * include/std/variant (__do_visit): Use a switch when we have a
            single variant with a small number of alternatives.

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

* [Bug libstdc++/78113] std::variant and std::visit's current implementations do not get optimized out (compared to "recursive visitation")
       [not found] <bug-78113-4@http.gcc.gnu.org/bugzilla/>
  2021-05-12  9:52 ` [Bug libstdc++/78113] std::variant and std::visit's current implementations do not get optimized out (compared to "recursive visitation") redi at gcc dot gnu.org
  2021-10-01 19:38 ` cvs-commit at gcc dot gnu.org
@ 2021-10-01 19:54 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-01 19:54 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for GCC 12.

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

end of thread, other threads:[~2021-10-01 19:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-78113-4@http.gcc.gnu.org/bugzilla/>
2021-05-12  9:52 ` [Bug libstdc++/78113] std::variant and std::visit's current implementations do not get optimized out (compared to "recursive visitation") redi at gcc dot gnu.org
2021-10-01 19:38 ` cvs-commit at gcc dot gnu.org
2021-10-01 19:54 ` redi 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).