[all-commits] [llvm/llvm-project] 555106: Optimize 'construct at end' loops in vector

Martijn Vels via All-commits all-commits at lists.llvm.org
Thu Jun 18 10:48:03 PDT 2020


  Branch: refs/heads/vector-construct-at-end
  Home:   https://github.com/llvm/llvm-project
  Commit: 555106aa69355c1e91903a85682e81dc9db57478
      https://github.com/llvm/llvm-project/commit/555106aa69355c1e91903a85682e81dc9db57478
  Author: Martijn Vels <mvels at google.com>
  Date:   2020-06-18 (Thu, 18 Jun 2020)

  Changed paths:
    M libcxx/include/vector

  Log Message:
  -----------
  Optimize 'construct at end' loops in vector

Summary:
This change adds local 'end' and 'pos' variables for the main loop inmstead of using the ConstructTransaction variables directly.

We observed that not all vector initialization and resize operations got properly vectorized, i.e., (partially) unrolled into XMM stores for floats.

For example, `vector<int32_t> v(n, 1)` gets vectorized, but `vector<float> v(n, 1)`. It looks like the compiler assumes the state is leaked / aliased in the latter case (unclear how/why for float, but not for int32), and because of this fails to see vectorization optimization?

See https://gcc.godbolt.org/z/UWhiie

By using a local `__new_end_` (fixed), and local `__pos` (copied into __tx.__pos_ per iteration), we offer the compiler a clean loop for unrolling.

A demonstration can be seen in the isolated logic in https://gcc.godbolt.org/z/KoCNWv

The com

Reviewers: EricWF, #libc!

Subscribers: libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D82111




More information about the All-commits mailing list