From 4c168635f8acd66f0ac693124d7626a5313242dd Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Sat, 2 Sep 2023 14:24:37 +0200 Subject: [PATCH] ac/llvm: Use float types for float atomics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák Part-of: --- src/amd/llvm/ac_nir_to_llvm.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index 13fc275ef08..dae2473802f 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -2080,6 +2080,22 @@ static LLVMValueRef visit_global_atomic(struct ac_nir_context *ctx, LLVMTypeRef data_type = LLVMTypeOf(data); + assert(instr->src[1].ssa->num_components == 1); + if (is_float) { + switch (instr->src[1].ssa->bit_size) { + case 32: + data_type = ctx->ac.f32; + break; + case 64: + data_type = ctx->ac.f64; + break; + default: + unreachable("Unsupported float bit size"); + } + + data = LLVMBuildBitCast(ctx->ac.builder, data, data_type, ""); + } + LLVMValueRef addr = get_global_address(ctx, instr, data_type); if (instr->intrinsic == nir_intrinsic_global_atomic_swap || @@ -2097,15 +2113,16 @@ static LLVMValueRef visit_global_atomic(struct ac_nir_context *ctx, params[arg_count++] = data; ac_build_type_name_for_intr(data_type, type, sizeof(type)); - snprintf(name, sizeof(name), "llvm.amdgcn.global.atomic.%s.%s.p1%s.%s", op, type, type, type); + snprintf(name, sizeof(name), "llvm.amdgcn.global.atomic.%s.%s.p1.%s", op, type, type); result = ac_build_intrinsic(&ctx->ac, name, data_type, params, arg_count, 0); - result = ac_to_integer(&ctx->ac, result); } else { op = translate_atomic_op(nir_op); result = ac_build_atomic_rmw(&ctx->ac, op, addr, ac_to_integer(&ctx->ac, data), sync_scope); } + result = ac_to_integer(&ctx->ac, result); + return result; }