agx: let if-fusing opts interact

total instructions in shared programs: 2115031 -> 2114800 (-0.01%)
instructions in affected programs: 46937 -> 46706 (-0.49%)
helped: 147
HURT: 30
Instructions are helped.

total alu in shared programs: 1669893 -> 1669655 (-0.01%)
alu in affected programs: 38134 -> 37896 (-0.62%)
helped: 147
HURT: 28
Alu are helped.

total fscib in shared programs: 1666017 -> 1665779 (-0.01%)
fscib in affected programs: 38134 -> 37896 (-0.62%)
helped: 147
HURT: 28
Fscib are helped.

total bytes in shared programs: 14059380 -> 14057364 (-0.01%)
bytes in affected programs: 306294 -> 304278 (-0.66%)
helped: 147
HURT: 28
Bytes are helped.

total regs in shared programs: 656483 -> 656491 (<.01%)
regs in affected programs: 257 -> 265 (3.11%)
helped: 3
HURT: 4
Inconclusive result (value mean confidence interval includes 0).

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30633>
This commit is contained in:
Alyssa Rosenzweig 2024-08-04 13:08:06 -04:00
parent 64239ac12c
commit c50e0934e7
2 changed files with 27 additions and 3 deletions

View file

@ -292,14 +292,14 @@ agx_optimizer_copyprop(agx_context *ctx, agx_instr **defs, agx_instr *I)
/*
* Fuse conditions into if. Specifically, acts on if_icmp and fuses:
*
* if_icmp(cmp(x, y, *), 0, ne) -> if_cmp(x, y, *)
* if_icmp(cmp(x, y, *), 0, ne/eq) -> if_cmp(x, y, *)
*/
static void
agx_optimizer_if_cmp(agx_instr **defs, agx_instr *I)
{
/* Check for unfused if */
if (!agx_is_equiv(I->src[1], agx_zero()) || I->icond != AGX_ICOND_UEQ ||
!I->invert_cond || I->src[0].type != AGX_INDEX_NORMAL)
I->src[0].type != AGX_INDEX_NORMAL)
return;
/* Check for condition */
@ -310,7 +310,7 @@ agx_optimizer_if_cmp(agx_instr **defs, agx_instr *I)
/* Fuse */
I->src[0] = def->src[0];
I->src[1] = def->src[1];
I->invert_cond = def->invert_cond;
I->invert_cond = def->invert_cond ^ !I->invert_cond;
if (def->op == AGX_OPCODE_ICMP) {
I->op = AGX_OPCODE_IF_ICMP;

View file

@ -365,3 +365,27 @@ TEST_F(Optimizer, IfInverted)
1, AGX_ICOND_UEQ, false, NULL),
agx_if_icmp(b, hx, agx_zero(), 1, AGX_ICOND_UEQ, true, NULL));
}
TEST_F(Optimizer, IfInvertedCondition)
{
CASE_NO_RETURN(
agx_if_icmp(
b,
agx_xor(b, agx_icmp(b, wx, wy, AGX_ICOND_UEQ, true), agx_immediate(1)),
agx_zero(), 1, AGX_ICOND_UEQ, true, NULL),
agx_if_icmp(b, wx, wy, 1, AGX_ICOND_UEQ, false, NULL));
CASE_NO_RETURN(
agx_if_icmp(
b,
agx_xor(b, agx_fcmp(b, wx, wy, AGX_FCOND_EQ, true), agx_immediate(1)),
agx_zero(), 1, AGX_ICOND_UEQ, true, NULL),
agx_if_fcmp(b, wx, wy, 1, AGX_FCOND_EQ, false, NULL));
CASE_NO_RETURN(
agx_if_icmp(
b,
agx_xor(b, agx_fcmp(b, hx, hy, AGX_FCOND_LT, false), agx_immediate(1)),
agx_zero(), 1, AGX_ICOND_UEQ, true, NULL),
agx_if_fcmp(b, hx, hy, 1, AGX_FCOND_LT, true, NULL));
}