nir: replace nir_opt_remove_phis_block with a single source version

This is what callers actually want, and it simplifies nir_opt_remove_phis
because we can assume dominance meta data is valid.

Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31031>
This commit is contained in:
Georg Lehmann 2024-09-06 14:01:30 +02:00 committed by Marge Bot
parent a4cbc903a8
commit a9f8089240
5 changed files with 26 additions and 9 deletions

View file

@ -88,7 +88,7 @@ sanitize_if(nir_function_impl* impl, nir_if* nif)
* or dead control-flow passes and are perfectly legal. Run a quick phi
* removal on the block after the if to clean up any such phis.
*/
nir_opt_remove_phis_block(nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node)));
nir_remove_single_src_phis_block(nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node)));
/* Finally, move the continue from branch after the if-statement. */
nir_block* last_continue_from_blk = then_jump ? else_block : then_block;

View file

@ -6817,7 +6817,7 @@ bool nir_opt_reassociate_bfi(nir_shader *shader);
bool nir_opt_rematerialize_compares(nir_shader *shader);
bool nir_opt_remove_phis(nir_shader *shader);
bool nir_opt_remove_phis_block(nir_block *block);
bool nir_remove_single_src_phis_block(nir_block *block);
bool nir_opt_phi_precision(nir_shader *shader);

View file

@ -766,7 +766,7 @@ opt_if_simplification(nir_builder *b, nir_if *nif)
*/
nir_block *const next_block =
nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node));
nir_opt_remove_phis_block(next_block);
nir_remove_single_src_phis_block(next_block);
}
rewrite_phi_predecessor_blocks(nif, then_block, else_block, else_block,

View file

@ -162,7 +162,7 @@ opt_loop_terminator(nir_if *nif)
* or dead control-flow passes and are perfectly legal. Run a quick phi
* removal on the block after the if to clean up any such phis.
*/
nir_opt_remove_phis_block(nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node)));
nir_remove_single_src_phis_block(nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node)));
/* Finally, move the continue from branch after the if-statement. */
nir_cf_list tmp;
@ -266,7 +266,7 @@ opt_loop_last_block(nir_block *block, bool is_trivial_continue, bool is_trivial_
continue;
/* If there are single-source phis after the IF, get rid of them first */
nir_opt_remove_phis_block(nir_cf_node_cf_tree_next(prev));
nir_remove_single_src_phis_block(nir_cf_node_cf_tree_next(prev));
/* We are about to remove one predecessor. */
nir_lower_phis_to_regs_block(block->successors[0]);
@ -405,7 +405,7 @@ opt_loop_peel_initial_break(nir_loop *loop)
* or dead control-flow passes and are perfectly legal. Run a quick phi
* removal on the block after the if to clean up any such phis.
*/
nir_opt_remove_phis_block(nir_cf_node_cf_tree_next(if_node));
nir_remove_single_src_phis_block(nir_cf_node_cf_tree_next(if_node));
/* We need LCSSA because we are going to wrap the loop into an IF. */
nir_convert_loop_to_lcssa(loop);

View file

@ -133,10 +133,27 @@ remove_phis_block(nir_block *block, nir_builder *b)
}
bool
nir_opt_remove_phis_block(nir_block *block)
nir_remove_single_src_phis_block(nir_block *block)
{
nir_builder b = nir_builder_create(nir_cf_node_get_function(&block->cf_node));
return remove_phis_block(block, &b);
assert(block->predecessors->entries <= 1);
bool progress = false;
nir_foreach_phi_safe(phi, block) {
nir_def *def = NULL;
nir_foreach_phi_src(src, phi) {
def = src->src.ssa;
break;
}
if (!def) {
nir_builder b = nir_builder_create(nir_cf_node_get_function(&block->cf_node));
b.cursor = nir_after_phis(block);
def = nir_undef(&b, phi->def.num_components, phi->def.bit_size);
}
nir_def_replace(&phi->def, def);
progress = true;
}
return progress;
}
static bool