Mesa (staging/22.1): broadcom/compiler: disable flags optimization for loop conditions

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 15 16:22:56 UTC 2022


Module: Mesa
Branch: staging/22.1
Commit: 8c4e62054ac740c0508e81497261db5cc54f8d3d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8c4e62054ac740c0508e81497261db5cc54f8d3d

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Fri Jun 10 10:46:51 2022 +0200

broadcom/compiler: disable flags optimization for loop conditions

This is not safe because it may skip regenerating the flags for the
loop condition in the loop continue block and these flags may be
stomped in the loop body by other conditionals.

Fixes: 9909fe6ba ('broadcom/compiler: Skip bool_to_cond where possible')
Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17020>
(cherry picked from commit a97f78eb144ebc8964b891bbf708659e70e5f1c3)

---

 .pick_status.json                  |  2 +-
 src/broadcom/compiler/nir_to_vir.c | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index c8e5dd068ef..216baaef0f0 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1579,7 +1579,7 @@
         "description": "broadcom/compiler: disable flags optimization for loop conditions",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "9909fe6bac53dc32c6599820387545f5019f8a85"
     },
diff --git a/src/broadcom/compiler/nir_to_vir.c b/src/broadcom/compiler/nir_to_vir.c
index 1f9c2fa5bf5..5c7d8443166 100644
--- a/src/broadcom/compiler/nir_to_vir.c
+++ b/src/broadcom/compiler/nir_to_vir.c
@@ -4169,7 +4169,6 @@ ntq_emit_nonuniform_loop(struct v3d_compile *c, nir_loop *loop)
 static void
 ntq_emit_uniform_loop(struct v3d_compile *c, nir_loop *loop)
 {
-
         c->loop_cont_block = vir_new_block(c);
         c->loop_break_block = vir_new_block(c);
 
@@ -4189,6 +4188,23 @@ ntq_emit_uniform_loop(struct v3d_compile *c, nir_loop *loop)
 static void
 ntq_emit_loop(struct v3d_compile *c, nir_loop *loop)
 {
+        /* Disable flags optimization for loop conditions. The problem here is
+         * that we can have code like this:
+         *
+         *  // block_0
+         *  vec1 32 con ssa_9 = ine32 ssa_8, ssa_2
+         *  loop {
+         *     // block_1
+         *     if ssa_9 {
+         *
+         * In this example we emit flags to compute ssa_9 and the optimization
+         * will skip regenerating them again for the loop condition in the
+         * loop continue block (block_1). However, this is not safe after the
+         * first iteration because the loop body can stomp the flags if it has
+         * any conditionals.
+         */
+        c->flags_temp = -1;
+
         bool was_in_control_flow = c->in_control_flow;
         c->in_control_flow = true;
 



More information about the mesa-commit mailing list