From e9e1a891585d21d94b9c8481ad320bb3bbe2659b 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: (cherry picked from commit b9519297955c3a75095f986b0e29afaf3a8c923a) --- .pick_status.json | 2 +- src/compiler/nir/nir_opt_if.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index af84a5dc0e7..9f159835b00 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -49,7 +49,7 @@ "description": "nir/opt_if: Don't split ALU for single block infinite loops", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "0881e90c09965818b02e359474a6f7446b41d647" }, 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;