From 3f377407622886395fe50d4ffc467b27670f9ff3 Mon Sep 17 00:00:00 2001 From: Qiang Yu Date: Wed, 10 Dec 2025 16:57:17 +0800 Subject: [PATCH] ac/llvm: workaround legacy fma intrinsic crash on gfx12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a llvm bug: https://github.com/llvm/llvm-project/issues/170437 Cc: mesa-stable Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14359 Reviewed-by: Marek Olšák Part-of: --- src/amd/llvm/ac_nir_to_llvm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index ece97735712..4e00f6ed952 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -857,8 +857,18 @@ 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]); - result = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.fma.legacy", ctx->ac.f32, - src, 3, 0); +#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); + } break; case nir_op_ldexp: src[0] = ac_to_float(&ctx->ac, src[0]);