nir: Take call instruction into account in copy_prop_vars
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Sat, 15 Sep 2018 01:17:51 +0000 (18:17 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Tue, 16 Oct 2018 00:29:46 +0000 (17:29 -0700)
Calls are not used yet (functions are inlined), but since new code is
already taking them into account, do it here too.  The convention here
and in other places is that no writable memory is assumed to remain
unchanged, as well as global variables.

Also, explicitly state the modes affected (instead of using the
reverse logic) in one of the apply_for_barrier_modes calls.

Suggested by Jason.

v2: Consider local vars used by a call to be conservative, SPIR-V has
    such cases. (Jason)

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_opt_copy_prop_vars.c

index 5276aa176d82deed01218b2f0a6bd77287fc491c..b3f4e86bab111eb0109f36a9d4fac2d32636c8b1 100644 (file)
@@ -404,6 +404,15 @@ copy_prop_vars_block(struct copy_prop_var_state *state,
       copy_entry_remove(state, iter);
 
    nir_foreach_instr_safe(instr, block) {
+      if (instr->type == nir_instr_type_call) {
+         apply_barrier_for_modes(copies, nir_var_shader_out |
+                                         nir_var_global |
+                                         nir_var_local |
+                                         nir_var_shader_storage |
+                                         nir_var_shared);
+         continue;
+      }
+
       if (instr->type != nir_instr_type_intrinsic)
          continue;
 
@@ -411,12 +420,9 @@ copy_prop_vars_block(struct copy_prop_var_state *state,
       switch (intrin->intrinsic) {
       case nir_intrinsic_barrier:
       case nir_intrinsic_memory_barrier:
-         /* If we hit a barrier, we need to trash everything that may possibly
-          * be accessible to another thread.  Locals, globals, and things of
-          * the like are safe, however.
-          */
-         apply_barrier_for_modes(state, ~(nir_var_local | nir_var_global |
-                                          nir_var_shader_in | nir_var_uniform));
+         apply_barrier_for_modes(copies, nir_var_shader_out |
+                                         nir_var_shader_storage |
+                                         nir_var_shared);
          break;
 
       case nir_intrinsic_emit_vertex: