[llvm] [LV] Initial support for stores in early exit loops (PR #137774)
Graham Hunter via llvm-commits
llvm-commits at lists.llvm.org
Wed May 14 07:50:34 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))
----------------
huntergr-arm wrote:
So there shouldn't be a problem with stores since dependencies for the EarlyExitLoad are checked later (in canVectorizeMemory()), but I didn't check for a uniform load. I've added the !loopInvariant check for now.
Technically it would have been rejected by the vplan transformation and the plan deleted (since that's looking for a load with an address based on the canonical IV), but it's nice if we can reject earlier instead.
https://github.com/llvm/llvm-project/pull/137774
More information about the llvm-commits
mailing list