Module: Mesa
Branch: master
Commit: 214e7de90935774d6743c75c7cd1f5aa49c2f9fe
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=214e7de90935774d6743c75c7cd1f5aa49c2f9fe

Author: Alyssa Rosenzweig <[email protected]>
Date:   Tue Feb  9 19:45:03 2021 -0500

pan/bi: Fix 'last tuple' for terminal-NOP clauses

This incorrectly assumed the last tuple was nontrivial, an invariant
that holds by accident on the current scheduler but will break
momentarily. Fix this, and document the invariants.

Signed-off-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8962>

---

 src/panfrost/bifrost/compiler.h | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index 346ac86a72b..049b0740bc4 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -840,18 +840,33 @@ bi_after_instr(bi_instr *instr)
     };
 }
 
-static inline bi_instr *
+/* Invariant: a tuple must be nonempty UNLESS it is the last tuple of a clause,
+ * in which case there must exist a nonempty penultimate tuple */
+
+ATTRIBUTE_RETURNS_NONNULL static inline bi_instr *
 bi_first_instr_in_clause(bi_clause *clause)
 {
         bi_tuple tuple = clause->tuples[0];
-        return tuple.fma ?: tuple.add;
+        bi_instr *instr = tuple.fma ?: tuple.add;
+
+        assert(instr != NULL);
+        return instr;
 }
 
-static inline bi_instr *
+ATTRIBUTE_RETURNS_NONNULL static inline bi_instr *
 bi_last_instr_in_clause(bi_clause *clause)
 {
         bi_tuple tuple = clause->tuples[clause->tuple_count - 1];
-        return tuple.add ?: tuple.fma;
+        bi_instr *instr = tuple.add ?: tuple.fma;
+
+        if (!instr) {
+                assert(clause->tuple_count >= 2);
+                tuple = clause->tuples[clause->tuple_count - 2];
+                instr = tuple.add ?: tuple.fma;
+        }
+
+        assert(instr != NULL);
+        return instr;
 }
 
 /* Implemented by expanding bi_foreach_instr_in_block_from(_rev) with the start

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to