From 04976beac7d9d5455753a0e964db71c37b7cb3d8 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Tue, 25 Apr 2023 20:56:18 +0200 Subject: [PATCH] aco: don't apply dpp if the alu instr uses the operand twice CP77 has a ton of fma(dpp(a), dpp(a), b). Reviewed-by: Rhys Perry Part-of: --- src/amd/compiler/aco_optimizer.cpp | 7 +++++++ src/amd/compiler/aco_optimizer_postRA.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/amd/compiler/aco_optimizer.cpp b/src/amd/compiler/aco_optimizer.cpp index a6d1a60415a..885ffc54bb4 100644 --- a/src/amd/compiler/aco_optimizer.cpp +++ b/src/amd/compiler/aco_optimizer.cpp @@ -4819,6 +4819,13 @@ select_instruction(opt_ctx& ctx, aco_ptr& instr) if (!info.is_dpp() || info.instr->pass_flags != instr->pass_flags) continue; + /* We won't eliminate the DPP mov if the operand is used twice */ + bool op_used_twice = false; + for (unsigned j = 0; j < instr->operands.size(); j++) + op_used_twice |= i != j && instr->operands[i] == instr->operands[j]; + if (op_used_twice) + continue; + if (i != 0) { if (!can_swap_operands(instr, &instr->opcode, 0, i)) continue; diff --git a/src/amd/compiler/aco_optimizer_postRA.cpp b/src/amd/compiler/aco_optimizer_postRA.cpp index e8d593915f2..d04b3c6c0f6 100644 --- a/src/amd/compiler/aco_optimizer_postRA.cpp +++ b/src/amd/compiler/aco_optimizer_postRA.cpp @@ -505,6 +505,13 @@ try_combine_dpp(pr_opt_ctx& ctx, aco_ptr& instr) if (is_overwritten_since(ctx, mov->operands[0], op_instr_idx)) continue; + /* We won't eliminate the DPP mov if the operand is used twice */ + bool op_used_twice = false; + for (unsigned j = 0; j < instr->operands.size(); j++) + op_used_twice |= i != j && instr->operands[i] == instr->operands[j]; + if (op_used_twice) + continue; + bool dpp8 = mov->isDPP8(); bool input_mods = instr_info.can_use_input_modifiers[(int)instr->opcode] && instr_info.operand_size[(int)instr->opcode] == 32;