From e73e2f26f7839f47ee01f0769fad32debcfceee5 Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Tue, 19 Sep 2023 11:04:25 +0200 Subject: [PATCH] ac/llvm: Fix DENORM_FLUSH_TO_ZERO with exact instructions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cc: mesa-stable Reviewed-by: Marek Olšák Part-of: (cherry picked from commit 2b38d4922e8e1024b6d5d29c9bd30d8cd937a8b7) --- .pick_status.json | 2 +- src/amd/ci/radv-navi21-llvm-fails.txt | 4 ---- src/amd/llvm/ac_nir_to_llvm.c | 17 +++++------------ 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index d507445d9e6..8abd1eccf9a 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -734,7 +734,7 @@ "description": "ac/llvm: Fix DENORM_FLUSH_TO_ZERO with exact instructions", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/amd/ci/radv-navi21-llvm-fails.txt b/src/amd/ci/radv-navi21-llvm-fails.txt index 12cd7f2dfc9..e67a41a341f 100644 --- a/src/amd/ci/radv-navi21-llvm-fails.txt +++ b/src/amd/ci/radv-navi21-llvm-fails.txt @@ -1,8 +1,4 @@ -dEQP-VK.spirv_assembly.instruction.compute.float_controls.fp32.input_args.tanh_denorm_flush_to_zero,Fail -dEQP-VK.spirv_assembly.instruction.graphics.float_controls.fp32.input_args.tanh_denorm_flush_to_zero_frag,Fail -dEQP-VK.spirv_assembly.instruction.graphics.float_controls.fp32.input_args.tanh_denorm_flush_to_zero_vert,Fail - dEQP-VK.pipeline.monolithic.multisample.storage_image.64x64_1.r32g32b32a32_sfloat.samples_8,Fail dEQP-VK.pipeline.monolithic.multisample.storage_image.64x64_1.r8g8b8a8_unorm.samples_8,Fail dEQP-VK.pipeline.monolithic.multisample.storage_image.64x64_4.r32g32b32a32_sfloat.samples_8,Fail diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index a41f7dba776..0e58956a8ec 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -555,12 +555,6 @@ static bool visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr) case nir_op_fneg: src[0] = ac_to_float(&ctx->ac, src[0]); result = LLVMBuildFNeg(ctx->ac.builder, src[0], ""); - if (ctx->ac.float_mode == AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO) { - /* fneg will be optimized by backend compiler with sign - * bit removed via XOR. This is probably a LLVM bug. - */ - result = ac_build_canonicalize(&ctx->ac, result, instr->def.bit_size); - } break; case nir_op_inot: result = LLVMBuildNot(ctx->ac.builder, src[0], ""); @@ -704,12 +698,6 @@ static bool visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr) case nir_op_fabs: result = emit_intrin_1f_param(&ctx->ac, "llvm.fabs", ac_to_float_type(&ctx->ac, def_type), src[0]); - if (ctx->ac.float_mode == AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO) { - /* fabs will be optimized by backend compiler with sign - * bit removed via AND. - */ - result = ac_build_canonicalize(&ctx->ac, result, instr->def.bit_size); - } break; case nir_op_fsat: src[0] = ac_to_float(&ctx->ac, src[0]); @@ -1247,6 +1235,11 @@ static bool visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr) } if (result) { + LLVMTypeKind type_kind = LLVMGetTypeKind(LLVMTypeOf(result)); + bool is_float = type_kind == LLVMHalfTypeKind || type_kind == LLVMFloatTypeKind || type_kind == LLVMDoubleTypeKind; + if (ctx->ac.float_mode == AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO && is_float) + result = ac_build_canonicalize(&ctx->ac, result, instr->def.bit_size); + result = ac_to_integer_or_pointer(&ctx->ac, result); ctx->ssa_defs[instr->def.index] = result; }