[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
================
@@ -1209,6 +1210,36 @@ bool LoopVectorizationLegality::canVectorizeMemory() {
});
}
+ // FIXME: Remove or reduce this restriction. We're in a bit of an odd spot
+ // since we're (potentially) doing the load out of its normal order
+ // in the loop and that may throw off dependency checking.
+ // A forward dependency should be fine, but a backwards dep may not
+ // be even if LAA thinks it is due to performing the load for the
+ // vector iteration i+1 in vector iteration i.
+ if (isConditionCopyRequired()) {
+ assert(EarlyExitLoad.has_value() && "EE Store without condition load.");
+
+ if (LAI->canVectorizeMemory()) {
+ const MemoryDepChecker &DepChecker = LAI->getDepChecker();
+ const auto *Deps = DepChecker.getDependences();
+
+ for (const MemoryDepChecker::Dependence &Dep : *Deps) {
+ if (Dep.getDestination(DepChecker) == EarlyExitLoad ||
+ Dep.getSource(DepChecker) == EarlyExitLoad) {
+ // Refine language a little? This currently only applies when a store
+ // is present in the early exit loop.
+ reportVectorizationFailure(
+ "No dependencies allowed for early exit condition load",
+ "Early exit condition loads may not have a dependence with another"
+ " memory operation.",
+ "CantVectorizeStoreToLoopInvariantAddress", ORE,
+ TheLoop);
+ return false;
+ }
+ }
+ }
----------------
david-arm wrote:
What happens in the else case? Looks like we fall through to:
```
if (!LAI->canVectorizeMemory())
return canVectorizeIndirectUnsafeDependences();
```
and so we may still treat the loop as legal. Worth adding a test for this case I think.
https://github.com/llvm/llvm-project/pull/137774
More information about the llvm-commits
mailing list