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

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 11:25:40 PDT 2024


================
@@ -1362,9 +1378,24 @@ bool VPlanTransforms::tryAddExplicitVectorLength(VPlan &Plan) {
   // Create the ExplicitVectorLengthPhi recipe in the main loop.
   auto *EVLPhi = new VPEVLBasedIVPHIRecipe(StartV, DebugLoc());
   EVLPhi->insertAfter(CanonicalIVPHI);
-  auto *VPEVL = new VPInstruction(VPInstruction::ExplicitVectorLength,
-                                  {EVLPhi, Plan.getTripCount()});
-  VPEVL->insertBefore(*Header, Header->getFirstNonPhi());
+  VPRecipeBase *AVL = EVLPhi;
+  if (MaxEVLSafeElements) {
+    VPValue *EVLSafe = Plan.getOrAddLiveIn(
+        ConstantInt::get(CanonicalIVPHI->getScalarType(), *MaxEVLSafeElements));
+    auto *Cmp = new VPInstruction(Instruction::ICmp, ICmpInst::ICMP_ULT, EVLPhi,
+                                  EVLSafe);
+    Cmp->insertBefore(*Header, Header->getFirstNonPhi());
+    AVL = new VPInstruction(Instruction::Select, {Cmp, EVLPhi, EVLSafe},
+                            DebugLoc(), "safe_avl");
+    AVL->insertAfter(Cmp);
+  }
+  auto *VPEVL = new VPInstruction(
+      VPInstruction::ExplicitVectorLength,
+      {AVL->getVPSingleValue(), Plan.getTripCount()}, DebugLoc());
+  if (MaxEVLSafeElements)
+    VPEVL->insertAfter(AVL);
+  else
+    VPEVL->insertBefore(*Header, Header->getFirstNonPhi());
----------------
alexey-bataev wrote:

EVLPhi better do in the separate patch

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


More information about the llvm-commits mailing list