[llvm] [VPlan] Add legal checks in VPWidenMemoryRecipe::computeCost(). NFC (PR #110445)

Elvis Wang via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 29 22:40:13 PDT 2024


https://github.com/ElvisWang123 updated https://github.com/llvm/llvm-project/pull/110445

>From c324fc59600f2bbfcd7b7b93d2390e4fa0d0e5d0 Mon Sep 17 00:00:00 2001
From: Elvis Wang <elvis.wang at sifive.com>
Date: Fri, 27 Sep 2024 00:04:27 -0700
Subject: [PATCH] [VPlan] Add legal checks in
 VPWidenMemoryRecipe::computeCost(). NFC

Add legal checks in the vplan-based cost model that align to the legacy
cost model (setCostBasedWideningDecision()).

This is patch is not quite a NFC patch but currently we don't have a
target that support `ActiveVectorLength && ScalableVector` but not support
`gather/scatter` nor return valid cost by `TTI.getGatherScatterOpCost`.

Fixing the gap can prevent potentail failure in the future.
---
 llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 75908638532950..5a4dbcad1cdcdc 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2237,6 +2237,11 @@ InstructionCost VPWidenMemoryRecipe::computeCost(ElementCount VF,
     const Value *Ptr = getLoadStorePointerOperand(&Ingredient);
     assert(!Reverse &&
            "Inconsecutive memory access should not have the order.");
+    if ((isa<LoadInst>(Ingredient) &&
+         !Ctx.TTI.isLegalMaskedGather(Ty, Alignment)) ||
+        (isa<StoreInst>(Ingredient) &&
+         !Ctx.TTI.isLegalMaskedScatter(Ty, Alignment)))
+      return InstructionCost::getInvalid();
     return Ctx.TTI.getAddressComputationCost(Ty) +
            Ctx.TTI.getGatherScatterOpCost(Ingredient.getOpcode(), Ty, Ptr,
                                           IsMasked, Alignment, CostKind,



More information about the llvm-commits mailing list