From 70ff262cda8a8e3566f73afec669386ddb4fa70c Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 16 Oct 2020 13:18:08 +0100 Subject: [PATCH] aco: use v_mov_b32_sdwa for some 16-bit constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rhys Perry Reviewed-by: Timur Kristóf Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_lower_to_hw_instr.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/amd/compiler/aco_lower_to_hw_instr.cpp b/src/amd/compiler/aco_lower_to_hw_instr.cpp index 8c6766b17c8..f7a401209e1 100644 --- a/src/amd/compiler/aco_lower_to_hw_instr.cpp +++ b/src/amd/compiler/aco_lower_to_hw_instr.cpp @@ -1028,7 +1028,14 @@ void copy_constant(lower_context *ctx, Builder& bld, Definition dst, Operand op) } } else if (dst.regClass() == v2b && op.isConstant() && !op.isLiteral()) { assert(ctx->program->chip_class >= GFX8); - bld.vop2_sdwa(aco_opcode::v_add_f16, dst, op, Operand(0u)); + if (op.constantValue() >= 0xfff0 || op.constantValue() <= 64) { + /* use v_mov_b32 to avoid possible issues with denormal flushing or + * NaN. v_add_f16 is still needed for float constants. */ + uint32_t val32 = (int32_t)(int16_t)op.constantValue(); + bld.vop1_sdwa(aco_opcode::v_mov_b32, dst, Operand(val32)); + } else { + bld.vop2_sdwa(aco_opcode::v_add_f16, dst, op, Operand(0u)); + } } else if (dst.regClass() == v2b && op.isLiteral()) { if (ctx->program->chip_class < GFX10 || !(ctx->block->fp_mode.denorm16_64 & fp_denorm_keep_in)) { unsigned offset = dst.physReg().byte() * 8u;