Module: Mesa Branch: main Commit: abfd208cb047b24802938576d0f5bd1a7f809eb6 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=abfd208cb047b24802938576d0f5bd1a7f809eb6
Author: Samuel Pitoiset <[email protected]> Date: Thu Nov 2 10:40:00 2023 +0100 nir: fix inserting the break instruction for partial loop unrolling If the break in the original loop isn't in the first top-level if, this would have re-inserted it in the wrong block. Fixes this by re-inserting the break block to the corresponding break block in the new loop by using the remap hashtable. fossils-db (NAVI21): Totals from 88 (0.11% of 79330) affected shaders: Instrs: 109602 -> 109929 (+0.30%); split: -0.10%, +0.40% CodeSize: 570968 -> 573332 (+0.41%); split: -0.08%, +0.49% Latency: 1682510 -> 1682505 (-0.00%); split: -0.01%, +0.01% Copies: 12832 -> 12746 (-0.67%); split: -1.54%, +0.87% Branches: 2879 -> 2930 (+1.77%) Deathloop and F1 2023 are affected but I'm not aware of any issues for these two games. Cc: mesa-stable Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10001 Signed-off-by: Samuel Pitoiset <[email protected]> Reviewed-by: Rhys Perry <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26009> --- src/compiler/nir/nir_opt_loop_unroll.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/compiler/nir/nir_opt_loop_unroll.c b/src/compiler/nir/nir_opt_loop_unroll.c index 221775071a5..2d342fbb9ce 100644 --- a/src/compiler/nir/nir_opt_loop_unroll.c +++ b/src/compiler/nir/nir_opt_loop_unroll.c @@ -760,12 +760,8 @@ partial_unroll(nir_shader *shader, nir_loop *loop, unsigned trip_count) /* Insert break back into terminator */ nir_jump_instr *brk = nir_jump_instr_create(shader, nir_jump_break); - nir_if *nif = nir_block_get_following_if(nir_loop_first_block(new_loop)); - if (terminator->continue_from_then) { - nir_instr_insert_after_block(nir_if_last_else_block(nif), &brk->instr); - } else { - nir_instr_insert_after_block(nir_if_last_then_block(nif), &brk->instr); - } + nir_block *break_block = _mesa_hash_table_search(remap_table, terminator->break_block)->data; + nir_instr_insert_after_block(break_block, &brk->instr); /* Delete the original loop header and body */ nir_cf_delete(&lp_header);
