[llvm] [AMDGPU] Promote FMA bf16 ops to use v2bf16 (PR #215805)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 06:41:24 PDT 2026
https://github.com/LU-JOHN created https://github.com/llvm/llvm-project/pull/215805
Promote FMA bf16 ops to use v2bf16.
Implement Promote action for 3-op FP instructions.
>From 7e8a53a397b6810c70148dc4c8a506458b29d3d3 Mon Sep 17 00:00:00 2001
From: John Lu <John.Lu at amd.com>
Date: Wed, 12 Aug 2026 08:34:48 -0500
Subject: [PATCH] Promote FMA bf16 ops to use v2bf16
Signed-off-by: John Lu <John.Lu at amd.com>
---
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 13 +++++++++++++
llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 4 ++--
llvm/test/CodeGen/AMDGPU/bf16.ll | 4 ++--
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index 9f58ee4024c3a..1e03276ef2741 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -5948,6 +5948,19 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
Results.push_back(Tmp1.getValue(1));
break;
case ISD::FMA:
+ // Promote scalar operations to vector using SCALAR_TO_VECTOR
+ if (!OVT.isVector() && NVT.isVector() &&
+ NVT.getVectorElementType() == OVT) {
+ Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, NVT, Node->getOperand(0));
+ Tmp2 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, NVT, Node->getOperand(1));
+ Tmp3 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, NVT, Node->getOperand(2));
+ SDValue Result =
+ DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2, Tmp3,
+ Node->getFlags());
+ Results.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, OVT, Result,
+ DAG.getConstant(0, dl, MVT::i32)));
+ break;
+ }
Tmp1 = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(0));
Tmp2 = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(1));
Tmp3 = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(2));
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 939a90b7d2461..e1b11cb0f484b 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -250,8 +250,8 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM,
setOperationAction(ISD::FSUB, MVT::bf16, Custom);
// Promote scalar operations to a v2bf16 operation with an unused high
// lane.
- for (unsigned Opc : {ISD::FADD, ISD::FMUL, ISD::FMAXNUM, ISD::FMINNUM,
- ISD::FCANONICALIZE})
+ for (unsigned Opc : {ISD::FADD, ISD::FMUL, ISD::FMA, ISD::FMAXNUM,
+ ISD::FMINNUM, ISD::FCANONICALIZE})
AddPromotedToType(Opc, MVT::bf16, MVT::v2bf16);
}
diff --git a/llvm/test/CodeGen/AMDGPU/bf16.ll b/llvm/test/CodeGen/AMDGPU/bf16.ll
index c95eeb1fbacd6..b2ef99e4fd32f 100644
--- a/llvm/test/CodeGen/AMDGPU/bf16.ll
+++ b/llvm/test/CodeGen/AMDGPU/bf16.ll
@@ -45915,7 +45915,7 @@ define bfloat @v_fma_bf16(bfloat %a, bfloat %b, bfloat %c) #0 {
; GFX1250: ; %bb.0:
; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: v_fma_mixlo_bf16 v0, v0, v1, v2 op_sel_hi:[1,1,1]
+; GFX1250-NEXT: v_pk_fma_bf16 v0, v0, v1, v2
; GFX1250-NEXT: s_set_pc_i64 s[30:31]
%op = call bfloat @llvm.fma.bf16(bfloat %a, bfloat %b, bfloat %c)
ret bfloat %op
@@ -50912,7 +50912,7 @@ define bfloat @v_fmuladd_bf16(bfloat %a, bfloat %b, bfloat %c) #0 {
; GFX1250: ; %bb.0:
; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: v_fma_mixlo_bf16 v0, v0, v1, v2 op_sel_hi:[1,1,1]
+; GFX1250-NEXT: v_pk_fma_bf16 v0, v0, v1, v2
; GFX1250-NEXT: s_set_pc_i64 s[30:31]
%op = call bfloat @llvm.fmuladd.bf16(bfloat %a, bfloat %b, bfloat %c)
ret bfloat %op
More information about the llvm-commits
mailing list