public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109150] New: std::fill should use __gnu_cxx::__is_scalar overloads for all scalars Date: Wed, 15 Mar 2023 20:49:30 +0000 [thread overview] Message-ID: <bug-109150-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2023-03-15 20:49 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-15 20:49 redi at gcc dot gnu.org [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-109150-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).