From 9e94b87b6012450d714edc6d0c46b15a89d5ce61 Mon Sep 17 00:00:00 2001 From: Ilia Mirkin Date: Thu, 1 Jan 2015 01:01:13 -0500 Subject: [PATCH] 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 patterns were observed in some st/nine shaders. Signed-off-by: Ilia Mirkin --- .../nouveau/codegen/nv50_ir_peephole.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp index 719f9805af8..21d20caffdf 100644 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp @@ -784,6 +784,29 @@ ConstantFolding::opnd(Instruction *i, ImmediateValue &imm0, int s) i->src(1).mod = 0; } break; + case OP_MAD: + if (imm0.isInteger(0)) { + i->setSrc(0, i->getSrc(2)); + i->src(0).mod = i->src(2).mod; + i->setSrc(1, NULL); + i->setSrc(2, NULL); + i->op = i->src(0).mod.getOp(); + if (i->op != OP_CVT) + i->src(0).mod = 0; + } 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 = i->src(2).mod; + i->setSrc(2, NULL); + i->op = OP_ADD; + } + break; case OP_ADD: if (i->usesFlags()) break; -- 2.30.2