nir/vec_to_movs: Don't generate MOVs for undef channels.
authorEric Anholt <eric@anholt.net>
Mon, 1 Mar 2021 19:57:19 +0000 (11:57 -0800)
committerMarge Bot <eric+marge@anholt.net>
Wed, 3 Mar 2021 00:51:44 +0000 (00:51 +0000)
This appeared in softpipe's image operations, since NIR always uses
4-component values for the coords, while the GLSL IR only has 2 components
for a 2D image (for example).
arb_shader_image_load_store-shader-mem-barrier (which times out in CI and
spends its time inside of tgsi_exec) was spending 4/51 of its instructions
on moving these undefs around.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9345>

src/compiler/nir/nir_lower_vec_to_movs.c

index 3efe709..c9572f6 100644 (file)
@@ -63,6 +63,10 @@ insert_mov(nir_alu_instr *vec, unsigned start_idx, nir_shader *shader)
 {
    assert(start_idx < nir_op_infos[vec->op].num_inputs);
 
+   /* No sense generating a MOV from undef, we can just leave the dst channel undef. */
+   if (nir_src_is_undef(vec->src[start_idx].src))
+      return 1 << start_idx;
+
    nir_alu_instr *mov = nir_alu_instr_create(shader, nir_op_mov);
    nir_alu_src_copy(&mov->src[0], &vec->src[start_idx], mov);
    nir_alu_dest_copy(&mov->dest, &vec->dest, mov);