Module: Mesa
Branch: main
Commit: dfbc8e019234020c7e5fbf6232182c94d3dc478e
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=dfbc8e019234020c7e5fbf6232182c94d3dc478e

Author: Rhys Perry <[email protected]>
Date:   Wed Nov 16 18:10:38 2022 +0000

aco: change order in combine_minmax()

Prepare for future optimizations.

Signed-off-by: Rhys Perry <[email protected]>
Reviewed-by: Daniel Schürmann <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>

---

 src/amd/compiler/aco_optimizer.cpp        | 10 +++++-----
 src/amd/compiler/tests/test_optimizer.cpp |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/amd/compiler/aco_optimizer.cpp 
b/src/amd/compiler/aco_optimizer.cpp
index 822ea9967fb..1902acee531 100644
--- a/src/amd/compiler/aco_optimizer.cpp
+++ b/src/amd/compiler/aco_optimizer.cpp
@@ -2625,22 +2625,22 @@ bool
 combine_minmax(opt_ctx& ctx, aco_ptr<Instruction>& instr, aco_opcode opposite, 
aco_opcode minmax3)
 {
    /* TODO: this can handle SDWA min/max instructions by using opsel */
-   if (combine_three_valu_op(ctx, instr, instr->opcode, minmax3, "012", 1 | 2))
+   if (combine_three_valu_op(ctx, instr, instr->opcode, minmax3, "120", 1 | 2))
       return true;
 
-   /* min(-max(a, b), c) -> min3(c, -a, -b) *
-    * max(-min(a, b), c) -> max3(c, -a, -b) */
+   /* min(-max(a, b), c) -> min3(-a, -b, c) *
+    * max(-min(a, b), c) -> max3(-a, -b, c) */
    for (unsigned swap = 0; swap < 2; swap++) {
       Operand operands[3];
       bool neg[3], abs[3], clamp, precise;
       uint8_t opsel = 0, omod = 0;
       bool inbetween_neg;
-      if (match_op3_for_vop3(ctx, instr->opcode, opposite, instr.get(), swap, 
"012", operands, neg,
+      if (match_op3_for_vop3(ctx, instr->opcode, opposite, instr.get(), swap, 
"120", operands, neg,
                              abs, &opsel, &clamp, &omod, &inbetween_neg, NULL, 
NULL, &precise) &&
           inbetween_neg) {
          ctx.uses[instr->operands[swap].tempId()]--;
+         neg[0] = !neg[0];
          neg[1] = !neg[1];
-         neg[2] = !neg[2];
          create_vop3_for_op3(ctx, minmax3, instr, operands, neg, abs, opsel, 
clamp, omod);
          return true;
       }
diff --git a/src/amd/compiler/tests/test_optimizer.cpp 
b/src/amd/compiler/tests/test_optimizer.cpp
index 10593783e7f..7b6fd01b5ef 100644
--- a/src/amd/compiler/tests/test_optimizer.cpp
+++ b/src/amd/compiler/tests/test_optimizer.cpp
@@ -718,14 +718,14 @@ BEGIN_TEST(optimize.minmax)
       if (!setup_cs("v1", (amd_gfx_level)i))
          continue;
 
-      //! v1: %res0 = v_max3_f32 0, -0, %a
+      //! v1: %res0 = v_max3_f32 -0, %a, 0
       //! p_unit_test 0, %res0
       Temp xor0 = fneg(inputs[0]);
       Temp min = bld.vop2(aco_opcode::v_min_f32, bld.def(v1), Operand::zero(), 
xor0);
       Temp xor1 = fneg(min);
       writeout(0, bld.vop2(aco_opcode::v_max_f32, bld.def(v1), 
Operand::zero(), xor1));
 
-      //! v1: %res1 = v_max3_f32 0, -0, -%a
+      //! v1: %res1 = v_max3_f32 -0, -%a, 0
       //! p_unit_test 1, %res1
       min = bld.vop2(aco_opcode::v_min_f32, bld.def(v1), Operand::zero(), 
Operand(inputs[0]));
       xor1 = fneg(min);

Reply via email to