mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 13:00:09 +01:00
nir/opt_if: Specify which branches are valid for evaluate_if_condition
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38321>
This commit is contained in:
parent
0216f09e45
commit
a3b6d05a3b
1 changed files with 22 additions and 8 deletions
|
|
@ -834,14 +834,27 @@ opt_if_phi_is_condition(nir_builder *b, nir_if *nif)
|
|||
return progress;
|
||||
}
|
||||
|
||||
enum branch_to_eval {
|
||||
either_branch,
|
||||
then_branch,
|
||||
else_branch
|
||||
};
|
||||
|
||||
static bool
|
||||
evaluate_if_condition(nir_if *nif, nir_cursor cursor, bool *value, bool invert)
|
||||
evaluate_if_condition(nir_if *nif, nir_cursor cursor, bool *value, bool invert,
|
||||
enum branch_to_eval branch)
|
||||
{
|
||||
nir_block *use_block = nir_cursor_current_block(cursor);
|
||||
if (nir_block_dominates(nir_if_first_then_block(nif), use_block)) {
|
||||
if (branch == else_branch)
|
||||
return false;
|
||||
|
||||
*value = !invert;
|
||||
return true;
|
||||
} else if (nir_block_dominates(nir_if_first_else_block(nif), use_block)) {
|
||||
if (branch == then_branch)
|
||||
return false;
|
||||
|
||||
*value = invert;
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -922,11 +935,12 @@ clone_alu_and_replace_src_defs(nir_builder *b, const nir_alu_instr *alu,
|
|||
*/
|
||||
static bool
|
||||
propagate_condition_eval(nir_builder *b, nir_if *nif, nir_src *use_src,
|
||||
nir_src *alu_use, nir_alu_instr *alu, bool invert)
|
||||
nir_src *alu_use, nir_alu_instr *alu, bool invert,
|
||||
enum branch_to_eval branch)
|
||||
{
|
||||
bool bool_value;
|
||||
b->cursor = nir_before_src(alu_use);
|
||||
if (!evaluate_if_condition(nif, b->cursor, &bool_value, invert))
|
||||
if (!evaluate_if_condition(nif, b->cursor, &bool_value, invert, branch))
|
||||
return false;
|
||||
|
||||
nir_def *def[NIR_MAX_VEC_COMPONENTS] = { 0 };
|
||||
|
|
@ -966,14 +980,14 @@ can_propagate_through_alu(nir_src *src)
|
|||
|
||||
static bool
|
||||
evaluate_condition_use(nir_builder *b, nir_if *nif, nir_src *use_src,
|
||||
bool invert)
|
||||
bool invert, enum branch_to_eval branch)
|
||||
{
|
||||
bool progress = false;
|
||||
|
||||
b->cursor = nir_before_src(use_src);
|
||||
|
||||
bool bool_value;
|
||||
if (evaluate_if_condition(nif, b->cursor, &bool_value, invert)) {
|
||||
if (evaluate_if_condition(nif, b->cursor, &bool_value, invert, branch)) {
|
||||
/* Rewrite use to use const */
|
||||
nir_src_rewrite(use_src, nir_imm_bool(b, bool_value));
|
||||
progress = true;
|
||||
|
|
@ -984,7 +998,7 @@ evaluate_condition_use(nir_builder *b, nir_if *nif, nir_src *use_src,
|
|||
|
||||
nir_foreach_use_including_if_safe(alu_use, &alu->def) {
|
||||
progress |= propagate_condition_eval(b, nif, use_src, alu_use, alu,
|
||||
invert);
|
||||
invert, branch);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -999,7 +1013,7 @@ opt_if_evaluate_condition_use(nir_builder *b, nir_if *nif)
|
|||
/* Evaluate any uses of the if condition inside the if branches */
|
||||
nir_foreach_use_including_if_safe(use_src, nif->condition.ssa) {
|
||||
if (!(nir_src_is_if(use_src) && nir_src_parent_if(use_src) == nif))
|
||||
progress |= evaluate_condition_use(b, nif, use_src, false);
|
||||
progress |= evaluate_condition_use(b, nif, use_src, false, either_branch);
|
||||
}
|
||||
|
||||
nir_alu_instr *alu = nir_src_as_alu_instr(nif->condition);
|
||||
|
|
@ -1019,7 +1033,7 @@ opt_if_evaluate_condition_use(nir_builder *b, nir_if *nif)
|
|||
*/
|
||||
nir_foreach_use_including_if_safe(use_src, alu->src[0].src.ssa) {
|
||||
if (nir_src_is_if(use_src) || nir_src_parent_instr(use_src) != &alu->instr)
|
||||
progress |= evaluate_condition_use(b, nif, use_src, true);
|
||||
progress |= evaluate_condition_use(b, nif, use_src, true, either_branch);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue