From: Eric Anholt Date: Thu, 9 Oct 2014 12:45:14 +0000 (+0200) Subject: vc4: Dead code eliminate unused SF instructions. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b73cab6826b54cdfa138aefb476f1f0d42b87b6a;p=mesa.git vc4: Dead code eliminate unused SF instructions. --- diff --git a/src/gallium/drivers/vc4/vc4_opt_dead_code.c b/src/gallium/drivers/vc4/vc4_opt_dead_code.c index 9f7606fb52b..0c273fff8f5 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;