Skip to content

Commit

Permalink
[RISCV] Use getRISCVInstructionCost for split cost in mask reductions…
Browse files Browse the repository at this point in the history
…. NFC

This is effectively the same due to how the mask instructions have an
LMUL of 1 and cost of 1, but matches how we use LT.first elsewhere in
RISCVTargetTransformInfo.cpp by using it to multiply another
instruction cost.
  • Loading branch information
lukel97 committed Dec 2, 2024
1 parent fec0eb4 commit df10f1c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,35 +1489,37 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
return BaseT::getArithmeticReductionCost(Opcode, Ty, FMF, CostKind);

std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
SmallVector<unsigned, 3> Opcodes;
Type *ElementTy = Ty->getElementType();
if (ElementTy->isIntegerTy(1)) {
if (ISD == ISD::AND) {
// Example sequences:
// vsetvli a0, zero, e8, mf8, ta, ma
// vmand.mm v8, v9, v8 ; needed every time type is split
// vmnot.m v8, v0
// vcpop.m a0, v8
// seqz a0, a0
Opcodes = {RISCV::VMNAND_MM, RISCV::VCPOP_M};
return (LT.first - 1) +
getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
return LT.first * getRISCVInstructionCost(RISCV::VMNAND_MM, LT.second,
CostKind) +
getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) +
getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
CmpInst::ICMP_EQ, CostKind);
} else {
// Example sequences:
// vsetvli a0, zero, e8, mf8, ta, ma
// vmxor.mm v8, v9, v8 ; needed every time type is split
// vcpop.m a0, v0
// snez a0, a0
Opcodes = {RISCV::VCPOP_M};
return (LT.first - 1) +
getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
return (LT.first - 1) *
getRISCVInstructionCost(RISCV::VMXOR_MM, LT.second, CostKind) +
getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) +
getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
CmpInst::ICMP_NE, CostKind);
}
}

// IR Reduction is composed by two vmv and one rvv reduction instruction.
unsigned SplitOp;
SmallVector<unsigned, 3> Opcodes;
switch (ISD) {
case ISD::ADD:
SplitOp = RISCV::VADD_VV;
Expand Down

0 comments on commit df10f1c

Please sign in to comment.