Skip to contentSkip to conversation

nv50/ir: fold MAD when one of the multiplicands is const

PATCH New Ilia Mirkin 1 participant 1 message Jan 1, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nv50/ir: fold MAD when one of the multiplicands is const

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.

---

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(+)
src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp +20 -0
index 719f980..466134f 100644
@@ -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;
Signature · 6 lines
2.0.5

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau