summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/panfrost/midgard
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <[email protected]>2019-06-06 11:19:13 -0700
committerAlyssa Rosenzweig <[email protected]>2019-06-07 09:05:28 -0700
commitae20bee75e9de3698dd40fb13e7e1324186536ed (patch)
tree9faff9c69410adeae8fb02c56efef1d65ad47951 /src/gallium/drivers/panfrost/midgard
parentc62f2ff8529df6b0f5351fb59e47cb0b31ffbad8 (diff)
panfrost/midgard: Cull dead branches
This fixes bugs with complex control flow. Signed-off-by: Alyssa Rosenzweig <[email protected]>
Diffstat (limited to 'src/gallium/drivers/panfrost/midgard')
-rw-r--r--src/gallium/drivers/panfrost/midgard/midgard_compile.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/gallium/drivers/panfrost/midgard/midgard_compile.c b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
index 92bfe51ce85..faf5d086518 100644
--- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c
+++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
@@ -1713,6 +1713,30 @@ midgard_opt_dead_code_eliminate(compiler_context *ctx, midgard_block *block)
return progress;
}
+/* Dead code elimination for branches at the end of a block - only one branch
+ * per block is legal semantically */
+
+static void
+midgard_opt_cull_dead_branch(compiler_context *ctx, midgard_block *block)
+{
+ bool branched = false;
+
+ mir_foreach_instr_in_block_safe(block, ins) {
+ if (!midgard_is_branch_unit(ins->unit)) continue;
+
+ /* We ignore prepacked branches since the fragment epilogue is
+ * just generally special */
+ if (ins->prepacked_branch) continue;
+
+ if (branched) {
+ /* We already branched, so this is dead */
+ mir_remove_instruction(ins);
+ }
+
+ branched = true;
+ }
+}
+
static bool
mir_nontrivial_mod(midgard_vector_alu_src src, bool is_int, unsigned mask)
{
@@ -2401,6 +2425,13 @@ midgard_compile_shader_nir(nir_shader *nir, midgard_program *program, bool is_bl
}
} while (progress);
+ /* Nested control-flow can result in dead branches at the end of the
+ * block. This messes with our analysis and is just dead code, so cull
+ * them */
+ mir_foreach_block(ctx, block) {
+ midgard_opt_cull_dead_branch(ctx, block);
+ }
+
/* Schedule! */
schedule_program(ctx);