nir: Call nir_metadata_preserve on !progress
[mesa.git] / src / compiler / nir / nir_lower_global_vars_to_local.c
index 4df87aba366fdd93aceed69cca826b0e2fe7b9a0..563fa3960cca95cdb8de76685a5c72556df7da16 100644 (file)
@@ -83,8 +83,11 @@ nir_lower_global_vars_to_local(nir_shader *shader)
       }
    }
 
-   hash_table_foreach(var_func_table, entry) {
-      nir_variable *var = (void *)entry->key;
+   nir_foreach_variable_safe(var, &shader->globals) {
+      struct hash_entry *entry = _mesa_hash_table_search(var_func_table, var);
+      if (!entry)
+         continue;
+
       nir_function_impl *impl = entry->data;
 
       assert(var->data.mode == nir_var_shader_temp);
@@ -105,13 +108,10 @@ nir_lower_global_vars_to_local(nir_shader *shader)
    if (progress)
       nir_fixup_deref_modes(shader);
 
-#ifndef NDEBUG
    nir_foreach_function(function, shader) {
-      if (function->impl) {
-         function->impl->valid_metadata &= ~nir_metadata_not_properly_reset;
-      }
+      if (function->impl)
+         nir_metadata_preserve(function->impl, nir_metadata_all);
    }
-#endif
 
    return progress;
 }