[llvm] [LV] Drop prefetches from vector loops (PR #226895)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 27 23:52:28 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-vectorizers
Author: Dávid Bolvanský (davidbolvansky)
<details>
<summary>Changes</summary>
`llvm.prefetch` can currently prevent an otherwise vectorizable loop from being vectorized. For example:
```c
void add(int *restrict a, int *restrict b, int n) {
for (int i = 0; i < n; ++i) {
a[i] += b[i];
__builtin_prefetch(&b[i + 8]);
}
}
```
Permit LoopVectorize to omit prefetches from the vector loop. Ignore them during memory dependence and legality checks, and remove their VPlan recipes before call-widening decisions. VPlan DCE then removes address calculations used only by the hint. The scalar remainder retains its original prefetch.
This is sound because `llvm.prefetch` has no observable behavior and cannot trap, so removing it does not change program semantics. Conditional prefetches can be handled in the same way.
---
Full diff: https://github.com/llvm/llvm-project/pull/226895.diff
4 Files Affected:
- (modified) llvm/lib/Analysis/LoopAccessAnalysis.cpp (+7)
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp (+9)
- (modified) llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp (+15)
- (added) llvm/test/Transforms/LoopVectorize/prefetch.ll (+161)
``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````
</details>
https://github.com/llvm/llvm-project/pull/226895
More information about the llvm-commits
mailing list