[llvm] [LV] Don't mark ptrs as safe to speculate if fed by UB/poison op. (PR #143204)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 9 05:01:31 PDT 2025


================
@@ -1493,10 +1493,51 @@ bool LoopVectorizationLegality::canVectorizeWithIfConvert() {
     SmallVector<const SCEVPredicate *, 4> Predicates;
     for (Instruction &I : *BB) {
       LoadInst *LI = dyn_cast<LoadInst>(&I);
+
+      // Make sure we can execute all computations feeding into Ptr in the loop
+      // w/o triggering UB and that none of the out-of-loop operands are poison.
+      // We do not need to check if operations inside the loop can produce
+      // poison due to flags (e.g. due to an inbounds GEP going out of bounds),
----------------
david-arm wrote:

Does include things like nsw, nuw for sub/add operations? I'm just thinking of a scalar loop that has something like:

```
  %index = phi i64 ...
  %index_plus_offset = add nuw nsw i64 %index, 12345678
  %gep = getelementptr inbounds i64, ptr %ptr, i64 %index_plus_offset
```

where the `%index_plus_offset` could be poison-generating. Are you saying that after vectorisation any such flags on adds or subs that feed into the GEP cannot survive?

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


More information about the llvm-commits mailing list