[llvm] [VPlan] Make VPInstruction::AnyOf poison-safe. (PR #154156)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 25 05:47:48 PDT 2025


fhahn wrote:

> > 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.
> 
> Yeah you're right and I admit I don't fully understand the rules here. If we have branch-on-poison do we still have to make sure that both destination blocks contain functionally correct code? Or will branch-on-poison just turn into an unreachable?

If we exit before branch-on-poison, then the code we generate is correct, as all lanes before the first active on must be non-poison. If a lane before the exit is poison, the vector code in the exits may result in a poison index/lane. But in that case the scalar loop will also have undefined behavior, so that is fine. LLVM may be able to prove that the scalar loop is guaranateed to execute branch-on-poison, and in that case should remove the loop itself, as it can never execute due to UB.

https://github.com/llvm/llvm-project/pull/154156


More information about the llvm-commits mailing list