Skip to content

Commit 1ec3313

Browse files
authored
TTI: Check legalization cost of fptosi_sat/fptoui_sat nodes (#100521)
1 parent 7e175b3 commit 1ec3313

File tree

2 files changed

+231
-225
lines changed

2 files changed

+231
-225
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,31 +2183,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
21832183
ISD = ISD::UMULO;
21842184
break;
21852185
case Intrinsic::fptosi_sat:
2186-
case Intrinsic::fptoui_sat: {
2187-
if (Tys.empty())
2188-
break;
2189-
Type *FromTy = Tys[0];
2190-
bool IsSigned = IID == Intrinsic::fptosi_sat;
2191-
2192-
InstructionCost Cost = 0;
2193-
IntrinsicCostAttributes Attrs1(Intrinsic::minnum, FromTy,
2194-
{FromTy, FromTy});
2195-
Cost += thisT()->getIntrinsicInstrCost(Attrs1, CostKind);
2196-
IntrinsicCostAttributes Attrs2(Intrinsic::maxnum, FromTy,
2197-
{FromTy, FromTy});
2198-
Cost += thisT()->getIntrinsicInstrCost(Attrs2, CostKind);
2199-
Cost += thisT()->getCastInstrCost(
2200-
IsSigned ? Instruction::FPToSI : Instruction::FPToUI, RetTy, FromTy,
2201-
TTI::CastContextHint::None, CostKind);
2202-
if (IsSigned) {
2203-
Type *CondTy = RetTy->getWithNewBitWidth(1);
2204-
Cost += thisT()->getCmpSelInstrCost(
2205-
BinaryOperator::FCmp, FromTy, CondTy, CmpInst::FCMP_UNO, CostKind);
2206-
Cost += thisT()->getCmpSelInstrCost(
2207-
BinaryOperator::Select, RetTy, CondTy, CmpInst::FCMP_UNO, CostKind);
2208-
}
2209-
return Cost;
2210-
}
2186+
ISD = ISD::FP_TO_SINT_SAT;
2187+
break;
2188+
case Intrinsic::fptoui_sat:
2189+
ISD = ISD::FP_TO_UINT_SAT;
2190+
break;
22112191
case Intrinsic::ctpop:
22122192
ISD = ISD::CTPOP;
22132193
// In case of legalization use TCC_Expensive. This is cheaper than a
@@ -2422,6 +2402,32 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
24222402
Cost += thisT()->getArithmeticInstrCost(Instruction::Or, RetTy, CostKind);
24232403
return Cost;
24242404
}
2405+
case Intrinsic::fptosi_sat:
2406+
case Intrinsic::fptoui_sat: {
2407+
if (Tys.empty())
2408+
break;
2409+
Type *FromTy = Tys[0];
2410+
bool IsSigned = IID == Intrinsic::fptosi_sat;
2411+
2412+
InstructionCost Cost = 0;
2413+
IntrinsicCostAttributes Attrs1(Intrinsic::minnum, FromTy,
2414+
{FromTy, FromTy});
2415+
Cost += thisT()->getIntrinsicInstrCost(Attrs1, CostKind);
2416+
IntrinsicCostAttributes Attrs2(Intrinsic::maxnum, FromTy,
2417+
{FromTy, FromTy});
2418+
Cost += thisT()->getIntrinsicInstrCost(Attrs2, CostKind);
2419+
Cost += thisT()->getCastInstrCost(
2420+
IsSigned ? Instruction::FPToSI : Instruction::FPToUI, RetTy, FromTy,
2421+
TTI::CastContextHint::None, CostKind);
2422+
if (IsSigned) {
2423+
Type *CondTy = RetTy->getWithNewBitWidth(1);
2424+
Cost += thisT()->getCmpSelInstrCost(
2425+
BinaryOperator::FCmp, FromTy, CondTy, CmpInst::FCMP_UNO, CostKind);
2426+
Cost += thisT()->getCmpSelInstrCost(
2427+
BinaryOperator::Select, RetTy, CondTy, CmpInst::FCMP_UNO, CostKind);
2428+
}
2429+
return Cost;
2430+
}
24252431
default:
24262432
break;
24272433
}

0 commit comments

Comments
 (0)