From 3154df232b7d75ea1a3f2c5e9a8ccf0ebcd6814b Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 22 Dec 2021 13:22:21 -0500 Subject: [PATCH] pan/bi: Use a progress loop for constant folding Needed to fold the dependent patterns produced by texture instructions during NIR->Valhall. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bi_opt_constant_fold.c | 7 ++++++- src/panfrost/bifrost/bifrost_compile.c | 6 ++++-- src/panfrost/bifrost/compiler.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) 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 */