From: Michael Tretter <m.tret...@pengutronix.de> If the source to a mov instruction is undefined, the result is undefined as well. In that case it is valid to drop the mov instruction.
Signed-off-by: Michael Tretter <m.tret...@pengutronix.de> Signed-off-by: Philipp Zabel <p.za...@pengutronix.de> --- src/gallium/drivers/etnaviv/etnaviv_nir.c | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/gallium/drivers/etnaviv/etnaviv_nir.c b/src/gallium/drivers/etnaviv/etnaviv_nir.c index 1a71459c3a20..7889adf473ab 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_nir.c +++ b/src/gallium/drivers/etnaviv/etnaviv_nir.c @@ -198,6 +198,40 @@ etna_opt_merge_alu_mov_pair(nir_shader *shader) } } +/* Remove mov alu_ops from undefined variables, because the destination will + * be undefined as well and the write is unnecessary. + */ +static void +etna_opt_remove_mov_undef(nir_shader *shader) +{ + nir_foreach_function(function, shader) { + nir_foreach_block(block, function->impl) { + nir_foreach_instr_safe(instr, block) { + if (instr->type != nir_instr_type_alu) + continue; + + nir_alu_instr *alu = nir_instr_as_alu(instr); + if (alu->op != nir_op_imov) + continue; + + unsigned i; + for (i = 0; i < nir_op_infos[alu->op].num_inputs; i++) { + if (!alu->src[i].src.is_ssa || + alu->src[i].src.ssa->parent_instr->type != nir_instr_type_ssa_undef) + break; + } + if (i != nir_op_infos[alu->op].num_inputs) + continue; + + nir_instr_remove(instr); + /* TODO Remove nir_instr_type_ssa_undef instruction */ + } + } + nir_metadata_preserve(function->impl, nir_metadata_block_index | + nir_metadata_dominance); + } +} + /* Move const loads, input load intrinsics, and uniform load intrinsics to the * beginning of the function implementation. * @@ -935,6 +969,7 @@ etna_optimize_nir(struct etna_shader *shader, NIR_PASS_V(s, nir_move_vec_src_uses_to_dest); NIR_PASS_V(s, nir_lower_vec_to_movs); NIR_PASS_V(s, etna_opt_merge_alu_mov_pair); + NIR_PASS_V(s, etna_opt_remove_mov_undef); nir_sweep(s); -- 2.17.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev