[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 08:25:43 PDT 2025
================
@@ -1732,13 +1794,53 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
// TODO: Handle loops that may fault.
Predicates.clear();
- if (!isDereferenceableReadOnlyLoop(TheLoop, PSE.getSE(), DT, AC,
- &Predicates)) {
+
+ if (HasStore && EELoad.has_value()) {
+ LoadInst *LI = *EELoad;
+ if (isDereferenceableAndAlignedInLoop(LI, TheLoop, *PSE.getSE(), *DT, AC,
+ &Predicates)) {
+ ICFLoopSafetyInfo SafetyInfo;
+ SafetyInfo.computeLoopSafetyInfo(TheLoop);
+ // FIXME: We may have multiple levels of conditional loads, so will
+ // need to improve on outright rejection at some point.
+ if (!SafetyInfo.isGuaranteedToExecute(*LI, DT, TheLoop)) {
+ LLVM_DEBUG(
+ dbgs() << "Early exit condition load not guaranteed to execute.\n");
+ reportVectorizationFailure(
+ "Early exit condition load not guaranteed to execute",
+ "Cannot vectorize early exit loop when condition load is not "
+ "guaranteed to execute",
+ "EarlyExitLoadNotGuaranteed", ORE, TheLoop);
+ }
+ } else {
+ LLVM_DEBUG(dbgs() << "Early exit condition load potentially unsafe.\n");
+ reportVectorizationFailure("Uncounted loop condition not known safe",
+ "Cannot vectorize early exit loop with "
+ "possibly unsafe condition load",
+ "PotentiallyFaultingEarlyExitLoop", ORE,
+ TheLoop);
+ return false;
+ }
+ } else if (HasStore) {
+ LLVM_DEBUG(dbgs() << "Found early exit store but no condition load.\n");
reportVectorizationFailure(
- "Loop may fault",
- "Cannot vectorize potentially faulting early exit loop",
- "PotentiallyFaultingEarlyExitLoop", ORE, TheLoop);
+ "Early exit loop with store but no condition load",
+ "Cannot vectorize early exit loop with store but no condition load",
+ "NoConditionLoadForEarlyExitLoop", ORE, TheLoop);
return false;
+ } else {
+ // Read-only loop.
+ // FIXME: as with the loops with stores, only the loads contributing to
----------------
huntergr-arm wrote:
No, that's why it's a FIXME. Future work :)
https://github.com/llvm/llvm-project/pull/137774
More information about the llvm-commits
mailing list