nir/from_ssa: Don't rewrite derefs destinations to registers
authorJason Ekstrand <jason.ekstrand@intel.com>
Sat, 22 Sep 2018 11:59:22 +0000 (06:59 -0500)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 2 Oct 2018 15:24:56 +0000 (10:24 -0500)
We already call nir_rematerialize_derefs_in_use_blocks_impl prior to
calling nir_lower_ssa_defs_to_regs_block so the assertion that all deref
uses in the block should hold.  This fixes the following CTS test when
SPIR-V optimization recipe 1:

dEQP-VK.glsl.struct.local.loop_nested_struct_array_vertex

Fixes: 606eb56ab9449b "intel/nir: Only lower load/store derefs"
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
src/compiler/nir/nir_from_ssa.c

index 19d4bc3382036d04fdc38992b72504fa07b77f40..08d480f119c6f022d32f7bd6ef8d1f4d8e22c9a7 100644 (file)
@@ -976,6 +976,12 @@ nir_lower_ssa_defs_to_regs_block(nir_block *block)
          mov->dest.dest = nir_dest_for_reg(reg);
          mov->dest.write_mask = (1 << reg->num_components) - 1;
          nir_instr_insert(nir_after_instr(&load->instr), &mov->instr);
+      } else if (instr->type == nir_instr_type_deref) {
+         /* Derefs should always be SSA values, don't rewrite them. */
+         nir_deref_instr *deref = nir_instr_as_deref(instr);
+         nir_foreach_use_safe(use, &deref->dest.ssa)
+            assert(use->parent_instr->block == block);
+         assert(list_empty(&deref->dest.ssa.if_uses));
       } else {
          nir_foreach_dest(instr, dest_replace_ssa_with_reg, &state);
       }