From fe0c72caec78d9181e446d7a1b81dd6eac515b89 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Mon, 9 Dec 2024 10:15:38 +0100 Subject: [PATCH] aco/ra: don't write to exec/ttmp with mulk/addk/cmovk ttmp sgprs are readonly outside of trap handlers, so the instructions were probably skipped. RA should also never create additional exec writes. Fixes: e06773281b3 ("aco/ra: Optimize some SOP2 instructions with literal to SOPK.") Reviewed-by: Rhys Perry Part-of: --- src/amd/compiler/aco_register_allocation.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp index f3083fc86b4..9600b92b121 100644 --- a/src/amd/compiler/aco_register_allocation.cpp +++ b/src/amd/compiler/aco_register_allocation.cpp @@ -514,6 +514,17 @@ print_regs(ra_ctx& ctx, PhysRegInterval regs, const RegisterFile& reg_file) } } +bool +is_sgpr_writable_without_side_effects(amd_gfx_level gfx_level, PhysReg reg) +{ + assert(reg < 256); + bool has_flat_scr_lo_gfx89 = gfx_level >= GFX8 && gfx_level <= GFX9; + bool has_flat_scr_lo_gfx7_or_xnack_mask = gfx_level <= GFX9; + return (reg <= vcc_hi || reg == m0) && + (!has_flat_scr_lo_gfx89 || (reg != flat_scr_lo && reg != flat_scr_hi)) && + (!has_flat_scr_lo_gfx7_or_xnack_mask || (reg != 104 || reg != 105)); +} + unsigned get_subdword_operand_stride(amd_gfx_level gfx_level, const aco_ptr& instr, unsigned idx, RegClass rc) @@ -2906,7 +2917,8 @@ optimize_encoding_sopk(ra_ctx& ctx, RegisterFile& register_file, aco_ptroperands[1].isLiteral(); - if (instr->operands[!literal_idx].physReg() >= 128) + PhysReg op_reg = instr->operands[!literal_idx].physReg(); + if (!is_sgpr_writable_without_side_effects(ctx.program->gfx_level, op_reg)) return; unsigned def_id = instr->definitions[0].tempId();