From a805d999c0e1effb14c28d8777c4657845c4249b Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 11 Feb 2021 15:23:01 -0500 Subject: [PATCH] pan/bi: Fix jumps to terminal block again New scheduler broke this. We need to shuffle some code around so we do the lower pre-schedule instead of post-schedule (no clauses to work with). Fixes: 77933d16d8c ("pan/bi: Switch to new scheduler") Reported-by: Icecream95 Signed-off-by: Alyssa Rosenzweig Reviewed-by: Boris Brezillon Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 14 ++++++++++---- src/panfrost/bifrost/compiler.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) 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 */