[llvm] [VPlan] Make VPInstruction::AnyOf poison-safe. (PR #154156)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 19 08:02:10 PDT 2025
fhahn wrote:
> Yeah that's my understanding of @llvm.experimental.cttz.elts as well. My point was more that we repeatedly use the comparison in the early exit block every time we want to calculate the last index in order to know which element to extract. Suppose the comparison was genuinely poison, then we'll end up using poison many times without freezing it. Suppose you had a loop like this:
>
> ```
> unsigned i = 0;
> memcpy(tmp, v, n * sizeof(int));
> for (; i < n; i++) {
> if (v[i] >> i)
> break;
> }
> if (v[i] != tmp[i])
> abort();
> ```
>
> An arithmetic shift right of `v[i]` could lead to poison and we may or may not trigger the early exit.
Hm, if the shift is poison before we exit the loop, then we have a branch-on-poison in the loop, which is undefined bevhavior.
> However, even if poison does lead to an early exit then v[i] should still always equal tmp[i], but the vectoriser effectively recalculates the indices for v[i] and tmp[i] using the unfrozen vector comparison v[i] >> i != 0. My point is that after vectorising this loop we may abort.
But we will only use the result the result from `@llvm.experimental.cttz.elts` where it can count without encountering poison before the first 1. If there's poison before, the original loop has branch-on-poison IIUC
https://github.com/llvm/llvm-project/pull/154156
More information about the llvm-commits
mailing list