From d85eb51e17cef033e3d12723672b8629290e0ffd Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 16 Apr 2026 10:22:17 -0400 Subject: [PATCH] jay/register_allocate: don't depend on indexing this can get messed up by optimizations. Totals: Instrs: 2768612 -> 2764317 (-0.16%); split: -0.29%, +0.13% CodeSize: 44367648 -> 44300352 (-0.15%); split: -0.28%, +0.13% Totals from 867 (32.75% of 2647) affected shaders: Instrs: 1694745 -> 1690450 (-0.25%); split: -0.47%, +0.22% CodeSize: 27387648 -> 27320352 (-0.25%); split: -0.46%, +0.21% Signed-off-by: Alyssa Rosenzweig Part-of: --- .../compiler/jay/jay_register_allocate.c | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/intel/compiler/jay/jay_register_allocate.c b/src/intel/compiler/jay/jay_register_allocate.c index bb015e3daaf..5221883af29 100644 --- a/src/intel/compiler/jay/jay_register_allocate.c +++ b/src/intel/compiler/jay/jay_register_allocate.c @@ -1623,21 +1623,28 @@ jay_register_allocate_function(jay_function *f) */ construct_phi_webs(ra.phi_web, f); + /* We track the order of instructions in the program to inform coalescing */ + uint32_t *order = linear_alloc_array(lin_ctx, uint32_t, f->ssa_alloc); + uint32_t order_counter = 0; + jay_foreach_inst_in_func(f, block, I) { + jay_foreach_dst_index(I, _, index) { + order[index] = order_counter++; + } + jay_foreach_src_index(I, s, c, index) { /* We check repr==0 to try to coalesce with the first vector use, as * the closest to the definition. This heuristic reduces shuffling. */ if (jay_num_values(I->src[s]) > 1 && !ra.affinities[index].repr) { - uint32_t repr = UINT_MAX, repr_c = 0; + uint32_t repr = UINT_MAX, repr_c = 0, best_order = UINT_MAX; - /* Pick the representative with the smallest index, as it most - * likely dominates the other components. - */ - jay_foreach_comp(I->src[s], j) { - if (jay_channel(I->src[s], j) < repr) { - repr = jay_channel(I->src[s], j); + /* Pick the earliest representative to maximize freedom */ + jay_foreach_index(I->src[s], j, index) { + if (order[index] < best_order) { + repr = index; repr_c = j; + best_order = order[index]; } }