pan/bi: Add "soft" mode to DCE
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 30 Dec 2020 18:41:14 +0000 (13:41 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 29 Jan 2021 16:55:43 +0000 (16:55 +0000)
We would like to reuse the DCE logic to eliminate register writes
without eliminating instructions, as a post-sched pass. This type of
operation will eventually generalize to intrinsics that write a register
*and* have side effects (just atomics, I think).

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8723>

src/panfrost/bifrost/bi_opt_dce.c
src/panfrost/bifrost/bifrost_compile.c
src/panfrost/bifrost/compiler.h

index a86bb77..517ff11 100644 (file)
 #include "compiler.h"
 #include "util/u_memory.h"
 
+/* A simple liveness-based dead code elimination pass. In 'soft' mode, dead
+ * instructions are kept but write to null, which is required for correct
+ * operation post-schedule pass (where dead instructions correspond to
+ * instructions whose destinations are consumed immediately as a passthrough
+ * register. If the destinations are not garbage collected, impossible register
+ * encodings will result.)
+ */
+
 bool
-bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block)
+bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block, bool soft)
 {
         bool progress = false;
         unsigned temp_count = bi_max_temp(ctx);
@@ -40,7 +48,11 @@ bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block)
                 unsigned index = bi_get_node(ins->dest[0]);
 
                 if (index < temp_count && !live[index]) {
-                        bi_remove_instruction(ins);
+                        if (soft)
+                                ins->dest[0] = bi_null();
+                        else
+                                bi_remove_instruction(ins);
+
                         progress |= true;
                 }
 
index 03c8f76..6e34ab7 100644 (file)
@@ -2389,7 +2389,7 @@ bifrost_compile_shader_nir(void *mem_ctx, nir_shader *nir,
 
                 bi_foreach_block(ctx, _block) {
                         bi_block *block = (bi_block *) _block;
-                        progress |= bi_opt_dead_code_eliminate(ctx, block);
+                        progress |= bi_opt_dead_code_eliminate(ctx, block, false);
                 }
         } while(progress);
 
index fb52045..db8da72 100644 (file)
@@ -703,7 +703,7 @@ void bi_print_shader(bi_context *ctx, FILE *fp);
 
 /* BIR passes */
 
-bool bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block);
+bool bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block, bool soft);
 void bi_schedule(bi_context *ctx);
 void bi_register_allocate(bi_context *ctx);