public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/109150] New: std::fill should use __gnu_cxx::__is_scalar overloads for all scalars
@ 2023-03-15 20:49 redi at gcc dot gnu.org
  2023-03-15 20:54 ` [Bug libstdc++/109150] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-15 20:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109150
           Summary: std::fill should use __gnu_cxx::__is_scalar overloads
                    for all scalars
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

std::fill and std::fill_n have optimized implementations for simple types, but
dispatching on std::__is_scalar which is not true for enumeration types or
pointer-to-member types.

  template<typename _ForwardIterator, typename _Tp>
    _GLIBCXX20_CONSTEXPR
    inline typename
    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
    __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
              const _Tp& __value)
    {
      const _Tp __tmp = __value;
      for (; __first != __last; ++__first)
        *__first = __tmp;
    }

Where __is_scalar doesn't match the semantics of std::is_scalar, but rather:

  template<typename _Tp>
    struct __is_scalar
    : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
    { };

We should enable this optimization for more types. Maybe use the same set of
types matches by std::is_scalar? Or all types that are trivially copy
constructible and trivially copy assignable?

I think the point of the optimization is so the compiler knows that __tmp
doesn't alias anything in the iterator range. But if the iterators value type
is not _Tp, this optimization might actually be wrong (the value type's
assignment operator might care about the identity of _Tp).

Review this, decide whether the traits in cpp_type_traits.h make sense to keep,
or should be reimplemented in terms of <type_traits> and/or built-ins.

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

end of thread, other threads:[~2024-06-21 16:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 20:49 [Bug libstdc++/109150] New: std::fill should use __gnu_cxx::__is_scalar overloads for all scalars redi at gcc dot gnu.org
2023-03-15 20:54 ` [Bug libstdc++/109150] " redi at gcc dot gnu.org
2024-06-19 14:00 ` redi at gcc dot gnu.org
2024-06-19 15:11 ` redi at gcc dot gnu.org
2024-06-19 15:31 ` arthur.j.odwyer at gmail dot com
2024-06-19 15:44 ` redi at gcc dot gnu.org
2024-06-19 15:48 ` redi at gcc dot gnu.org
2024-06-20 15:37 ` redi at gcc dot gnu.org
2024-06-21 16:07 ` cvs-commit at gcc dot gnu.org
2024-06-21 16:10 ` 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).