[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
Thu Apr 27 16:22:31 PDT 2023


hiraditya added a comment.

In D147741#4303326 <https://reviews.llvm.org/D147741#4303326>, @philnik wrote:

> I would have expected a lot higher improvements from this. Does clang generate better vectorized code for copies now?

Updated the results after rerunning. With this change clang would generate memcpy for copying vector<int>.

For the following testcase, the copy is deleted because the compiler would figure out that it is a dead code.

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

With the above patch and the following command:

$ /usr/bin/clang++ -I/usr/local/home/llvm-project/build/include/c++/v1 -I/usr/local/home/llvm-project/build/libcxx/benchmarks/benchmark-libcxx/include -I/usr/local/home/llvm-project/libcxx/test/support -I/usr/local/home/llvm-project/libcxxabi/include -O3 -nostdinc++ -std=c++20 -S ../build/test.cpp -w -fno-exceptions -o -

  asm
  _Z8vec_copyNSt3__16vectorIiNS_9allocatorIiEEEE: # @_Z8vec_copyNSt3__16vectorIiNS_9allocatorIiEEEE
          .cfi_startproc
  # %bb.0:
          subq    $24, %rsp
          .cfi_def_cfa_offset 32
          xorps   %xmm0, %xmm0
          movaps  %xmm0, (%rsp)
          movq    $0, 16(%rsp)
          movq    8(%rdi), %rax
          cmpq    (%rdi), %rax
          js      .LBB0_2
  # %bb.1:
          movl    $10, %eax
          addq    $24, %rsp
          .cfi_def_cfa_offset 8
          retq
  .LBB0_2:
          .cfi_def_cfa_offset 32
          movq    %rsp, %rdi
          callq   _ZNKSt3__16vectorIiNS_9allocatorIiEEE20__throw_length_errorB7v170000Ev
  .Lfunc_end0:
          .size   _Z8vec_copyNSt3__16vectorIiNS_9allocatorIiEEEE, .Lfunc_end0-_Z8vec_copyNSt3__16vectorIiNS_9allocatorIiEEEE
          .cfi_endproc


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

https://reviews.llvm.org/D147741



More information about the libcxx-commits mailing list