From ffde1f359bf42566df0740c93004fb3017101b82 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 26 Jul 2021 20:19:48 -0400 Subject: [PATCH] pan/bi: Adapt bi_lower_branch for Valhall Disable the Bifrost optimization; it's not portable. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index 3c7baec3b18..e3a6f761889 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -3795,12 +3795,23 @@ bifrost_nir_lower_store_component(struct nir_builder *b, /* 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. - * Likewise we can generate jumps to the terminal block which need to be - * lowered away to a jump to #0x0, which induces successful termination. */ + * Likewise on Bifrost we can generate jumps to the terminal block which need + * to be lowered away to a jump to #0x0, which induces successful termination. + * That trick doesn't work on Valhall, which needs a NOP inserted in the + * terminal block instead. + */ static void -bi_lower_branch(bi_block *block) +bi_lower_terminal_block(bi_context *ctx, bi_block *block) { + bi_builder b = bi_init_builder(ctx, bi_after_block(block)); + bi_nop(&b); +} + +static void +bi_lower_branch(bi_context *ctx, bi_block *block) +{ + bool cull_terminal = (ctx->arch <= 8); bool branched = false; ASSERTED bool was_jump = false; @@ -3816,8 +3827,13 @@ bi_lower_branch(bi_block *block) branched = true; was_jump = ins->op == BI_OPCODE_JUMP; - if (bi_is_terminal_block(ins->branch_target)) + if (!bi_is_terminal_block(ins->branch_target)) + continue; + + if (cull_terminal) ins->branch_target = NULL; + else if (ins->branch_target) + bi_lower_terminal_block(ctx, ins->branch_target); } } @@ -4038,7 +4054,7 @@ bi_compile_variant_nir(nir_shader *nir, } bi_foreach_block(ctx, block) { - bi_lower_branch(block); + bi_lower_branch(ctx, block); } if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal)