[llvm] [LV] Vectorize early exit loops with stores using masking (PR #178454)
Graham Hunter via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 19 10:04:40 PST 2026
================
@@ -2059,12 +2063,24 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
return false;
}
- // Bail out for state-changing loops with uncountable exits for now.
- if (UncountableExitWithSideEffects) {
- reportVectorizationFailure(
- "Writes to memory unsupported in early exit loops",
- "Cannot vectorize early exit loop with writes to memory",
- "WritesInEarlyExitLoop", ORE, TheLoop);
+ // TODO: Remove this restriction once we're sure it's safe to do so.
+ // Handling stores to invariant addresses will be slightly different
+ // based on the approach taken. If we bail out before executing any
+ // lane that would take the uncountable exit, then the store that occurs
----------------
huntergr-arm wrote:
If we bail out in the vector iteration before _any_ exit, we can just let the scalar loop perform the loop-invariant store. We don't even have to include the store in the vectorized code.
If we're doing at least part of the final iterations in vector code, we may need to extract the last active lane based on the mask for the data instead of just using the last lane based on VF.
It shouldn't be too much work to support it, but I'm trying to keep the initial patch size down.
https://github.com/llvm/llvm-project/pull/178454
More information about the llvm-commits
mailing list