Loops containing assignments of trivially copyable data structures are not vectorized
- 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
Assessment
This issue has not been assessed yet.