vc4: Add some optimization of FADD(FSUB(0, x)).
authorEric Anholt <eric@anholt.net>
Thu, 9 Oct 2014 07:32:10 +0000 (09:32 +0200)
committerEric Anholt <eric@anholt.net>
Thu, 9 Oct 2014 09:01:18 +0000 (11:01 +0200)
This is a common production of st_glsl_to_tgsi, which uses negate flags on
source arguments to handle subtraction.

src/gallium/drivers/vc4/vc4_opt_algebraic.c

index f88a5c17d2ad7fc1eccc386cf2ee47d1067ca84c..4155e72fd21676fa9328a56784dd56db114acb71 100644 (file)
@@ -128,6 +128,37 @@ qir_opt_algebraic(struct vc4_compile *c)
                         }
                         break;
 
+                case QOP_FADD:
+                        /* FADD(a, FSUB(0, b)) -> FSUB(a, b) */
+                        if (inst->src[1].file == QFILE_TEMP &&
+                            defs[inst->src[1].index]->op == QOP_FSUB) {
+                                struct qinst *fsub = defs[inst->src[1].index];
+                                if (is_zero(c, defs, fsub->src[0])) {
+                                        dump_from(c, inst);
+                                        inst->op = QOP_FSUB;
+                                        inst->src[1] = fsub->src[1];
+                                        progress = true;
+                                        dump_to(c, inst);
+                                        break;
+                                }
+                        }
+
+                        /* FADD(FSUB(0, b), a) -> FSUB(a, b) */
+                        if (inst->src[0].file == QFILE_TEMP &&
+                            defs[inst->src[0].index]->op == QOP_FSUB) {
+                                struct qinst *fsub = defs[inst->src[0].index];
+                                if (is_zero(c, defs, fsub->src[0])) {
+                                        dump_from(c, inst);
+                                        inst->op = QOP_FSUB;
+                                        inst->src[0] = inst->src[1];
+                                        inst->src[1] = fsub->src[1];
+                                        dump_to(c, inst);
+                                        progress = true;
+                                        break;
+                                }
+                        }
+                        break;
+
                 default:
                         break;
                 }