vc4: Dead code eliminate unused SF instructions.
authorEric Anholt <eric@anholt.net>
Thu, 9 Oct 2014 12:45:14 +0000 (14:45 +0200)
committerEric Anholt <eric@anholt.net>
Thu, 9 Oct 2014 19:47:06 +0000 (21:47 +0200)
src/gallium/drivers/vc4/vc4_opt_dead_code.c

index 9f7606fb52bda1e330dc9896b8345c451ad834b6..0c273fff8f53d2fbbe239f5ea3ca0bc1124b630b 100644 (file)
 
 #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;