aco: use uses helpers for pk_fma opt
authorGeorg Lehmann <dadschoorse@gmail.com>
Thu, 9 Mar 2023 13:17:53 +0000 (14:17 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 20 Jun 2023 14:29:24 +0000 (14:29 +0000)
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21819>

src/amd/compiler/aco_optimizer.cpp

index 8e28570..411c63f 100644 (file)
@@ -3856,27 +3856,17 @@ combine_vop3p(opt_ctx& ctx, aco_ptr<Instruction>& instr)
       if (!mul_instr)
          return;
 
-      /* convert to mad */
-      Operand op[3] = {mul_instr->operands[0], mul_instr->operands[1], instr->operands[add_op_idx]};
-      ctx.uses[mul_instr->definitions[0].tempId()]--;
-      if (ctx.uses[mul_instr->definitions[0].tempId()]) {
-         if (op[0].isTemp())
-            ctx.uses[op[0].tempId()]++;
-         if (op[1].isTemp())
-            ctx.uses[op[1].tempId()]++;
-      }
-
       /* turn packed mul+add into v_pk_fma_f16 */
       assert(mul_instr->isVOP3P());
       aco_opcode mad = fadd ? aco_opcode::v_pk_fma_f16 : aco_opcode::v_pk_mad_u16;
       aco_ptr<VALU_instruction> fma{create_instruction<VALU_instruction>(mad, Format::VOP3P, 3, 1)};
       VALU_instruction* mul = &mul_instr->valu();
       for (unsigned i = 0; i < 2; i++) {
-         fma->operands[i] = op[i];
+         fma->operands[i] = copy_operand(ctx, mul_instr->operands[i]);
          fma->neg_lo[i] = mul->neg_lo[i];
          fma->neg_hi[i] = mul->neg_hi[i];
       }
-      fma->operands[2] = op[2];
+      fma->operands[2] = instr->operands[add_op_idx];
       fma->clamp = vop3p->clamp;
       fma->opsel_lo = mul->opsel_lo;
       fma->opsel_hi = mul->opsel_hi;
@@ -3891,6 +3881,7 @@ combine_vop3p(opt_ctx& ctx, aco_ptr<Instruction>& instr)
       fma->pass_flags = instr->pass_flags;
       instr = std::move(fma);
       ctx.info[instr->definitions[0].tempId()].set_vop3p(instr.get());
+      decrease_uses(ctx, mul_instr);
       return;
    }
 }