[llvm] df10f1c - [RISCV] Use getRISCVInstructionCost for split cost in mask reductions. NFC
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 2 01:16:04 PST 2024
Author: Luke Lau
Date: 2024-12-02T17:15:53+08:00
New Revision: df10f1c6f79a77e45e44c62974a186decb0f1f33
URL: https://github.com/llvm/llvm-project/commit/df10f1c6f79a77e45e44c62974a186decb0f1f33
DIFF: https://github.com/llvm/llvm-project/commit/df10f1c6f79a77e45e44c62974a186decb0f1f33.diff
LOG: [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.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 57f635ca6f42a8..20f3b717f8b1d8 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1489,28 +1489,29 @@ 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);
}
@@ -1518,6 +1519,7 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
// 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;
More information about the llvm-commits
mailing list