[llvm] [LV] Add initial legality checks for loops with unbound loads. (PR #152422)

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 03:06:38 PDT 2025


================
@@ -1760,16 +1760,30 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
   assert(LatchBB->getUniquePredecessor() == SingleUncountableExitingBlock &&
          "Expected latch predecessor to be the early exiting block");
 
-  // TODO: Handle loops that may fault.
   Predicates.clear();
-  if (!isDereferenceableReadOnlyLoop(TheLoop, PSE.getSE(), DT, AC,
-                                     &Predicates)) {
-    reportVectorizationFailure(
-        "Loop may fault",
-        "Cannot vectorize potentially faulting early exit loop",
-        "PotentiallyFaultingEarlyExitLoop", ORE, TheLoop);
+  SmallVector<LoadInst *, 4> NonDerefLoads;
+  if (!isReadOnlyLoop(TheLoop, PSE.getSE(), DT, AC, &NonDerefLoads,
+                      &Predicates)) {
+    reportVectorizationFailure("Loop may fault",
+                               "Cannot vectorize non-read-only early exit loop",
+                               "NonReadOnlyEarlyExitLoop", ORE, TheLoop);
     return false;
   }
+  // Check non-dereferenceable loads if any.
+  for (LoadInst *LI : NonDerefLoads) {
+    // Only support unit-stride access for now.
----------------
huntergr-arm wrote:

Yes, SVE's first faulting gathers have the same alignment rules as normal gathers, so no extra checks required.

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


More information about the llvm-commits mailing list