From fc29821d3ba26f068ec4a8c0850ca501d3b8b7de Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Tue, 25 Nov 2025 14:24:31 +0100 Subject: [PATCH] aco/optimizer: move med3 -> add_clamp opt later MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Soon we will apply omod later, when the combine_instruction reaches the multiplication with constant. Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_optimizer.cpp | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/amd/compiler/aco_optimizer.cpp b/src/amd/compiler/aco_optimizer.cpp index 02b3cb98a2a..aa8f1192933 100644 --- a/src/amd/compiler/aco_optimizer.cpp +++ b/src/amd/compiler/aco_optimizer.cpp @@ -2015,7 +2015,7 @@ bool detect_clamp(Instruction* instr, unsigned* clamped_idx) { VALU_instruction& valu = instr->valu(); - if (valu.omod != 0 || valu.opsel != 0) + if (valu.omod != 0 || valu.opsel != 0 || instr->isDPP()) return false; unsigned idx = 0; @@ -4585,24 +4585,6 @@ combine_instruction(opt_ctx& ctx, aco_ptr& instr) ctx.info[instr->definitions[0].tempId()].set_combined(ctx.pre_combine_instrs.size() - 1); } #undef add_opt - - if (instr->opcode == aco_opcode::v_med3_f32 || instr->opcode == aco_opcode::v_med3_f16) { - /* Optimize v_med3 to v_add so that it can be dual issued on GFX11. We start with v_med3 in - * case omod can be applied. - */ - unsigned idx; - if (detect_clamp(instr.get(), &idx)) { - instr->format = asVOP3(Format::VOP2); - instr->operands[0] = instr->operands[idx]; - instr->operands[1] = Operand::zero(); - instr->opcode = - instr->opcode == aco_opcode::v_med3_f32 ? aco_opcode::v_add_f32 : aco_opcode::v_add_f16; - instr->valu().clamp = true; - instr->valu().abs = (uint8_t)instr->valu().abs[idx]; - instr->valu().neg = (uint8_t)instr->valu().neg[idx]; - instr->operands.pop_back(); - } - } } struct remat_entry { @@ -4772,6 +4754,24 @@ select_instruction(opt_ctx& ctx, aco_ptr& instr) return; } + if (instr->opcode == aco_opcode::v_med3_f32 || instr->opcode == aco_opcode::v_med3_f16) { + /* Optimize v_med3 to v_add so that it can be dual issued on GFX11. We start with v_med3 in + * case omod can be applied. + */ + unsigned idx; + if (detect_clamp(instr.get(), &idx)) { + instr->format = asVOP3(Format::VOP2); + instr->operands[0] = instr->operands[idx]; + instr->operands[1] = Operand::zero(); + instr->opcode = + instr->opcode == aco_opcode::v_med3_f32 ? aco_opcode::v_add_f32 : aco_opcode::v_add_f16; + instr->valu().clamp = true; + instr->valu().abs = (uint8_t)instr->valu().abs[idx]; + instr->valu().neg = (uint8_t)instr->valu().neg[idx]; + instr->operands.pop_back(); + } + } + /* convert split_vector into a copy or extract_vector if only one definition is ever used */ if (instr->opcode == aco_opcode::p_split_vector) { unsigned num_used = 0;