pan/bi: Use builder for MUX -> CSEL opt
authorAlyssa Rosenzweig <alyssa@collabora.com>
Fri, 22 Jul 2022 19:38:08 +0000 (15:38 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Sep 2022 16:03:23 +0000 (16:03 +0000)
This is yet another case where we add a source, which will require reallocation.
It's easy enough to rebuild the instruction here.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17794>

src/panfrost/bifrost/bi_schedule.c
src/panfrost/bifrost/bir.c
src/panfrost/bifrost/compiler.h
src/panfrost/bifrost/valhall/va_lower_isel.c

index f183fd2..d121a73 100644 (file)
@@ -1299,7 +1299,11 @@ bi_take_instr(bi_context *ctx, struct bi_worklist st,
                 instr->src[2] = bi_zero();
                 instr->nr_srcs = 3;
         } else if (fma && bi_can_replace_with_csel(instr)) {
-                bi_replace_mux_with_csel(instr, false);
+                bi_builder b = bi_init_builder(ctx, bi_before_instr(instr));
+                bi_instr *csel = bi_csel_from_mux(&b, instr, false);
+
+                bi_remove_instruction(instr);
+                instr = csel;
         }
 
         return instr;
index 37f8a28..8958756 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "compiler.h"
+#include "bi_builder.h"
 
 bool
 bi_has_arg(const bi_instr *ins, bi_index arg)
@@ -287,19 +288,17 @@ bi_csel_for_mux(bool must_sign, bool b32, enum bi_mux mux)
         }
 }
 
-void
-bi_replace_mux_with_csel(bi_instr *I, bool must_sign)
+bi_instr *
+bi_csel_from_mux(bi_builder *b, const bi_instr *I, bool must_sign)
 {
         assert(I->op == BI_OPCODE_MUX_I32 || I->op == BI_OPCODE_MUX_V2I16);
-        I->op = bi_csel_for_mux(must_sign, I->op == BI_OPCODE_MUX_I32, I->mux);
-        I->cmpf = (I->mux == BI_MUX_NEG) ? BI_CMPF_LT : BI_CMPF_EQ;
-        I->mux = 0;
 
-        bi_index vTrue = I->src[0], vFalse = I->src[1], cond = I->src[2];
+        /* Build a new CSEL */
+        enum bi_cmpf cmpf = (I->mux == BI_MUX_NEG) ? BI_CMPF_LT : BI_CMPF_EQ;
+        bi_instr *csel = bi_csel_u32_to(b, I->dest[0], I->src[2], bi_zero(),
+                                        I->src[0], I->src[1], cmpf);
 
-        I->src[0] = cond;
-        I->src[1] = bi_zero();
-        I->src[2] = vTrue;
-        I->src[3] = vFalse;
-        I->nr_srcs = 4;
+        /* Fixup the opcode and use it */
+        csel->op = bi_csel_for_mux(must_sign, I->op == BI_OPCODE_MUX_I32, I->mux);
+        return csel;
 }
index beefe64..61e19dd 100644 (file)
@@ -1098,7 +1098,6 @@ bool bi_side_effects(const bi_instr *I);
 bool bi_reconverge_branches(bi_block *block);
 
 bool bi_can_replace_with_csel(bi_instr *I);
-void bi_replace_mux_with_csel(bi_instr *I, bool must_sign);
 
 void bi_print_instr(const bi_instr *I, FILE *fp);
 void bi_print_slots(bi_registers *regs, FILE *fp);
@@ -1400,6 +1399,8 @@ bi_builder_insert(bi_cursor *cursor, bi_instr *I)
     unreachable("Invalid cursor option");
 }
 
+bi_instr *bi_csel_from_mux(bi_builder *b, const bi_instr *I, bool must_sign);
+
 /* Read back power-efficent garbage, TODO maybe merge with null? */
 static inline bi_index
 bi_dontcare(bi_builder *b)
index 62a4db7..ec244d6 100644 (file)
@@ -111,7 +111,7 @@ lower(bi_builder *b, bi_instr *I)
    case BI_OPCODE_MUX_I32:
    case BI_OPCODE_MUX_V2I16:
       if (bi_can_replace_with_csel(I))
-         bi_replace_mux_with_csel(I, true);
+         return bi_csel_from_mux(b, I, true);
 
       return NULL;