[libcxx-commits] [PATCH] D147741: [libc++, std::vector] call the optimized version of __uninitialized_allocator_copy for trivial types

Aditya Kumar via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 16 23:40:32 PDT 2023


hiraditya added a comment.

> I wouldn't remove the test -- just wanted to make sure we understand why there's a difference. I'm a little surprised the compiler could optimize the assignment case but not the construction case, but if that's what the assembly shows, then I don't think we need to dig any further.

The assembly does show the difference. only that performance numbers didn't show any measurable difference on my machine. For example the following test case:

  #include<vector>
  using namespace std;
  using T = int;
  T vec_copy(std::vector<T> v1, std::vector<T> &v2) {
      v2 = v1; 
      return 10; 
  }

And with the patch, clang does generate an extra memmove for a for loop.

$ clang++  -I ~/g/llvm-project/build-runtimes/include/c++/v1 -I ~/g/llvm-project/build-runtimes/libcxx/benchmarks/benchmark-libcxx/include -I ~/g/llvm-project/libcxx/test/support -I ~/g/llvm-project/libcxxabi/include  -O3 -nostdinc++  -std=c++20 -S test1.cpp -w -fno-exceptions

$ grep memmove test1.base.s | wc -l

  2 

$ grep memmove test1.s | wc -l

  3


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147741/new/

https://reviews.llvm.org/D147741



More information about the libcxx-commits mailing list