[llvm] [AMDGPU] Saturate at i16 for f16 to i1/i8 conversion (PR #187467)
Igor Wodiany via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 19 09:06:59 PDT 2026
================
@@ -3905,60 +3905,75 @@ SDValue AMDGPUTargetLowering::LowerFP_TO_INT_SAT(const SDValue Op,
if (DstVT == MVT::i16 && SatWidth == DstWidth && SrcVT == MVT::f16)
return Op;
- const SDValue Int32VT = DAG.getValueType(MVT::i32);
+ // By default perform all saturation at i32
+ MVT ResultVT = MVT::i32;
- // Perform all saturation at i32 and truncate
+ // For f16 to i1/i8/i16 conversion with sub-i16 saturation perform saturation
+ // at i16, if available in the target. This removes the need for extra f16 to
+ // f32 conversion
+ if (Subtarget->has16BitInsts() &&
+ (DstVT == MVT::i16 || DstVT == MVT::i8 || DstVT == MVT::i1) &&
+ SrcVT == MVT::f16 && (SatWidth == 8 || SatWidth == 1)) {
+ ResultVT = MVT::i16;
----------------
IgWod wrote:
I've simplified this a lot and I've also realized this whole `if` can be nested in `SatWidth < DstWidt` `if` below.
https://github.com/llvm/llvm-project/pull/187467
More information about the llvm-commits
mailing list