Skip to content

[RISCV][TTI] Model partial reduce of ext for zvqdotq #146788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 17 additions & 4 deletions llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,29 @@ InstructionCost RISCVTTIImpl::getPartialReductionCost(
// zve32x is broken for partial_reduce_umla, but let's make sure we
// don't generate them.
if (!ST->hasStdExtZvqdotq() || ST->getELen() < 64 ||
Opcode != Instruction::Add || !BinOp || *BinOp != Instruction::Mul ||
InputTypeA != InputTypeB || !InputTypeA->isIntegerTy(8) ||
Opcode != Instruction::Add || !InputTypeA->isIntegerTy(8) ||
!AccumType->isIntegerTy(32) || !VF.isKnownMultipleOf(4))
return InstructionCost::getInvalid();

// We support both the plain dot product idiom, and the use of dotproduct
// to compute a a reduction of an extended value.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think this should be to compute a reduction

if (BinOp && (*BinOp != Instruction::Mul || InputTypeA != InputTypeB))
return InstructionCost::getInvalid();

InstructionCost IntMatCost = 0;
if (!BinOp) {
// Cost to produce one vmv.v.i -- since the constant is shared across any
// unrolled copies, don't need to scale by LT.first.
Type *Tp = VectorType::get(InputTypeA, VF);
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Tp);
IntMatCost = getRISCVInstructionCost(RISCV::VMV_V_I, LT.second, CostKind);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really familiar with RISCV lowering, but wouldn't the materialisation in practice be free since only the loop vectoriser uses getPartialReductionCost and for vectorised loops the constant should be hoisted out?

}

Type *Tp = VectorType::get(AccumType, VF.divideCoefficientBy(4));
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Tp);
// Note: Asuming all vqdot* variants are equal cost
return LT.first *
getRISCVInstructionCost(RISCV::VQDOT_VV, LT.second, CostKind);
return IntMatCost + LT.first * getRISCVInstructionCost(RISCV::VQDOT_VV,
LT.second, CostKind);
}

bool RISCVTTIImpl::shouldExpandReduction(const IntrinsicInst *II) const {
Expand Down
Loading
Loading