From 0d70716c8a5e4a4dddf777a0c9529ada69f8aee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 12 Nov 2025 12:41:12 +0100 Subject: [PATCH] nir/opt_large_constants: Fix dead deref instructions accessing lowered variables It could happen that unused derefs weren't removed if DCE wasn't called prior to nir_opt_large_constants. Cc: mesa-stable Part-of: --- src/compiler/nir/nir_opt_large_constants.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c index 749429b20a0..963043c08b2 100644 --- a/src/compiler/nir/nir_opt_large_constants.c +++ b/src/compiler/nir/nir_opt_large_constants.c @@ -481,6 +481,10 @@ nir_opt_large_constants(nir_shader *shader, /* Fix up indices after we sorted. */ info->var->index = i; + /* Don't bother with dead variables. */ + if (info->constant_data_size == 0) + info->is_constant = false; + if (!info->is_constant) continue; @@ -529,6 +533,17 @@ nir_opt_large_constants(nir_shader *shader, nir_foreach_block(block, impl) { nir_foreach_instr_safe(instr, block) { + if (instr->type == nir_instr_type_deref) { + /* Ensure all derefs accessing the lowered arrays get removed. */ + nir_deref_instr *deref = nir_instr_as_deref(instr); + if (!nir_deref_mode_is(deref, nir_var_function_temp)) + continue; + + nir_variable *var = nir_deref_instr_get_variable(deref); + if (var && var_infos[var->index].is_constant) + nir_deref_instr_remove_if_unused(deref); + } + if (instr->type != nir_instr_type_intrinsic) continue;