From: Jonathan Wakely <jwakely@redhat.com>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: Matthias Kretz <m.kretz@gsi.de>,
libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: libstdc++: Speed up push_back
Date: Fri, 24 Nov 2023 21:55:52 +0000 [thread overview]
Message-ID: <CACb0b4mwXyyzGsCV8415z3U9hGHsaNOTmRfyaXsJh7xDMKc_JQ@mail.gmail.com> (raw)
In-Reply-To: <ZWECh8DQFpocwj+0@kam.mff.cuni.cz>
On Fri, 24 Nov 2023 at 20:07, Jan Hubicka <hubicka@ucw.cz> wrote:
> The vector.tcc change was regtested on x86_64-linux, OK?
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/vector.tcc (reserve): Copy _M_start and _M_finish
> to local variables to allow propagation across call to
> allocator.
>
> diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc
> index 0ccef7911b3..0a9db29c1c7 100644
> --- a/libstdc++-v3/include/bits/vector.tcc
> +++ b/libstdc++-v3/include/bits/vector.tcc
> @@ -72,27 +72,30 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
> if (this->capacity() < __n)
> {
> const size_type __old_size = size();
> + // Make local copies of these members because the compiler thinks
> + // the allocator can alter them if 'this' is globally reachable.
> + pointer __old_start = this->_M_impl._M_start;
> + pointer __old_finish = this->_M_impl._M_finish;
> pointer __tmp;
> #if __cplusplus >= 201103L
> if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
> {
> __tmp = this->_M_allocate(__n);
> - _S_relocate(this->_M_impl._M_start, this->_M_impl._M_finish,
> + _S_relocate(__old_start, __old_finish,
> __tmp, _M_get_Tp_allocator());
Please move "__tmp," to the first line, as it will fit there now that
the line got shorter:
_S_relocate(__old_start, __old_finish, __tmp,
_M_get_Tp_allocator());
> }
> else
> #endif
> {
> __tmp = _M_allocate_and_copy(__n,
> - _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start),
> - _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish));
> - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
> + _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__old_start),
> + _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__old_finish));
> + std::_Destroy(__old_start, __old_finish,
> _M_get_Tp_allocator());
The _Destroy call will fit on one line now:
std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator());
> }
> _GLIBCXX_ASAN_ANNOTATE_REINIT;
> - _M_deallocate(this->_M_impl._M_start,
> - this->_M_impl._M_end_of_storage
> - - this->_M_impl._M_start);
> + _M_deallocate(__old_start,
> + this->_M_impl._M_end_of_storage - __old_finish);
This should be __old_start.
I think what you have here will show Asan and/or valgrind errors, as
the wrong length will be passed to operator delete.
> this->_M_impl._M_start = __tmp;
> this->_M_impl._M_finish = __tmp + __old_size;
> this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
>
prev parent reply other threads:[~2023-11-24 21:56 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-19 21:53 Jan Hubicka
2023-11-20 12:09 ` Jonathan Wakely
2023-11-20 15:44 ` Jan Hubicka
2023-11-20 16:46 ` Jonathan Wakely
2023-11-21 12:50 ` Jan Hubicka
2023-11-21 13:07 ` Jonathan Wakely
2023-11-23 8:15 ` Matthias Kretz
2023-11-23 15:07 ` Jan Hubicka
2023-11-23 15:33 ` Jan Hubicka
2023-11-23 15:43 ` Jan Hubicka
2023-11-23 16:26 ` Jonathan Wakely
2023-11-23 16:20 ` Jonathan Wakely
2023-11-24 10:21 ` Martin Jambor
2023-11-24 10:23 ` Richard Biener
2023-11-24 19:45 ` Marc Glisse
2023-11-24 20:07 ` Jan Hubicka
2023-11-24 21:55 ` Jonathan Wakely [this message]
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=CACb0b4mwXyyzGsCV8415z3U9hGHsaNOTmRfyaXsJh7xDMKc_JQ@mail.gmail.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=libstdc++@gcc.gnu.org \
--cc=m.kretz@gsi.de \
/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: link
Be 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).