[llvm] [AArch64][SDAG] Lower f16->s16 FP_TO_INT_SAT to *v1f16 (PR #154822)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 21 12:54:51 PDT 2025


================
@@ -4912,6 +4912,24 @@ SDValue AArch64TargetLowering::LowerFP_TO_INT_SAT(SDValue Op,
   if (DstWidth < SatWidth)
     return SDValue();
 
+  if (SrcVT == MVT::f16 && SatVT == MVT::i16 && DstVT == MVT::i32) {
+    auto Opcode = (Op.getOpcode() == ISD::FP_TO_SINT_SAT)
+                      ? AArch64::FCVTZSv1f16
+                      : AArch64::FCVTZUv1f16;
+    auto Cvt = SDValue(DAG.getMachineNode(Opcode, DL, MVT::f16, SrcVal), 0);
----------------
efriedma-quic wrote:

It's never been a good idea to use machine nodes during legalization; it blocks optimizations you'd normally expect to happen, and there are some weird interactions with instruction selection.  But there isn't any direct enforcement in the code, so a few bits of code have slipped through.

In any case, yes, this is roughly what I expected the patch to look like.

https://github.com/llvm/llvm-project/pull/154822


More information about the llvm-commits mailing list