public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/114821] New: _M_realloc_append should use memcpy instead of loop to copy data when possible
@ 2024-04-23  8:14 hubicka at gcc dot gnu.org
  2024-04-23  8:30 ` [Bug libstdc++/114821] " redi at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: hubicka at gcc dot gnu.org @ 2024-04-23  8:14 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-04-24 14:23 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23  8:14 [Bug libstdc++/114821] New: _M_realloc_append should use memcpy instead of loop to copy data when possible hubicka at gcc dot gnu.org
2024-04-23  8:30 ` [Bug libstdc++/114821] " redi at gcc dot gnu.org
2024-04-23  8:52 ` hubicka at gcc dot gnu.org
2024-04-23 10:41 ` redi at gcc dot gnu.org
2024-04-23 10:51 ` redi at gcc dot gnu.org
2024-04-23 11:01 ` redi at gcc dot gnu.org
2024-04-23 12:08 ` hubicka at gcc dot gnu.org
2024-04-23 12:33 ` redi at gcc dot gnu.org
2024-04-23 12:38 ` hubicka at gcc dot gnu.org
2024-04-23 12:41 ` hubicka at gcc dot gnu.org
2024-04-23 12:42 ` redi at gcc dot gnu.org
2024-04-23 13:11 ` redi at gcc dot gnu.org
2024-04-23 15:53 ` redi at gcc dot gnu.org
2024-04-24 14:23 ` hubicka at gcc dot gnu.org

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).