From 3ea594f42b0ba8abf361a43d4042dd293b3b71c2 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Mon, 18 May 2026 14:47:29 +0200 Subject: [PATCH] ac/llvm: never create ffmaz for broken llvm The workaround wasn't proper fused ffma. Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/common/nir/ac_nir.c | 12 ++++++++++++ src/amd/llvm/ac_nir_to_llvm.c | 14 ++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/amd/common/nir/ac_nir.c b/src/amd/common/nir/ac_nir.c index 610fa31aaff..66c9be306b1 100644 --- a/src/amd/common/nir/ac_nir.c +++ b/src/amd/common/nir/ac_nir.c @@ -10,6 +10,10 @@ #include "nir_builder.h" #include "nir_intrinsics.h" +#if AMD_LLVM_AVAILABLE +#include +#endif + /* Set NIR options shared by ACO, LLVM, RADV, and radeonsi. */ void ac_nir_set_options(const struct ac_compiler_info *info, bool use_llvm, nir_shader_compiler_options *options) @@ -144,6 +148,14 @@ void ac_nir_set_options(const struct ac_compiler_info *info, bool use_llvm, options->max_workgroup_count[1] = UINT16_MAX; options->max_workgroup_count[2] = UINT16_MAX; options->max_samples = 8; + + /* Workaround for LLVM bug that crashes when using legacy fma on GFX12. */ +#if AMD_LLVM_AVAILABLE + if (info->gfx_level == GFX12 && use_llvm && LLVM_VERSION_MAJOR <= 21) + options->has_ffmaz_no_denorms = false; +#else + assert(!use_llvm); +#endif } /* Sleep for the given number of clock cycles. */ diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index 5726b65566e..b66211c1e03 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -767,18 +767,8 @@ static bool visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr) src[0] = ac_to_float(&ctx->ac, src[0]); src[1] = ac_to_float(&ctx->ac, src[1]); src[2] = ac_to_float(&ctx->ac, src[2]); -#if LLVM_VERSION_MAJOR <= 21 - /* Workaround for LLVM bug that crashes when using legacy fma on GFX12. */ - if (ctx->ac.gfx_level == GFX12) { - LLVMValueRef mulz = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.fmul.legacy", - ctx->ac.f32, src, 2, 0); - result = LLVMBuildFAdd(ctx->ac.builder, mulz, src[2], ""); - } else -#endif - { - result = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.fma.legacy", ctx->ac.f32, - src, 3, 0); - } + result = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.fma.legacy", ctx->ac.f32, + src, 3, 0); break; case nir_op_ldexp: src[0] = ac_to_float(&ctx->ac, src[0]);