nir: Use var->data.mode instead of deref->mode in a few cases

We already have the variable so we know the mode exactly.  Just use that
instead of the deref mode.  If these paths ever have to handle variable
pointers (not likely since they're OpenGL-specific), we can fix them to
handle crazy deref modes then.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6332>
diff --git a/src/compiler/glsl/gl_nir_lower_images.c b/src/compiler/glsl/gl_nir_lower_images.c
index 632af71..ee74004 100644
--- a/src/compiler/glsl/gl_nir_lower_images.c
+++ b/src/compiler/glsl/gl_nir_lower_images.c
@@ -87,7 +87,7 @@
       return false;
    }
 
-   bool bindless = deref->mode != nir_var_uniform || var->data.bindless;
+   bool bindless = var->data.mode != nir_var_uniform || var->data.bindless;
    if (bindless_only && !bindless)
       return false;
 
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index cddfaada1..4c29aa4 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -634,8 +634,8 @@
       nir_ssa_def *offset;
       nir_ssa_def *vertex_index = NULL;
       unsigned component_offset = var->data.location_frac;
-      bool bindless_type_size = mode == nir_var_shader_in ||
-                                mode == nir_var_shader_out ||
+      bool bindless_type_size = var->data.mode == nir_var_shader_in ||
+                                var->data.mode == nir_var_shader_out ||
                                 var->data.bindless;
 
      if (nir_deref_instr_is_known_out_of_bounds(deref)) {
diff --git a/src/compiler/nir/nir_lower_io_to_scalar.c b/src/compiler/nir/nir_lower_io_to_scalar.c
index 5746f9f..77524ba 100644
--- a/src/compiler/nir/nir_lower_io_to_scalar.c
+++ b/src/compiler/nir/nir_lower_io_to_scalar.c
@@ -314,11 +314,11 @@
       return false;
 
    nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
-   nir_variable_mode mode = deref->mode;
-   if (!(mode & state->mask))
+   if (!(deref->mode & state->mask))
       return false;
 
    nir_variable *var = nir_deref_instr_get_variable(deref);
+   nir_variable_mode mode = var->data.mode;
 
    /* TODO: add patch support */
    if (var->data.patch)
diff --git a/src/compiler/nir/nir_lower_io_to_vector.c b/src/compiler/nir/nir_lower_io_to_vector.c
index 022f9e2..be87c4b 100644
--- a/src/compiler/nir/nir_lower_io_to_vector.c
+++ b/src/compiler/nir/nir_lower_io_to_vector.c
@@ -442,10 +442,10 @@
 
             const unsigned loc = get_slot(old_var);
             const unsigned old_frac = old_var->data.location_frac;
-            nir_variable *new_var = old_deref->mode == nir_var_shader_in ?
+            nir_variable *new_var = old_var->data.mode == nir_var_shader_in ?
                                     new_inputs[loc][old_frac] :
                                     new_outputs[loc][old_frac];
-            bool flat = old_deref->mode == nir_var_shader_in ?
+            bool flat = old_var->data.mode == nir_var_shader_in ?
                         flat_inputs[loc] : flat_outputs[loc];
             if (!new_var)
                break;
diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c
index 3ee67b6..f4ef4d3 100644
--- a/src/compiler/nir/nir_opt_large_constants.c
+++ b/src/compiler/nir/nir_opt_large_constants.c
@@ -208,7 +208,7 @@
              */
             nir_deref_instr *deref = nir_instr_as_deref(instr);
             if (deref->deref_type == nir_deref_type_var &&
-                deref->mode == nir_var_function_temp &&
+                deref->var->data.mode == nir_var_function_temp &&
                 nir_deref_instr_has_complex_use(deref))
                var_infos[deref->var->index].is_constant = false;
             continue;
diff --git a/src/compiler/nir/nir_remove_dead_variables.c b/src/compiler/nir/nir_remove_dead_variables.c
index 5037b86..3d1df3a 100644
--- a/src/compiler/nir/nir_remove_dead_variables.c
+++ b/src/compiler/nir/nir_remove_dead_variables.c
@@ -70,8 +70,9 @@
    /* If it's not a local that never escapes the shader, then any access at
     * all means we need to keep it alive.
     */
-   assert(deref->mode == deref->var->data.mode);
-   if (!(deref->mode & (nir_var_function_temp | nir_var_shader_temp | nir_var_mem_shared)) ||
+   if (!(deref->var->data.mode & (nir_var_function_temp |
+                                  nir_var_shader_temp |
+                                  nir_var_mem_shared)) ||
        deref_used_for_not_store(deref))
       _mesa_set_add(live, deref->var);
 }
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c
index eddf438..81c2b5d 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -189,7 +189,7 @@
       nir_variable *var = deref ? nir_deref_instr_get_variable(deref) : NULL;
 
       if (var) {
-         if (deref->mode != nir_var_uniform || var->data.bindless)
+         if (var->data.mode != nir_var_uniform || var->data.bindless)
             info->uses_bindless_samplers = true;
       }
    } else if (instr->type == nir_instr_type_intrinsic) {