Mesa (staging/22.1): nir/deref: Re-arrange variable checks in compare_deref_paths
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jun 16 21:43:16 UTC 2022
Module: Mesa
Branch: staging/22.1
Commit: 981fd932245e3b6c94efb53ce914788c05e17edb
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=981fd932245e3b6c94efb53ce914788c05e17edb
Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date: Fri Jun 3 15:06:46 2022 -0500
nir/deref: Re-arrange variable checks in compare_deref_paths
Instead of having a bunch of mode checks as special cases, assert that
the modes equal and then switch on the mode. This should make the
special cases a bit easier to understand. Handling of `a_var == b_var`
looks redundant now but it won't be in the next patch.
Tested-by: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Reviewed-by: M Henning <drawoc at darkrefraction.com>
Reviewed-by: Rhys Perry <pendingchaos02 at gmail.com>
Cc: mesa-stable at lists.freedesktop.org
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16894>
(cherry picked from commit 0ad2dfe942dff42ea230786c23502d208b50928f)
---
.pick_status.json | 2 +-
src/compiler/nir/nir_deref.c | 51 +++++++++++++++++++++++++++-----------------
2 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index e463de3866b..60dfa80cd71 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -4009,7 +4009,7 @@
"description": "nir/deref: Re-arrange variable checks in compare_deref_paths",
"nominated": true,
"nomination_type": 0,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": null
},
diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c
index 95bb5c9a474..f40e7b71500 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -573,32 +573,43 @@ nir_compare_deref_paths(nir_deref_path *a_path,
return nir_derefs_may_alias_bit;
if (a_path->path[0]->deref_type == nir_deref_type_var) {
- if (a_path->path[0]->var != b_path->path[0]->var) {
- /* Shader and function temporaries aren't backed by memory so two
- * distinct variables never alias.
- */
- static const nir_variable_mode temp_var_modes =
- nir_var_shader_temp | nir_var_function_temp;
- if (!(a_path->path[0]->modes & ~temp_var_modes) ||
- !(b_path->path[0]->modes & ~temp_var_modes))
- return nir_derefs_do_not_alias;
+ const nir_variable *a_var = a_path->path[0]->var;
+ const nir_variable *b_var = b_path->path[0]->var;
+
+ /* If we got here, the two variables must have the same mode. The
+ * only way modes_may_alias() can return true for two different modes
+ * is if one is global and the other ssbo. However, Global variables
+ * only exist in OpenCL and SSBOs don't exist there. No API allows
+ * both for variables.
+ */
+ assert(a_var->data.mode == b_var->data.mode);
+
+ switch (a_var->data.mode) {
+ case nir_var_mem_shared:
+ if (a_var == b_var)
+ break;
- /* Per SPV_KHR_workgroup_memory_explicit_layout and GL_EXT_shared_memory_block,
- * shared blocks alias each other.
+ /* Per SPV_KHR_workgroup_memory_explicit_layout and
+ * GL_EXT_shared_memory_block, shared blocks alias each other.
+ * We will have either all blocks or all non-blocks.
*/
- if (a_path->path[0]->modes & nir_var_mem_shared &&
- b_path->path[0]->modes & nir_var_mem_shared &&
- (glsl_type_is_interface(a_path->path[0]->var->type) ||
- glsl_type_is_interface(b_path->path[0]->var->type))) {
- assert(glsl_type_is_interface(a_path->path[0]->var->type) &&
- glsl_type_is_interface(b_path->path[0]->var->type));
+ if (glsl_type_is_interface(a_var->type) ||
+ glsl_type_is_interface(b_var->type)) {
+ assert(glsl_type_is_interface(a_var->type) &&
+ glsl_type_is_interface(b_var->type));
return nir_derefs_may_alias_bit;
}
- /* If we can chase the deref all the way back to the variable and
- * they're not the same variable and at least one is not declared
- * coherent, we know they can't possibly alias.
+ /* Otherwise, distinct shared vars don't alias */
+ return nir_derefs_do_not_alias;
+
+ default:
+ /* For any other variable types, if we can chase them back to the
+ * variable, and the variables are different, they don't alias.
*/
+ if (a_var == b_var)
+ break;
+
return nir_derefs_do_not_alias;
}
} else {
More information about the mesa-commit
mailing list