[llvm] [RISCV][CostModel] Add cost model for experimental.cttz.elts (PR #91778)
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Mon May 13 10:10:47 PDT 2024
================
@@ -901,6 +902,29 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
getRISCVInstructionCost(RISCV::VADD_VX, LT.second, CostKind);
return 1 + (LT.first - 1);
}
+ case Intrinsic::experimental_cttz_elts: {
+ Type *ArgTy = ICA.getArgTypes()[0];
+ EVT ArgType = TLI->getValueType(DL, ArgTy, true);
+ if (getTLI()->shouldExpandCttzElements(ArgType))
+ break;
+ auto LT = getTypeLegalizationCost(RetTy);
+ InstructionCost Cost =
+ getRISCVInstructionCost(
+ RISCV::VFIRST_M, getTypeLegalizationCost(ArgTy).second, CostKind) +
+ (LT.first - 1);
----------------
mshockwave wrote:
I thought in many places we multiply `LT.first` by instruction cost because if an intrinsic / LLVM instruction will eventually be lowered into multiple RISC-V instructions, says 5 instructions, each of these 5 instructions operates on the same data type, therefore we have to pay the same legalization cost (i.e. `LT.first`) for each of them.
But in the case of experimental.cttz.elts, the operand type and result type are different, and `LT.first` here is only subject to the result type. So that's why I used addition to "amend" the cost of legalizing the result. Please correct me if I'm wrong though.
https://github.com/llvm/llvm-project/pull/91778
More information about the llvm-commits
mailing list