nir: Fix helgrind complaints about data race in trivial_swizzle init.
authorEric Anholt <eric@anholt.net>
Thu, 25 Jul 2019 20:37:28 +0000 (13:37 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 29 Jul 2019 19:50:49 +0000 (12:50 -0700)
Even if the data race wasn't real (I'm not great at reasoning about
this), helgrind is a nice enough tool that keeping noise out of it is
probably worthwhile.  Besides, typing out the numbers keeps the data
in the read-only data section instead of emitting code to initialize
it every time.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
src/compiler/nir/nir_builder.h

index 35e4a2857144aac7ecd9631586a25e8aa9e65a82..2fed76106eb4c2939131916a7213d65c4fb406b1 100644 (file)
@@ -807,9 +807,9 @@ nir_ssa_for_src(nir_builder *build, nir_src src, int num_components)
 static inline nir_ssa_def *
 nir_ssa_for_alu_src(nir_builder *build, nir_alu_instr *instr, unsigned srcn)
 {
-   static uint8_t trivial_swizzle[NIR_MAX_VEC_COMPONENTS];
-   for (int i = 0; i < NIR_MAX_VEC_COMPONENTS; ++i)
-      trivial_swizzle[i] = i;
+   static uint8_t trivial_swizzle[] = { 0, 1, 2, 3 };
+   STATIC_ASSERT(ARRAY_SIZE(trivial_swizzle) == NIR_MAX_VEC_COMPONENTS);
+
    nir_alu_src *src = &instr->src[srcn];
    unsigned num_components = nir_ssa_alu_instr_src_components(instr, srcn);