[SLP] ExtractElement Cost Calculation
I noticed we calculate the extraction cost differently in different places, I'm curious why we would want to use different models at these different times.
When we are trying to include an ExtractElement instruction in our Vector Chain (SLPVectorizer.cpp::14677). This was updated in #125725
auto GetVectorCost = [&, &TTI = *TTI](InstructionCost CommonCost) {
return CommonCost - (DemandedElts.isZero()
? TTI::TCC_Free
: TTI.getScalarizationOverhead(
SrcVecTy, DemandedElts, /*Insert=*/false,
/*Extract=*/true, CostKind));
};
But when we have an external use that will require an ExtractElement (SLPVectorizer.cpp::16305):
ExtraCost =
getVectorInstrCost(*TTI, ScalarTy, Instruction::ExtractElement, VecTy,
CostKind, EU.Lane, EU.Scalar, ScalarUserAndIdx);
For class TargetTransformInfoImplBase:
virtual InstructionCost getScalarizationOverhead(
VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
ArrayRef<Value *> VL = {}) const {
return 0;
}
...
virtual InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
TTI::TargetCostKind CostKind,
unsigned Index, const Value *Op0,
const Value *Op1) const {
return 1;
}
Generally speaking, all getVectorInstrCost should be replaced by getScalarizationOverhead calls. Just need to implement grouping by the vector nodes. PS. Do not look into base implementations, look into specific target implementations. Base implementation does not mean much in many cases
Generally speaking, all getVectorInstrCost should be replaced by getScalarizationOverhead calls. Just need to implement grouping by the vector nodes.
Thanks for the response! The getVectorInstrCost use in SLPVectorizer.cpp::16305 is used on a per-element basis, so I don't think it would be feasible to group the nodes so that we make a single call to getScalarizationOverhead since we need the individual cost of each element. It don't know if it would be reasonable to create a bitfield with just one bit set and use that to call getScalarizationOverhead() rather than getVectorInstrCost().
PS. Do not look into base implementations, look into specific target implementations. Base implementation does not mean much in many cases
Noted, thanks