Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't getGatherScatterOpCost return Invalid in those cases as we pass IsMasked ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I think the difference is that while the legacy cost model needs to consider all options for the input, no masked VPWidenMemoryRecipe should be created , if masked mem-ops aren't legal I think

return Ctx.TTI.getAddressComputationCost(Ty) +
Ctx.TTI.getGatherScatterOpCost(Ingredient.getOpcode(), Ty, Ptr,
IsMasked, Alignment, CostKind,
Expand Down