-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV][TTI] Implement vector costs for llvm.fpto{u|s}i.sat()
.
#143655
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1497,6 +1497,36 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, | |
cast<VectorType>(ICA.getArgTypes()[0]), {}, CostKind, | ||
0, cast<VectorType>(ICA.getReturnType())); | ||
} | ||
case Intrinsic::fptoui_sat: | ||
case Intrinsic::fptosi_sat: { | ||
InstructionCost Cost = 0; | ||
bool IsSigned = ICA.getID() == Intrinsic::fptosi_sat; | ||
Type *SrcTy = ICA.getArgTypes()[0]; | ||
|
||
auto SrcLT = getTypeLegalizationCost(SrcTy); | ||
auto DstLT = getTypeLegalizationCost(RetTy); | ||
if (!SrcTy->isVectorTy()) | ||
break; | ||
|
||
if (!SrcLT.first.isValid() || !DstLT.first.isValid()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to skip scalar type here as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, added. Thanks! |
||
return InstructionCost::getInvalid(); | ||
|
||
IntrinsicCostAttributes Attrs1(Intrinsic::minnum, SrcTy, {SrcTy, SrcTy}); | ||
Cost += getIntrinsicInstrCost(Attrs1, CostKind); | ||
IntrinsicCostAttributes Attrs2(Intrinsic::maxnum, SrcTy, {SrcTy, SrcTy}); | ||
Cost += getIntrinsicInstrCost(Attrs2, CostKind); | ||
Cost += | ||
getCastInstrCost(IsSigned ? Instruction::FPToSI : Instruction::FPToUI, | ||
RetTy, SrcTy, TTI::CastContextHint::None, CostKind); | ||
if (IsSigned) { | ||
Type *CondTy = RetTy->getWithNewBitWidth(1); | ||
Cost += getCmpSelInstrCost(BinaryOperator::FCmp, SrcTy, CondTy, | ||
CmpInst::FCMP_UNO, CostKind); | ||
Cost += getCmpSelInstrCost(BinaryOperator::Select, RetTy, CondTy, | ||
CmpInst::FCMP_UNO, CostKind); | ||
} | ||
return Cost; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need to scale by the maximum of SrcLT.first and DstLT.first? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I guess each function does its own costing and scaling? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
} | ||
} | ||
|
||
if (ST->hasVInstructions() && RetTy->isVectorTy()) { | ||
|
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.
Can we do this in target independent code? The missing scalarization for the source type isn't just a RISC-V bug.
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.
I think it is not only missing the scalarization for the source type, the cost of
fptoui_sat
is much lower than expect.This can be implemented in
BasicTTI::getIntrinsicInstrCost()
. But when using type-based query it will try to get cost fromBasicTTI::getTypeBasedIntrinsicInstrCost()
which will return the cost different from the value-based query.IIUC #97463 make the precedent that cost of intrinsics in
getTypeBasedIntrinsicInstrCost()
and not implemented beforellvm-project/llvm/include/llvm/CodeGen/BasicTTIImpl.h
Line 2511 in a3201ce