aco: don't apply dpp if the alu instr uses the operand twice
authorGeorg Lehmann <dadschoorse@gmail.com>
Tue, 25 Apr 2023 18:56:18 +0000 (20:56 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 12 May 2023 13:31:16 +0000 (13:31 +0000)
CP77 has a ton of fma(dpp(a), dpp(a), b).

Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22698>

src/amd/compiler/aco_optimizer.cpp
src/amd/compiler/aco_optimizer_postRA.cpp

index a6d1a60..885ffc5 100644 (file)
@@ -4819,6 +4819,13 @@ select_instruction(opt_ctx& ctx, aco_ptr<Instruction>& 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;
index e8d5939..d04b3c6 100644 (file)
@@ -505,6 +505,13 @@ try_combine_dpp(pr_opt_ctx& ctx, aco_ptr<Instruction>& 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;