[llvm] [LV][VPlan] Extract the implementation of transform Recipe to EVLRecipe into a small function. NFC (PR #119510)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 11 23:11:32 PST 2024


================
@@ -1438,13 +1438,100 @@ void VPlanTransforms::addActiveLaneMask(
     HeaderMask->replaceAllUsesWith(LaneMask);
 }
 
+static VPRecipeBase *createEVLRecipe(VPValue &EVL, VPValue *HeaderMask,
+                                     VPValue *AllOneMask,
+                                     VPRecipeBase *CurRecipe,
+                                     VPTypeAnalysis TypeInfo) {
+  using namespace llvm::VPlanPatternMatch;
+  auto GetNewMask = [&](VPValue *OrigMask) -> VPValue * {
+    assert(OrigMask && "Unmasked recipe when folding tail");
+    return HeaderMask == OrigMask ? nullptr : OrigMask;
+  };
+
+  return TypeSwitch<VPRecipeBase *, VPRecipeBase *>(CurRecipe)
+      .Case<VPWidenLoadRecipe>([&](VPWidenLoadRecipe *L) {
+        VPValue *NewMask = GetNewMask(L->getMask());
+        return new VPWidenLoadEVLRecipe(*L, EVL, NewMask);
+      })
+      .Case<VPWidenStoreRecipe>([&](VPWidenStoreRecipe *S) {
+        VPValue *NewMask = GetNewMask(S->getMask());
+        return new VPWidenStoreEVLRecipe(*S, EVL, NewMask);
+      })
+      .Case<VPWidenRecipe>([&](VPWidenRecipe *W) -> VPRecipeBase * {
+        unsigned Opcode = W->getOpcode();
+        if (!Instruction::isBinaryOp(Opcode) && !Instruction::isUnaryOp(Opcode))
+          return nullptr;
+        return new VPWidenEVLRecipe(*W, EVL);
+      })
+      .Case<VPReductionRecipe>([&](VPReductionRecipe *Red) {
+        VPValue *NewMask = GetNewMask(Red->getCondOp());
+        return new VPReductionEVLRecipe(*Red, EVL, NewMask);
+      })
+      .Case<VPWidenIntrinsicRecipe>(
+          [&](VPWidenIntrinsicRecipe *CInst) -> VPRecipeBase * {
+            auto *CI = cast<CallInst>(CInst->getUnderlyingInstr());
+            Intrinsic::ID VPID = VPIntrinsic::getForIntrinsic(
+                CI->getCalledFunction()->getIntrinsicID());
+            assert(VPID != Intrinsic::not_intrinsic &&
+                   "Expected VP Instrinsic");
+
+            SmallVector<VPValue *> Ops(CInst->operands());
+            assert(VPIntrinsic::getMaskParamPos(VPID) &&
+                   VPIntrinsic::getVectorLengthParamPos(VPID) &&
+                   "Expected VP intrinsic");
+
+            Ops.push_back(AllOneMask);
+            Ops.push_back(&EVL);
+            return new VPWidenIntrinsicRecipe(*CI, VPID, Ops,
+                                              TypeInfo.inferScalarType(CInst),
+                                              CInst->getDebugLoc());
+          })
+      .Case<VPWidenCastRecipe>([&](VPWidenCastRecipe *CInst) -> VPRecipeBase * {
+        auto *CI = dyn_cast<CastInst>(CInst->getUnderlyingInstr());
+        Intrinsic::ID VPID = VPIntrinsic::getForOpcode(CI->getOpcode());
+        assert(VPID != Intrinsic::not_intrinsic &&
+               "Expected vp.casts Instrinsic");
+
+        SmallVector<VPValue *> Ops(CInst->operands());
+        assert(VPIntrinsic::getMaskParamPos(VPID) &&
+               VPIntrinsic::getVectorLengthParamPos(VPID) &&
+               "Expected VP intrinsic");
----------------
LiqinWeng wrote:

done

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


More information about the llvm-commits mailing list