[Mesa-dev] [PATCH 29/30] pan/midgard: Add csel invert optimization
Alyssa Rosenzweig
alyssa.rosenzweig at collabora.com
Sat Sep 28 19:02:34 UTC 2019
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
---
src/panfrost/midgard/compiler.h | 1 +
src/panfrost/midgard/midgard_compile.c | 1 +
src/panfrost/midgard/midgard_opt_invert.c | 25 +++++++++++++++++++++++
3 files changed, 27 insertions(+)
diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h
index 8bbf67aa4e7..b0b5ba07143 100644
--- a/src/panfrost/midgard/compiler.h
+++ b/src/panfrost/midgard/compiler.h
@@ -654,6 +654,7 @@ void midgard_lower_invert(compiler_context *ctx, midgard_block *block);
bool midgard_opt_not_propagate(compiler_context *ctx, midgard_block *block);
bool midgard_opt_fuse_src_invert(compiler_context *ctx, midgard_block *block);
bool midgard_opt_fuse_dest_invert(compiler_context *ctx, midgard_block *block);
+bool midgard_opt_csel_invert(compiler_context *ctx, midgard_block *block);
bool midgard_opt_promote_fmov(compiler_context *ctx, midgard_block *block);
#endif
diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
index f1f8b7ecb9a..857e6c70112 100644
--- a/src/panfrost/midgard/midgard_compile.c
+++ b/src/panfrost/midgard/midgard_compile.c
@@ -2512,6 +2512,7 @@ midgard_compile_shader_nir(struct midgard_screen *screen, nir_shader *nir, midga
progress |= midgard_opt_not_propagate(ctx, block);
progress |= midgard_opt_fuse_src_invert(ctx, block);
progress |= midgard_opt_fuse_dest_invert(ctx, block);
+ progress |= midgard_opt_csel_invert(ctx, block);
}
} while (progress);
diff --git a/src/panfrost/midgard/midgard_opt_invert.c b/src/panfrost/midgard/midgard_opt_invert.c
index f846bca5bf9..3a4c455877c 100644
--- a/src/panfrost/midgard/midgard_opt_invert.c
+++ b/src/panfrost/midgard/midgard_opt_invert.c
@@ -275,3 +275,28 @@ midgard_opt_fuse_src_invert(compiler_context *ctx, midgard_block *block)
return progress;
}
+
+/* Optimizes a .not away when used as the source of a conditional select:
+ *
+ * csel(a, b, c) = { b if a, c if !a }
+ * csel(!a, b, c) = { b if !a, c if !(!a) } = { c if a, b if !a } = csel(a, c, b)
+ * csel(!a, b, c) = csel(a, c, b)
+ */
+
+bool
+midgard_opt_csel_invert(compiler_context *ctx, midgard_block *block)
+{
+ bool progress = false;
+
+ mir_foreach_instr_in_block_safe(block, ins) {
+ if (ins->type != TAG_ALU_4) continue;
+ if (!OP_IS_CSEL(ins->alu.op)) continue;
+ if (!mir_single_use(ctx, ins->src[2])) continue;
+ if (!mir_strip_inverted(ctx, ins->src[2])) continue;
+
+ mir_flip(ins);
+ progress |= true;
+ }
+
+ return progress;
+}
--
2.23.0
More information about the mesa-dev
mailing list