[llvm] [LV] Add support for partial alias masking with tail folding (PR #182457)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 10 10:08:14 PDT 2026
================
@@ -8682,6 +8747,49 @@ void LoopVectorizationPlanner::attachRuntimeChecks(
}
}
+void LoopVectorizationPlanner::materializeAliasMask(
+ VPlan &Plan, ArrayRef<PointerDiffInfo> DiffChecks, bool HasBranchWeights) {
+ assert(CM.foldTailByMasking() && "Expected tail folding to be enabled");
+ VPBasicBlock *ClampedVFCheck =
+ Plan.createVPBasicBlock("vector.clamped.vf.check");
+
+ VPValue *ClampedVF = VPlanTransforms::materializeAliasMask(
+ Plan, ClampedVFCheck,
+ *CM.Legal->getRuntimePointerChecking()->getDiffChecks());
+ VPBuilder Builder(ClampedVFCheck);
+ DebugLoc DL = DebugLoc::getCompilerGenerated();
+ Type *TCTy = VPTypeAnalysis(Plan).inferScalarType(Plan.getTripCount());
+
+ // Check the "ClampedVF" from the alias mask is not scalar.
+ VPValue *IsScalar =
+ Builder.createICmp(CmpInst::ICMP_ULE, ClampedVF,
+ Plan.getConstantInt(TCTy, 1), DL, "vf.is.scalar");
+
+ VPValue *TripCount = Plan.getTripCount();
+ VPValue *MaxUIntTripCount =
+ Plan.getConstantInt(cast<IntegerType>(TCTy)->getMask());
+ VPValue *DistanceToMax = Builder.createSub(MaxUIntTripCount, TripCount);
+
+ // For tail-folding: Don't execute the vector loop if (UMax - n) < ClampedVF.
----------------
sdesmalen-arm wrote:
nit: maybe explain that this is required because the ClampVF is not guaranteed to be a power of 2.
https://github.com/llvm/llvm-project/pull/182457
More information about the llvm-commits
mailing list