From fd427803375d023d22cbfde207deb65738465cae Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 22 Jul 2022 15:38:08 -0400 Subject: [PATCH] pan/bi: Use builder for MUX -> CSEL opt 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 Part-of: --- src/panfrost/bifrost/bi_schedule.c | 6 +++++- src/panfrost/bifrost/bir.c | 21 ++++++++++---------- src/panfrost/bifrost/compiler.h | 3 ++- src/panfrost/bifrost/valhall/va_lower_isel.c | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/panfrost/bifrost/bi_schedule.c b/src/panfrost/bifrost/bi_schedule.c index f183fd266a8..d121a733fec 100644 --- a/src/panfrost/bifrost/bi_schedule.c +++ b/src/panfrost/bifrost/bi_schedule.c @@ -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; diff --git a/src/panfrost/bifrost/bir.c b/src/panfrost/bifrost/bir.c index 37f8a28c956..8958756c235 100644 --- a/src/panfrost/bifrost/bir.c +++ b/src/panfrost/bifrost/bir.c @@ -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; } diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index beefe645592..61e19dd8276 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -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) diff --git a/src/panfrost/bifrost/valhall/va_lower_isel.c b/src/panfrost/bifrost/valhall/va_lower_isel.c index 62a4db7c51c..ec244d66524 100644 --- a/src/panfrost/bifrost/valhall/va_lower_isel.c +++ b/src/panfrost/bifrost/valhall/va_lower_isel.c @@ -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;