[llvm] [LV] Don't mark ptrs as safe to speculate if fed by UB/poison op. (PR #143204)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 9 14:52:19 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),
+ // because flags will be dropped when executing them unconditionally.
+ // TODO: Results could be improved by considering poison-propagation
+ // properties of visited ops.
+ auto CanSpeculateOp = [this](Value *Ptr) {
----------------
fhahn wrote:
It checks both for instructions that trigger immediate UB when computing the pointer and cases where the pointer itself may be poison, thus triggering UB if dereferenced, which is why I tried to keep the name generic, but it's not 100% clear at the moment.
https://github.com/llvm/llvm-project/pull/143204
More information about the llvm-commits
mailing list