From ce4d2d7faabdf7d2b4c23904caed05fd9c93af2d Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 3 Jun 2026 11:27:28 -0400 Subject: [PATCH] jay/register_allocate: make phi webs conservative Noticed in a bunch of vkpeak shaders which had extra moves in the loop. SIMD16: Totals from 547 (20.66% of 2647) affected shaders: Instrs: 1139024 -> 1131482 (-0.66%); split: -0.68%, +0.02% CodeSize: 15919528 -> 15834088 (-0.54%); split: -0.56%, +0.02% SIMD32: Totals from 523 (19.76% of 2647) affected shaders: Instrs: 1271749 -> 1263534 (-0.65%); split: -0.75%, +0.10% CodeSize: 18180076 -> 18091180 (-0.49%); split: -0.60%, +0.11% Signed-off-by: Alyssa Rosenzweig Part-of: --- src/intel/compiler/jay/jay_register_allocate.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/intel/compiler/jay/jay_register_allocate.c b/src/intel/compiler/jay/jay_register_allocate.c index e2873fea1eb..aa395bd7212 100644 --- a/src/intel/compiler/jay/jay_register_allocate.c +++ b/src/intel/compiler/jay/jay_register_allocate.c @@ -1198,6 +1198,12 @@ local_ra(jay_ra_state *ra, jay_block *block) * Record all phi webs. First initialize the union-find data structure * with all SSA defs in their own singletons, then union together anything * related by a phi. The resulting union-find structure will be the webs. + * + * As a heuristic, we skip the union if the phi source interferes with the phi + * destination (equivalently: the phi source is live-out of the source block). + * These phis could never be coalesced, so the union can only hurt (and it does + * in practice in complex web scenarios). Note this case is only possible + * because we do not lower the input program to conventional SSA (CSSA) form. */ static void construct_phi_webs(struct phi_web_node *web, jay_function *f) @@ -1208,7 +1214,9 @@ construct_phi_webs(struct phi_web_node *web, jay_function *f) jay_foreach_block(f, block) { jay_foreach_phi_src_in_block(block, phi) { - phi_web_union(web, jay_index(phi->src[0]), jay_phi_src_index(phi)); + if (!u_sparse_bitset_test(&block->live_out, jay_index(phi->src[0]))) { + phi_web_union(web, jay_index(phi->src[0]), jay_phi_src_index(phi)); + } } } }