nir/builder: Add a nir_imm_zero helper
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 2 Apr 2019 02:31:26 +0000 (21:31 -0500)
committerKarol Herbst <kherbst@redhat.com>
Sun, 14 Apr 2019 20:25:56 +0000 (22:25 +0200)
v2: replace nir_zero_vec with nir_imm_zero (Karol Herbst)

Reviewed-by: Karol Herbst <kherbst@redhat.com>
src/compiler/nir/nir_builder.h
src/compiler/nir/nir_lower_int64.c
src/compiler/nir/nir_lower_io.c
src/intel/compiler/brw_nir_lower_image_load_store.c

index 66a028bac97b73a152733a4b5eb14a618d7a80ba..9ee58dafd2183f8578aaa7f17d17bb2b08fa9934 100644 (file)
@@ -208,6 +208,19 @@ nir_build_imm(nir_builder *build, unsigned num_components,
    return &load_const->def;
 }
 
+static inline nir_ssa_def *
+nir_imm_zero(nir_builder *build, unsigned num_components, unsigned bit_size)
+{
+   nir_load_const_instr *load_const =
+      nir_load_const_instr_create(build->shader, num_components, bit_size);
+
+   /* nir_load_const_instr_create uses rzalloc so it's already zero */
+
+   nir_builder_instr_insert(build, &load_const->instr);
+
+   return &load_const->def;
+}
+
 static inline nir_ssa_def *
 nir_imm_bool(nir_builder *build, bool x)
 {
index e7d361da6da7aab948d472353127d9351c8b5bc5..b3b78c6649a14de1c5a35cbdafd7d99c0cd9f303 100644 (file)
@@ -493,9 +493,8 @@ lower_udiv64_mod64(nir_builder *b, nir_ssa_def *n, nir_ssa_def *d,
    nir_ssa_def *d_lo = nir_unpack_64_2x32_split_x(b, d);
    nir_ssa_def *d_hi = nir_unpack_64_2x32_split_y(b, d);
 
-   nir_const_value v = { .u32 = { 0, 0, 0, 0 } };
-   nir_ssa_def *q_lo = nir_build_imm(b, n->num_components, 32, v);
-   nir_ssa_def *q_hi = nir_build_imm(b, n->num_components, 32, v);
+   nir_ssa_def *q_lo = nir_imm_zero(b, n->num_components, 32);
+   nir_ssa_def *q_hi = nir_imm_zero(b, n->num_components, 32);
 
    nir_ssa_def *n_hi_before_if = n_hi;
    nir_ssa_def *q_hi_before_if = q_hi;
index 331ecc08324ed88e52d5fdc3f6cecbd2c12e5ede..c666fe16f7b22e87f8908d9a4160391ffdd7a779 100644 (file)
@@ -754,10 +754,8 @@ build_explicit_io_load(nir_builder *b, nir_intrinsic_instr *intrin,
        * as to what we can do with an OOB read.  Unfortunately, returning
        * undefined values isn't one of them so we return an actual zero.
        */
-      nir_const_value zero_val;
-      memset(&zero_val, 0, sizeof(zero_val));
-      nir_ssa_def *zero = nir_build_imm(b, load->num_components,
-                                        load->dest.ssa.bit_size, zero_val);
+      nir_ssa_def *zero = nir_imm_zero(b, load->num_components,
+                                          load->dest.ssa.bit_size);
 
       const unsigned load_size =
          (load->dest.ssa.bit_size / 8) * load->num_components;
index 48b98bc57bdaa32f18ae280625fc2bc35c5dbfd5..c23f64fb33875a57aad62ec72df0c701ce266de6 100644 (file)
@@ -312,15 +312,6 @@ get_format_info(enum isl_format fmt)
    };
 }
 
-static nir_ssa_def *
-nir_zero_vec(nir_builder *b, unsigned num_components)
-{
-   nir_const_value v;
-   memset(&v, 0, sizeof(v));
-
-   return nir_build_imm(b, num_components, 32, v);
-}
-
 static nir_ssa_def *
 convert_color_for_load(nir_builder *b, const struct gen_device_info *devinfo,
                        nir_ssa_def *color,
@@ -498,7 +489,7 @@ lower_image_load_instr(nir_builder *b,
 
       nir_push_else(b, NULL);
 
-      nir_ssa_def *zero = nir_zero_vec(b, load->num_components);
+      nir_ssa_def *zero = nir_imm_zero(b, load->num_components, 32);
 
       nir_pop_if(b, NULL);