From 4a7f0aa2e034c7f82cb143367efadb0e3eeca08e Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 1 Dec 2020 09:48:30 -0600 Subject: [PATCH] intel/fs: Remove unnecessary HALT_TARGET in opt_redundant_halt() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This means the pass has to walk all the instructions but it was doing that in a bunch of cases anyway when it didn't have a HALT_TARGET. However, removing HALT_TARGET frees up the scheduler a bit because HALT_TARGET is considered a scheduling barrier. The shader-db results are kind-of a wash but we're about to add HALT_TARGET unconditionally so we want to be able to get rid of it. Shader-db results on Ice Lake: total instructions in shared programs: 19935623 -> 19935623 (0.00%) instructions in affected programs: 0 -> 0 helped: 0 HURT: 0 total cycles in shared programs: 976758472 -> 976766135 (<.01%) cycles in affected programs: 11097707 -> 11105370 (0.07%) helped: 1750 HURT: 875 helped stats (abs) min: 1 max: 866 x̄: 26.39 x̃: 4 helped stats (rel) min: <.01% max: 39.24% x̄: 1.25% x̃: 0.46% HURT stats (abs) min: 1 max: 1678 x̄: 61.54 x̃: 10 HURT stats (rel) min: <.01% max: 65.69% x̄: 1.86% x̃: 0.42% 95% mean confidence interval for cycles value: -2.48 8.32 95% mean confidence interval for cycles %-change: -0.40% -0.03% Inconclusive result (value mean confidence interval includes 0). LOST: 62 GAINED: 46 All of the lost/gained programs are SIMD32 fragment shaders. Reviewed-by: Francisco Jerez Part-of: --- src/intel/compiler/brw_fs.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp index 15362c7c79b..87dd28f23cc 100644 --- a/src/intel/compiler/brw_fs.cpp +++ b/src/intel/compiler/brw_fs.cpp @@ -3033,24 +3033,36 @@ fs_visitor::opt_redundant_halt() { bool progress = false; - bblock_t *last_bblock = cfg->blocks[cfg->num_blocks - 1]; - + unsigned halt_count = 0; fs_inst *halt_target = NULL; - foreach_inst_in_block_reverse(fs_inst, inst, last_bblock) { + bblock_t *halt_target_block = NULL; + foreach_block_and_inst(block, fs_inst, inst, cfg) { + if (inst->opcode == BRW_OPCODE_HALT) + halt_count++; + if (inst->opcode == SHADER_OPCODE_HALT_TARGET) { halt_target = inst; + halt_target_block = block; break; } } - if (!halt_target) + if (!halt_target) { + assert(halt_count == 0); return false; + } /* Delete any HALTs immediately before the halt target. */ for (fs_inst *prev = (fs_inst *) halt_target->prev; !prev->is_head_sentinel() && prev->opcode == BRW_OPCODE_HALT; prev = (fs_inst *) halt_target->prev) { - prev->remove(last_bblock); + prev->remove(halt_target_block); + halt_count--; + progress = true; + } + + if (halt_count == 0) { + halt_target->remove(halt_target_block); progress = true; }