-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[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
Conversation
@llvm/pr-subscribers-backend-risc-v Author: LiqinWeng (LiqinWeng) ChangesFull diff: https://github.com/llvm/llvm-project/pull/115978.diff 1 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 6344bc4664d3b6..fdf362e8ec686e 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -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: {
@@ -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());
+ return getCastInstrCost(*FOp, RetTy, ICA.getArgTypes()[0],
+ TTI::CastContextHint::None, CostKind);
+ }
+
if (ST->hasVInstructions() && RetTy->isVectorTy()) {
if (auto LT = getTypeLegalizationCost(RetTy);
LT.second.isVector()) {
|
if (VPCastIntrinsic::isVPCast(ICA.getID())) { | ||
std::optional<unsigned> FOp = | ||
VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID()); | ||
assert(FOp.has_value() && !ICA.getArgTypes().empty()); |
There was a problem hiding this comment.
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()
.
Hi, I noticed we have very similar code for this in BasicTTIImpl.h so I opened up an alternative PR that would deduplicate these: #115983 |
OK~ |
No description provided.