gcc/libstdc++-v3/include
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
..
backward non-gcc: Remove trailing whitespace 2024-10-25 10:03:17 +02:00
bits improve std::deque::_M_reallocate_map 2024-11-26 13:54:21 +01:00
c libstdc++: #ifdef out #pragma GCC system_header 2024-09-25 08:20:45 -04:00
c_compatibility libstdc++: Deprecate useless <cxxx> compatibility headers for C++17 2024-11-06 12:47:19 +00:00
c_global libstdc++: Deprecate useless <cxxx> compatibility headers for C++17 2024-11-06 12:47:19 +00:00
c_std libstdc++: Deprecate useless <cxxx> compatibility headers for C++17 2024-11-06 12:47:19 +00:00
debug libstdc++: Do not define _Insert_base::try_emplace before C++17 2024-11-08 14:39:56 +00:00
decimal libstdc++: #ifdef out #pragma GCC system_header 2024-09-25 08:20:45 -04:00
experimental libstdc++: Refactor experimental::filesystem::path string conversions 2024-09-27 23:55:09 +01:00
ext non-gcc: Remove trailing whitespace 2024-10-25 10:03:17 +02:00
parallel non-gcc: Remove trailing whitespace 2024-10-25 10:03:17 +02:00
precompiled libstdc++: stdc++.h and <coroutine> 2024-11-14 11:39:31 -05:00
pstl libgcc, libstdc++: Make declarations no longer TU-local [PR115126] 2024-09-27 09:16:53 +10:00
std libstdc++: Implement LWG 3563 changes to keys_view and values_view 2024-11-14 13:27:41 -05:00
tr1 non-gcc: Remove trailing whitespace 2024-10-25 10:03:17 +02:00
tr2 libstdc++: #ifdef out #pragma GCC system_header 2024-09-25 08:20:45 -04:00
Makefile.am libstdc++: add ARM SVE support to std::experimental::simd 2024-03-27 15:14:36 +01:00
Makefile.in libstdc++: add ARM SVE support to std::experimental::simd 2024-03-27 15:14:36 +01:00