From 8251a5b8465fbd51b800cae3227bbf6666206be3 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Mon, 17 Feb 2025 23:24:14 +0100 Subject: [PATCH] nir/peephole_select: don't completely ignore ifs with dont_flatten MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apps are misusing this for cases where the if-else are empty (except for phis) or for conditional discard which will become relevant in the next commit. Foz-DB Navi21: Totals from 173 (0.22% of 79188) affected shaders: Instrs: 1465214 -> 1464987 (-0.02%); split: -0.04%, +0.03% CodeSize: 7960472 -> 7965188 (+0.06%); split: -0.01%, +0.07% Latency: 10001176 -> 10012782 (+0.12%); split: -0.01%, +0.12% InvThroughput: 2336017 -> 2338979 (+0.13%); split: -0.00%, +0.13% Copies: 140105 -> 138225 (-1.34%) Branches: 49746 -> 49732 (-0.03%) VALU: 975632 -> 976322 (+0.07%); split: -0.01%, +0.08% SALU: 201369 -> 200688 (-0.34%) Reviewed-by: Daniel Schürmann Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_opt_peephole_select.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir_opt_peephole_select.c b/src/compiler/nir/nir_opt_peephole_select.c index 700456d1fa6..3735cd29caa 100644 --- a/src/compiler/nir/nir_opt_peephole_select.c +++ b/src/compiler/nir/nir_opt_peephole_select.c @@ -299,6 +299,9 @@ get_options_for_if(nir_if *if_stmt, if_options.limit = UINT_MAX - 1; /* Maximum without unsafe flattening. */ if_options.indirect_load_ok = true; if_options.expensive_alu_ok = true; + } else if (if_stmt->control == nir_selection_control_dont_flatten) { + if_options.limit = 0; + if_options.indirect_load_ok = false; } return if_options; @@ -366,8 +369,6 @@ nir_opt_collapse_if(nir_if *if_stmt, nir_shader *shader, return false; nir_if *parent_if = nir_cf_node_as_if(if_stmt->cf_node.parent); - if (parent_if->control == nir_selection_control_dont_flatten) - return false; /* check if the else block is empty */ if (!nir_cf_list_is_empty_block(&if_stmt->else_list)) @@ -483,9 +484,6 @@ nir_opt_peephole_select_block(nir_block *block, nir_shader *shader, if (nir_opt_collapse_if(if_stmt, shader, options)) return true; - if (if_stmt->control == nir_selection_control_dont_flatten) - return false; - nir_block *then_block = nir_if_first_then_block(if_stmt); nir_block *else_block = nir_if_first_else_block(if_stmt);