[llvm] [RISCV][CostModel] Correct the cost of some reductions (PR #118072)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 2 00:37:06 PST 2024


================
@@ -1534,6 +1534,13 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
              getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
              getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
                                 CmpInst::ICMP_EQ, CostKind);
+    } else if (ISD == ISD::XOR) {
+      // Example sequences:
+      //   vsetvli a0, zero, e8, mf8, ta, ma
+      //   vcpop.m a0, v0
+      //   andi a0, a0, 1
+      Opcodes = {RISCV::VCPOP_M};
+      return LT.first + getRISCVInstructionCost(Opcodes, LT.second, CostKind);
----------------
lukel97 wrote:

Yeah LT.first is the cost of type legalization, i.e. splitting. But it's the number of times the operation will be split, so we need to multiply that by the cost of whatever node. I'll open up a PR to fix the existing cases, but for this PR we might as well do it the correct way i.e. by multiplying. (Although I don't think it will make a difference to the costs, since these mask instructions are always LMUL 1!)

https://github.com/llvm/llvm-project/pull/118072


More information about the llvm-commits mailing list