From 73da872a66deef2bc0923619b8388494527ad136 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 1 Jul 2023 12:56:02 -0400 Subject: [PATCH] agx: Try to allocate phis compatibly with sources 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 Part-of: --- src/asahi/compiler/agx_register_allocate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/asahi/compiler/agx_register_allocate.c b/src/asahi/compiler/agx_register_allocate.c index 7c9364f629e..4c0f5df9cc5 100644 --- a/src/asahi/compiler/agx_register_allocate.c +++ b/src/asahi/compiler/agx_register_allocate.c @@ -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) {