Module: Mesa Branch: staging/23.3 Commit: cf3bd8bedc533a227eb66a0cc8cc507f57ae08ae URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=cf3bd8bedc533a227eb66a0cc8cc507f57ae08ae
Author: Samuel Pitoiset <samuel.pitoi...@gmail.com> 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 <samuel.pitoi...@gmail.com> Reviewed-by: Rhys Perry <pendingchao...@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26009> (cherry picked from commit abfd208cb047b24802938576d0f5bd1a7f809eb6) --- .pick_status.json | 2 +- src/compiler/nir/nir_opt_loop_unroll.c | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 9d7debc1f93..cce18ab5e13 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1024,7 +1024,7 @@ "description": "nir: fix inserting the break instruction for partial loop unrolling", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null 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);