[Mesa-dev] [PATCH v3 3/9] nv50/ir: teach load propagation about src2
Samuel Pitoiset
samuel.pitoiset at gmail.com
Tue Sep 13 19:36:06 UTC 2016
With OP_ADD3, we might want to swap sources 2 and 1.
Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
.../drivers/nouveau/codegen/nv50_ir_peephole.cpp | 29 ++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index a9172f8..f212eba 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -153,6 +153,7 @@ private:
virtual bool visit(BasicBlock *);
void checkSwapSrc01(Instruction *);
+ void checkSwapSrc21(Instruction *);
bool isCSpaceLoad(Instruction *);
bool isImmdLoad(Instruction *);
@@ -239,6 +240,32 @@ LoadPropagation::checkSwapSrc01(Instruction *insn)
}
}
+void
+LoadPropagation::checkSwapSrc21(Instruction *insn)
+{
+ const Target *targ = prog->getTarget();
+ if (insn->op != OP_ADD3)
+ return;
+ if (insn->src(2).getFile() != FILE_GPR)
+ return;
+
+ Instruction *i1 = insn->getSrc(1)->getInsn();
+ Instruction *i2 = insn->getSrc(2)->getInsn();
+
+ // Swap sources to inline the less frequently used source. That way,
+ // optimistically, it will eventually be able to remove the instruction.
+ int i1refs = insn->getSrc(1)->refCount();
+ int i2refs = insn->getSrc(2)->refCount();
+
+ if ((isCSpaceLoad(i2) || isImmdLoad(i2)) && targ->insnCanLoad(insn, 1, i2)) {
+ if ((!isImmdLoad(i1) && !isCSpaceLoad(i1)) ||
+ !targ->insnCanLoad(insn, 1, i1) ||
+ i2refs < i1refs) {
+ insn->swapSources(2, 1);
+ }
+ }
+}
+
bool
LoadPropagation::visit(BasicBlock *bb)
{
@@ -256,6 +283,8 @@ LoadPropagation::visit(BasicBlock *bb)
if (i->srcExists(1))
checkSwapSrc01(i);
+ if (i->srcExists(2))
+ checkSwapSrc21(i);
for (int s = 0; i->srcExists(s); ++s) {
Instruction *ld = i->getSrc(s)->getInsn();
--
2.9.3
More information about the mesa-dev
mailing list