diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index 4b23cf11421..39b8eeacfc5 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -2424,10 +2424,12 @@ bifrost_nir_lower_i8_fragout(nir_shader *shader) } /* 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 */ + * per block is legal semantically, but unreachable jumps can be generated. + * Likewise we can generate jumps to the terminal block which need to be + * lowered away to a jump to #0x0, which induces successful termination. */ static void -bi_cull_dead_branch(bi_block *block) +bi_lower_branch(bi_block *block) { bool branched = false; ASSERTED bool was_jump = false; @@ -2436,12 +2438,16 @@ bi_cull_dead_branch(bi_block *block) if (!ins->branch_target) continue; if (branched) { - assert(was_jump); + assert(was_jump && (ins->op == BI_OPCODE_JUMP)); bi_remove_instruction(ins); + break; } branched = true; was_jump = ins->op == BI_OPCODE_JUMP; + + if (bi_is_terminal_block(ins->branch_target)) + ins->branch_target = NULL; } } @@ -2525,7 +2531,7 @@ bifrost_compile_shader_nir(void *mem_ctx, nir_shader *nir, * consistent */ block->base.name = block_source_count++; - bi_cull_dead_branch(block); + bi_lower_branch(block); } /* Runs before copy prop */ diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 278006ad054..24536b8d2a8 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -784,7 +784,7 @@ bi_is_terminal_block(bi_block *block) { return block->base.successors[0] == NULL && block->base.successors[1] == NULL && - list_is_empty(&block->clauses); + list_is_empty(&block->base.instructions); } /* Code emit */