Some created shaders can contain instructions like: mov t0 t0 This simple pass removes that kind of mov instructions.
Signed-off-by: Christian Gmeiner <christian.gmei...@gmail.com> --- src/etnaviv/compiler/eir_opt_peephole.c | 63 +++++++++++++++++++++++++ src/etnaviv/compiler/eir_optimize.c | 4 +- src/etnaviv/compiler/eir_optimize.h | 5 ++ src/etnaviv/compiler/meson.build | 1 + 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/etnaviv/compiler/eir_opt_peephole.c diff --git a/src/etnaviv/compiler/eir_opt_peephole.c b/src/etnaviv/compiler/eir_opt_peephole.c new file mode 100644 index 00000000000..a8cf848d652 --- /dev/null +++ b/src/etnaviv/compiler/eir_opt_peephole.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2019 Etnaviv Project + * Copyright (C) 2019 Zodiac Inflight Innovations + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sub license, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Christian Gmeiner <christian.gmei...@gmail.com> + */ + +#include "eir.h" +#include "eir_optimize.h" + +static bool +eir_opt_peephole_impl(struct eir_instruction *instr) +{ + /* remove "mov t0 t0" as seen with bin/gl-2.0-vertex-attr-0 */ + + if (instr->gc.opcode != GC_MOV) + return false; + + if (instr->src[0].index != instr->dst.index) + return false; + + if (instr->dst.writemask != (INST_COMPS_X | INST_COMPS_Y | INST_COMPS_Z | INST_COMPS_W)) + return false; + + if (instr->src[0].swizzle != INST_SWIZ_IDENTITY) + return false; + + list_del(&instr->node); + + return true; +} + +bool +eir_opt_peephole(struct eir *ir) +{ + bool progress = false; + + eir_for_each_block(block, ir) + eir_for_each_inst_safe(inst, block) + progress |= eir_opt_peephole_impl(inst); + + return progress; +} diff --git a/src/etnaviv/compiler/eir_optimize.c b/src/etnaviv/compiler/eir_optimize.c index 6eae8e9c9ec..695ef76001a 100644 --- a/src/etnaviv/compiler/eir_optimize.c +++ b/src/etnaviv/compiler/eir_optimize.c @@ -44,5 +44,7 @@ void eir_optimize(struct eir *ir) { - const bool print_opt_debug = true; + const bool print_opt_debug = false; + + OPTPASS(eir_opt_peephole); } diff --git a/src/etnaviv/compiler/eir_optimize.h b/src/etnaviv/compiler/eir_optimize.h index b840a273c25..ecc9e44713c 100644 --- a/src/etnaviv/compiler/eir_optimize.h +++ b/src/etnaviv/compiler/eir_optimize.h @@ -28,4 +28,9 @@ #ifndef H_EIR_OPTIMIZE #define H_EIR_OPTIMIZE +struct eir; + +bool +eir_opt_peephole(struct eir *ir); + #endif // H_EIR_OPTIMIZE diff --git a/src/etnaviv/compiler/meson.build b/src/etnaviv/compiler/meson.build index 8343e6b91ad..f43e868208a 100644 --- a/src/etnaviv/compiler/meson.build +++ b/src/etnaviv/compiler/meson.build @@ -31,6 +31,7 @@ libetnaviv_compiler_files = files( 'eir_nir_lower_alu_to_scalar.c', 'eir_nir.c', 'eir_nir.h', + 'eir_opt_peephole.c', 'eir_optimize.c', 'eir_print.c', 'eir_register_allocate.c', -- 2.21.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev