From 33c8dc4f1839b350cc763074d269064ea9ac4365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Ondra=C4=8Dka?= Date: Mon, 17 Jun 2024 11:49:01 +0200 Subject: [PATCH] nir/nir_group_loads: reduce chance of max_distance check overflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Helps for the case when max_distance is set to ~0, where the pass would now only create groups of two loads together due to overflow. Found while experimenting with this pass on r300, however the only driver currently affected is i915. With i915 this change gains around 20 shaders in my small shader-db (most notably some GLMark2, Unigine Tropics, Tesseract, Amnesia) at the expense of increased register pressure in few other cases. I'm assuming this is a good deal for such old HW, and this seems like what was intended when the pass was introduced to i915, but anyway this could be tweaked further driver side with a more optimized max_distance value. Only shader-db tested. Relevant i915 shader-db stats (lpt): total tex_indirect in shared programs: 1529 -> 1493 (-2.35%) tex_indirect in affected programs: 96 -> 60 (-37.50%) helped: 29 HURT: 2 total temps in shared programs: 3015 -> 3200 (6.14%) temps in affected programs: 465 -> 650 (39.78%) helped: 1 HURT: 91 GAINED: 20 Signed-off-by: Pavel Ondračka Reviewed-by: Marek Olšák Tested-by: GKraats Fixes: 33b4eb149ea7 Part-of: --- src/compiler/nir/nir_group_loads.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_group_loads.c b/src/compiler/nir/nir_group_loads.c index eae6431643e..bdc689136db 100644 --- a/src/compiler/nir/nir_group_loads.c +++ b/src/compiler/nir/nir_group_loads.c @@ -289,8 +289,9 @@ static void handle_load_range(nir_instr **first, nir_instr **last, nir_instr *current, unsigned max_distance) { + assert(!current || !*first || current->index >= (*first)->index); if (*first && *last && - (!current || current->index > (*first)->index + max_distance)) { + (!current || current->index - (*first)->index > max_distance)) { assert(*first != *last); group_loads(*first, *last); set_instr_indices((*first)->block);