radv: use NIR_LOOP_PASS helpers

A somewhat random collection of fossils:
    N           Min           Max        Median           Avg        Stddev
x   6         16.59         16.61        16.605     16.603333  0.0081649658
+   6         15.99            16            16     15.998333  0.0040824829
Difference at 95.0% confidence
	-0.605 +/- 0.00830327
	-3.64385% +/- 0.0485573%
	(Student's t, pooled s = 0.00645497)

I'm not sure if nir_opt_if and nir_opt_loop_unroll are actually idempotent
or not.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24197>
This commit is contained in:
Rhys Perry 2023-07-14 19:30:36 +01:00 committed by Marge Bot
parent debddca134
commit 7de34ad3ef

View file

@ -173,50 +173,55 @@ radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively)
{
bool progress;
struct set *skip = _mesa_pointer_set_create(NULL);
do {
progress = false;
NIR_PASS(progress, shader, nir_split_array_vars, nir_var_function_temp);
NIR_PASS(progress, shader, nir_shrink_vec_array_vars, nir_var_function_temp);
NIR_LOOP_PASS(progress, skip, shader, nir_split_array_vars, nir_var_function_temp);
NIR_LOOP_PASS(progress, skip, shader, nir_shrink_vec_array_vars, nir_var_function_temp);
if (!shader->info.var_copies_lowered) {
/* Only run this pass if nir_lower_var_copies was not called
* yet. That would lower away any copy_deref instructions and we
* don't want to introduce any more.
*/
NIR_PASS(progress, shader, nir_opt_find_array_copies);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_find_array_copies);
}
NIR_PASS(progress, shader, nir_opt_copy_prop_vars);
NIR_PASS(progress, shader, nir_opt_dead_write_vars);
NIR_PASS(_, shader, nir_lower_vars_to_ssa);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_copy_prop_vars);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_dead_write_vars);
NIR_LOOP_PASS(_, skip, shader, nir_lower_vars_to_ssa);
NIR_PASS(_, shader, nir_lower_alu_width, vectorize_vec2_16bit, NULL);
NIR_PASS(_, shader, nir_lower_phis_to_scalar, true);
NIR_LOOP_PASS(_, skip, shader, nir_lower_alu_width, vectorize_vec2_16bit, NULL);
NIR_LOOP_PASS(_, skip, shader, nir_lower_phis_to_scalar, true);
NIR_PASS(progress, shader, nir_copy_prop);
NIR_PASS(progress, shader, nir_opt_remove_phis);
NIR_PASS(progress, shader, nir_opt_dce);
if (nir_opt_trivial_continues(shader)) {
NIR_LOOP_PASS(progress, skip, shader, nir_copy_prop);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_remove_phis);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_dce);
bool trivial_continues_progress = false;
NIR_LOOP_PASS(trivial_continues_progress, skip, shader, nir_opt_trivial_continues);
if (trivial_continues_progress) {
progress = true;
NIR_PASS(progress, shader, nir_copy_prop);
NIR_PASS(progress, shader, nir_opt_remove_phis);
NIR_PASS(progress, shader, nir_opt_dce);
NIR_LOOP_PASS(progress, skip, shader, nir_copy_prop);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_remove_phis);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_dce);
}
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_cse);
NIR_PASS(progress, shader, nir_opt_peephole_select, 8, true, true);
NIR_PASS(progress, shader, nir_opt_constant_folding);
NIR_PASS(progress, shader, nir_opt_intrinsics);
NIR_PASS(progress, shader, nir_opt_algebraic);
NIR_LOOP_PASS_NOT_IDEMPOTENT(progress, skip, shader, nir_opt_if,
nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_dead_cf);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_cse);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_peephole_select, 8, true, true);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_constant_folding);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_intrinsics);
NIR_LOOP_PASS_NOT_IDEMPOTENT(progress, skip, shader, nir_opt_algebraic);
NIR_PASS(progress, shader, nir_opt_undef);
NIR_LOOP_PASS(progress, skip, shader, nir_opt_undef);
if (shader->options->max_unroll_iterations) {
NIR_PASS(progress, shader, nir_opt_loop_unroll);
NIR_LOOP_PASS_NOT_IDEMPOTENT(progress, skip, shader, nir_opt_loop_unroll);
}
} while (progress && !optimize_conservatively);
_mesa_set_destroy(skip, NULL);
NIR_PASS(progress, shader, nir_opt_shrink_vectors);
NIR_PASS(progress, shader, nir_remove_dead_variables, nir_var_function_temp | nir_var_shader_in | nir_var_shader_out,
@ -259,14 +264,16 @@ radv_optimize_nir_algebraic(nir_shader *nir, bool opt_offsets)
* fneg(fneg(a)).
*/
bool more_late_algebraic = true;
struct set *skip = _mesa_pointer_set_create(NULL);
while (more_late_algebraic) {
more_late_algebraic = false;
NIR_PASS(more_late_algebraic, nir, nir_opt_algebraic_late);
NIR_PASS(_, nir, nir_opt_constant_folding);
NIR_PASS(_, nir, nir_copy_prop);
NIR_PASS(_, nir, nir_opt_dce);
NIR_PASS(_, nir, nir_opt_cse);
NIR_LOOP_PASS_NOT_IDEMPOTENT(more_late_algebraic, skip, nir, nir_opt_algebraic_late);
NIR_LOOP_PASS(_, skip, nir, nir_opt_constant_folding);
NIR_LOOP_PASS(_, skip, nir, nir_copy_prop);
NIR_LOOP_PASS(_, skip, nir, nir_opt_dce);
NIR_LOOP_PASS(_, skip, nir, nir_opt_cse);
}
_mesa_set_destroy(skip, NULL);
}
static void