pan/bi: Use a progress loop for constant folding
authorAlyssa Rosenzweig <alyssa@collabora.com>
Wed, 22 Dec 2021 18:22:21 +0000 (13:22 -0500)
committerMarge Bot <emma+marge@anholt.net>
Tue, 1 Mar 2022 19:43:22 +0000 (19:43 +0000)
Needed to fold the dependent patterns produced by texture instructions
during NIR->Valhall.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15204>

src/panfrost/bifrost/bi_opt_constant_fold.c
src/panfrost/bifrost/bifrost_compile.c
src/panfrost/bifrost/compiler.h

index f69866c..2679b9d 100644 (file)
@@ -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;
 }
index 0450e73..9a1feb2 100644 (file)
@@ -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);
 
index f71478e..25c5673 100644 (file)
@@ -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 */