From be036a778acb9f84bbfe4f437d88d0b52ca6f9ff Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Mon, 26 Aug 2024 14:01:04 +0200 Subject: [PATCH] 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 Part-of: (cherry picked from commit 0fc3c52e438cc2f0fb8fd0e04094423736afa0b6) --- .pick_status.json | 2 +- src/compiler/nir/nir_opt_loop.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index c640b7433cc..b784c0f31a1 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -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 diff --git a/src/compiler/nir/nir_opt_loop.c b/src/compiler/nir/nir_opt_loop.c index 1f996854146..f52f23843aa 100644 --- a/src/compiler/nir/nir_opt_loop.c +++ b/src/compiler/nir/nir_opt_loop.c @@ -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); }