Mesa (main): nir/opt_if: Don't split ALU for single block infinite loops

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jun 25 23:15:25 UTC 2021


Module: Mesa
Branch: main
Commit: b9519297955c3a75095f986b0e29afaf3a8c923a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b9519297955c3a75095f986b0e29afaf3a8c923a

Author: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Date:   Fri Jun 18 12:24:11 2021 -0700

nir/opt_if: Don't split ALU for single block infinite loops

Some infinite loop cases were already covered by other
restrictions (e.g. if the loop had a body), but the case with a single
block in the loop body wasn't yet.

This prevents an infinite loop when optimizing the shader in
dEQP-VK.reconvergence.subgroup_uniform_control_flow_ballot.compute.nesting2.3.2
and various others reconvergence tests.

Fixes: 0881e90c099 ("nir: Split ALU instructions in loops that read phis")
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com> [v1]
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11476>

---

 src/compiler/nir/nir_opt_if.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_opt_if.c b/src/compiler/nir/nir_opt_if.c
index 2882ed4287a..3fa6f6ec637 100644
--- a/src/compiler/nir/nir_opt_if.c
+++ b/src/compiler/nir/nir_opt_if.c
@@ -408,6 +408,10 @@ opt_split_alu_of_phi(nir_builder *b, nir_loop *loop)
    if (header_block->predecessors->entries != 2)
       return false;
 
+   nir_block *continue_block = find_continue_block(loop);
+   if (continue_block == header_block)
+      return false;
+
    nir_foreach_instr_safe(instr, header_block) {
       if (instr->type != nir_instr_type_alu)
          continue;
@@ -499,8 +503,6 @@ opt_split_alu_of_phi(nir_builder *b, nir_loop *loop)
       }
 
       /* Split ALU of Phi */
-      nir_block *const continue_block = find_continue_block(loop);
-
       b->cursor = nir_after_block(prev_block);
       nir_ssa_def *prev_value = clone_alu_and_replace_src_defs(b, alu, prev_srcs);
 
@@ -683,7 +685,7 @@ opt_simplify_bcsel_of_phi(nir_builder *b, nir_loop *loop)
        * continue_block from the other bcsel source.  Both sources have
        * already been verified to be phi nodes.
        */
-      nir_block *const continue_block = find_continue_block(loop);
+      nir_block *continue_block = find_continue_block(loop);
       nir_phi_instr *const phi = nir_phi_instr_create(b->shader);
       nir_phi_src *phi_src;
 



More information about the mesa-commit mailing list