[llvm] [LV] Initial support for stores in early exit loops (PR #137774)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri May 9 07:28:01 PDT 2025


================
@@ -1656,6 +1688,21 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
         return false;
       }
 
+      // For loops with stores.
+      // Record load for analysis by isDereferenceableAndAlignedInLoop
+      // and later by dependence analysis.
+      if (BranchInst *Br = dyn_cast<BranchInst>(BB->getTerminator())) {
+        // FIXME: Handle exit conditions with multiple users, more complex exit
+        //        conditions than br(icmp(load, loop_inv)).
+        ICmpInst *Cmp = dyn_cast<ICmpInst>(Br->getCondition());
+        if (Cmp && Cmp->hasOneUse() &&
+            TheLoop->isLoopInvariant(Cmp->getOperand(1))) {
+          LoadInst *Load = dyn_cast<LoadInst>(Cmp->getOperand(0));
+          if (Load && Load->hasOneUse() && TheLoop->contains(Load))
+            EELoad = Load;
----------------
david-arm wrote:

Maybe you can avoid doing the work here and only do the analysis if you find a store? You can do this by simply keeping a copy of the terminator's condition, since we only support a single early uncountable exit anyway.

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


More information about the llvm-commits mailing list