Skip to content

Commit df10f1c

Browse files
committed
[RISCV] Use getRISCVInstructionCost for split cost in mask reductions. 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.
1 parent fec0eb4 commit df10f1c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,35 +1489,37 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
14891489
return BaseT::getArithmeticReductionCost(Opcode, Ty, FMF, CostKind);
14901490

14911491
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
1492-
SmallVector<unsigned, 3> Opcodes;
14931492
Type *ElementTy = Ty->getElementType();
14941493
if (ElementTy->isIntegerTy(1)) {
14951494
if (ISD == ISD::AND) {
14961495
// Example sequences:
14971496
// vsetvli a0, zero, e8, mf8, ta, ma
1497+
// vmand.mm v8, v9, v8 ; needed every time type is split
14981498
// vmnot.m v8, v0
14991499
// vcpop.m a0, v8
15001500
// seqz a0, a0
1501-
Opcodes = {RISCV::VMNAND_MM, RISCV::VCPOP_M};
1502-
return (LT.first - 1) +
1503-
getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
1501+
return LT.first * getRISCVInstructionCost(RISCV::VMNAND_MM, LT.second,
1502+
CostKind) +
1503+
getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) +
15041504
getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
15051505
CmpInst::ICMP_EQ, CostKind);
15061506
} else {
15071507
// Example sequences:
15081508
// vsetvli a0, zero, e8, mf8, ta, ma
1509+
// vmxor.mm v8, v9, v8 ; needed every time type is split
15091510
// vcpop.m a0, v0
15101511
// snez a0, a0
1511-
Opcodes = {RISCV::VCPOP_M};
1512-
return (LT.first - 1) +
1513-
getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
1512+
return (LT.first - 1) *
1513+
getRISCVInstructionCost(RISCV::VMXOR_MM, LT.second, CostKind) +
1514+
getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) +
15141515
getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
15151516
CmpInst::ICMP_NE, CostKind);
15161517
}
15171518
}
15181519

15191520
// IR Reduction is composed by two vmv and one rvv reduction instruction.
15201521
unsigned SplitOp;
1522+
SmallVector<unsigned, 3> Opcodes;
15211523
switch (ISD) {
15221524
case ISD::ADD:
15231525
SplitOp = RISCV::VADD_VV;

0 commit comments

Comments
 (0)