From 13d0ae593be02cf9b3ed77eea9abeeb7181dd0e5 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 14 Sep 2022 10:18:05 +1000 Subject: [PATCH] nir/loop_analyze: delay instruction cost calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Here we move the calculation of the instruction cost of the loop after we have processed other information such as finding the induction variables. This is useful because we can use this further information to find instructions that will be eliminated if the loop was to unroll and therefore give them a cost of 0. Acked-by: Marek Olšák Reviewed-by: Ian Romanick Part-of: --- src/compiler/nir/nir_loop_analyze.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c index 1a498248aed..9fce903b163 100644 --- a/src/compiler/nir/nir_loop_analyze.c +++ b/src/compiler/nir/nir_loop_analyze.c @@ -208,15 +208,13 @@ instr_cost(nir_instr *instr, const nir_shader_compiler_options *options) static bool init_loop_block(nir_block *block, loop_info_state *state, - bool in_if_branch, bool in_nested_loop, - const nir_shader_compiler_options *options) + bool in_if_branch, bool in_nested_loop) { init_loop_state init_state = {.in_if_branch = in_if_branch, .in_nested_loop = in_nested_loop, .state = state }; nir_foreach_instr(instr, block) { - state->loop->info->instr_cost += instr_cost(instr, options); nir_foreach_ssa_def(instr, init_loop_def, &init_state); } @@ -1299,18 +1297,17 @@ get_loop_info(loop_info_state *state, nir_function_impl *impl) switch (node->type) { case nir_cf_node_block: - init_loop_block(nir_cf_node_as_block(node), state, - false, false, options); + init_loop_block(nir_cf_node_as_block(node), state, false, false); break; case nir_cf_node_if: nir_foreach_block_in_cf_node(block, node) - init_loop_block(block, state, true, false, options); + init_loop_block(block, state, true, false); break; case nir_cf_node_loop: nir_foreach_block_in_cf_node(block, node) { - init_loop_block(block, state, false, true, options); + init_loop_block(block, state, false, true); } break; @@ -1343,9 +1340,15 @@ get_loop_info(loop_info_state *state, nir_function_impl *impl) find_trip_count(state, impl->function->shader->info.float_controls_execution_mode); nir_foreach_block_in_cf_node(block, &state->loop->cf_node) { + nir_foreach_instr(instr, block) { + state->loop->info->instr_cost += instr_cost(instr, options); + } + + if (state->loop->info->force_unroll) + continue; + if (force_unroll_heuristics(state, block)) { state->loop->info->force_unroll = true; - break; } } }