Skip to content

Commit 2137354

Browse files
[TTI] Check type legalization of both src and result for fpto{u|s}i.sat. (#147657)
For the cast instructions such ass `fptoui.sat`, `fptosi.sat`, need to check both type of the source and the result type can be lowering legally. If one of them is invalid, return invalid cost. -- Fixes #142973. --------- Co-authored-by: Craig Topper <craig.topper@sifive.com>
1 parent 20becf3 commit 2137354

File tree

2 files changed

+594
-4
lines changed

2 files changed

+594
-4
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,11 +2498,18 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
24982498
ISD = ISD::UMULO;
24992499
break;
25002500
case Intrinsic::fptosi_sat:
2501-
ISD = ISD::FP_TO_SINT_SAT;
2502-
break;
2503-
case Intrinsic::fptoui_sat:
2504-
ISD = ISD::FP_TO_UINT_SAT;
2501+
case Intrinsic::fptoui_sat: {
2502+
std::pair<InstructionCost, MVT> SrcLT = getTypeLegalizationCost(Tys[0]);
2503+
std::pair<InstructionCost, MVT> RetLT = getTypeLegalizationCost(RetTy);
2504+
2505+
// For cast instructions, types are different between source and
2506+
// destination. Also need to check if the source type can be legalize.
2507+
if (!SrcLT.first.isValid() || !RetLT.first.isValid())
2508+
return InstructionCost::getInvalid();
2509+
ISD = IID == Intrinsic::fptosi_sat ? ISD::FP_TO_SINT_SAT
2510+
: ISD::FP_TO_UINT_SAT;
25052511
break;
2512+
}
25062513
case Intrinsic::ctpop:
25072514
ISD = ISD::CTPOP;
25082515
// In case of legalization use TCC_Expensive. This is cheaper than a

0 commit comments

Comments
 (0)