Skip to content

Commit 3431d13

Browse files
ElvisWang123preames
authored andcommitted
[RISCV][TTI] Implement instruction cost for vp.reduce.* #114184
The VP variants simply return the same costs as the non-VP variants. This assumes that reductions are VL predicated, and that VL predication has no additional cost.
1 parent 2b5b57c commit 3431d13

File tree

2 files changed

+118
-32
lines changed

2 files changed

+118
-32
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,37 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
11911191
return getCmpSelInstrCost(Instruction::Select, ICA.getReturnType(),
11921192
ICA.getArgTypes()[0], CmpInst::BAD_ICMP_PREDICATE,
11931193
CostKind);
1194+
case Intrinsic::vp_reduce_add:
1195+
case Intrinsic::vp_reduce_fadd:
1196+
case Intrinsic::vp_reduce_mul:
1197+
case Intrinsic::vp_reduce_fmul:
1198+
case Intrinsic::vp_reduce_and:
1199+
case Intrinsic::vp_reduce_or:
1200+
case Intrinsic::vp_reduce_xor: {
1201+
std::optional<Intrinsic::ID> RedID =
1202+
VPIntrinsic::getFunctionalIntrinsicIDForVP(ICA.getID());
1203+
assert(RedID.has_value());
1204+
unsigned RedOp = getArithmeticReductionInstruction(*RedID);
1205+
return getArithmeticReductionCost(RedOp,
1206+
cast<VectorType>(ICA.getArgTypes()[1]),
1207+
ICA.getFlags(), CostKind);
1208+
}
1209+
case Intrinsic::vp_reduce_smax:
1210+
case Intrinsic::vp_reduce_smin:
1211+
case Intrinsic::vp_reduce_umax:
1212+
case Intrinsic::vp_reduce_umin:
1213+
case Intrinsic::vp_reduce_fmax:
1214+
case Intrinsic::vp_reduce_fmaximum:
1215+
case Intrinsic::vp_reduce_fmin:
1216+
case Intrinsic::vp_reduce_fminimum: {
1217+
std::optional<Intrinsic::ID> RedID =
1218+
VPIntrinsic::getFunctionalIntrinsicIDForVP(ICA.getID());
1219+
assert(RedID.has_value());
1220+
Intrinsic::ID MinMaxID = getMinMaxReductionIntrinsicOp(*RedID);
1221+
return getMinMaxReductionCost(MinMaxID,
1222+
cast<VectorType>(ICA.getArgTypes()[1]),
1223+
ICA.getFlags(), CostKind);
1224+
}
11941225
}
11951226

11961227
if (ST->hasVInstructions() && RetTy->isVectorTy()) {

0 commit comments

Comments
 (0)