From b9519297955c3a75095f986b0e29afaf3a8c923a Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Fri, 18 Jun 2021 12:24:11 -0700 Subject: [PATCH] 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 [v1] Reviewed-by: Jason Ekstrand Part-of: --- 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 2882ed4..3fa6f6e 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; -- 2.7.4