From: Alyssa Rosenzweig Date: Thu, 21 Jan 2021 00:09:34 +0000 (-0500) Subject: pan/bi: Add dead branch elimination pass X-Git-Tag: upstream/21.2.3~8765 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=623bd2127f7dd80c1eed967f25db0ea17ac8dd4f;p=platform%2Fupstream%2Fmesa.git pan/bi: Add dead branch elimination pass Ported from Midgard due to the same quirk of our code generation. Additional validation, though. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Boris Brezillon Part-of: --- diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index a51b3e4..03c8f76 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -2281,6 +2281,28 @@ bifrost_nir_lower_i8_fragout(nir_shader *shader) NULL); } +/* Dead code elimination for branches at the end of a block - only one branch + * per block is legal semantically, but unreachable jumps can be generated */ + +static void +bi_cull_dead_branch(bi_block *block) +{ + bool branched = false; + ASSERTED bool was_jump = false; + + bi_foreach_instr_in_block_safe(block, ins) { + if (!ins->branch_target) continue; + + if (branched) { + assert(was_jump); + bi_remove_instruction(ins); + } + + branched = true; + was_jump = ins->op == BI_OPCODE_JUMP; + } +} + panfrost_program * bifrost_compile_shader_nir(void *mem_ctx, nir_shader *nir, const struct panfrost_compile_inputs *inputs) @@ -2356,6 +2378,8 @@ bifrost_compile_shader_nir(void *mem_ctx, nir_shader *nir, /* Name blocks now that we're done emitting so the order is * consistent */ block->base.name = block_source_count++; + + bi_cull_dead_branch(block); } bool progress = false;