[llvm] [AArch64][SVE] Use NEON for ISD::FP_ROUND cases (PR #171776)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 11 06:16:23 PST 2025


================
@@ -4776,6 +4777,36 @@ SDValue AArch64TargetLowering::LowerFP_ROUND(SDValue Op,
     return getSVESafeBitCast(VT, Narrow, DAG);
   }
 
+  // Split fp_rounds where VT == 128 bits and SrcVT == 256 bits,
+  // When the minimum SVE vector length is 256 bits, it is best to manually
+  // lower this with NEON for v8f16, and v8bf16 will crash without doing so as
+  // both types are legal and will not automatically split in legalization.
+  auto SplitConcat = [&](MVT DestTy, MVT HalfDestTy, MVT HalfSrcTy) {
+    SDValue Concat = Op->getOperand(0);
+    if (Concat.getOpcode() == ISD::CONCAT_VECTORS) {
+      SDValue ConcatOp0 = Concat.getOperand(0);
+      SDValue ConcatOp1 = Concat.getOperand(1);
+      SDLoc DL(Op);
+      SDValue L = DAG.getNode(ISD::FP_ROUND, DL, HalfDestTy, ConcatOp0,
+                              Op->getOperand(1));
+      SDValue R = DAG.getNode(ISD::FP_ROUND, DL, HalfDestTy, ConcatOp1,
+                              Op->getOperand(1));
+      return DAG.getNode(ISD::CONCAT_VECTORS, DL, DestTy, L, R);
+    }
+    return SDValue();
+  };
+
+  if (VT == MVT::v8bf16) {
+    if (SrcVT == MVT::v8f32 && Subtarget->hasBF16())
+      if (auto Split = SplitConcat(MVT::v8bf16, MVT::v4bf16, MVT::v4f32))
+        return Split;
+    // Anything else for v8bf16 is legal
+    return Op;
+  }
+  if (VT == MVT::v8f16 && SrcVT == MVT::v8f32)
----------------
david-arm wrote:

There is also the problem of doubles, because this doesn't seem to work either:

```
define <8 x bfloat> @fptrunc_shuffle_v8f16_2(<4 x double> %a, <4 x double> %b) #1 {
  %shuffle = shufflevector <4 x double> %a, <4 x double> %b, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
  %fpt = fptrunc <8 x double> %shuffle to <8 x bfloat>
  ret <8 x bfloat> %fpt
}

attributes #1 = { vscale_range(4,4) "target-features"="+bf16,+sve" }
```

but this was already broken before this PR so I'm not expecting you to fix it in this PR!

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


More information about the llvm-commits mailing list