[llvm] [LV]Initial support for safe distance in predicated DataWithEVL vectorization mode. (PR #102897)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 16:08:22 PDT 2024


================
@@ -4071,15 +4093,25 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
     InterleaveInfo.invalidateGroupsRequiringScalarEpilogue();
   }
 
-  FixedScalableVFPair MaxFactors = computeFeasibleMaxVF(MaxTC, UserVF, true);
+  // If we don't know the precise trip count, or if the trip count that we
+  // found modulo the vectorization factor is not zero, try to fold the tail
+  // by masking.
+  // FIXME: look for a smaller MaxVF that does divide TC rather than masking.
+  setTailFoldingStyles(UserIC);
+  FixedScalableVFPair MaxFactors =
+      computeFeasibleMaxVF(MaxTC, UserVF, foldTailByMasking());
 
   // Avoid tail folding if the trip count is known to be a multiple of any VF
   // we choose.
   std::optional<unsigned> MaxPowerOf2RuntimeVF =
       MaxFactors.FixedVF.getFixedValue();
   if (MaxFactors.ScalableVF) {
     std::optional<unsigned> MaxVScale = getMaxVScale(*TheFunction, TTI);
-    if (MaxVScale && TTI.isVScaleKnownToBeAPowerOfTwo()) {
+    // If scalable vector factor is not set or power-of-2 or tail folding with
+    // EVL is not set, try to avoid tail folding if the trip count is known to
+    // be a multiple of any chosen VF.
----------------
ayalz wrote:

Explanation above talks about the complementary condition checked in the code below, better have them consistent.
What if tail folding with EVL is set - but MaxEVLSafeElements is not a power of 2? Unclear why the latter matters - EVL should presumably handle any max safe distance(?)

https://github.com/llvm/llvm-project/pull/102897


More information about the llvm-commits mailing list