Mesa (main): pan/bi: Consider flow control in DCE

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 7 14:35:00 UTC 2022


Module: Mesa
Branch: main
Commit: 2b57303eaf0ee00b0ea2cb2974c222acd6e96f67
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2b57303eaf0ee00b0ea2cb2974c222acd6e96f67

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Thu Apr  7 09:47:46 2022 -0400

pan/bi: Consider flow control in DCE

We don't want to remove instructions like `NOP.wait` on Valhall; this would be
tantamount to deleting barriers.

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

---

 src/panfrost/bifrost/bi_opt_dce.c |  2 +-
 src/panfrost/bifrost/bir.c        | 16 +++++++++++-----
 src/panfrost/bifrost/compiler.h   |  2 +-
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/panfrost/bifrost/bi_opt_dce.c b/src/panfrost/bifrost/bi_opt_dce.c
index 5fbb2cf0f01..85182d6ac47 100644
--- a/src/panfrost/bifrost/bi_opt_dce.c
+++ b/src/panfrost/bifrost/bi_opt_dce.c
@@ -55,7 +55,7 @@ bi_opt_dead_code_eliminate(bi_context *ctx)
                                 all_null &= bi_is_null(ins->dest[d]);
                         }
 
-                        if (all_null && !bi_side_effects(ins->op))
+                        if (all_null && !bi_side_effects(ins))
                                 bi_remove_instruction(ins);
                         else
                                 bi_liveness_ins_update(live, ins, temp_count);
diff --git a/src/panfrost/bifrost/bir.c b/src/panfrost/bifrost/bir.c
index 86e42fa7a8c..d7ac4b283c0 100644
--- a/src/panfrost/bifrost/bir.c
+++ b/src/panfrost/bifrost/bir.c
@@ -156,12 +156,18 @@ bi_next_clause(bi_context *ctx, bi_block *block, bi_clause *clause)
  * implies no loss of generality */
 
 bool
-bi_side_effects(enum bi_opcode op)
+bi_side_effects(const bi_instr *I)
 {
-        if (bi_opcode_props[op].last)
+        if (bi_opcode_props[I->op].last)
                 return true;
 
-        switch (op) {
+        /* On Valhall, nontrivial flow control acts as a side effect and should
+         * not be dead code eliminated away.
+         */
+        if (I->flow)
+                return true;
+
+        switch (I->op) {
         case BI_OPCODE_DISCARD_F32:
         case BI_OPCODE_DISCARD_B32:
                 return true;
@@ -169,7 +175,7 @@ bi_side_effects(enum bi_opcode op)
                 break;
         }
 
-        switch (bi_opcode_props[op].message) {
+        switch (bi_opcode_props[I->op].message) {
         case BIFROST_MESSAGE_NONE:
         case BIFROST_MESSAGE_VARYING:
         case BIFROST_MESSAGE_ATTRIBUTE:
@@ -189,7 +195,7 @@ bi_side_effects(enum bi_opcode op)
                 return true;
 
         case BIFROST_MESSAGE_TILE:
-                return (op != BI_OPCODE_LD_TILE);
+                return (I->op != BI_OPCODE_LD_TILE);
         }
 
         unreachable("Invalid message type");
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index 04a3838a4d7..3675965fd15 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -1016,7 +1016,7 @@ unsigned bi_count_write_registers(const bi_instr *ins, unsigned dest);
 bool bi_is_regfmt_16(enum bi_register_format fmt);
 unsigned bi_writemask(const bi_instr *ins, unsigned dest);
 bi_clause * bi_next_clause(bi_context *ctx, bi_block *block, bi_clause *clause);
-bool bi_side_effects(enum bi_opcode op);
+bool bi_side_effects(const bi_instr *I);
 bool bi_reconverge_branches(bi_block *block);
 
 void bi_print_instr(const bi_instr *I, FILE *fp);



More information about the mesa-commit mailing list