c++: fewer allocator temps [PR105838]
commit1e1847612d7f169f82c985b0b3a5e3301d6fe999
authorJason Merrill <jason@redhat.com>
Mon, 5 Dec 2022 20:19:27 +0000 (5 15:19 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 8 Dec 2022 18:32:11 +0000 (8 13:32 -0500)
tree43886abb4a1ab759fb6ebaf3d7472a7819de2c77
parent3da5ae7a347b7d74765053f4a08eaf7ec58f8735
c++: fewer allocator temps [PR105838]

In this PR, initializing the array of std::string to pass to the vector
initializer_list constructor gets very confusing to the optimizers as the
number of elements increases, primarily because of all the std::allocator
temporaries passed to all the string constructors.  Instead of creating one
for each string, let's share an allocator between all the strings; we can do
this safely because we know that std::allocator is stateless and that string
doesn't care about the object identity of its allocator parameter.

PR c++/105838

gcc/cp/ChangeLog:

* cp-tree.h (is_std_allocator): Declare.
* constexpr.cc (is_std_allocator): Split out  from...
(is_std_allocator_allocate): ...here.
* init.cc (find_temps_r): New.
(find_allocator_temp): New.
(build_vec_init): Use it.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/allocator-opt1.C: New test.
gcc/cp/constexpr.cc
gcc/cp/cp-tree.h
gcc/cp/init.cc
gcc/testsuite/g++.dg/tree-ssa/allocator-opt1.C [new file with mode: 0644]