public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/116754] New: libstdc++ std::ranges::copy performance issue
@ 2024-09-17 21:59 addmlbx at gmail dot com
  2024-09-17 22:01 ` [Bug libstdc++/116754] " addmlbx at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: addmlbx at gmail dot com @ 2024-09-17 21:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 116754
           Summary: libstdc++ std::ranges::copy performance issue
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: addmlbx at gmail dot com
  Target Milestone: ---

Created attachment 59130
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59130&action=edit
struct __memcpyable definition

libstdc++ std::ranges::copy implementation has bug which prevents calling
memmove in case iterators are pointers:
there is an `if constexpr (__memcpyable<_Iter, _Out>::__value)`
statement used to determine whether memmove should be called and _Iter and _Out
template parameters are swapped (__memcpyable expects output iterator to be
given first). Therefore this statement evaluates to false and memmove is not
called.

I noticed this bug when I was comparing the assembly produced for copying some
containers like std::vector, std::array and C-style array in the std::copy and
std::ranges::copy:
When calling std::copy on these containers, it's inlined down to the memmove
call. But for the std::ranges::copy the assembly is different: it fallback to
the generic cycle-based implementation.

Definition of the struct __memcpyable is shown on the attached picture in order
to demonstrate that it (and it's specializations) expect output iterator to be
passed first

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

* [Bug libstdc++/116754] libstdc++ std::ranges::copy performance issue
  2024-09-17 21:59 [Bug libstdc++/116754] New: libstdc++ std::ranges::copy performance issue addmlbx at gmail dot com
@ 2024-09-17 22:01 ` addmlbx at gmail dot com
  2024-09-18 22:21 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: addmlbx at gmail dot com @ 2024-09-17 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from df fd <addmlbx at gmail dot com> ---
Created attachment 59131
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59131&action=edit
struct __memcpyable usage in the std::ranges::copy

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

* [Bug libstdc++/116754] libstdc++ std::ranges::copy performance issue
  2024-09-17 21:59 [Bug libstdc++/116754] New: libstdc++ std::ranges::copy performance issue addmlbx at gmail dot com
  2024-09-17 22:01 ` [Bug libstdc++/116754] " addmlbx at gmail dot com
@ 2024-09-18 22:21 ` redi at gcc dot gnu.org
  2024-09-22 16:50 ` cvs-commit at gcc dot gnu.org
  2024-09-23 19:24 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-09-18 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-09-18
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
   Target Milestone|---                         |13.4
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED

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

* [Bug libstdc++/116754] libstdc++ std::ranges::copy performance issue
  2024-09-17 21:59 [Bug libstdc++/116754] New: libstdc++ std::ranges::copy performance issue addmlbx at gmail dot com
  2024-09-17 22:01 ` [Bug libstdc++/116754] " addmlbx at gmail dot com
  2024-09-18 22:21 ` redi at gcc dot gnu.org
@ 2024-09-22 16:50 ` cvs-commit at gcc dot gnu.org
  2024-09-23 19:24 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-09-22 16:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC 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:83c6fe130a00c6c28cfffcc787a0a719966adfaf

commit r15-3775-g83c6fe130a00c6c28cfffcc787a0a719966adfaf
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Sep 18 17:47:49 2024 +0100

    libstdc++: Fix condition for ranges::copy to use memmove [PR116754]

    libstdc++-v3/ChangeLog:

            PR libstdc++/116754
            * include/bits/ranges_algobase.h (__copy_or_move): Fix order of
            arguments to __memcpyable.

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

* [Bug libstdc++/116754] libstdc++ std::ranges::copy performance issue
  2024-09-17 21:59 [Bug libstdc++/116754] New: libstdc++ std::ranges::copy performance issue addmlbx at gmail dot com
                   ` (2 preceding siblings ...)
  2024-09-22 16:50 ` cvs-commit at gcc dot gnu.org
@ 2024-09-23 19:24 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-09-23 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

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

commit r14-10707-gf4fc6d2aa809d0c4b5b1825af17bed4a601a3d7f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Sep 18 17:47:49 2024 +0100

    libstdc++: Fix condition for ranges::copy to use memmove [PR116754]

    libstdc++-v3/ChangeLog:

            PR libstdc++/116754
            * include/bits/ranges_algobase.h (__copy_or_move): Fix order of
            arguments to __memcpyable.

    (cherry picked from commit 83c6fe130a00c6c28cfffcc787a0a719966adfaf)

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

end of thread, other threads:[~2024-09-23 19:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-17 21:59 [Bug libstdc++/116754] New: libstdc++ std::ranges::copy performance issue addmlbx at gmail dot com
2024-09-17 22:01 ` [Bug libstdc++/116754] " addmlbx at gmail dot com
2024-09-18 22:21 ` redi at gcc dot gnu.org
2024-09-22 16:50 ` cvs-commit at gcc dot gnu.org
2024-09-23 19:24 ` cvs-commit 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).