@@ -1963,7 +1963,7 @@ ARMTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
1963
1963
LT.second .getScalarSizeInBits () == MTy.getScalarSizeInBits ())
1964
1964
return LT.first * ST->getMVEVectorCostFactor (CostKind);
1965
1965
1966
- // Otherwise we use a legal convert followed by a min+max
1966
+ // If we can we use a legal convert followed by a min+max
1967
1967
if (((ST->hasVFP2Base () && LT.second == MVT::f32) ||
1968
1968
(ST->hasFP64 () && LT.second == MVT::f64) ||
1969
1969
(ST->hasFullFP16 () && LT.second == MVT::f16) ||
@@ -1984,7 +1984,25 @@ ARMTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
1984
1984
Cost += getIntrinsicInstrCost (Attrs2, CostKind);
1985
1985
return LT.first * Cost;
1986
1986
}
1987
- break ;
1987
+ // Otherwise we need to follow the default expansion that clamps the value
1988
+ // using a float min/max with a fcmp+sel for nan handling when signed.
1989
+ Type *FPTy = ICA.getArgTypes ()[0 ];
1990
+ Type *RetTy = ICA.getReturnType ();
1991
+ IntrinsicCostAttributes Attrs1 (Intrinsic::minnum, FPTy, {FPTy, FPTy});
1992
+ InstructionCost Cost = getIntrinsicInstrCost (Attrs1, CostKind);
1993
+ IntrinsicCostAttributes Attrs2 (Intrinsic::maxnum, FPTy, {FPTy, FPTy});
1994
+ Cost += getIntrinsicInstrCost (Attrs2, CostKind);
1995
+ Cost +=
1996
+ getCastInstrCost (IsSigned ? Instruction::FPToSI : Instruction::FPToUI,
1997
+ RetTy, FPTy, TTI::CastContextHint::None, CostKind);
1998
+ if (IsSigned) {
1999
+ Type *CondTy = RetTy->getWithNewBitWidth (1 );
2000
+ Cost += getCmpSelInstrCost (BinaryOperator::FCmp, FPTy, CondTy,
2001
+ CmpInst::FCMP_UNO, CostKind);
2002
+ Cost += getCmpSelInstrCost (BinaryOperator::Select, RetTy, CondTy,
2003
+ CmpInst::FCMP_UNO, CostKind);
2004
+ }
2005
+ return Cost;
1988
2006
}
1989
2007
}
1990
2008
0 commit comments