From c50e0934e7d5f1105dd3a4e6402dca75d45c5e65 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sun, 4 Aug 2024 13:08:06 -0400 Subject: [PATCH] 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 Part-of: --- src/asahi/compiler/agx_optimizer.c | 6 +++--- src/asahi/compiler/test/test-optimizer.cpp | 24 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/asahi/compiler/agx_optimizer.c b/src/asahi/compiler/agx_optimizer.c index 915ebb804d6..ac49703b072 100644 --- a/src/asahi/compiler/agx_optimizer.c +++ b/src/asahi/compiler/agx_optimizer.c @@ -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; diff --git a/src/asahi/compiler/test/test-optimizer.cpp b/src/asahi/compiler/test/test-optimizer.cpp index 4dbca759cf0..77b09c120b5 100644 --- a/src/asahi/compiler/test/test-optimizer.cpp +++ b/src/asahi/compiler/test/test-optimizer.cpp @@ -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)); +}