nir: Use the nir_builder _imm helpers in setting up deref offsets.
authorEric Anholt <eric@anholt.net>
Wed, 17 Apr 2019 17:12:48 +0000 (10:12 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 19 Apr 2019 15:45:14 +0000 (08:45 -0700)
When looking at the dEQP nested_struct_array_dynamic_index_fragment code
after lowering, I was horrified at the amount of adding and multiplying by
0 we were doing.  The builder _imm helpers handle that for you so that the
following optimization passes have less work to do.  Plus, it's easier to
read.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_deref.c

index 93412b1eb6de0662b84abaccc1531f9bae4617f3..f1e6eee7745a7a5e69958732a7691250418bcd6c 100644 (file)
@@ -206,16 +206,15 @@ nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
    for (nir_deref_instr **p = &path.path[1]; *p; p++) {
       if ((*p)->deref_type == nir_deref_type_array) {
          nir_ssa_def *index = nir_ssa_for_src(b, (*p)->arr.index, 1);
-         nir_ssa_def *stride =
-            nir_imm_int(b, type_get_array_stride((*p)->type, size_align));
-         offset = nir_iadd(b, offset, nir_imul(b, index, stride));
+         int stride = type_get_array_stride((*p)->type, size_align);
+         offset = nir_iadd(b, offset, nir_imul_imm(b, index, stride));
       } else if ((*p)->deref_type == nir_deref_type_struct) {
          /* p starts at path[1], so this is safe */
          nir_deref_instr *parent = *(p - 1);
          unsigned field_offset =
             struct_type_get_field_offset(parent->type, size_align,
                                          (*p)->strct.index);
-         offset = nir_iadd(b, offset, nir_imm_int(b, field_offset));
+         offset = nir_iadd_imm(b, offset, field_offset);
       } else {
          unreachable("Unsupported deref type");
       }