nir: Allow atomics as non-complex uses for var-splitting passes
authorJesse Natalie <jenatali@microsoft.com>
Fri, 19 May 2023 21:40:17 +0000 (14:40 -0700)
committerMarge Bot <emma+marge@anholt.net>
Tue, 13 Jun 2023 00:43:36 +0000 (00:43 +0000)
The var splitting pass can rearrange the variables as long as their
position in memory doesn't matter. For block-arranged variables,
or things like memcpys or casts, the layout matters, but atomics
don't imply anything about the layout of the overall variable, so
don't treat them as "complex" for this use case.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23173>

src/compiler/nir/nir.h
src/compiler/nir/nir_deref.c
src/compiler/nir/nir_split_vars.c

index cf7242f..bdc3d45 100644 (file)
@@ -1811,6 +1811,7 @@ bool nir_deref_instr_is_known_out_of_bounds(nir_deref_instr *instr);
 typedef enum {
    nir_deref_instr_has_complex_use_allow_memcpy_src = (1 << 0),
    nir_deref_instr_has_complex_use_allow_memcpy_dst = (1 << 1),
+   nir_deref_instr_has_complex_use_allow_atomics = (1 << 2),
 } nir_deref_instr_has_complex_use_options;
 
 bool nir_deref_instr_has_complex_use(nir_deref_instr *instr,
index f22a268..2d968de 100644 (file)
@@ -227,6 +227,12 @@ nir_deref_instr_has_complex_use(nir_deref_instr *deref,
                continue;
             return true;
 
+         case nir_intrinsic_deref_atomic:
+         case nir_intrinsic_deref_atomic_swap:
+            if (opts & nir_deref_instr_has_complex_use_allow_atomics)
+               continue;
+            return true;
+
          default:
             return true;
          }
index f1800f6..0d242e8 100644 (file)
@@ -49,7 +49,8 @@ get_complex_used_vars(nir_shader *shader, void *mem_ctx)
              * nir_deref_instr_has_complex_use is recursive.
              */
             if (deref->deref_type == nir_deref_type_var &&
-                nir_deref_instr_has_complex_use(deref, 0))
+                nir_deref_instr_has_complex_use(deref,
+                                                nir_deref_instr_has_complex_use_allow_atomics))
                _mesa_set_add(complex_vars, deref->var);
          }
       }
@@ -1080,7 +1081,7 @@ mark_deref_if_complex(nir_deref_instr *deref,
    if (!(deref->var->data.mode & modes))
       return;
 
-   if (!nir_deref_instr_has_complex_use(deref, 0))
+   if (!nir_deref_instr_has_complex_use(deref, nir_deref_instr_has_complex_use_allow_atomics))
       return;
 
    struct vec_var_usage *usage =