diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c index 7797bcb2b57..e46a356e924 100644 --- a/src/freedreno/ir3/ir3_nir.c +++ b/src/freedreno/ir3/ir3_nir.c @@ -1163,11 +1163,6 @@ ir3_nir_lower_variant(struct ir3_shader_variant *so, progress |= OPT(s, ir3_nir_lower_64b_intrinsics); progress |= OPT(s, nir_lower_64bit_phis); - /* Cleanup code leftover from lowering passes before opt_preamble */ - if (progress) { - progress |= OPT(s, nir_opt_constant_folding); - } - progress |= OPT(s, ir3_nir_opt_subgroups, so); if (so->compiler->load_shader_consts_via_preamble) @@ -1177,6 +1172,16 @@ ir3_nir_lower_variant(struct ir3_shader_variant *so, ir3_setup_const_state(s, so, ir3_const_state_mut(so)); } + /* Cleanup code leftover from lowering passes before opt_preamble */ + if (progress) { + ir3_optimize_loop(so->compiler, options, s); + + /* No need to run the optimize loop again if there's no progress after + * this point. + */ + progress = false; + } + /* Do the preamble before analysing UBO ranges, because it's usually * higher-value and because it can result in eliminating some indirect UBO * accesses where otherwise we'd have to push the whole range. However we