nir/remove_dead_variables: Properly handle deref casts
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 28 Nov 2018 23:27:57 +0000 (17:27 -0600)
committerJason Ekstrand <jason@jlekstrand.net>
Tue, 8 Jan 2019 00:38:30 +0000 (00:38 +0000)
We already detect any incomplete deref chains (where the deref is used
for something other than another deref or a load/store) and flag the
variable as used thanks to deref_used_for_not_store.  All that's left to
do is to properly skip casts when cleaning up.

Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
src/compiler/nir/nir_remove_dead_variables.c

index fadc51a69778c0115b5e6a18c2dea74760477f55..5e972491a1c2bfcfa031563372975022449ed9a8 100644 (file)
@@ -103,6 +103,9 @@ remove_dead_var_writes(nir_shader *shader, struct set *live)
             switch (instr->type) {
             case nir_instr_type_deref: {
                nir_deref_instr *deref = nir_instr_as_deref(instr);
+               if (deref->deref_type == nir_deref_type_cast &&
+                   !nir_deref_instr_parent(deref))
+                  continue;
 
                nir_variable_mode parent_mode;
                if (deref->deref_type == nir_deref_type_var)