Skip to content

[RISCV] Use VP's interfaces to reconstruct cast/cmp/binop cost. NFC #115978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 29 additions & 59 deletions llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,65 +1104,6 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
return Cost * LT.first;
break;
}
// vp integer arithmetic ops.
case Intrinsic::vp_add:
case Intrinsic::vp_and:
case Intrinsic::vp_ashr:
case Intrinsic::vp_lshr:
case Intrinsic::vp_mul:
case Intrinsic::vp_or:
case Intrinsic::vp_sdiv:
case Intrinsic::vp_shl:
case Intrinsic::vp_srem:
case Intrinsic::vp_sub:
case Intrinsic::vp_udiv:
case Intrinsic::vp_urem:
case Intrinsic::vp_xor:
// vp float arithmetic ops.
case Intrinsic::vp_fadd:
case Intrinsic::vp_fsub:
case Intrinsic::vp_fmul:
case Intrinsic::vp_fdiv:
case Intrinsic::vp_frem: {
std::optional<unsigned> FOp =
VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID());
assert(FOp.has_value());
return getArithmeticInstrCost(*FOp, ICA.getReturnType(), CostKind);
break;
}
// vp int cast ops.
case Intrinsic::vp_trunc:
case Intrinsic::vp_zext:
case Intrinsic::vp_sext:
// vp float cast ops.
case Intrinsic::vp_fptoui:
case Intrinsic::vp_fptosi:
case Intrinsic::vp_uitofp:
case Intrinsic::vp_sitofp:
case Intrinsic::vp_fptrunc:
case Intrinsic::vp_fpext: {
std::optional<unsigned> FOp =
VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID());
assert(FOp.has_value() && !ICA.getArgTypes().empty());
return getCastInstrCost(*FOp, RetTy, ICA.getArgTypes()[0],
TTI::CastContextHint::None, CostKind);
break;
}

// vp compare
case Intrinsic::vp_icmp:
case Intrinsic::vp_fcmp: {
Intrinsic::ID IID = ICA.getID();
std::optional<unsigned> FOp = VPIntrinsic::getFunctionalOpcodeForVP(IID);
// We can only handle vp_cmp intrinsics with underlying instructions.
if (!ICA.getInst())
break;

assert(FOp);
auto *UI = cast<VPCmpIntrinsic>(ICA.getInst());
return getCmpSelInstrCost(*FOp, ICA.getArgTypes()[0], ICA.getReturnType(),
UI->getPredicate(), CostKind);
}
// vp load/store
case Intrinsic::vp_load:
case Intrinsic::vp_store: {
Expand Down Expand Up @@ -1193,6 +1134,35 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
CostKind);
}

if (VPBinOpIntrinsic::isVPBinOp(ICA.getID())) {
std::optional<unsigned> FOp =
VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID());
assert(FOp.has_value());
return getArithmeticInstrCost(*FOp, ICA.getReturnType(), CostKind);
}

// vp cmp ops
if (VPCmpIntrinsic::isVPCmp(ICA.getID())) {
Intrinsic::ID IID = ICA.getID();
std::optional<unsigned> FOp = VPIntrinsic::getFunctionalOpcodeForVP(IID);
// We can only handle vp_cmp intrinsics with underlying instructions.
if (ICA.getInst()) {
assert(FOp);
auto *UI = cast<VPCmpIntrinsic>(ICA.getInst());
return getCmpSelInstrCost(*FOp, ICA.getArgTypes()[0], ICA.getReturnType(),
UI->getPredicate(), CostKind);
}
}

// vp cast ops
if (VPCastIntrinsic::isVPCast(ICA.getID())) {
std::optional<unsigned> FOp =
VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID());
assert(FOp.has_value() && !ICA.getArgTypes().empty());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

nit: We could remove the assertion of FOp.has_value() since it already checked in the isVPCast().

return getCastInstrCost(*FOp, RetTy, ICA.getArgTypes()[0],
TTI::CastContextHint::None, CostKind);
}

if (ST->hasVInstructions() && RetTy->isVectorTy()) {
if (auto LT = getTypeLegalizationCost(RetTy);
LT.second.isVector()) {
Expand Down
Loading