aco: fix packed 16bit fneg/fsat optimization
authorDaniel Schürmann <daniel@schuermann.dev>
Thu, 7 Jul 2022 10:27:08 +0000 (12:27 +0200)
committerMarge Bot <emma+marge@anholt.net>
Mon, 11 Jul 2022 10:10:00 +0000 (10:10 +0000)
Make sure that the Operand is '1.0.xx'.

Fixes: b03be30e07546b813acc1156407b964e68892beb ('aco: optimize packed fneg')
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17395>

src/amd/compiler/aco_optimizer.cpp

index e7c2cac..d833741 100644 (file)
@@ -3458,7 +3458,8 @@ combine_vop3p(opt_ctx& ctx, aco_ptr<Instruction>& instr)
 
    /* apply clamp */
    if (instr->opcode == aco_opcode::v_pk_mul_f16 && instr->operands[1].constantEquals(0x3C00) &&
-       vop3p->clamp && instr->operands[0].isTemp() && ctx.uses[instr->operands[0].tempId()] == 1) {
+       vop3p->clamp && instr->operands[0].isTemp() && ctx.uses[instr->operands[0].tempId()] == 1 &&
+       !((vop3p->opsel_lo | vop3p->opsel_hi) & 2)) {
 
       ssa_info& info = ctx.info[instr->operands[0].tempId()];
       if (info.is_vop3p() && instr_info.can_use_output_modifiers[(int)info.instr->opcode]) {
@@ -3482,6 +3483,12 @@ combine_vop3p(opt_ctx& ctx, aco_ptr<Instruction>& instr)
          ssa_info& info = ctx.info[op.tempId()];
          if (info.is_vop3p() && info.instr->opcode == aco_opcode::v_pk_mul_f16 &&
              info.instr->operands[1].constantEquals(0x3C00)) {
+
+            VOP3P_instruction* fneg = &info.instr->vop3p();
+
+            if ((fneg->opsel_lo | fneg->opsel_hi) & 2)
+               continue;
+
             Operand ops[3];
             for (unsigned j = 0; j < instr->operands.size(); j++)
                ops[j] = instr->operands[j];
@@ -3489,7 +3496,6 @@ combine_vop3p(opt_ctx& ctx, aco_ptr<Instruction>& instr)
             if (!check_vop3_operands(ctx, instr->operands.size(), ops))
                continue;
 
-            VOP3P_instruction* fneg = &info.instr->vop3p();
             if (fneg->clamp)
                continue;
             instr->operands[i] = fneg->operands[0];