deref_path_contains_coherent_decoration(b_path))
return nir_derefs_may_alias_bit;
+ /* Per SPV_KHR_workgroup_memory_explicit_layout and GL_EXT_shared_memory_block,
+ * shared blocks alias each other.
+ */
+ 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));
+ 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.
* make them live. Only keep them if they are used by some intrinsic.
*/
if ((deref->var->data.mode & (nir_var_function_temp |
- nir_var_shader_temp |
- nir_var_mem_shared)) &&
+ nir_var_shader_temp)) &&
+ !deref_used_for_not_store(deref))
+ return;
+
+ /*
+ * Shared memory blocks (interface type) alias each other, so be
+ * conservative in that case.
+ */
+ if ((deref->var->data.mode & nir_var_mem_shared) &&
+ !glsl_type_is_interface(deref->var->type) &&
!deref_used_for_not_store(deref))
return;