[llvm] [VPlan] Add legal checks in VPWidenMemoryRecipe::computeCost(). NFC (PR #110445)
Elvis Wang via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 16:21:52 PDT 2024
================
@@ -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();
----------------
ElvisWang123 wrote:
I am not sure who has the responsibility to do the legal check transformations or TTI.
In RISCV, `getGatherScatterOpCost` will do the legal check and return invalid cost when it fail.
In the default target, `getGatherScatterOpCost` just return the constant cost no matter it is legal or not.
I found the legacy cost model explicit check if the `gather/scatter` is legal in `LoopVectorizationCostModel::setCostBasedWideningDecision()`.
So adding this check can prevent misaligned between legacy cost model and the vplan-based cost model when a target `isLegalMaskedGather() = false && getGatherScatterOpCost() is valid` .
https://github.com/llvm/llvm-project/pull/110445
More information about the llvm-commits
mailing list