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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 01:43:58 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.
----------------
lukel97 wrote:

Just a question about potential AArch64 support, SVE has [first-fault gathers](https://developer.arm.com/documentation/ddi0602/2025-06/SVE-Instructions/LDFF1W--scalar-plus-vector---Gather-load-first-fault-unsigned-words-to-vector--vector-index--) IIUC which could be used for strided accesses. I presume we don't need to check for alignment there? From quickly scanning the docs it looks like an unaligned access non-first-fault will be handled the same as any other non-first-fault. 

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


More information about the llvm-commits mailing list