agx: Try to allocate phis compatibly with sources
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 1 Jul 2023 16:56:02 +0000 (12:56 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 20 Jul 2023 15:33:28 +0000 (15:33 +0000)
All shaders affected for thread count are in pubg... by chance the allocation
before used fewer registers than the calculated register demand (I guess because
we're conservative with our vector handling) and so got lucky and got higher
thread count. That shader is also helped massively for instructions.

The halfreg change doesn't matter -- we're not actually increasing register
demand, we're just being more choosy about our registers.

total instructions in shared programs: 1799738 -> 1790901 (-0.49%)
instructions in affected programs: 306081 -> 297244 (-2.89%)
helped: 889
HURT: 14
Instructions are helped.

total bytes in shared programs: 12263290 -> 12210266 (-0.43%)
bytes in affected programs: 2150966 -> 2097942 (-2.47%)
helped: 889
HURT: 14
Bytes are helped.

total halfregs in shared programs: 531981 -> 532130 (0.03%)
halfregs in affected programs: 1925 -> 2074 (7.74%)
helped: 0
HURT: 26
Halfregs are HURT.

total threads in shared programs: 18885184 -> 18884224 (<.01%)
threads in affected programs: 13440 -> 12480 (-7.14%)
helped: 0
HURT: 15

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24258>

src/asahi/compiler/agx_register_allocate.c

index 7c9364f..4c0f5df 100644 (file)
@@ -769,6 +769,18 @@ pick_regs(struct ra_ctx *rctx, agx_instr *I, unsigned d)
 
    unsigned align = count;
 
+   /* Try to allocate phis compatibly with their sources */
+   if (I->op == AGX_OPCODE_PHI) {
+      agx_foreach_ssa_src(I, s) {
+         /* Loop headers have phis with a source preceding the definition */
+         bool may_be_unvisited = rctx->block->loop_header;
+
+         unsigned out;
+         if (try_coalesce_with(rctx, I->src[s], count, may_be_unvisited, &out))
+            return out;
+      }
+   }
+
    /* Try to allocate collects compatibly with their sources */
    if (I->op == AGX_OPCODE_COLLECT) {
       agx_foreach_ssa_src(I, s) {