Mesa (master): vc4: Add some optimization of FADD(FSUB(0, x)).

Eric Anholt anholt at kemper.freedesktop.org
Thu Oct 9 09:05:57 UTC 2014


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

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Oct  9 09:32:10 2014 +0200

vc4: Add some optimization of FADD(FSUB(0, x)).

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 |   31 +++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/gallium/drivers/vc4/vc4_opt_algebraic.c b/src/gallium/drivers/vc4/vc4_opt_algebraic.c
index f88a5c1..4155e72 100644
--- a/src/gallium/drivers/vc4/vc4_opt_algebraic.c
+++ b/src/gallium/drivers/vc4/vc4_opt_algebraic.c
@@ -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;
                 }




More information about the mesa-commit mailing list