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

Shih-Po Hung via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 22 00:28:28 PDT 2025


================
@@ -856,16 +856,19 @@ bool llvm::canReplacePointersIfEqual(const Value *From, const Value *To,
   return isPointerAlwaysReplaceable(From, To, DL);
 }
 
-bool llvm::isDereferenceableReadOnlyLoop(
+bool llvm::isReadOnlyLoopWithSafeOrSpeculativeLoads(
     Loop *L, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC,
+    SmallVectorImpl<LoadInst *> *SpeculativeLoads,
     SmallVectorImpl<const SCEVPredicate *> *Predicates) {
   for (BasicBlock *BB : L->blocks()) {
     for (Instruction &I : *BB) {
       if (auto *LI = dyn_cast<LoadInst>(&I)) {
         if (!isDereferenceableAndAlignedInLoop(LI, L, *SE, *DT, AC, Predicates))
-          return false;
-      } else if (I.mayReadFromMemory() || I.mayWriteToMemory() || I.mayThrow())
+          SpeculativeLoads->push_back(LI);
----------------
arcbbb wrote:

> There seems to be quite a bit of logic related to checking alignment in `isDereferenceableAndAlignedInLoop`. Are we sure we don't need it for vleff?

My explanation:
For countable loops, vector loads can be emitted without proven alignment.
For early‑exit loops: regular loads require a guarantee that no lane faults;
    with vleff, only the first lane can fault, so the safety requirement  is equivalent to the countable‑loop case.

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


More information about the llvm-commits mailing list