From ebfc5b919fb0f044019c7c40cee651a2a9a46654 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 16 May 2022 19:51:25 -0400 Subject: [PATCH] pan/bi: Don't optimize if without else MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to emit a jump over the else body when constructing the IR, even if the else body appears empty in NIR, because instructions could be added when going out-of-SSA. This optimization should instead happen post-RA, but doing so is nontrivial and the cycle count regression is minimal, so punting on this for now. total instructions in shared programs: 2728364 -> 2731495 (0.11%) instructions in affected programs: 580462 -> 583593 (0.54%) helped: 0 HURT: 1272 HURT stats (abs) min: 1.0 max: 17.0 x̄: 2.46 x̃: 2 HURT stats (rel) min: 0.09% max: 22.22% x̄: 0.88% x̃: 0.59% 95% mean confidence interval for instructions value: 2.37 2.56 95% mean confidence interval for instructions %-change: 0.80% 0.97% Instructions are HURT. total cycles in shared programs: 140628.52 -> 140631.50 (<.01%) cycles in affected programs: 474.45 -> 477.44 (0.63%) helped: 0 HURT: 116 HURT stats (abs) min: 0.015625 max: 0.0625 x̄: 0.03 x̃: 0 HURT stats (rel) min: 0.21% max: 9.09% x̄: 1.16% x̃: 0.39% 95% mean confidence interval for cycles value: 0.02 0.03 95% mean confidence interval for cycles %-change: 0.88% 1.43% Cycles are HURT. total cvt in shared programs: 14816.20 -> 14865.12 (0.33%) cvt in affected programs: 4954.31 -> 5003.23 (0.99%) helped: 0 HURT: 1272 HURT stats (abs) min: 0.015625 max: 0.265625 x̄: 0.04 x̃: 0 HURT stats (rel) min: 0.16% max: 28.57% x̄: 1.88% x̃: 1.17% 95% mean confidence interval for cvt value: 0.04 0.04 95% mean confidence interval for cvt %-change: 1.74% 2.02% Cvt are HURT. total quadwords in shared programs: 1476536 -> 1478512 (0.13%) quadwords in affected programs: 54496 -> 56472 (3.63%) helped: 0 HURT: 247 HURT stats (abs) min: 8.0 max: 8.0 x̄: 8.00 x̃: 8 HURT stats (rel) min: 0.93% max: 20.00% x̄: 5.78% x̃: 4.17% 95% mean confidence interval for quadwords value: 8.00 8.00 95% mean confidence interval for quadwords %-change: 5.21% 6.34% Quadwords are HURT. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 23 ++++++++--------------- src/panfrost/bifrost/compiler.h | 1 - 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index 56d51f8c96a..52e50e56ba2 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -3988,7 +3988,6 @@ emit_block(bi_context *ctx, nir_block *block) nir_foreach_instr(instr, block) { bi_emit_instr(&_b, instr); - ++ctx->instruction_count; } return ctx->current_block; @@ -4009,9 +4008,8 @@ emit_if(bi_context *ctx, nir_if *nif) bi_block *then_block = emit_cf_list(ctx, &nif->then_list); bi_block *end_then_block = ctx->current_block; - /* Emit second block, and check if it's empty */ + /* Emit second block */ - int count_in = ctx->instruction_count; bi_block *else_block = emit_cf_list(ctx, &nif->else_list); bi_block *end_else_block = ctx->current_block; ctx->after_block = create_empty_block(ctx); @@ -4021,20 +4019,15 @@ emit_if(bi_context *ctx, nir_if *nif) assert(then_block); assert(else_block); - if (ctx->instruction_count == count_in) { - then_branch->branch_target = ctx->after_block; - bi_block_add_successor(end_then_block, ctx->after_block); /* fallthrough */ - } else { - then_branch->branch_target = else_block; + then_branch->branch_target = else_block; - /* Emit a jump from the end of the then block to the end of the else */ - _b.cursor = bi_after_block(end_then_block); - bi_instr *then_exit = bi_jump(&_b, bi_zero()); - then_exit->branch_target = ctx->after_block; + /* Emit a jump from the end of the then block to the end of the else */ + _b.cursor = bi_after_block(end_then_block); + bi_instr *then_exit = bi_jump(&_b, bi_zero()); + then_exit->branch_target = ctx->after_block; - bi_block_add_successor(end_then_block, then_exit->branch_target); - bi_block_add_successor(end_else_block, ctx->after_block); /* fallthrough */ - } + bi_block_add_successor(end_then_block, then_exit->branch_target); + bi_block_add_successor(end_else_block, ctx->after_block); /* fallthrough */ bi_block_add_successor(before_block, then_branch->branch_target); /* then_branch */ bi_block_add_successor(before_block, then_block); /* fallthrough */ diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index bb8f5821606..2d70b2f91dc 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -836,7 +836,6 @@ typedef struct { struct hash_table_u64 *allocated_vec; /* Stats for shader-db */ - unsigned instruction_count; unsigned loop_count; unsigned spills; unsigned fills;