nir/builder: Cast array indices in build_deref_follower
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 5 Mar 2019 22:06:31 +0000 (16:06 -0600)
committerJason Ekstrand <jason@jlekstrand.net>
Thu, 7 Mar 2019 21:20:30 +0000 (21:20 +0000)
There's no guarantee when build_deref_follower is called that the two
derefs have the same bit size destination.  Insert a cast on the array
index in case we have differing bit sizes.  While we're here, insert
some asserts in build_deref_array and build_deref_ptr_as_array.  The
validator will catch violations here but they're easier to debug if we
catch them while building.

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/compiler/nir/nir_builder.h

index 42004a2fe54b33de294e4943c27a5da4b59b8282..56e76ddcb3979f4424d26e96c21dac8cfc1f0c28 100644 (file)
@@ -824,6 +824,8 @@ nir_build_deref_array(nir_builder *build, nir_deref_instr *parent,
           glsl_type_is_matrix(parent->type) ||
           glsl_type_is_vector(parent->type));
 
+   assert(index->bit_size == parent->dest.ssa.bit_size);
+
    nir_deref_instr *deref =
       nir_deref_instr_create(build->shader, nir_deref_type_array);
 
@@ -849,6 +851,8 @@ nir_build_deref_ptr_as_array(nir_builder *build, nir_deref_instr *parent,
           parent->deref_type == nir_deref_type_ptr_as_array ||
           parent->deref_type == nir_deref_type_cast);
 
+   assert(index->bit_size == parent->dest.ssa.bit_size);
+
    nir_deref_instr *deref =
       nir_deref_instr_create(build->shader, nir_deref_type_ptr_as_array);
 
@@ -965,7 +969,9 @@ nir_build_deref_follower(nir_builder *b, nir_deref_instr *parent,
 
       if (leader->deref_type == nir_deref_type_array) {
          assert(leader->arr.index.is_ssa);
-         return nir_build_deref_array(b, parent, leader->arr.index.ssa);
+         nir_ssa_def *index = nir_i2i(b, leader->arr.index.ssa,
+                                         parent->dest.ssa.bit_size);
+         return nir_build_deref_array(b, parent, index);
       } else {
          return nir_build_deref_array_wildcard(b, parent);
       }