nir/opt_if: Use early returns in opt_if_merge()

We would've had to add yet another level of indentation, or duplicated
finding the if conditions in the next commit. Refactor this function to
use early returns like our other optimizations, so that this isn't an
issue.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6866>
This commit is contained in:
Connor Abbott
2019-04-16 19:39:11 +02:00
committed by Marge Bot
parent 656e428ff4
commit 7f0cd6f153

View File

@@ -1230,12 +1230,14 @@ opt_if_merge(nir_if *nif)
bool progress = false; bool progress = false;
nir_block *next_blk = nir_cf_node_cf_tree_next(&nif->cf_node); nir_block *next_blk = nir_cf_node_cf_tree_next(&nif->cf_node);
if (next_blk && nif->condition.is_ssa) { if (!next_blk || !nif->condition.is_ssa)
nir_if *next_if = nir_block_get_following_if(next_blk); return false;
if (next_if && next_if->condition.is_ssa) {
/* Here we merge two consecutive ifs that have the same nir_if *next_if = nir_block_get_following_if(next_blk);
* condition e.g: if (!next_if || !next_if->condition.is_ssa)
return false;
/* Here we merge two consecutive ifs that have the same condition e.g:
* *
* if ssa_12 { * if ssa_12 {
* ... * ...
@@ -1248,11 +1250,10 @@ opt_if_merge(nir_if *nif)
* ... * ...
* } * }
* *
* Note: This only merges if-statements when the block between them * Note: This only merges if-statements when the block between them is
* is empty. The reason we don't try to merge ifs that just have phis * empty. The reason we don't try to merge ifs that just have phis between
* between them is because this can results in increased register * them is because this can result in increased register pressure. For
* pressure. For example when merging if ladders created by indirect * example when merging if ladders created by indirect indexing.
* indexing.
*/ */
if (nif->condition.ssa == next_if->condition.ssa && if (nif->condition.ssa == next_if->condition.ssa &&
exec_list_is_empty(&next_blk->instr_list)) { exec_list_is_empty(&next_blk->instr_list)) {
@@ -1281,8 +1282,8 @@ opt_if_merge(nir_if *nif)
new_then_block, new_then_block,
new_else_block); new_else_block);
/* Move phis after merged if to avoid them being deleted when we /* Move phis after merged if to avoid them being deleted when we remove
* remove the merged if-statement. * the merged if-statement.
*/ */
nir_block *after_next_if_block = nir_block *after_next_if_block =
nir_cf_node_as_block(nir_cf_node_next(&next_if->cf_node)); nir_cf_node_as_block(nir_cf_node_next(&next_if->cf_node));
@@ -1300,8 +1301,6 @@ opt_if_merge(nir_if *nif)
progress = true; progress = true;
} }
}
}
return progress; return progress;
} }