pan/bi: Use canonical next_clause_prefetch

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7081>
diff --git a/src/panfrost/bifrost/bi_pack.c b/src/panfrost/bifrost/bi_pack.c
index 8fef1a4..7e758a5 100644
--- a/src/panfrost/bifrost/bi_pack.c
+++ b/src/panfrost/bifrost/bi_pack.c
@@ -48,7 +48,7 @@
                 .back_to_back = clause->back_to_back,
                 .no_end_of_shader = (next_1 != NULL),
                 .terminate_discarded_threads = is_fragment,
-                .branch_cond = clause->branch_conditional || clause->back_to_back,
+                .next_clause_prefetch = clause->next_clause_prefetch,
                 .datareg_writebarrier = clause->data_register_write_barrier,
                 .datareg = clause->data_register,
                 .scoreboard_deps = scoreboard_deps,
@@ -59,8 +59,6 @@
                 .suppress_nan = true,
         };
 
-        header.branch_cond |= header.back_to_back;
-
         uint64_t u = 0;
         memcpy(&u, &header, sizeof(header));
         return u;
diff --git a/src/panfrost/bifrost/bi_print.c b/src/panfrost/bifrost/bi_print.c
index a97663c..e30ef8a 100644
--- a/src/panfrost/bifrost/bi_print.c
+++ b/src/panfrost/bifrost/bi_print.c
@@ -410,7 +410,10 @@
         }
 
         if (!clause->back_to_back)
-                fprintf(fp, " nbb %s", clause->branch_conditional ? "branch-cond" : "branch-uncond");
+                fprintf(fp, " nbb");
+
+        if (!clause->next_clause_prefetch)
+               fprintf(fp, " no_prefetch");
 
         if (clause->data_register_write_barrier)
                 fprintf(fp, " drwb");
diff --git a/src/panfrost/bifrost/bi_schedule.c b/src/panfrost/bifrost/bi_schedule.c
index a336e5e..ea526a1 100644
--- a/src/panfrost/bifrost/bi_schedule.c
+++ b/src/panfrost/bifrost/bi_schedule.c
@@ -227,11 +227,13 @@
                         u->constants[0] = ins->constant.u64;
 
                         /* No indirect jumps yet */
-                        if (ins->type == BI_BRANCH) {
+                        if (ins->type == BI_BRANCH)
                                 u->branch_constant = true;
-                                u->branch_conditional =
-                                        (ins->cond != BI_COND_ALWAYS);
-                        }
+
+                        /* We always prefetch except unconditional branches */
+                        u->next_clause_prefetch = !(
+                                (ins->type == BI_BRANCH) &&
+                                (ins->cond == BI_COND_ALWAYS));
 
                         u->clause_type = bi_clause_type_for_ins(ins);
                         u->block = (struct bi_block *) block;
diff --git a/src/panfrost/bifrost/bifrost.h b/src/panfrost/bifrost/bifrost.h
index acb1035..d57df43 100644
--- a/src/panfrost/bifrost/bifrost.h
+++ b/src/panfrost/bifrost/bifrost.h
@@ -88,11 +88,10 @@
          * for fragment shaders for standard GL behaviour of DISCARD. */
         unsigned terminate_discarded_threads : 1;
 
-        // If backToBack is off:
-        // - true for conditional branches and fallthrough
-        // - false for unconditional branches
-        // The blob seems to always set it to true if back-to-back is on.
-        unsigned branch_cond : 1;
+        /* If set, the hardware may prefetch the next clause. If false, the
+         * hardware may not. Clear for unconditional branches. */
+        unsigned next_clause_prefetch : 1;
+
         // This bit is set when the next clause writes to the data register of some
         // previous clause.
         unsigned datareg_writebarrier: 1;
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index eaacf74..c13a7e9 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -400,7 +400,10 @@
          * the emitted code it's always set if back-to-bit is, whereas we use
          * the actual value (without back-to-back so to speak) internally */
         bool back_to_back;
-        bool branch_conditional;
+
+        /* Can we prefetch the next clause? Usually it makes sense, except for
+         * clauses ending in unconditional branches */
+        bool next_clause_prefetch;
 
         /* Assigned data register */
         unsigned data_register;
diff --git a/src/panfrost/bifrost/disassemble.c b/src/panfrost/bifrost/disassemble.c
index 0b972b4..83be8d5 100644
--- a/src/panfrost/bifrost/disassemble.c
+++ b/src/panfrost/bifrost/disassemble.c
@@ -109,10 +109,6 @@
 
         if (!header.back_to_back) {
                 fprintf(fp, "nbb ");
-                if (header.branch_cond)
-                        fprintf(fp, "branch-cond ");
-                else
-                        fprintf(fp, "branch-uncond ");
         }
 
         if (header.suppress_inf)
@@ -146,6 +142,9 @@
         if (header.terminate_discarded_threads)
                 fprintf(fp, "td ");
 
+        if (header.next_clause_prefetch)
+                fprintf(fp, "ncph ");
+
         fprintf(fp, "\n");
 
         if (verbose) {