Skip to content

Commit

Permalink
[CostModel][X86] Add generic costs for vXi32 MUL -> v2Xi16 PMADDDW folds
Browse files Browse the repository at this point in the history
Based off the improved fold in D108522

This should eventually allow us to replace the SLM only cost patterns with generic versions.
  • Loading branch information
RKSimon committed Sep 5, 2021
1 parent 9962eba commit f114ef3
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 81 deletions.
17 changes: 17 additions & 0 deletions llvm/lib/Target/X86/X86TargetTransformInfo.cpp
Expand Up @@ -206,6 +206,22 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");

if (ISD == ISD::MUL && Args.size() == 2 && LT.second.isVector() &&
LT.second.getScalarType() == MVT::i32) {
// Check if the operands can be represented as a smaller datatype.
bool Op1Signed = false, Op2Signed = false;
unsigned Op1MinSize = BaseT::minRequiredElementSize(Args[0], Op1Signed);
unsigned Op2MinSize = BaseT::minRequiredElementSize(Args[1], Op2Signed);
unsigned OpMinSize = std::max(Op1MinSize, Op2MinSize);

// If both are representable as i15 and at least one is zero-extended,
// then we can treat this as PMADDWD which has the same costs
// as a vXi16 multiply..
if (OpMinSize <= 15 && (!Op1Signed || !Op2Signed) && !ST->isPMADDWDSlow())
LT.second =
MVT::getVectorVT(MVT::i16, 2 * LT.second.getVectorNumElements());
}

if ((ISD == ISD::SDIV || ISD == ISD::SREM || ISD == ISD::UDIV ||
ISD == ISD::UREM) &&
(Op2Info == TargetTransformInfo::OK_UniformConstantValue ||
Expand Down Expand Up @@ -288,6 +304,7 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
if (ST->isSLM()) {
if (Args.size() == 2 && ISD == ISD::MUL && LT.second == MVT::v4i32) {
// Check if the operands can be shrinked into a smaller datatype.
// TODO: Merge this into generiic vXi32 MUL patterns above.
bool Op1Signed = false;
unsigned Op1MinSize = BaseT::minRequiredElementSize(Args[0], Op1Signed);
bool Op2Signed = false;
Expand Down

0 comments on commit f114ef3

Please sign in to comment.