https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114821
Bug ID: 114821 Summary: _M_realloc_append should use memcpy instead of loop to copy data when possible Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: hubicka at gcc dot gnu.org Target Milestone: --- In thestcase #include <vector> typedef unsigned int uint32_t; std::pair<uint32_t, uint32_t> pair; void test() { std::vector<std::pair<uint32_t, uint32_t>> stack; stack.push_back (pair); while (!stack.empty()) { std::pair<uint32_t, uint32_t> cur = stack.back(); stack.pop_back(); if (!cur.first) { cur.second++; stack.push_back (cur); stack.push_back (cur); } if (cur.second > 10000) break; } } int main() { for (int i = 0; i < 10000; i++) test(); } We produce _M_reallloc_append which uses loop to copy data instead of memcpy. This is bigger and slower. The reason why __relocate_a does not use memcpy seems to be fact that pair has copy constructor. It still can be pattern matched by ldist but it fails with: (compute_affine_dependence ref_a: *__first_1, stmt_a: *__cur_37 = *__first_1; ref_b: *__cur_37, stmt_b: *__cur_37 = *__first_1; ) -> dependence analysis failed So we can not disambiguate old and new vector memory and prove that loop is indeed memcpy loop. I think this is valid since operator new is not required to return new memory, but I think adding __restrict should solve this. Problem is that I got lost on where to add them, since relocate_a uses iterators instead of pointers