Mesa (master): vc4: Dead code eliminate unused SF instructions.

Eric Anholt anholt at kemper.freedesktop.org
Thu Oct 9 19:50:06 UTC 2014


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

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Oct  9 14:45:14 2014 +0200

vc4: Dead code eliminate unused SF instructions.

---

 src/gallium/drivers/vc4/vc4_opt_dead_code.c |   33 +++++++++++++++++++++------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/vc4/vc4_opt_dead_code.c b/src/gallium/drivers/vc4/vc4_opt_dead_code.c
index 9f7606f..0c273ff 100644
--- a/src/gallium/drivers/vc4/vc4_opt_dead_code.c
+++ b/src/gallium/drivers/vc4/vc4_opt_dead_code.c
@@ -33,12 +33,25 @@
 
 #include "vc4_qir.h"
 
+static bool debug;
+
+static void
+dce(struct vc4_compile *c, struct qinst *inst)
+{
+        if (debug) {
+                fprintf(stderr, "Removing: ");
+                qir_dump_inst(c, inst);
+                fprintf(stderr, "\n");
+        }
+        qir_remove_instruction(inst);
+}
+
 bool
 qir_opt_dead_code(struct vc4_compile *c)
 {
         bool progress = false;
-        bool debug = false;
         bool *used = calloc(c->num_temps, sizeof(bool));
+        bool sf_used = false;
 
         struct simple_node *node, *t;
         for (node = c->instructions.prev, t = node->prev;
@@ -49,16 +62,22 @@ qir_opt_dead_code(struct vc4_compile *c)
                 if (inst->dst.file == QFILE_TEMP &&
                     !used[inst->dst.index] &&
                     !qir_has_side_effects(inst)) {
-                        if (debug) {
-                                fprintf(stderr, "Removing: ");
-                                qir_dump_inst(c, inst);
-                                fprintf(stderr, "\n");
-                        }
-                        qir_remove_instruction(inst);
+                        dce(c, inst);
                         progress = true;
                         continue;
                 }
 
+                if (qir_depends_on_flags(inst))
+                        sf_used = true;
+                if (inst->op == QOP_SF) {
+                        if (!sf_used) {
+                                dce(c, inst);
+                                progress = true;
+                                continue;
+                        }
+                        sf_used = false;
+                }
+
                 for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
                         if (inst->src[i].file == QFILE_TEMP)
                                 used[inst->src[i].index] = true;




More information about the mesa-commit mailing list