[llvm] [LoopVectorize] Perform loop versioning for some early exit loops (PR #120603)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 13 12:28:10 PST 2025


================
@@ -1609,6 +1609,43 @@ bool LoopVectorizationLegality::canVectorizeLoopNestCFG(
   return Result;
 }
 
+bool LoopVectorizationLegality::analyzePotentiallyFaultingLoads(
+    SmallVectorImpl<LoadInst *> *Loads) {
+  LLVM_DEBUG(dbgs() << "LV: Looking for potentially faulting loads in loop "
+                       "with uncountable early exit:\n");
+  for (LoadInst *LI : *Loads) {
+    LLVM_DEBUG(dbgs() << "LV:   Load: " << *LI << '\n');
+    Value *Ptr = LI->getPointerOperand();
+    if (!Ptr)
+      return false;
+    const SCEV *PtrExpr = PSE.getSCEV(Ptr);
+    const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrExpr);
+    // TODO: Deal with loop invariant pointers.
+    if (!AR || AR->getLoop() != TheLoop || !AR->isAffine())
----------------
fhahn wrote:

Would be good to explain here that we check for add-recs because the reasoning is only safe if the load executes at least once?

We should probably also restrict this just for loads from the default address space (0) for now

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


More information about the llvm-commits mailing list