- unsigned num_vars = nir_intrinsic_infos[instr->intrinsic].num_variables;
-
- switch (instr->intrinsic) {
- case nir_intrinsic_copy_var:
- _mesa_set_add(live, instr->variables[1]->var);
- /* Fall through */
- case nir_intrinsic_store_var: {
- /* The first source in both copy_var and store_var is the destination.
- * If the variable is a local that never escapes the shader, then we
- * don't mark it as live for just a store.
- */
- nir_variable_mode mode = instr->variables[0]->var->data.mode;
- if (!(mode & (nir_var_local | nir_var_global | nir_var_shared)))
- _mesa_set_add(live, instr->variables[0]->var);
- break;
- }
-
- /* This pass can't be used on I/O variables after they've been lowered. */
- case nir_intrinsic_load_input:
- assert(!(modes & nir_var_shader_in));
- break;
- case nir_intrinsic_store_output:
- assert(!(modes & nir_var_shader_out));
- break;
-
- default:
- for (unsigned i = 0; i < num_vars; i++) {
- _mesa_set_add(live, instr->variables[i]->var);
+ nir_foreach_use(src, &deref->dest.ssa) {
+ switch (src->parent_instr->type) {
+ case nir_instr_type_deref:
+ if (deref_used_for_not_store(nir_instr_as_deref(src->parent_instr)))
+ return true;
+ break;
+
+ case nir_instr_type_intrinsic: {
+ nir_intrinsic_instr *intrin =
+ nir_instr_as_intrinsic(src->parent_instr);
+ /* The first source of copy and store intrinsics is the deref to
+ * write. Don't record those.
+ */
+ if ((intrin->intrinsic != nir_intrinsic_store_deref &&
+ intrin->intrinsic != nir_intrinsic_copy_deref) ||
+ src != &intrin->src[0])
+ return true;
+ break;