From 6924a412220cf60b044803a1579364950c26717a Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Sat, 6 Aug 2016 18:27:45 -0700 Subject: dp2 -> add --- src/compiler/nir/nir_opt_peephole_dot.c | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/compiler/nir/nir_opt_peephole_dot.c b/src/compiler/nir/nir_opt_peephole_dot.c index 4fe7ab292e2..4d633e20810 100644 --- a/src/compiler/nir/nir_opt_peephole_dot.c +++ b/src/compiler/nir/nir_opt_peephole_dot.c @@ -83,6 +83,18 @@ get_src_idx_for_use(const nir_alu_instr *alu, const nir_src *use) return src_idx; } +static bool +swizzle_contains(const uint8_t swizzle[static 4], unsigned channels, uint8_t c) +{ + for (unsigned i = 0; i < channels; i++) { + if (swizzle[i] == c) { + return true; + } + } + + return false; +} + static bool nir_opt_peephole_dot_block(nir_block *block, nir_builder *b, void *mem_ctx) { @@ -146,6 +158,36 @@ nir_opt_peephole_dot_block(nir_block *block, nir_builder *b, void *mem_ctx) unsigned add_arg = 1 - src_idx; if (nir_srcs_equal(src->src, add->src[add_arg].src)) { } else { + if (add->src[add_arg].src.is_ssa) { + if (add->src[add_arg].src.ssa->parent_instr->type == + nir_instr_type_alu) { + nir_alu_instr *neg = + nir_instr_as_alu(add->src[add_arg].src.ssa->parent_instr); + if (neg->op == nir_op_fneg) { + if (nir_srcs_equal(src->src, neg->src[0].src)) { + if (swizzle_contains(src->swizzle, 2, neg->src[0].swizzle[0])) { + b->cursor = nir_before_instr(&neg->instr); + + nir_ssa_def *other_chan; + unsigned swiz[4] = {0}; + + if (src->swizzle[0] == neg->src[0].swizzle[0]) { + swiz[0] = src->swizzle[1]; + } else { + swiz[0] = src->swizzle[0]; + } + + other_chan = nir_swizzle(b, src->src.ssa, swiz, 1, true); + + nir_ssa_def_rewrite_uses(&add->dest.dest.ssa, + nir_src_for_ssa(other_chan)); + nir_instr_remove(&add->instr); + progress = true; + } + } + } + } + } continue; } -- cgit v1.2.3