nir/opt_loop: Fix handling else-breaks in merge_terminators

If both breaks are in the else branch, we have to use iand.

Fixes: 9995f33 ("nir: add merge loop terminators optimisation")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11726
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30850>
(cherry picked from commit 0fc3c52e43)
This commit is contained in:
Konstantin Seurer 2024-08-26 14:01:04 +02:00 committed by Eric Engestrom
parent 8390fe9932
commit be036a778a
2 changed files with 8 additions and 2 deletions

View file

@ -94,7 +94,7 @@
"description": "nir/opt_loop: Fix handling else-breaks in merge_terminators",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "9995f336e60c2197236c7d815e8ab20ede18b781",
"notes": null

View file

@ -557,7 +557,13 @@ merge_terminators(nir_builder *b, nir_if *dest_if, nir_if *src_if)
}
b->cursor = nir_before_src(&dest_if->condition);
nir_def *new_c = nir_ior(b, dest_if->condition.ssa, src_if->condition.ssa);
nir_def *new_c = NULL;
if (then_break)
new_c = nir_ior(b, dest_if->condition.ssa, src_if->condition.ssa);
else
new_c = nir_iand(b, dest_if->condition.ssa, src_if->condition.ssa);
nir_src_rewrite(&dest_if->condition, new_c);
}