nir/peephole_select: don't completely ignore ifs with dont_flatten

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 <daniel@schuermann.dev>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33590>
This commit is contained in:
Georg Lehmann 2025-02-17 23:24:14 +01:00 committed by Marge Bot
parent cfee9e1d9f
commit 8251a5b846

View file

@ -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);