Skip to content

[TTI] Check type legalization of both src and result for fpto{u|s}i.sat. #147657

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

Merged
merged 5 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 11 additions & 4 deletions llvm/include/llvm/CodeGen/BasicTTIImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2486,11 +2486,18 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
ISD = ISD::UMULO;
break;
case Intrinsic::fptosi_sat:
ISD = ISD::FP_TO_SINT_SAT;
break;
case Intrinsic::fptoui_sat:
ISD = ISD::FP_TO_UINT_SAT;
case Intrinsic::fptoui_sat: {
std::pair<InstructionCost, MVT> SrcLT = getTypeLegalizationCost(Tys[0]);
std::pair<InstructionCost, MVT> RetLT = getTypeLegalizationCost(RetTy);

// For cast instructions, types are differnt between source and
// destination. Also need to check if the source type can be legalize.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this, any type should be legalizable. Why would this ever return an invalid cost?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of the vector type might not be legalize if the target not support.

For example, fptoui.sat(<vscale x 1 x double> ...) is illegal type under riscv64, +zve32f (target only support f32 vectors no f64 vector support) and cannot be scalarize since the element counts is unknown at compile time. So the cost of fptoui.sat(<vscale x 1 x double> ...) should be invalid.

if (!SrcLT.first.isValid() || !RetLT.first.isValid())
return InstructionCost::getInvalid();
ISD = IID == Intrinsic::fptosi_sat ? ISD::FP_TO_SINT_SAT
: ISD::FP_TO_UINT_SAT;
break;
}
case Intrinsic::ctpop:
ISD = ISD::CTPOP;
// In case of legalization use TCC_Expensive. This is cheaper than a
Expand Down
Loading
Loading