gcc/libstdc++-v3
Jan Hubicka 1729147f2b improve std::deque::_M_reallocate_map
Looking into reason why we still do throw_bad_alloc in clang binary I noticed
that quite few calls come from deque::_M_reallocate_map.  This patch adds
unreachable to limit the size of realloc_map.  _M_reallocate_map is called only
if new size is smaller then max_size.  map is an array holding pointers to
entries of fixed size.

Since rellocation is done by doubling the map size, I think the maximal size of
map allocated is max_size / deque_buf_size rounded up times two.  This should
be also safe for overflows since we have extra bit.

map size is always at least 8. Theoretically this computation may be wrong for
very large T, but in that case callers should never reallocate.

On the testcase I get:
jh@shroud:~> ~/trunk-install-new4/bin/g++ -O2 dq.C -c ; size -A dq.o | grep text
.text                                              284      0
.text._ZNSt5dequeIiSaIiEE17_M_reallocate_mapEmb    485      0
.text.unlikely                                      10      0
jh@shroud:~> ~/trunk-install-new5/bin/g++ -O2 dq.C -c ; size -A dq.o | grep text
.text                                              284      0
.text._ZNSt5dequeIiSaIiEE17_M_reallocate_mapEmb    465      0
.text.unlikely                                      10      0

so this saves about 20 bytes of rellocate_map, which I think is worthwhile.
Curiously enough gcc14 does:

jh@shroud:~> g++ -O2 dq.C -c ; size -A dq.o | grep text
.text                 604      0
.text.unlikely         10      0

which is 145 bytes smaller. Obvoius difference is that _M_reallocate_map gets inlined.
Compiling gcc14 preprocessed file with trunk gives:

jh@shroud:~> g++ -O2 dq.C -S ; size -A dq.o | grep text
.text                 762      0
.text.unlikely         10      0

So inlining is due to changes at libstdc++ side, but code size growth is due to
something else.

For clang this reduced number of thris_bad_new_array_length from 121 to 61.

libstdc++-v3/ChangeLog:

	* include/bits/deque.tcc (std::deque::_M_reallocate_map): Add
	__builtin_unreachable check to declare that maps are not very large.
	* include/bits/stl_deque.h (std::deque::size): Add __builtin_unreachable
	to check for maximal size of map.

gcc/testsuite/ChangeLog:

	* g++.dg/tree-ssa/deque-1.C: New test.
	* g++.dg/tree-ssa/deque-2.C: New test.
2024-11-26 13:54:21 +01:00
..
config aarch64: libstdc++: Use shufflevector instead of shuffle in opt_random.h 2024-10-24 15:01:23 +01:00
doc libstdc++: Update reference to Angelika Langer's article 2024-11-18 08:33:49 +01:00
include improve std::deque::_M_reallocate_map 2024-11-26 13:54:21 +01:00
libsupc++ ibstdc++: Add some further attributes to ::operator new in <new> 2024-11-08 22:07:33 +01:00
po Update copyright years. 2024-01-03 12:19:35 +01:00
python libstdc++: Fix Python deprecation warning in printers.py 2024-10-16 10:09:16 +01:00
scripts libstdc++: Write timestamp to libstdc++-performance.sum file 2024-11-13 20:21:29 +00:00
src libstdc++: Move std::error_category symbol to separate file [PR117630] 2024-11-26 08:31:26 +00:00
testsuite libstdc++: Add conditional noexcept to range access functions 2024-11-26 08:31:27 +00:00
.editorconfig libstdc++: Add .editorconfig files 2024-09-16 10:10:23 +01:00
acinclude.m4 libstdc++: #ifdef out #pragma GCC system_header 2024-09-25 08:20:45 -04:00
aclocal.m4
ChangeLog Daily bump. 2024-11-21 00:20:27 +00:00
ChangeLog-1998
ChangeLog-1999
ChangeLog-2000
ChangeLog-2001
ChangeLog-2002
ChangeLog-2003
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-2014
ChangeLog-2015
ChangeLog-2016
ChangeLog-2017
ChangeLog-2018
ChangeLog-2019
ChangeLog-2020
ChangeLog-2021
ChangeLog-2022
ChangeLog-2023 Rotate ChangeLog files. 2024-01-03 11:29:39 +01:00
config.h.in libstdc++: Fix autoconf check for O_NONBLOCK in <fcntl.h> 2024-08-28 21:34:22 +01:00
configure libstdc++: #ifdef out #pragma GCC system_header 2024-09-25 08:20:45 -04:00
configure.ac libstdc++: Fix autoconf check for O_NONBLOCK in <fcntl.h> 2024-08-28 21:34:22 +01:00
configure.host Fix up duplicated words mostly in comments, part 1 2024-04-02 13:39:11 +02:00
crossconfig.m4
fragment.am
linkage.m4 libstdc++: Remove handling for underscore-prefixed libm functions [PR111638] 2023-11-11 00:41:08 +00:00
Makefile.am libstdc++: Use -C option to run recursive make in sub-directories 2024-11-16 01:05:06 +00:00
Makefile.in libstdc++: Use -C option to run recursive make in sub-directories 2024-11-16 01:05:06 +00:00
README

file: libstdc++-v3/README

New users may wish to point their web browsers to the file
index.html in the 'doc/html' subdirectory.  It contains brief
building instructions and notes on how to configure the library in
interesting ways.