nir: add a nir_opt_if_options enum

And don't enable nir_opt_if_optimize_phi_true_false on radeonsi with
LLVM 14 because it crashes Blender.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6976
Cc: mesa-stable
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17949>
This commit is contained in:
Pierre-Eric Pelloux-Prayer
2022-08-08 17:12:14 +02:00
committed by Marge Bot
parent 0ca0d2d450
commit 70891edd97
20 changed files with 39 additions and 29 deletions

View File

@@ -197,7 +197,8 @@ radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively, bool
NIR_PASS(progress, shader, nir_opt_remove_phis); NIR_PASS(progress, shader, nir_opt_remove_phis);
NIR_PASS(progress, shader, nir_opt_dce); NIR_PASS(progress, shader, nir_opt_dce);
} }
NIR_PASS(progress, shader, nir_opt_if, true); NIR_PASS(progress, shader, nir_opt_if,
nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
NIR_PASS(progress, shader, nir_opt_dead_cf); NIR_PASS(progress, shader, nir_opt_dead_cf);
NIR_PASS(progress, shader, nir_opt_cse); NIR_PASS(progress, shader, nir_opt_cse);
NIR_PASS(progress, shader, nir_opt_peephole_select, 8, true, true); NIR_PASS(progress, shader, nir_opt_peephole_select, 8, true, true);

View File

@@ -325,7 +325,7 @@ nir_optimize(nir_shader *nir, bool allow_copies)
OPT(nir_opt_remove_phis); OPT(nir_opt_remove_phis);
OPT(nir_opt_gcm, false); OPT(nir_opt_gcm, false);
OPT(nir_opt_if, false); OPT(nir_opt_if, nir_opt_if_optimize_phi_true_false);
OPT(nir_opt_undef); OPT(nir_opt_undef);
OPT(nir_lower_pack); OPT(nir_lower_pack);

View File

@@ -100,7 +100,7 @@ clc_libclc_optimize(nir_shader *s)
NIR_PASS(progress, s, nir_copy_prop); NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_remove_phis); NIR_PASS(progress, s, nir_opt_remove_phis);
NIR_PASS(progress, s, nir_opt_dce); NIR_PASS(progress, s, nir_opt_dce);
NIR_PASS(progress, s, nir_opt_if, true); NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
NIR_PASS(progress, s, nir_opt_dead_cf); NIR_PASS(progress, s, nir_opt_dead_cf);
NIR_PASS(progress, s, nir_opt_cse); NIR_PASS(progress, s, nir_opt_cse);
NIR_PASS(progress, s, nir_opt_peephole_select, 8, true, true); NIR_PASS(progress, s, nir_opt_peephole_select, 8, true, true);

View File

@@ -75,7 +75,7 @@ gl_nir_opts(nir_shader *nir)
NIR_PASS(progress, nir, nir_copy_prop); NIR_PASS(progress, nir, nir_copy_prop);
NIR_PASS(progress, nir, nir_opt_dce); NIR_PASS(progress, nir, nir_opt_dce);
} }
NIR_PASS(progress, nir, nir_opt_if, false); NIR_PASS(progress, nir, nir_opt_if, 0);
NIR_PASS(progress, nir, nir_opt_dead_cf); NIR_PASS(progress, nir, nir_opt_dead_cf);
NIR_PASS(progress, nir, nir_opt_cse); NIR_PASS(progress, nir, nir_opt_cse);
NIR_PASS(progress, nir, nir_opt_peephole_select, 8, true, true); NIR_PASS(progress, nir, nir_opt_peephole_select, 8, true, true);

View File

@@ -5499,7 +5499,12 @@ bool nir_opt_gcm(nir_shader *shader, bool value_number);
bool nir_opt_idiv_const(nir_shader *shader, unsigned min_bit_size); bool nir_opt_idiv_const(nir_shader *shader, unsigned min_bit_size);
bool nir_opt_if(nir_shader *shader, bool aggressive_last_continue); typedef enum {
nir_opt_if_aggressive_last_continue = (1 << 0),
nir_opt_if_optimize_phi_true_false = (1 << 1),
} nir_opt_if_options;
bool nir_opt_if(nir_shader *shader, nir_opt_if_options options);
bool nir_opt_intrinsics(nir_shader *shader); bool nir_opt_intrinsics(nir_shader *shader);

View File

@@ -1214,7 +1214,7 @@ nir_lower_shader_calls(nir_shader *shader,
replace_resume_with_halt(resume_shaders[i], resume_instr); replace_resume_with_halt(resume_shaders[i], resume_instr);
nir_opt_remove_phis(resume_shaders[i]); nir_opt_remove_phis(resume_shaders[i]);
/* Remove the dummy blocks added by flatten_resume_if_ladder() */ /* Remove the dummy blocks added by flatten_resume_if_ladder() */
nir_opt_if(resume_shaders[i], false); nir_opt_if(resume_shaders[i], nir_opt_if_optimize_phi_true_false);
} }
*resume_shaders_out = resume_shaders; *resume_shaders_out = resume_shaders;

View File

@@ -1597,7 +1597,7 @@ opt_if_merge(nir_if *nif)
static bool static bool
opt_if_cf_list(nir_builder *b, struct exec_list *cf_list, opt_if_cf_list(nir_builder *b, struct exec_list *cf_list,
bool aggressive_last_continue) nir_opt_if_options options)
{ {
bool progress = false; bool progress = false;
foreach_list_typed(nir_cf_node, cf_node, node, cf_list) { foreach_list_typed(nir_cf_node, cf_node, node, cf_list) {
@@ -1608,23 +1608,24 @@ opt_if_cf_list(nir_builder *b, struct exec_list *cf_list,
case nir_cf_node_if: { case nir_cf_node_if: {
nir_if *nif = nir_cf_node_as_if(cf_node); nir_if *nif = nir_cf_node_as_if(cf_node);
progress |= opt_if_cf_list(b, &nif->then_list, progress |= opt_if_cf_list(b, &nif->then_list,
aggressive_last_continue); options);
progress |= opt_if_cf_list(b, &nif->else_list, progress |= opt_if_cf_list(b, &nif->else_list,
aggressive_last_continue); options);
progress |= opt_if_loop_terminator(nif); progress |= opt_if_loop_terminator(nif);
progress |= opt_if_merge(nif); progress |= opt_if_merge(nif);
progress |= opt_if_simplification(b, nif); progress |= opt_if_simplification(b, nif);
progress |= opt_if_phi_is_condition(b, nif); if (options & nir_opt_if_optimize_phi_true_false)
progress |= opt_if_phi_is_condition(b, nif);
break; break;
} }
case nir_cf_node_loop: { case nir_cf_node_loop: {
nir_loop *loop = nir_cf_node_as_loop(cf_node); nir_loop *loop = nir_cf_node_as_loop(cf_node);
progress |= opt_if_cf_list(b, &loop->body, progress |= opt_if_cf_list(b, &loop->body,
aggressive_last_continue); options);
progress |= opt_simplify_bcsel_of_phi(b, loop); progress |= opt_simplify_bcsel_of_phi(b, loop);
progress |= opt_if_loop_last_continue(loop, progress |= opt_if_loop_last_continue(loop,
aggressive_last_continue); options & nir_opt_if_aggressive_last_continue);
break; break;
} }
@@ -1717,7 +1718,7 @@ opt_if_safe_cf_list(nir_builder *b, struct exec_list *cf_list)
} }
bool bool
nir_opt_if(nir_shader *shader, bool aggressive_last_continue) nir_opt_if(nir_shader *shader, nir_opt_if_options options)
{ {
bool progress = false; bool progress = false;
@@ -1736,7 +1737,7 @@ nir_opt_if(nir_shader *shader, bool aggressive_last_continue)
bool preserve = true; bool preserve = true;
if (opt_if_cf_list(&b, &function->impl->body, aggressive_last_continue)) { if (opt_if_cf_list(&b, &function->impl->body, options)) {
preserve = false; preserve = false;
progress = true; progress = true;
} }

View File

@@ -79,7 +79,7 @@ TEST_F(nir_opt_if_test, opt_if_simplification)
nir_pop_if(&bld, NULL); nir_pop_if(&bld, NULL);
ASSERT_TRUE(nir_opt_if(bld.shader, false)); ASSERT_TRUE(nir_opt_if(bld.shader, nir_opt_if_optimize_phi_true_false));
nir_validate_shader(bld.shader, NULL); nir_validate_shader(bld.shader, NULL);
@@ -130,7 +130,7 @@ TEST_F(nir_opt_if_test, opt_if_simplification_single_source_phi_after_if)
nir_builder_instr_insert(&bld, &phi->instr); nir_builder_instr_insert(&bld, &phi->instr);
ASSERT_TRUE(nir_opt_if(bld.shader, false)); ASSERT_TRUE(nir_opt_if(bld.shader, nir_opt_if_optimize_phi_true_false));
nir_validate_shader(bld.shader, NULL); nir_validate_shader(bld.shader, NULL);
@@ -169,7 +169,7 @@ TEST_F(nir_opt_if_test, opt_if_alu_of_phi_progress)
int progress_count = 0; int progress_count = 0;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
progress = nir_opt_if(bld.shader, false); progress = nir_opt_if(bld.shader, nir_opt_if_optimize_phi_true_false);
if (progress) if (progress)
progress_count++; progress_count++;
else else

View File

@@ -169,7 +169,7 @@ ir3_optimize_loop(struct ir3_compiler *compiler, nir_shader *s)
OPT(s, nir_copy_prop); OPT(s, nir_copy_prop);
OPT(s, nir_opt_dce); OPT(s, nir_opt_dce);
} }
progress |= OPT(s, nir_opt_if, false); progress |= OPT(s, nir_opt_if, nir_opt_if_optimize_phi_true_false);
progress |= OPT(s, nir_opt_loop_unroll); progress |= OPT(s, nir_opt_loop_unroll);
progress |= OPT(s, nir_lower_64bit_phis); progress |= OPT(s, nir_lower_64bit_phis);
progress |= OPT(s, nir_opt_remove_phis); progress |= OPT(s, nir_opt_remove_phis);

View File

@@ -3182,7 +3182,7 @@ ntt_optimize_nir(struct nir_shader *s, struct pipe_screen *screen)
NIR_PASS(progress, s, nir_opt_copy_prop_vars); NIR_PASS(progress, s, nir_opt_copy_prop_vars);
NIR_PASS(progress, s, nir_opt_dead_write_vars); NIR_PASS(progress, s, nir_opt_dead_write_vars);
NIR_PASS(progress, s, nir_opt_if, true); NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
NIR_PASS(progress, s, nir_opt_peephole_select, NIR_PASS(progress, s, nir_opt_peephole_select,
control_flow_depth == 0 ? ~0 : 8, true, true); control_flow_depth == 0 ? ~0 : 8, true, true);
NIR_PASS(progress, s, nir_opt_algebraic); NIR_PASS(progress, s, nir_opt_algebraic);

View File

@@ -2522,7 +2522,7 @@ ttn_optimize_nir(nir_shader *nir)
NIR_PASS(progress, nir, nir_copy_prop); NIR_PASS(progress, nir, nir_copy_prop);
NIR_PASS(progress, nir, nir_opt_dce); NIR_PASS(progress, nir, nir_opt_dce);
} }
NIR_PASS(progress, nir, nir_opt_if, false); NIR_PASS(progress, nir, nir_opt_if, nir_opt_if_optimize_phi_true_false);
NIR_PASS(progress, nir, nir_opt_dead_cf); NIR_PASS(progress, nir, nir_opt_dead_cf);
NIR_PASS(progress, nir, nir_opt_cse); NIR_PASS(progress, nir, nir_opt_cse);
NIR_PASS(progress, nir, nir_opt_peephole_select, 8, true, true); NIR_PASS(progress, nir, nir_opt_peephole_select, 8, true, true);

View File

@@ -167,7 +167,7 @@ etna_optimize_loop(nir_shader *s)
OPT(s, nir_opt_dce); OPT(s, nir_opt_dce);
} }
progress |= OPT(s, nir_opt_loop_unroll); progress |= OPT(s, nir_opt_loop_unroll);
progress |= OPT(s, nir_opt_if, false); progress |= OPT(s, nir_opt_if, nir_opt_if_optimize_phi_true_false);
progress |= OPT(s, nir_opt_remove_phis); progress |= OPT(s, nir_opt_remove_phis);
progress |= OPT(s, nir_opt_undef); progress |= OPT(s, nir_opt_undef);
} }

View File

@@ -96,7 +96,7 @@ ir2_optimize_loop(nir_shader *s)
OPT(s, nir_opt_dce); OPT(s, nir_opt_dce);
} }
progress |= OPT(s, nir_opt_loop_unroll); progress |= OPT(s, nir_opt_loop_unroll);
progress |= OPT(s, nir_opt_if, false); progress |= OPT(s, nir_opt_if, nir_opt_if_optimize_phi_true_false);
progress |= OPT(s, nir_opt_remove_phis); progress |= OPT(s, nir_opt_remove_phis);
progress |= OPT(s, nir_opt_undef); progress |= OPT(s, nir_opt_undef);

View File

@@ -202,7 +202,7 @@ i915_optimize_nir(struct nir_shader *s)
NIR_PASS(progress, s, nir_opt_dead_cf); NIR_PASS(progress, s, nir_opt_dead_cf);
NIR_PASS(progress, s, nir_opt_cse); NIR_PASS(progress, s, nir_opt_cse);
NIR_PASS(progress, s, nir_opt_find_array_copies); NIR_PASS(progress, s, nir_opt_find_array_copies);
NIR_PASS(progress, s, nir_opt_if, true); NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
NIR_PASS(progress, s, nir_opt_peephole_select, ~0 /* flatten all IFs. */, NIR_PASS(progress, s, nir_opt_peephole_select, ~0 /* flatten all IFs. */,
true, true); true, true);
NIR_PASS(progress, s, nir_opt_algebraic); NIR_PASS(progress, s, nir_opt_algebraic);

View File

@@ -560,7 +560,7 @@ optimize_once(nir_shader *shader)
NIR_PASS(progress, shader, nir_opt_dce); NIR_PASS(progress, shader, nir_opt_dce);
} }
NIR_PASS(progress, shader, nir_opt_if, false); NIR_PASS(progress, shader, nir_opt_if, nir_opt_if_optimize_phi_true_false);
NIR_PASS(progress, shader, nir_opt_dead_cf); NIR_PASS(progress, shader, nir_opt_dead_cf);
NIR_PASS(progress, shader, nir_opt_cse); NIR_PASS(progress, shader, nir_opt_cse);
NIR_PASS(progress, shader, nir_opt_peephole_select, 200, true, true); NIR_PASS(progress, shader, nir_opt_peephole_select, 200, true, true);

View File

@@ -80,7 +80,10 @@ void si_nir_opts(struct si_screen *sscreen, struct nir_shader *nir, bool first)
NIR_PASS(progress, nir, nir_copy_prop); NIR_PASS(progress, nir, nir_copy_prop);
NIR_PASS(progress, nir, nir_opt_remove_phis); NIR_PASS(progress, nir, nir_opt_remove_phis);
NIR_PASS(progress, nir, nir_opt_dce); NIR_PASS(progress, nir, nir_opt_dce);
NIR_PASS(lower_phis_to_scalar, nir, nir_opt_if, true); /* nir_opt_if_optimize_phi_true_false is disabled on LLVM14 (#6976) */
NIR_PASS(lower_phis_to_scalar, nir, nir_opt_if,
nir_opt_if_aggressive_last_continue |
(LLVM_VERSION_MAJOR == 14 ? 0 : nir_opt_if_optimize_phi_true_false));
NIR_PASS(progress, nir, nir_opt_dead_cf); NIR_PASS(progress, nir, nir_opt_dead_cf);
if (lower_alu_to_scalar) if (lower_alu_to_scalar)

View File

@@ -355,7 +355,7 @@ optimize(nir_shader *nir)
NIR_PASS(progress, nir, nir_opt_dce); NIR_PASS(progress, nir, nir_opt_dce);
NIR_PASS(progress, nir, nir_opt_remove_phis); NIR_PASS(progress, nir, nir_opt_remove_phis);
} }
NIR_PASS(progress, nir, nir_opt_if, true); NIR_PASS(progress, nir, nir_opt_if, nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
NIR_PASS(progress, nir, nir_opt_dead_cf); NIR_PASS(progress, nir, nir_opt_dead_cf);
NIR_PASS(progress, nir, nir_opt_conditional_discard); NIR_PASS(progress, nir, nir_opt_conditional_discard);
NIR_PASS(progress, nir, nir_opt_remove_phis); NIR_PASS(progress, nir, nir_opt_remove_phis);

View File

@@ -625,7 +625,7 @@ brw_nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
OPT(nir_copy_prop); OPT(nir_copy_prop);
OPT(nir_opt_dce); OPT(nir_opt_dce);
} }
OPT(nir_opt_if, false); OPT(nir_opt_if, nir_opt_if_optimize_phi_true_false);
OPT(nir_opt_conditional_discard); OPT(nir_opt_conditional_discard);
if (nir->options->max_unroll_iterations != 0) { if (nir->options->max_unroll_iterations != 0) {
OPT(nir_opt_loop_unroll); OPT(nir_opt_loop_unroll);

View File

@@ -856,7 +856,7 @@ clc_spirv_to_dxil(struct clc_libclc *lib,
NIR_PASS(progress, nir, nir_lower_var_copies); NIR_PASS(progress, nir, nir_lower_var_copies);
NIR_PASS(progress, nir, nir_lower_vars_to_ssa); NIR_PASS(progress, nir, nir_lower_vars_to_ssa);
NIR_PASS(progress, nir, nir_opt_algebraic); NIR_PASS(progress, nir, nir_opt_algebraic);
NIR_PASS(progress, nir, nir_opt_if, true); NIR_PASS(progress, nir, nir_opt_if, nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
NIR_PASS(progress, nir, nir_opt_dead_cf); NIR_PASS(progress, nir, nir_opt_dead_cf);
NIR_PASS(progress, nir, nir_opt_remove_phis); NIR_PASS(progress, nir, nir_opt_remove_phis);
NIR_PASS(progress, nir, nir_opt_peephole_select, 8, true, true); NIR_PASS(progress, nir, nir_opt_peephole_select, 8, true, true);

View File

@@ -5600,7 +5600,7 @@ optimize_nir(struct nir_shader *s, const struct nir_to_dxil_options *opts)
NIR_PASS(progress, s, dxil_nir_lower_16bit_conv); NIR_PASS(progress, s, dxil_nir_lower_16bit_conv);
NIR_PASS(progress, s, nir_opt_remove_phis); NIR_PASS(progress, s, nir_opt_remove_phis);
NIR_PASS(progress, s, nir_opt_dce); NIR_PASS(progress, s, nir_opt_dce);
NIR_PASS(progress, s, nir_opt_if, true); NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
NIR_PASS(progress, s, nir_opt_dead_cf); NIR_PASS(progress, s, nir_opt_dead_cf);
NIR_PASS(progress, s, nir_opt_cse); NIR_PASS(progress, s, nir_opt_cse);
NIR_PASS(progress, s, nir_opt_peephole_select, 8, true, true); NIR_PASS(progress, s, nir_opt_peephole_select, 8, true, true);