[Mesa-dev] [PATCH v2 7/7] nv50/ir: optimize mad/fma with third argument 0 to mul

Karol Herbst nouveau at karolherbst.de
Wed Jan 27 09:25:08 PST 2016


From: Karol Herbst <git at karolherbst.de>

total instructions in shared programs : 1895008 -> 1894759 (-0.01%)
total gprs used in shared programs    : 251728 -> 251715 (-0.01%)
total local used in shared programs   : 5673 -> 5673 (0.00%)
total bytes used in shared programs   : 17377840 -> 17375696 (-0.01%)

                local        gpr       inst      bytes
    helped           0          23         287         287
      hurt           0           5          25          25

Signed-off-by: Karol Herbst <nouveau at karolherbst.de>
---
 .../drivers/nouveau/codegen/nv50_ir_peephole.cpp      | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index 0c98100..3b4e3fb 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -339,6 +339,7 @@ private:
    void expr(Instruction *, ImmediateValue&, ImmediateValue&);
    void expr(Instruction *, ImmediateValue&, ImmediateValue&, ImmediateValue&);
    void opnd(Instruction *, ImmediateValue&, int s);
+   void opnd3(Instruction *, ImmediateValue&);
 
    void unary(Instruction *, const ImmediateValue&);
 
@@ -391,6 +392,8 @@ ConstantFolding::visit(BasicBlock *bb)
       else
       if (i->srcExists(1) && i->src(1).getImmediate(src1))
          opnd(i, src1, 1);
+      if (i->srcExists(2) && i->src(2).getImmediate(src2))
+         opnd3(i, src2);
    }
    return true;
 }
@@ -876,6 +879,22 @@ ConstantFolding::tryCollapseChainedMULs(Instruction *mul2,
 }
 
 void
+ConstantFolding::opnd3(Instruction *i, ImmediateValue &imm2)
+{
+   switch (i->op) {
+   case OP_MAD:
+   case OP_FMA:
+      if (imm2.isInteger(0)) {
+         i->op = OP_MUL;
+         i->setSrc(2, NULL);
+         return;
+      }
+   default:
+      return;
+   }
+}
+
+void
 ConstantFolding::opnd(Instruction *i, ImmediateValue &imm0, int s)
 {
    const int t = !s;
-- 
2.7.0



More information about the mesa-dev mailing list