diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index 50782fb5aa4..baf67ff077f 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -2973,8 +2973,6 @@ bifrost_compile_shader_nir(nir_shader *nir, /* Name blocks now that we're done emitting so the order is * consistent */ block->base.name = block_source_count++; - - bi_lower_branch(block); } /* Runs before copy prop */ @@ -2993,6 +2991,11 @@ bifrost_compile_shader_nir(nir_shader *nir, } } while(progress); + bi_foreach_block(ctx, _block) { + bi_block *block = (bi_block *) _block; + bi_lower_branch(block); + } + if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal) bi_print_shader(ctx, stdout); bi_schedule(ctx); diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 4030fa46081..809500c8e18 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -777,12 +777,16 @@ unsigned bi_clause_quadwords(bi_clause *clause); signed bi_block_offset(bi_context *ctx, bi_clause *start, bi_block *target); bool bi_ec0_packed(unsigned tuple_count); +/* Check if there are no more instructions starting with a given block, this + * needs to recurse in case a shader ends with multiple empty blocks */ + static inline bool bi_is_terminal_block(bi_block *block) { - return block->base.successors[0] == NULL && - block->base.successors[1] == NULL && - list_is_empty(&block->base.instructions); + return (block == NULL) || + (list_is_empty(&block->base.instructions) && + bi_is_terminal_block((bi_block *) block->base.successors[0]) && + bi_is_terminal_block((bi_block *) block->base.successors[1])); } /* Code emit */