[llvm] [LV] Support binary and unary operations with EVL-vectorization (PR #93854)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 11 23:35:40 PDT 2024
================
@@ -1405,6 +1407,62 @@ void VPlanTransforms::addActiveLaneMask(
HeaderMask->replaceAllUsesWith(LaneMask);
}
+/// Replace recipes with their EVL variants.
+static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
+ SmallVector<VPValue *> HeaderMasks = collectAllHeaderMasks(Plan);
+ for (VPValue *HeaderMask : collectAllHeaderMasks(Plan)) {
+ for (VPUser *U : collectUsersRecursively(HeaderMask)) {
+ auto *CurRecipe = dyn_cast<VPRecipeBase>(U);
+ if (!CurRecipe)
+ continue;
+ auto GetNewMask = [&](VPValue *OrigMask) -> VPValue * {
+ assert(OrigMask && "Unmasked recipe when folding tail");
+ return HeaderMask == OrigMask ? nullptr : OrigMask;
+ };
+
+ VPRecipeBase *NewRecipe =
+ 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) {
+ return new VPReductionEVLRecipe(*Red, EVL,
+ GetNewMask(Red->getCondOp()));
+ })
+ .Default([&](VPRecipeBase *R) { return nullptr; });
+
+ if (NewRecipe) {
----------------
fhahn wrote:
nit
```suggestion
if (!NewRecipe)
continue;
```
to reduce indent below
https://github.com/llvm/llvm-project/pull/93854
More information about the llvm-commits
mailing list