Skip to content

Commit 19f7331

Browse files
committed
TTI: Check legalization cost of fptosi_sat/fptoui_sat nodes
1 parent fc18583 commit 19f7331

File tree

4 files changed

+324
-297
lines changed

4 files changed

+324
-297
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,31 +2179,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
21792179
ISD = ISD::UMULO;
21802180
break;
21812181
case Intrinsic::fptosi_sat:
2182-
case Intrinsic::fptoui_sat: {
2183-
if (Tys.empty())
2184-
break;
2185-
Type *FromTy = Tys[0];
2186-
bool IsSigned = IID == Intrinsic::fptosi_sat;
2187-
2188-
InstructionCost Cost = 0;
2189-
IntrinsicCostAttributes Attrs1(Intrinsic::minnum, FromTy,
2190-
{FromTy, FromTy});
2191-
Cost += thisT()->getIntrinsicInstrCost(Attrs1, CostKind);
2192-
IntrinsicCostAttributes Attrs2(Intrinsic::maxnum, FromTy,
2193-
{FromTy, FromTy});
2194-
Cost += thisT()->getIntrinsicInstrCost(Attrs2, CostKind);
2195-
Cost += thisT()->getCastInstrCost(
2196-
IsSigned ? Instruction::FPToSI : Instruction::FPToUI, RetTy, FromTy,
2197-
TTI::CastContextHint::None, CostKind);
2198-
if (IsSigned) {
2199-
Type *CondTy = RetTy->getWithNewBitWidth(1);
2200-
Cost += thisT()->getCmpSelInstrCost(
2201-
BinaryOperator::FCmp, FromTy, CondTy, CmpInst::FCMP_UNO, CostKind);
2202-
Cost += thisT()->getCmpSelInstrCost(
2203-
BinaryOperator::Select, RetTy, CondTy, CmpInst::FCMP_UNO, CostKind);
2204-
}
2205-
return Cost;
2206-
}
2182+
ISD = ISD::FP_TO_SINT_SAT;
2183+
break;
2184+
case Intrinsic::fptoui_sat:
2185+
ISD = ISD::FP_TO_UINT_SAT;
2186+
break;
22072187
case Intrinsic::ctpop:
22082188
ISD = ISD::CTPOP;
22092189
// In case of legalization use TCC_Expensive. This is cheaper than a
@@ -2418,6 +2398,32 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
24182398
Cost += thisT()->getArithmeticInstrCost(Instruction::Or, RetTy, CostKind);
24192399
return Cost;
24202400
}
2401+
case Intrinsic::fptosi_sat:
2402+
case Intrinsic::fptoui_sat: {
2403+
if (Tys.empty())
2404+
break;
2405+
Type *FromTy = Tys[0];
2406+
bool IsSigned = IID == Intrinsic::fptosi_sat;
2407+
2408+
InstructionCost Cost = 0;
2409+
IntrinsicCostAttributes Attrs1(Intrinsic::minnum, FromTy,
2410+
{FromTy, FromTy});
2411+
Cost += thisT()->getIntrinsicInstrCost(Attrs1, CostKind);
2412+
IntrinsicCostAttributes Attrs2(Intrinsic::maxnum, FromTy,
2413+
{FromTy, FromTy});
2414+
Cost += thisT()->getIntrinsicInstrCost(Attrs2, CostKind);
2415+
Cost += thisT()->getCastInstrCost(
2416+
IsSigned ? Instruction::FPToSI : Instruction::FPToUI, RetTy, FromTy,
2417+
TTI::CastContextHint::None, CostKind);
2418+
if (IsSigned) {
2419+
Type *CondTy = RetTy->getWithNewBitWidth(1);
2420+
Cost += thisT()->getCmpSelInstrCost(
2421+
BinaryOperator::FCmp, FromTy, CondTy, CmpInst::FCMP_UNO, CostKind);
2422+
Cost += thisT()->getCmpSelInstrCost(
2423+
BinaryOperator::Select, RetTy, CondTy, CmpInst::FCMP_UNO, CostKind);
2424+
}
2425+
return Cost;
2426+
}
24212427
default:
24222428
break;
24232429
}

0 commit comments

Comments
 (0)