[llvm] [RISCV] Fix the cost of `llvm.vector.reduce.and` (PR #119160)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 3 13:34:28 PST 2025
================
@@ -1536,15 +1536,30 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
Type *ElementTy = Ty->getElementType();
if (ElementTy->isIntegerTy(1)) {
+ // Example sequences:
+ // vfirst.m a0, v0
+ // seqz a0, a0
+ if (LT.second == MVT::v1i1)
+ return getRISCVInstructionCost(RISCV::VFIRST_M, LT.second, CostKind) +
+ getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
+ CmpInst::ICMP_EQ, CostKind);
+
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
- return LT.first * getRISCVInstructionCost(RISCV::VMNAND_MM, LT.second,
- CostKind) +
+
+ // Fixed VT: In v512i1 and larger vector elements,
----------------
topperc wrote:
v512i1 shouldn't require a VMAND if VL is >= 64. This should depended on minimum vlen.
https://github.com/llvm/llvm-project/pull/119160
More information about the llvm-commits
mailing list