llvm / llvm/llvm-project

Loops containing assignments of trivially copyable data structures are not vectorized

Open
#198,530 0 comments 0 reactions 0 assignees View on GitHub
llvm:optimizations llvm:SLPVectorizer vectorizers
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

While working on the vectorization of our codebase we are currently hit by clang emitting calls to `memcpy` for trivially copyable data structures (https://en.cppreference.com/cpp/named_req/TriviallyCopyable). This is illustrated here: https://godbolt.org/z/xnqcEEe3P. Even though vectorization is enforced with `#pragma omp simd` the loop in function `h` cannot be vectorized due to the call to `memcpy`. When destroying the trivially copyable property by adding e.g. a custom copy constructor (when `CUSTOM_COPY` is defined in the example in the right-most window), the loop could be vectorized. This however also comes at a cost: For the trivially copyable data structure a single call to `memmove` is emitted when using `std::copy` in function `f`. if `CUSTOM_COPY` is defined, a loop is emitted here.

Maybe calls to `memcpy` can be replaced by load/store instructions before vectorizing the loop to overcome this.

In our codebase this of course is only a fragment of a more complex loop we want to vectorize, we do not intend to vectorize a loop simply copying memory.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.