[llvm] AMDGPU/GlobalISel: Legalize BF16 for FP math opcodes (PR #214059)
Petar Avramovic via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 7 06:29:19 PDT 2026
================
@@ -976,36 +974,42 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,
getActionDefinitionsBuilder(G_BLOCK_ADDR).legalFor({CodePtr});
auto &FPOpActions =
- getActionDefinitionsBuilder({G_FADD, G_FMUL, G_FMA, G_FCANONICALIZE,
- G_STRICT_FADD, G_STRICT_FMUL, G_STRICT_FMA})
+ getActionDefinitionsBuilder({G_FADD, G_FMUL, G_FMA, G_FCANONICALIZE})
+ .legalFor({F32, F64});
+ auto &StrictFPOpActions =
+ getActionDefinitionsBuilder({G_STRICT_FADD, G_STRICT_FMUL, G_STRICT_FMA})
.legalFor({F32, F64});
auto &TrigActions =
getActionDefinitionsBuilder({G_FSIN, G_FCOS}).customFor({F32, F64});
auto &FDIVActions = getActionDefinitionsBuilder(G_FDIV).customFor({F32, F64});
if (ST.has16BitInsts()) {
- if (ST.hasVOP3PInsts())
+ if (ST.hasVOP3PInsts()) {
FPOpActions.legalFor({F16, V2F16});
- else
+ StrictFPOpActions.legalFor({F16, V2F16});
+ } else {
FPOpActions.legalFor({F16});
+ StrictFPOpActions.legalFor({F16});
+ }
TrigActions.customFor({F16});
FDIVActions.customFor({F16});
}
+ FPOpActions.widenScalarFor({BF16}, changeElementTo(0, F32));
----------------
petar-avramovic wrote:
I see. I was checking and as far as I understand strict opcodes are there to stop some optimizations (rounding mode can't be assumed, so don't fold strict opcodes if fold is rounding dependent etc).
But in the end it should end up as same instruction as non-strict plain fadd.
Think we are simply missing support in SDAG as well for them.
Then let's proceed with current patch and if needed add bf16 struct fp ops lowering for both sdag and gisel later
https://github.com/llvm/llvm-project/pull/214059
More information about the llvm-commits
mailing list