agx: Add a bitop optimizer pass

Signed-off-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27616>
This commit is contained in:
Mary Guillemard 2024-01-08 19:58:54 +01:00 committed by Marge Bot
parent 2b89eb979e
commit 923767a968
2 changed files with 57 additions and 0 deletions

View file

@ -396,6 +396,33 @@ agx_optimizer_ballot(agx_context *ctx, agx_instr **defs, agx_instr *I)
agx_remove_instruction(I);
}
/*
* Fuse not srcs into bitop.
*/
static void
agx_optimizer_bitop(agx_instr **defs, agx_instr *I)
{
agx_foreach_ssa_src(I, s) {
agx_index src = I->src[s];
agx_instr *def = defs[src.value];
/* Check for not src */
if (def->op != AGX_OPCODE_NOT)
continue;
/* Select new operation */
if (s == 0) {
I->truth_table =
((I->truth_table & 0x5) << 1) | ((I->truth_table & 0xa) >> 1);
} else if (s == 1) {
I->truth_table = ((I->truth_table & 0x3) << 2) | (I->truth_table >> 2);
}
/* Fuse */
I->src[s] = def->src[0];
}
}
static void
agx_optimizer_forward(agx_context *ctx)
{
@ -430,6 +457,8 @@ agx_optimizer_forward(agx_context *ctx)
agx_optimizer_cmpsel(defs, I);
else if (I->op == AGX_OPCODE_BALLOT || I->op == AGX_OPCODE_QUAD_BALLOT)
agx_optimizer_ballot(ctx, defs, I);
else if (I->op == AGX_OPCODE_BITOP)
agx_optimizer_bitop(defs, I);
}
free(defs);

View file

@ -135,6 +135,34 @@ TEST_F(Optimizer, FusedNot)
CASE32(agx_not_to(b, out, agx_or(b, wx, wx)), agx_nor_to(b, out, wx, wx));
CASE32(agx_not_to(b, out, agx_xor(b, wx, wx)), agx_xnor_to(b, out, wx, wx));
CASE32(agx_xor_to(b, out, agx_not(b, wx), agx_not(b, wx)),
agx_xor_to(b, out, wx, wx));
CASE32(agx_xor_to(b, out, agx_not(b, wx), wx), agx_xnor_to(b, out, wx, wx));
CASE32(agx_xor_to(b, out, wx, agx_not(b, wx)), agx_xnor_to(b, out, wx, wx));
CASE32(agx_nand_to(b, out, agx_not(b, wx), agx_not(b, wx)),
agx_or_to(b, out, wx, wx));
CASE32(agx_andn1_to(b, out, agx_not(b, wx), wx), agx_and_to(b, out, wx, wx));
CASE32(agx_andn1_to(b, out, wx, agx_not(b, wx)), agx_nor_to(b, out, wx, wx));
CASE32(agx_andn2_to(b, out, agx_not(b, wx), wx), agx_nor_to(b, out, wx, wx));
CASE32(agx_andn2_to(b, out, wx, agx_not(b, wx)), agx_and_to(b, out, wx, wx));
CASE32(agx_xor_to(b, out, agx_not(b, wx), agx_uniform(8, AGX_SIZE_32)),
agx_xnor_to(b, out, wx, agx_uniform(8, AGX_SIZE_32)));
CASE32(agx_or_to(b, out, agx_immediate(123), agx_not(b, wx)),
agx_orn2_to(b, out, agx_immediate(123), wx));
CASE32(agx_xor_to(b, out, wx, agx_not(b, wy)), agx_xnor_to(b, out, wx, wy));
CASE32(agx_xor_to(b, out, wy, agx_not(b, wx)), agx_xnor_to(b, out, wy, wx));
}
TEST_F(Optimizer, FmulFsatF2F16)