[llvm] [AArch64] Add bfloat patterns for `partial_reduce_fmla` (PR #181982)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 18 05:56:39 PST 2026


https://github.com/MacDue updated https://github.com/llvm/llvm-project/pull/181982

>From 06d92bb72f008a418088ee68e2629128ca5fc76e Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <benjamin.maxwell at arm.com>
Date: Tue, 17 Feb 2026 16:55:31 +0000
Subject: [PATCH 1/5] Precommit tests

---
 .../AArch64/fixed-length-bf16-arith.ll        | 20 ++++++
 .../test/CodeGen/AArch64/sve-bf16-combines.ll | 61 +++++++++++++++++++
 2 files changed, 81 insertions(+)

diff --git a/llvm/test/CodeGen/AArch64/fixed-length-bf16-arith.ll b/llvm/test/CodeGen/AArch64/fixed-length-bf16-arith.ll
index 9147e56dde037..8c29f271f00de 100644
--- a/llvm/test/CodeGen/AArch64/fixed-length-bf16-arith.ll
+++ b/llvm/test/CodeGen/AArch64/fixed-length-bf16-arith.ll
@@ -964,3 +964,23 @@ define <8 x bfloat> @fsub_v8bf16(<8 x bfloat> %a, <8 x bfloat> %b) {
   %res = fsub <8 x bfloat> %a, %b
   ret <8 x bfloat> %res
 }
+
+define <4 x float> @partial_reduce_to_v4f32(<4 x float> %acc, <8 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: partial_reduce_to_v4f32:
+; CHECK:       // %bb.0: // %entry
+; CHECK-NEXT:    shll v3.4s, v1.4h, #16
+; CHECK-NEXT:    shll v4.4s, v2.4h, #16
+; CHECK-NEXT:    shll2 v1.4s, v1.8h, #16
+; CHECK-NEXT:    shll2 v2.4s, v2.8h, #16
+; CHECK-NEXT:    fmul v3.4s, v3.4s, v4.4s
+; CHECK-NEXT:    fmul v1.4s, v1.4s, v2.4s
+; CHECK-NEXT:    fadd v0.4s, v0.4s, v3.4s
+; CHECK-NEXT:    fadd v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:    ret
+entry:
+  %a.wide = fpext <8 x bfloat> %a to <8 x float>
+  %b.wide = fpext <8 x bfloat> %b to <8 x float>
+  %mult = fmul <8 x float> %a.wide, %b.wide
+  %partial.reduce = call <4 x float> @llvm.vector.partial.reduce.fadd(<4 x float> %acc, <8 x float> %mult)
+  ret <4 x float> %partial.reduce
+}
diff --git a/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll b/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll
index 35fc1c6a9773c..b0d83139b32a7 100644
--- a/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll
+++ b/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll
@@ -707,4 +707,65 @@ define <vscale x 8 x bfloat> @fsub_sel_fmul_negzero_nsz_nxv8bf16(<vscale x 8 x b
   ret <vscale x 8 x bfloat> %fsub
 }
 
+define <vscale x 4 x float> @partial_reduce_to_nxv4f32(<vscale x 4 x float> %acc, <vscale x 8 x bfloat> %a, <vscale x 8 x bfloat> %b) {
+; SVE2-LABEL: fdot_wide_nxv4f32:
+; SVE2:       // %bb.0: // %entry
+; SVE2-NEXT:    uunpklo z3.s, z1.h
+; SVE2-NEXT:    uunpklo z4.s, z2.h
+; SVE2-NEXT:    ptrue p0.s
+; SVE2-NEXT:    uunpkhi z1.s, z1.h
+; SVE2-NEXT:    uunpkhi z2.s, z2.h
+; SVE2-NEXT:    fcvt z3.s, p0/m, z3.h
+; SVE2-NEXT:    fcvt z4.s, p0/m, z4.h
+; SVE2-NEXT:    fcvt z1.s, p0/m, z1.h
+; SVE2-NEXT:    fcvt z2.s, p0/m, z2.h
+; SVE2-NEXT:    fmul z3.s, z3.s, z4.s
+; SVE2-NEXT:    fmul z1.s, z1.s, z2.s
+; SVE2-NEXT:    fadd z0.s, z0.s, z3.s
+; SVE2-NEXT:    fadd z0.s, z0.s, z1.s
+; SVE2-NEXT:    ret
+;
+; SVE2P1-LABEL: fdot_wide_nxv4f32:
+; SVE2P1:       // %bb.0: // %entry
+; SVE2P1-NEXT:    fdot z0.s, z1.h, z2.h
+; SVE2P1-NEXT:    ret
+; SVE-LABEL: partial_reduce_to_nxv4f32:
+; SVE:       // %bb.0: // %entry
+; SVE-NEXT:    uunpklo z3.s, z1.h
+; SVE-NEXT:    uunpklo z4.s, z2.h
+; SVE-NEXT:    uunpkhi z1.s, z1.h
+; SVE-NEXT:    uunpkhi z2.s, z2.h
+; SVE-NEXT:    lsl z3.s, z3.s, #16
+; SVE-NEXT:    lsl z4.s, z4.s, #16
+; SVE-NEXT:    lsl z1.s, z1.s, #16
+; SVE-NEXT:    lsl z2.s, z2.s, #16
+; SVE-NEXT:    fmul z3.s, z3.s, z4.s
+; SVE-NEXT:    fmul z1.s, z1.s, z2.s
+; SVE-NEXT:    fadd z0.s, z0.s, z3.s
+; SVE-NEXT:    fadd z0.s, z0.s, z1.s
+; SVE-NEXT:    ret
+;
+; SVE-B16B16-LABEL: partial_reduce_to_nxv4f32:
+; SVE-B16B16:       // %bb.0: // %entry
+; SVE-B16B16-NEXT:    uunpklo z3.s, z1.h
+; SVE-B16B16-NEXT:    uunpklo z4.s, z2.h
+; SVE-B16B16-NEXT:    uunpkhi z1.s, z1.h
+; SVE-B16B16-NEXT:    uunpkhi z2.s, z2.h
+; SVE-B16B16-NEXT:    lsl z3.s, z3.s, #16
+; SVE-B16B16-NEXT:    lsl z4.s, z4.s, #16
+; SVE-B16B16-NEXT:    lsl z1.s, z1.s, #16
+; SVE-B16B16-NEXT:    lsl z2.s, z2.s, #16
+; SVE-B16B16-NEXT:    fmul z3.s, z3.s, z4.s
+; SVE-B16B16-NEXT:    fmul z1.s, z1.s, z2.s
+; SVE-B16B16-NEXT:    fadd z0.s, z0.s, z3.s
+; SVE-B16B16-NEXT:    fadd z0.s, z0.s, z1.s
+; SVE-B16B16-NEXT:    ret
+entry:
+  %a.wide = fpext <vscale x 8 x bfloat> %a to <vscale x 8 x float>
+  %b.wide = fpext <vscale x 8 x bfloat> %b to <vscale x 8 x float>
+  %mult = fmul <vscale x 8 x float> %a.wide, %b.wide
+  %partial.reduce = call <vscale x 4 x float> @llvm.vector.partial.reduce.fadd(<vscale x 4 x float> %acc, <vscale x 8 x float> %mult)
+  ret <vscale x 4 x float> %partial.reduce
+}
+
 declare <vscale x 8 x bfloat> @llvm.fma.nxv8bf16(<vscale x 8 x bfloat>, <vscale x 8 x bfloat>, <vscale x 8 x bfloat>)

>From 4d7245b7be6d8ffdc0826a2882fffa0f531f144b Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <benjamin.maxwell at arm.com>
Date: Tue, 17 Feb 2026 17:21:54 +0000
Subject: [PATCH 2/5] [AArch64] Add bfloat patterns for `partial_reduce_fmla`

A BFMLALT/B pair exactly matches the semantics of a partial_reduce_fmla
from (nx)v8bf16 to (nx)v4f32.
---
 .../Target/AArch64/AArch64ISelLowering.cpp    |  8 ++++++
 llvm/lib/Target/AArch64/AArch64InstrInfo.td   |  4 +++
 .../lib/Target/AArch64/AArch64SVEInstrInfo.td |  4 +++
 .../AArch64/fixed-length-bf16-arith.ll        | 10 ++-----
 .../test/CodeGen/AArch64/sve-bf16-combines.ll | 28 +++----------------
 5 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index beb5a9216ef5c..48c0fbd362ad2 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -1507,6 +1507,10 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
       }
     }
 
+    if (Subtarget->hasBF16())
+      setPartialReduceMLAAction(ISD::PARTIAL_REDUCE_FMLA, MVT::v4f32,
+                                MVT::v8bf16, Legal);
+
     setOperationAction(ISD::CLMUL, {MVT::v8i8, MVT::v16i8}, Legal);
     if (Subtarget->hasAES())
       setOperationAction(ISD::CLMUL, {MVT::v1i64, MVT::v2i64}, Legal);
@@ -2022,6 +2026,10 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
       setPartialReduceMLAAction(ISD::PARTIAL_REDUCE_FMLA, MVT::v4f32,
                                 MVT::v8f16, Custom);
     }
+
+    if (Subtarget->hasBF16())
+      setPartialReduceMLAAction(ISD::PARTIAL_REDUCE_FMLA, MVT::nxv4f32,
+                                MVT::nxv8bf16, Legal);
   }
 
   if (Subtarget->hasSVEAES() &&
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
index a70f0e2f5da0c..50dd5e113dbb1 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -1748,6 +1748,10 @@ def BFCVTN2      : SIMD_BFCVTN2;
 
 def : Pat<(concat_vectors (v4bf16 V64:$Rd), (any_fpround (v4f32 V128:$Rn))),
           (BFCVTN2 (v8bf16 (INSERT_SUBREG (IMPLICIT_DEF), V64:$Rd, dsub)), V128:$Rn)>;
+
+def : Pat<(v4f32 (partial_reduce_fmla v4f32:$acc, v8bf16:$LHS, v8bf16:$RHS)),
+          (BFMLALT (BFMLALB v4f32:$acc, V128:$LHS, V128:$RHS),
+              V128:$LHS, V128:$RHS)>;
 }
 
 let Predicates = [HasNEONandIsStreamingSafe, HasBF16] in {
diff --git a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
index 2d24e22f682b9..b1b1203ab512f 100644
--- a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
@@ -2597,6 +2597,10 @@ let Predicates = [HasBF16, HasSVE_or_SME] in {
                 (nxv4f32 (AArch64fcvte_mt (SVEAllActive), nxv4bf16:$Zm, (undef))))),
             (BFMLALB_ZZZ nxv4f32:$acc, ZPR:$Zn, ZPR:$Zm)>;
 
+  def : Pat<(nxv4f32 (partial_reduce_fmla nxv4f32:$acc, nxv8bf16:$LHS, nxv8bf16:$RHS)),
+            (BFMLALT_ZZZ (BFMLALB_ZZZ nxv4f32:$acc, ZPR:$LHS, ZPR:$RHS),
+                ZPR:$LHS, ZPR:$RHS)>;
+
   defm BFCVT_ZPmZ   : sve_bfloat_convert<"bfcvt", int_aarch64_sve_fcvt_bf16f32_v2, AArch64fcvtr_mt>;
   defm BFCVTNT_ZPmZ : sve_bfloat_convert_top<"bfcvtnt", int_aarch64_sve_fcvtnt_bf16f32_v2>;
 } // End HasBF16, HasSVE_or_SME
diff --git a/llvm/test/CodeGen/AArch64/fixed-length-bf16-arith.ll b/llvm/test/CodeGen/AArch64/fixed-length-bf16-arith.ll
index 8c29f271f00de..14f2ce7bb6c6c 100644
--- a/llvm/test/CodeGen/AArch64/fixed-length-bf16-arith.ll
+++ b/llvm/test/CodeGen/AArch64/fixed-length-bf16-arith.ll
@@ -968,14 +968,8 @@ define <8 x bfloat> @fsub_v8bf16(<8 x bfloat> %a, <8 x bfloat> %b) {
 define <4 x float> @partial_reduce_to_v4f32(<4 x float> %acc, <8 x bfloat> %a, <8 x bfloat> %b) {
 ; CHECK-LABEL: partial_reduce_to_v4f32:
 ; CHECK:       // %bb.0: // %entry
-; CHECK-NEXT:    shll v3.4s, v1.4h, #16
-; CHECK-NEXT:    shll v4.4s, v2.4h, #16
-; CHECK-NEXT:    shll2 v1.4s, v1.8h, #16
-; CHECK-NEXT:    shll2 v2.4s, v2.8h, #16
-; CHECK-NEXT:    fmul v3.4s, v3.4s, v4.4s
-; CHECK-NEXT:    fmul v1.4s, v1.4s, v2.4s
-; CHECK-NEXT:    fadd v0.4s, v0.4s, v3.4s
-; CHECK-NEXT:    fadd v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:    bfmlalb v0.4s, v1.8h, v2.8h
+; CHECK-NEXT:    bfmlalt v0.4s, v1.8h, v2.8h
 ; CHECK-NEXT:    ret
 entry:
   %a.wide = fpext <8 x bfloat> %a to <8 x float>
diff --git a/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll b/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll
index b0d83139b32a7..e87d2cb610afe 100644
--- a/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll
+++ b/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll
@@ -731,34 +731,14 @@ define <vscale x 4 x float> @partial_reduce_to_nxv4f32(<vscale x 4 x float> %acc
 ; SVE2P1-NEXT:    ret
 ; SVE-LABEL: partial_reduce_to_nxv4f32:
 ; SVE:       // %bb.0: // %entry
-; SVE-NEXT:    uunpklo z3.s, z1.h
-; SVE-NEXT:    uunpklo z4.s, z2.h
-; SVE-NEXT:    uunpkhi z1.s, z1.h
-; SVE-NEXT:    uunpkhi z2.s, z2.h
-; SVE-NEXT:    lsl z3.s, z3.s, #16
-; SVE-NEXT:    lsl z4.s, z4.s, #16
-; SVE-NEXT:    lsl z1.s, z1.s, #16
-; SVE-NEXT:    lsl z2.s, z2.s, #16
-; SVE-NEXT:    fmul z3.s, z3.s, z4.s
-; SVE-NEXT:    fmul z1.s, z1.s, z2.s
-; SVE-NEXT:    fadd z0.s, z0.s, z3.s
-; SVE-NEXT:    fadd z0.s, z0.s, z1.s
+; SVE-NEXT:    bfmlalb z0.s, z1.h, z2.h
+; SVE-NEXT:    bfmlalt z0.s, z1.h, z2.h
 ; SVE-NEXT:    ret
 ;
 ; SVE-B16B16-LABEL: partial_reduce_to_nxv4f32:
 ; SVE-B16B16:       // %bb.0: // %entry
-; SVE-B16B16-NEXT:    uunpklo z3.s, z1.h
-; SVE-B16B16-NEXT:    uunpklo z4.s, z2.h
-; SVE-B16B16-NEXT:    uunpkhi z1.s, z1.h
-; SVE-B16B16-NEXT:    uunpkhi z2.s, z2.h
-; SVE-B16B16-NEXT:    lsl z3.s, z3.s, #16
-; SVE-B16B16-NEXT:    lsl z4.s, z4.s, #16
-; SVE-B16B16-NEXT:    lsl z1.s, z1.s, #16
-; SVE-B16B16-NEXT:    lsl z2.s, z2.s, #16
-; SVE-B16B16-NEXT:    fmul z3.s, z3.s, z4.s
-; SVE-B16B16-NEXT:    fmul z1.s, z1.s, z2.s
-; SVE-B16B16-NEXT:    fadd z0.s, z0.s, z3.s
-; SVE-B16B16-NEXT:    fadd z0.s, z0.s, z1.s
+; SVE-B16B16-NEXT:    bfmlalb z0.s, z1.h, z2.h
+; SVE-B16B16-NEXT:    bfmlalt z0.s, z1.h, z2.h
 ; SVE-B16B16-NEXT:    ret
 entry:
   %a.wide = fpext <vscale x 8 x bfloat> %a to <vscale x 8 x float>

>From ddb5a4169f06436d911e84150adf3708f487bcb1 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <benjamin.maxwell at arm.com>
Date: Wed, 18 Feb 2026 12:37:42 +0000
Subject: [PATCH 3/5] Fixups

---
 .../test/CodeGen/AArch64/sve-bf16-combines.ll | 21 -------------------
 1 file changed, 21 deletions(-)

diff --git a/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll b/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll
index e87d2cb610afe..2e3d1cc67ee51 100644
--- a/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll
+++ b/llvm/test/CodeGen/AArch64/sve-bf16-combines.ll
@@ -708,27 +708,6 @@ define <vscale x 8 x bfloat> @fsub_sel_fmul_negzero_nsz_nxv8bf16(<vscale x 8 x b
 }
 
 define <vscale x 4 x float> @partial_reduce_to_nxv4f32(<vscale x 4 x float> %acc, <vscale x 8 x bfloat> %a, <vscale x 8 x bfloat> %b) {
-; SVE2-LABEL: fdot_wide_nxv4f32:
-; SVE2:       // %bb.0: // %entry
-; SVE2-NEXT:    uunpklo z3.s, z1.h
-; SVE2-NEXT:    uunpklo z4.s, z2.h
-; SVE2-NEXT:    ptrue p0.s
-; SVE2-NEXT:    uunpkhi z1.s, z1.h
-; SVE2-NEXT:    uunpkhi z2.s, z2.h
-; SVE2-NEXT:    fcvt z3.s, p0/m, z3.h
-; SVE2-NEXT:    fcvt z4.s, p0/m, z4.h
-; SVE2-NEXT:    fcvt z1.s, p0/m, z1.h
-; SVE2-NEXT:    fcvt z2.s, p0/m, z2.h
-; SVE2-NEXT:    fmul z3.s, z3.s, z4.s
-; SVE2-NEXT:    fmul z1.s, z1.s, z2.s
-; SVE2-NEXT:    fadd z0.s, z0.s, z3.s
-; SVE2-NEXT:    fadd z0.s, z0.s, z1.s
-; SVE2-NEXT:    ret
-;
-; SVE2P1-LABEL: fdot_wide_nxv4f32:
-; SVE2P1:       // %bb.0: // %entry
-; SVE2P1-NEXT:    fdot z0.s, z1.h, z2.h
-; SVE2P1-NEXT:    ret
 ; SVE-LABEL: partial_reduce_to_nxv4f32:
 ; SVE:       // %bb.0: // %entry
 ; SVE-NEXT:    bfmlalb z0.s, z1.h, z2.h

>From 45dfafed03c31f985e6e5017a031cafb394726d5 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <benjamin.maxwell at arm.com>
Date: Wed, 18 Feb 2026 13:35:23 +0000
Subject: [PATCH 4/5] Precommit tests

---
 .../Target/AArch64/AArch64ISelLowering.cpp    |   3 +
 ...-streaming-mode-fixed-length-bf16-arith.ll | 142 ++++++++++++++++++
 2 files changed, 145 insertions(+)
 create mode 100644 llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-bf16-arith.ll

diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 48c0fbd362ad2..86fdef6219ec2 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -2422,6 +2422,9 @@ void AArch64TargetLowering::addTypeForFixedLengthSVE(MVT VT) {
                               MVT::getVectorVT(MVT::f16, NumElts * 2), Custom);
   }
 
+  // if (Subtarget->hasBF16() && VT == MVT::v4f32)
+  //   setPartialReduceMLAAction(ISD::PARTIAL_REDUCE_FMLA, VT, MVT::v8bf16, Custom);
+
   // Lower fixed length vector operations to scalable equivalents.
   setOperationAction(ISD::ABDS, VT, Default);
   setOperationAction(ISD::ABDU, VT, Default);
diff --git a/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-bf16-arith.ll b/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-bf16-arith.ll
new file mode 100644
index 0000000000000..c4f134f077bce
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-bf16-arith.ll
@@ -0,0 +1,142 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -enable-subreg-liveness -mattr=+sve,+bf16 -force-streaming-compatible  < %s | FileCheck %s
+; RUN: llc -enable-subreg-liveness -mattr=+sme,+bf16 -force-streaming  < %s | FileCheck %s
+; RUN: llc -enable-subreg-liveness -mattr=+bf16 -force-streaming-compatible < %s | FileCheck %s --check-prefix=NONEON-NOSVE
+
+target triple = "aarch64-unknown-linux-gnu"
+
+;
+; Partial reduce (BFMLALT/B)
+;
+
+define <4 x float> @partial_reduce_to_v4f32(<4 x float> %acc, <8 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: partial_reduce_to_v4f32:
+; CHECK:       // %bb.0: // %entry
+; CHECK-NEXT:    uunpklo z3.s, z1.h
+; CHECK-NEXT:    stp q1, q2, [sp, #-32]!
+; CHECK-NEXT:    .cfi_def_cfa_offset 32
+; CHECK-NEXT:    uunpklo z1.s, z2.h
+; CHECK-NEXT:    ldr d4, [sp, #8]
+; CHECK-NEXT:    ldr d2, [sp, #24]
+; CHECK-NEXT:    lsl z3.s, z3.s, #16
+; CHECK-NEXT:    ptrue p0.s, vl4
+; CHECK-NEXT:    uunpklo z4.s, z4.h
+; CHECK-NEXT:    uunpklo z2.s, z2.h
+; CHECK-NEXT:    lsl z1.s, z1.s, #16
+; CHECK-NEXT:    lsl z2.s, z2.s, #16
+; CHECK-NEXT:    fmul z1.s, p0/m, z1.s, z3.s
+; CHECK-NEXT:    lsl z3.s, z4.s, #16
+; CHECK-NEXT:    fmul z2.s, p0/m, z2.s, z3.s
+; CHECK-NEXT:    fadd z0.s, p0/m, z0.s, z1.s
+; CHECK-NEXT:    fadd z0.s, p0/m, z0.s, z2.s
+; CHECK-NEXT:    add sp, sp, #32
+; CHECK-NEXT:    ret
+;
+; NONEON-NOSVE-LABEL: partial_reduce_to_v4f32:
+; NONEON-NOSVE:       // %bb.0: // %entry
+; NONEON-NOSVE-NEXT:    stp q1, q2, [sp, #-96]!
+; NONEON-NOSVE-NEXT:    .cfi_def_cfa_offset 96
+; NONEON-NOSVE-NEXT:    ldp d2, d1, [sp]
+; NONEON-NOSVE-NEXT:    str q0, [sp, #32]
+; NONEON-NOSVE-NEXT:    ldr s0, [sp, #44]
+; NONEON-NOSVE-NEXT:    stp d1, d2, [sp, #48]
+; NONEON-NOSVE-NEXT:    ldr d2, [sp, #16]
+; NONEON-NOSVE-NEXT:    ldr h16, [sp, #62]
+; NONEON-NOSVE-NEXT:    ldr h17, [sp, #54]
+; NONEON-NOSVE-NEXT:    ldr h7, [sp, #60]
+; NONEON-NOSVE-NEXT:    str d2, [sp, #72]
+; NONEON-NOSVE-NEXT:    ldr d2, [sp, #24]
+; NONEON-NOSVE-NEXT:    ldr h6, [sp, #52]
+; NONEON-NOSVE-NEXT:    fmov w8, s16
+; NONEON-NOSVE-NEXT:    ldr h5, [sp, #58]
+; NONEON-NOSVE-NEXT:    ldr h19, [sp, #74]
+; NONEON-NOSVE-NEXT:    str d2, [sp, #64]
+; NONEON-NOSVE-NEXT:    ldr h2, [sp, #78]
+; NONEON-NOSVE-NEXT:    ldr h4, [sp, #50]
+; NONEON-NOSVE-NEXT:    ldr h18, [sp, #68]
+; NONEON-NOSVE-NEXT:    ldr h20, [sp, #66]
+; NONEON-NOSVE-NEXT:    ldr h3, [sp, #56]
+; NONEON-NOSVE-NEXT:    fmov w9, s2
+; NONEON-NOSVE-NEXT:    lsl w8, w8, #16
+; NONEON-NOSVE-NEXT:    ldr h2, [sp, #70]
+; NONEON-NOSVE-NEXT:    ldr h1, [sp, #48]
+; NONEON-NOSVE-NEXT:    ldr h21, [sp, #64]
+; NONEON-NOSVE-NEXT:    fmov s16, w8
+; NONEON-NOSVE-NEXT:    fmov w8, s17
+; NONEON-NOSVE-NEXT:    lsl w9, w9, #16
+; NONEON-NOSVE-NEXT:    fmov s17, w9
+; NONEON-NOSVE-NEXT:    fmov w9, s2
+; NONEON-NOSVE-NEXT:    lsl w8, w8, #16
+; NONEON-NOSVE-NEXT:    ldr h2, [sp, #76]
+; NONEON-NOSVE-NEXT:    fmov s22, w8
+; NONEON-NOSVE-NEXT:    fmov w8, s7
+; NONEON-NOSVE-NEXT:    lsl w9, w9, #16
+; NONEON-NOSVE-NEXT:    fmul s16, s16, s17
+; NONEON-NOSVE-NEXT:    ldr h17, [sp, #72]
+; NONEON-NOSVE-NEXT:    fmov s23, w9
+; NONEON-NOSVE-NEXT:    fmov w9, s2
+; NONEON-NOSVE-NEXT:    lsl w8, w8, #16
+; NONEON-NOSVE-NEXT:    fadd s0, s0, s16
+; NONEON-NOSVE-NEXT:    fmov s2, w8
+; NONEON-NOSVE-NEXT:    fmov w8, s6
+; NONEON-NOSVE-NEXT:    lsl w9, w9, #16
+; NONEON-NOSVE-NEXT:    fmul s22, s22, s23
+; NONEON-NOSVE-NEXT:    fmov s7, w9
+; NONEON-NOSVE-NEXT:    fmov w9, s18
+; NONEON-NOSVE-NEXT:    lsl w8, w8, #16
+; NONEON-NOSVE-NEXT:    fadd s0, s0, s22
+; NONEON-NOSVE-NEXT:    fmov s6, w8
+; NONEON-NOSVE-NEXT:    fmov w8, s5
+; NONEON-NOSVE-NEXT:    lsl w9, w9, #16
+; NONEON-NOSVE-NEXT:    fmul s2, s2, s7
+; NONEON-NOSVE-NEXT:    fmov s7, w9
+; NONEON-NOSVE-NEXT:    fmov w9, s19
+; NONEON-NOSVE-NEXT:    lsl w8, w8, #16
+; NONEON-NOSVE-NEXT:    str s0, [sp, #92]
+; NONEON-NOSVE-NEXT:    ldr s0, [sp, #40]
+; NONEON-NOSVE-NEXT:    lsl w9, w9, #16
+; NONEON-NOSVE-NEXT:    fadd s0, s0, s2
+; NONEON-NOSVE-NEXT:    fmov s2, w8
+; NONEON-NOSVE-NEXT:    fmov w8, s4
+; NONEON-NOSVE-NEXT:    fmul s6, s6, s7
+; NONEON-NOSVE-NEXT:    fmov s5, w9
+; NONEON-NOSVE-NEXT:    fmov w9, s20
+; NONEON-NOSVE-NEXT:    lsl w8, w8, #16
+; NONEON-NOSVE-NEXT:    lsl w9, w9, #16
+; NONEON-NOSVE-NEXT:    fmul s2, s2, s5
+; NONEON-NOSVE-NEXT:    fadd s7, s0, s6
+; NONEON-NOSVE-NEXT:    fmov s4, w8
+; NONEON-NOSVE-NEXT:    fmov w8, s3
+; NONEON-NOSVE-NEXT:    ldr s0, [sp, #36]
+; NONEON-NOSVE-NEXT:    fmov s5, w9
+; NONEON-NOSVE-NEXT:    fmov w9, s17
+; NONEON-NOSVE-NEXT:    fadd s0, s0, s2
+; NONEON-NOSVE-NEXT:    lsl w8, w8, #16
+; NONEON-NOSVE-NEXT:    fmul s4, s4, s5
+; NONEON-NOSVE-NEXT:    lsl w9, w9, #16
+; NONEON-NOSVE-NEXT:    fmov s2, w8
+; NONEON-NOSVE-NEXT:    fmov w8, s1
+; NONEON-NOSVE-NEXT:    fmov s3, w9
+; NONEON-NOSVE-NEXT:    fmov w9, s21
+; NONEON-NOSVE-NEXT:    fadd s0, s0, s4
+; NONEON-NOSVE-NEXT:    lsl w8, w8, #16
+; NONEON-NOSVE-NEXT:    lsl w9, w9, #16
+; NONEON-NOSVE-NEXT:    fmul s1, s2, s3
+; NONEON-NOSVE-NEXT:    fmov s2, w8
+; NONEON-NOSVE-NEXT:    fmov s3, w9
+; NONEON-NOSVE-NEXT:    stp s0, s7, [sp, #84]
+; NONEON-NOSVE-NEXT:    ldr s0, [sp, #32]
+; NONEON-NOSVE-NEXT:    fmul s2, s2, s3
+; NONEON-NOSVE-NEXT:    fadd s0, s0, s1
+; NONEON-NOSVE-NEXT:    fadd s0, s0, s2
+; NONEON-NOSVE-NEXT:    str s0, [sp, #80]
+; NONEON-NOSVE-NEXT:    ldr q0, [sp, #80]
+; NONEON-NOSVE-NEXT:    add sp, sp, #96
+; NONEON-NOSVE-NEXT:    ret
+entry:
+  %a.wide = fpext <8 x bfloat> %a to <8 x float>
+  %b.wide = fpext <8 x bfloat> %b to <8 x float>
+  %mult = fmul <8 x float> %a.wide, %b.wide
+  %partial.reduce = call <4 x float> @llvm.vector.partial.reduce.fadd(<4 x float> %acc, <8 x float> %mult)
+  ret <4 x float> %partial.reduce
+}

>From a237f70cdacfd06d426c7777df1cd92da43388b3 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <benjamin.maxwell at arm.com>
Date: Wed, 18 Feb 2026 13:52:20 +0000
Subject: [PATCH 5/5] Add fixed-length SVE

---
 .../Target/AArch64/AArch64ISelLowering.cpp    |  5 +++--
 ...-streaming-mode-fixed-length-bf16-arith.ll | 20 ++-----------------
 2 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 86fdef6219ec2..82a15f18ce9d7 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -2422,8 +2422,9 @@ void AArch64TargetLowering::addTypeForFixedLengthSVE(MVT VT) {
                               MVT::getVectorVT(MVT::f16, NumElts * 2), Custom);
   }
 
-  // if (Subtarget->hasBF16() && VT == MVT::v4f32)
-  //   setPartialReduceMLAAction(ISD::PARTIAL_REDUCE_FMLA, VT, MVT::v8bf16, Custom);
+  if (Subtarget->hasBF16() && VT == MVT::v4f32)
+    setPartialReduceMLAAction(ISD::PARTIAL_REDUCE_FMLA, VT, MVT::v8bf16,
+                              Custom);
 
   // Lower fixed length vector operations to scalable equivalents.
   setOperationAction(ISD::ABDS, VT, Default);
diff --git a/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-bf16-arith.ll b/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-bf16-arith.ll
index c4f134f077bce..39ad9e6971a31 100644
--- a/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-bf16-arith.ll
+++ b/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-bf16-arith.ll
@@ -12,24 +12,8 @@ target triple = "aarch64-unknown-linux-gnu"
 define <4 x float> @partial_reduce_to_v4f32(<4 x float> %acc, <8 x bfloat> %a, <8 x bfloat> %b) {
 ; CHECK-LABEL: partial_reduce_to_v4f32:
 ; CHECK:       // %bb.0: // %entry
-; CHECK-NEXT:    uunpklo z3.s, z1.h
-; CHECK-NEXT:    stp q1, q2, [sp, #-32]!
-; CHECK-NEXT:    .cfi_def_cfa_offset 32
-; CHECK-NEXT:    uunpklo z1.s, z2.h
-; CHECK-NEXT:    ldr d4, [sp, #8]
-; CHECK-NEXT:    ldr d2, [sp, #24]
-; CHECK-NEXT:    lsl z3.s, z3.s, #16
-; CHECK-NEXT:    ptrue p0.s, vl4
-; CHECK-NEXT:    uunpklo z4.s, z4.h
-; CHECK-NEXT:    uunpklo z2.s, z2.h
-; CHECK-NEXT:    lsl z1.s, z1.s, #16
-; CHECK-NEXT:    lsl z2.s, z2.s, #16
-; CHECK-NEXT:    fmul z1.s, p0/m, z1.s, z3.s
-; CHECK-NEXT:    lsl z3.s, z4.s, #16
-; CHECK-NEXT:    fmul z2.s, p0/m, z2.s, z3.s
-; CHECK-NEXT:    fadd z0.s, p0/m, z0.s, z1.s
-; CHECK-NEXT:    fadd z0.s, p0/m, z0.s, z2.s
-; CHECK-NEXT:    add sp, sp, #32
+; CHECK-NEXT:    bfmlalb z0.s, z1.h, z2.h
+; CHECK-NEXT:    bfmlalt z0.s, z1.h, z2.h
 ; CHECK-NEXT:    ret
 ;
 ; NONEON-NOSVE-LABEL: partial_reduce_to_v4f32:



More information about the llvm-commits mailing list