From bb311ce370d2243d9441618a99bce66c837d9444 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Fri, 19 May 2023 14:40:17 -0700 Subject: [PATCH] nir: Allow atomics as non-complex uses for var-splitting passes 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 Part-of: --- src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_deref.c | 6 ++++++ src/compiler/nir/nir_split_vars.c | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index cf7242f1a17..bdc3d45fa68 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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, diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index f22a268b648..2d968de107d 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -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; } diff --git a/src/compiler/nir/nir_split_vars.c b/src/compiler/nir/nir_split_vars.c index f1800f6b5a2..0d242e87c33 100644 --- a/src/compiler/nir/nir_split_vars.c +++ b/src/compiler/nir/nir_split_vars.c @@ -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 =