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

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 29 17:43:13 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Elvis Wang (ElvisWang123)

<details>
<summary>Changes</summary>

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 a valid cost by `TTI.getGatherScatterOpCost`.

Fixing the gap can prevent potentail failure in the future.

---
Full diff: https://github.com/llvm/llvm-project/pull/110445.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp (+5) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 2f0ba5510b8f34..c941479e7c6589 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2148,6 +2148,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,

``````````

</details>


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


More information about the llvm-commits mailing list