[llvm] ea7cc12 - [ARM] Add fallback fptoi_sat costs.
David Green via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 15:38:26 PDT 2024
Author: David Green
Date: 2024-07-28T23:38:21+01:00
New Revision: ea7cc12f612ef5c5f70082ebfdee378d80ec44bd
URL: https://github.com/llvm/llvm-project/commit/ea7cc12f612ef5c5f70082ebfdee378d80ec44bd
DIFF: https://github.com/llvm/llvm-project/commit/ea7cc12f612ef5c5f70082ebfdee378d80ec44bd.diff
LOG: [ARM] Add fallback fptoi_sat costs.
This makes sure that the custom operations get a fallback cost, even if they
are not perfect.
Added:
Modified:
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
index b5ca045058cbc..e940dce7faa14 100644
--- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
@@ -1963,7 +1963,7 @@ ARMTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
LT.second.getScalarSizeInBits() == MTy.getScalarSizeInBits())
return LT.first * ST->getMVEVectorCostFactor(CostKind);
- // Otherwise we use a legal convert followed by a min+max
+ // If we can we use a legal convert followed by a min+max
if (((ST->hasVFP2Base() && LT.second == MVT::f32) ||
(ST->hasFP64() && LT.second == MVT::f64) ||
(ST->hasFullFP16() && LT.second == MVT::f16) ||
@@ -1984,7 +1984,25 @@ ARMTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
Cost += getIntrinsicInstrCost(Attrs2, CostKind);
return LT.first * Cost;
}
- break;
+ // Otherwise we need to follow the default expansion that clamps the value
+ // using a float min/max with a fcmp+sel for nan handling when signed.
+ Type *FPTy = ICA.getArgTypes()[0];
+ Type *RetTy = ICA.getReturnType();
+ IntrinsicCostAttributes Attrs1(Intrinsic::minnum, FPTy, {FPTy, FPTy});
+ InstructionCost Cost = getIntrinsicInstrCost(Attrs1, CostKind);
+ IntrinsicCostAttributes Attrs2(Intrinsic::maxnum, FPTy, {FPTy, FPTy});
+ Cost += getIntrinsicInstrCost(Attrs2, CostKind);
+ Cost +=
+ getCastInstrCost(IsSigned ? Instruction::FPToSI : Instruction::FPToUI,
+ RetTy, FPTy, TTI::CastContextHint::None, CostKind);
+ if (IsSigned) {
+ Type *CondTy = RetTy->getWithNewBitWidth(1);
+ Cost += getCmpSelInstrCost(BinaryOperator::FCmp, FPTy, CondTy,
+ CmpInst::FCMP_UNO, CostKind);
+ Cost += getCmpSelInstrCost(BinaryOperator::Select, RetTy, CondTy,
+ CmpInst::FCMP_UNO, CostKind);
+ }
+ return Cost;
}
}
More information about the llvm-commits
mailing list