Mesa (staging/20.1): nir/opt_if: fix opt_if_merge when destination branch has a jump
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Sep 10 15:03:37 UTC 2020
Module: Mesa
Branch: staging/20.1
Commit: 861fd03bd17beaf8527c5c7cdcce87891edf6369
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=861fd03bd17beaf8527c5c7cdcce87891edf6369
Author: Rhys Perry <pendingchaos02 at gmail.com>
Date: Mon Sep 7 11:33:44 2020 +0100
nir/opt_if: fix opt_if_merge when destination branch has a jump
Fixes a case where opt_if_merge created code like:
if (...) {
break;
loop {
...
}
}
which caused opt_peel_loop_initial_if to complain that the loop pre-header
wasn't a predecessor of the loop header. This patch prevents this
(invalid, I think) unreachable code from being created.
Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3496
Fixes: 4d3f6cb9739 ('nir: merge some basic consecutive ifs')
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6633>
(cherry picked from commit 6cef8040672e84393e59ed6efa9953c95f5f8c92)
---
.pick_status.json | 2 +-
src/compiler/nir/nir_opt_if.c | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/.pick_status.json b/.pick_status.json
index be785fbf5f6..50f36527fd6 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -706,7 +706,7 @@
"description": "nir/opt_if: fix opt_if_merge when destination branch has a jump",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": "4d3f6cb9739dfeaf9605fcd2f5318e03acf5066e"
},
diff --git a/src/compiler/nir/nir_opt_if.c b/src/compiler/nir/nir_opt_if.c
index d1be3518877..65f540745f7 100644
--- a/src/compiler/nir/nir_opt_if.c
+++ b/src/compiler/nir/nir_opt_if.c
@@ -1276,6 +1276,13 @@ opt_if_merge(nir_if *nif)
if (nif->condition.ssa == next_if->condition.ssa &&
exec_list_is_empty(&next_blk->instr_list)) {
+ /* This optimization isn't made to work in this case and
+ * opt_if_evaluate_condition_use will optimize it later.
+ */
+ if (nir_block_ends_in_jump(nir_if_last_then_block(nif)) ||
+ nir_block_ends_in_jump(nir_if_last_else_block(nif)))
+ return false;
+
simple_merge_if(nif, next_if, true, true);
simple_merge_if(nif, next_if, false, false);
More information about the mesa-commit
mailing list