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>
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;
*/
#include "compiler.h"
+#include "bi_builder.h"
bool
bi_has_arg(const bi_instr *ins, bi_index arg)
}
}
-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;
}
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);
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)
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;