[llvm] [LV] Add initial legality checks for loops with unbound loads. (PR #152422)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 18 04:14:23 PDT 2025
lukel97 wrote:
> I would like to know why the vectorization of PotentiallyFaultingLoads was directly rejected. I think this is unreasonable. After all, the following code
>
> ```
> void bar(float *A, float* B, float K, int start, int end) {
> for (int i = start; i < end; ++i)
> A[i] *= B[i] + K;
> }
> ```
>
> The "load" operation is not necessarily valid, but it can also be vectorized.
We vectorize the loop above because A[i] and B[i] will at least exhibit the same observable trapping when vectorized, so they're considered dereferenceable.
PotentiallyFaultingLoads contains loads like this:
```
for (int i = 0; i < n; i++) {
if (A[i] == 0)
break;
A[i]++;
}
```
If A[2] == 0 but A[3] isn't dereferenceable, the original scalar loop won't trap.
If we vectorize this with VF=4 we would trap trying to access A[3]. We specifically need fault-only-first instructions to vectorize this safely, and the support for those hasn't landed yet.
https://github.com/llvm/llvm-project/pull/152422
More information about the llvm-commits
mailing list