diff --git a/src/panfrost/bifrost/bi_opt_constant_fold.c b/src/panfrost/bifrost/bi_opt_constant_fold.c index f69866c2214..2679b9da9ad 100644 --- a/src/panfrost/bifrost/bi_opt_constant_fold.c +++ b/src/panfrost/bifrost/bi_opt_constant_fold.c @@ -81,9 +81,11 @@ bi_fold_constant(bi_instr *I, bool *unsupported) return 0; } -void +bool bi_opt_constant_fold(bi_context *ctx) { + bool progress = false; + bi_foreach_instr_global_safe(ctx, ins) { bool unsupported = false; uint32_t replace = bi_fold_constant(ins, &unsupported); @@ -93,5 +95,8 @@ bi_opt_constant_fold(bi_context *ctx) bi_builder b = bi_init_builder(ctx, bi_after_instr(ins)); bi_mov_i32_to(&b, ins->dest[0], bi_imm_u32(replace)); bi_remove_instruction(ins); + progress = true; } + + return progress; } diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index 0450e73cb34..9a1feb2dfdd 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -4009,8 +4009,10 @@ bi_compile_variant_nir(nir_shader *nir, if (likely(optimize)) { bi_opt_copy_prop(ctx); - bi_opt_constant_fold(ctx); - bi_opt_copy_prop(ctx); + + while (bi_opt_constant_fold(ctx)) + bi_opt_copy_prop(ctx); + bi_opt_mod_prop_forward(ctx); bi_opt_mod_prop_backward(ctx); diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index f71478e0cfd..25c5673aebe 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -1013,7 +1013,7 @@ static inline void bi_validate(UNUSED bi_context *ctx, UNUSED const char *after_ #endif uint32_t bi_fold_constant(bi_instr *I, bool *unsupported); -void bi_opt_constant_fold(bi_context *ctx); +bool bi_opt_constant_fold(bi_context *ctx); /* Liveness */