[llvm] [AMDGPU] Use `v_cvt_pk_*` instructions for i16_f32 saturated conversions (PR #202680)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 26 03:19:53 PDT 2026
================
@@ -3941,12 +3941,21 @@ SDValue AMDGPUTargetLowering::LowerFP_TO_INT_SAT(const SDValue Op,
uint64_t SatWidth = SatVT.getScalarSizeInBits();
assert(SatWidth <= DstWidth && "Saturation width cannot exceed result width");
+ // Select v2f32 -> v2i16 natively to v_cvt_pk_[iu]16_f32.
+ if (DstVT.isVector()) {
+ if (DstVT == MVT::v2i16 && SatWidth == 16 && SrcVT == MVT::v2f32)
+ return Op;
+
+ return SDValue();
----------------
jayfoad wrote:
OK. I guess this is fine for now but it looks like it could maybe be cleaned up. For example there is no need for your `if`s to be nested here, you could check `DstVT == MVT::v2i16 && ...` first and then `DstVT.isVector()`. Also all of the cases that get selected directly could be inside one big `if (DstWidth == SatWidth) { ... }`.
https://github.com/llvm/llvm-project/pull/202680
More information about the llvm-commits
mailing list