[Nouveau] [PATCH] nv50/ir: fold MAD when one of the multiplicands is const

Ilia Mirkin imirkin at alum.mit.edu
Wed Dec 31 22:09:46 PST 2014


Fold MAD dst, src0, immed, src2 (or src0/immed swapped) when
 - immed = 0 -> MOV dst, src2
 - immed = +/- 1 -> ADD dst, src0, src2

These types of MAD pattersn were observed in some st/nine shaders.

Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---

Haven't tested this enough to push yet, but thought I'd get it out there.
Passes some simple test cases.

 .../drivers/nouveau/codegen/nv50_ir_peephole.cpp     | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index 719f980..466134f 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -784,6 +784,26 @@ ConstantFolding::opnd(Instruction *i, ImmediateValue &imm0, int s)
          i->src(1).mod = 0;
       }
       break;
+   case OP_MAD:
+      if (imm0.isInteger(0)) {
+         i->op = OP_MOV;
+         i->setSrc(0, i->getSrc(2));
+         i->setSrc(1, NULL);
+         i->setSrc(2, NULL);
+      } else
+      if (imm0.isInteger(1) || imm0.isInteger(-1)) {
+         if (imm0.isNegative())
+            i->src(t).mod = i->src(t).mod ^ Modifier(NV50_IR_MOD_NEG);
+         if (s == 0) {
+            i->setSrc(0, i->getSrc(1));
+            i->src(0).mod = i->src(1).mod;
+         }
+         i->setSrc(1, i->getSrc(2));
+         i->src(1).mod = 0;
+         i->setSrc(2, NULL);
+         i->op = OP_ADD;
+      }
+      break;
    case OP_ADD:
       if (i->usesFlags())
          break;
-- 
2.0.5



More information about the Nouveau mailing list