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 <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8723>
This commit is contained in:
Alyssa Rosenzweig 2021-01-20 19:09:34 -05:00 committed by Marge Bot
parent d0902aa2d4
commit 623bd2127f
1 changed files with 24 additions and 0 deletions

View File

@ -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;