From 82f7b3acfaa07dcad65e891e1993c13457474a8b Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Fri, 24 Mar 2023 13:30:01 +0100 Subject: [PATCH] aco: support neg(mul)/abs(mul) optimization in more cases Reviewed-by: Rhys Perry Part-of: --- src/amd/compiler/aco_optimizer.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/amd/compiler/aco_optimizer.cpp b/src/amd/compiler/aco_optimizer.cpp index 91ca8077daf..c7ef09517e4 100644 --- a/src/amd/compiler/aco_optimizer.cpp +++ b/src/amd/compiler/aco_optimizer.cpp @@ -4142,9 +4142,9 @@ combine_instruction(opt_ctx& ctx, aco_ptr& instr) if (mul_instr->operands[0].isLiteral()) return; - if (mul_instr->isVOP3() && mul_instr->valu().clamp) + if (mul_instr->valu().clamp) return; - if (mul_instr->isSDWA() || mul_instr->isDPP() || mul_instr->isVOP3P()) + if (mul_instr->isSDWA() || mul_instr->isDPP()) return; if (mul_instr->opcode == aco_opcode::v_mul_legacy_f32 && ctx.fp_mode.preserve_signed_zero_inf_nan32) @@ -4157,20 +4157,19 @@ combine_instruction(opt_ctx& ctx, aco_ptr& instr) Definition def = instr->definitions[0]; bool is_neg = ctx.info[instr->definitions[0].tempId()].is_neg(); bool is_abs = ctx.info[instr->definitions[0].tempId()].is_abs(); - instr.reset( - create_instruction(mul_instr->opcode, asVOP3(Format::VOP2), 2, 1)); - instr->operands[0] = mul_instr->operands[0]; - instr->operands[1] = mul_instr->operands[1]; + Format format = mul_instr->format == Format::VOP2 ? asVOP3(Format::VOP2) : mul_instr->format; + instr.reset(create_instruction(mul_instr->opcode, format, + mul_instr->operands.size(), 1)); + std::copy(mul_instr->operands.cbegin(), mul_instr->operands.cend(), instr->operands.begin()); instr->definitions[0] = def; VALU_instruction& new_mul = instr->valu(); - if (mul_instr->isVOP3()) { - VALU_instruction& mul = mul_instr->valu(); - new_mul.neg[0] = mul.neg[0]; - new_mul.neg[1] = mul.neg[1]; - new_mul.abs[0] = mul.abs[0]; - new_mul.abs[1] = mul.abs[1]; - new_mul.omod = mul.omod; - } + VALU_instruction& mul = mul_instr->valu(); + new_mul.neg = mul.neg; + new_mul.abs = mul.abs; + new_mul.omod = mul.omod; + new_mul.opsel = mul.opsel; + new_mul.opsel_lo = mul.opsel_lo; + new_mul.opsel_hi = mul.opsel_hi; if (is_abs) { new_mul.neg[0] = new_mul.neg[1] = false; new_mul.abs[0] = new_mul.abs[1] = true;