summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2016-08-06 18:27:45 -0700
committerMatt Turner <mattst88@gmail.com>2016-08-06 18:27:45 -0700
commit6924a412220cf60b044803a1579364950c26717a (patch)
tree5998279000420908510fd927426cecce887ae81d
parent134353a6601afd788017eaa3c9ee84d3814deb65 (diff)
dp2 -> addwip/dot
-rw-r--r--src/compiler/nir/nir_opt_peephole_dot.c42
1 files changed, 42 insertions, 0 deletions
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
@@ -84,6 +84,18 @@ get_src_idx_for_use(const nir_alu_instr *alu, const nir_src *use)
}
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)
{
bool progress = false;
@@ -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;
}