aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_builder.h
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2019-09-16 14:34:20 -0700
committerEric Anholt <[email protected]>2019-10-04 19:15:01 +0000
commit7025dbe794b53b030ae0a3cb55217ea831a810d9 (patch)
tree7c9a0da9721ac9de7daa59b60c7422ebd6d6220e /src/compiler/nir/nir_builder.h
parente7b754a05cc60818632d9968787dbdac6145fa82 (diff)
nir: Skip emitting no-op movs from the builder.
Having passes generate these is just making more work for copy propagation (and thus probably calling more optimization passes) later. Noticed while trying to debug nir_opt_algebraic() top-to-bottom having O(n^2) behavior due to not finding new matches in replacement code. Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_builder.h')
-rw-r--r--src/compiler/nir/nir_builder.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 0f300aef155..cad0e133cbf 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -458,6 +458,16 @@ static inline nir_ssa_def *
nir_mov_alu(nir_builder *build, nir_alu_src src, unsigned num_components)
{
assert(!src.abs && !src.negate);
+ if (src.src.is_ssa && src.src.ssa->num_components == num_components) {
+ bool any_swizzles = false;
+ for (unsigned i = 0; i < num_components; i++) {
+ if (src.swizzle[i] != i)
+ any_swizzles = true;
+ }
+ if (!any_swizzles)
+ return src.src.ssa;
+ }
+
nir_alu_instr *mov = nir_alu_instr_create(build->shader, nir_op_mov);
nir_ssa_dest_init(&mov->instr, &mov->dest.dest, num_components,
nir_src_bit_size(src.src), NULL);