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.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26009>
(cherry picked from commit abfd208cb0)
This commit is contained in:
Samuel Pitoiset
2023-11-02 10:40:00 +01:00
committed by Eric Engestrom
parent 45368572c8
commit cf3bd8bedc
2 changed files with 3 additions and 7 deletions

View File

@@ -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

View File

@@ -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);