From e362011ccaf1ddbbdc81e5f0e1262edc23f6b034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 4 Feb 2026 09:58:36 +0100 Subject: [PATCH] nir/loop_analyze: also set force_unroll if the array_size is larger than max_trip_count Loop peeling can reduce the trip_count. It is also not necessary that the array_size exactly matches the trip_count. Totals from 54 (0.06% of 84383) affected shaders: (Navi48) MaxWaves: 758 -> 884 (+16.62%) Instrs: 284511 -> 343292 (+20.66%) CodeSize: 1524940 -> 1837996 (+20.53%) VGPRs: 5904 -> 5544 (-6.10%) Scratch: 18432 -> 0 (-inf%) Latency: 7317179 -> 7186789 (-1.78%); split: -1.80%, +0.02% InvThroughput: 1646024 -> 1545357 (-6.12%); split: -6.19%, +0.08% VClause: 5840 -> 6867 (+17.59%); split: -1.92%, +19.50% SClause: 6959 -> 7935 (+14.03%) Copies: 25516 -> 31310 (+22.71%); split: -4.87%, +27.58% Branches: 9205 -> 10571 (+14.84%); split: -3.25%, +18.09% PreSGPRs: 5586 -> 5394 (-3.44%); split: -3.67%, +0.23% PreVGPRs: 5087 -> 4674 (-8.12%); split: -8.18%, +0.06% VALU: 145243 -> 174719 (+20.29%) SALU: 53128 -> 67594 (+27.23%); split: -0.00%, +27.23% VMEM: 8911 -> 10221 (+14.70%); split: -1.41%, +16.11% SMEM: 8519 -> 9509 (+11.62%) VOPD: 419 -> 796 (+89.98%) Part-of: --- src/compiler/nir/nir_loop_analyze.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c index 65737f8f9f3..099c55bffb5 100644 --- a/src/compiler/nir/nir_loop_analyze.c +++ b/src/compiler/nir/nir_loop_analyze.c @@ -1308,7 +1308,7 @@ force_unroll_array_access(loop_info_state *state, nir_deref_instr *deref, { unsigned array_size = find_array_access_via_induction(state, deref, NULL); if (array_size) { - if ((array_size == state->loop->info->max_trip_count) && + if ((array_size >= state->loop->info->max_trip_count) && nir_deref_mode_must_be(deref, nir_var_shader_in | nir_var_shader_out | nir_var_shader_temp |