[llvm] [LV, VP]VP intrinsics support for the Loop Vectorizer (PR #76172)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 13:33:50 PST 2024


================
@@ -4690,6 +4712,39 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
   // FIXME: look for a smaller MaxVF that does divide TC rather than masking.
   if (Legal->prepareToFoldTailByMasking()) {
----------------
fhahn wrote:

Early exit on `(!Legal->prepareToFoldTailByMasking())` won't work, because there is other code below.

But code can still be simplified by early exits, something like below should simplify things a bit
```diff
-    if (MaxFactors.ScalableVF.isVector()) {
-      assert(MaxFactors.ScalableVF.isScalable() &&
-             "Expected scalable vector factor.");
-      // FIXME: use actual opcode/data type for analysis here.
-      PreferEVL = getTailFoldingStyle() == TailFoldingStyle::DataWithEVL &&
-                  TTI.hasActiveVectorLength(0, nullptr, Align());
-#if !NDEBUG
-      if (getTailFoldingStyle() == TailFoldingStyle::DataWithEVL) {
-        if (PreferEVL)
-          dbgs() << "LV: Preference for VP intrinsics indicated. Will "
-                    "try to generate VP Intrinsics.\n";
-        else
-          dbgs() << "LV: Preference for VP intrinsics indicated. Will "
-                    "not try to generate VP Intrinsics since the target "
-                    "does not support vector length predication.\n";
-      }
-#endif // !NDEBUG
-
-      // Tail folded loop using VP intrinsics restricts the VF to be scalable
-      // for now.
-      // TODO: extend it for fixed vectors, if required.
-      if (PreferEVL)
-        MaxFactors.FixedVF = ElementCount::getFixed(1);
+    // FIXME: use actual opcode/data type for analysis here.
+    PreferEVL = MaxFactors.ScalableVF.isScalable() &&
+                getTailFoldingStyle() == TailFoldingStyle::DataWithEVL &&
+                TTI.hasActiveVectorLength(0, nullptr, Align());
+    if (!PreferEVL) {
+      LLVM_DEBUG(dbgs() << "LV: Preference for VP intrinsics indicated. Will "
+                           "not try to generate VP Intrinsics since the target "
+                           "does not support vector length predication.\n");
+      return MaxFactors;
     }

+    LLVM_DEBUG(dbgs() << "LV: Preference for VP intrinsics indicated. Will "
+                         "try to generate VP Intrinsics.\n");
+
+    // Tail folded loop using VP intrinsics restricts the VF to be scalable
+    // for now.
+    // TODO: extend it for fixed vectors, if required.
+    assert(MaxFactors.ScalableVF.isScalable() &&
+           "Expected scalable vector factor.");
+    MaxFactors.FixedVF = ElementCount::getFixed(1);
```

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


More information about the llvm-commits mailing list