[Mesa-dev] [PATCH] nv50/ir: add more advanced slct constant folding code

Karol Herbst kherbst at redhat.com
Tue Mar 27 22:36:03 UTC 2018


From: Karol Herbst <karolherbst at gmail.com>

shader-db changes:
total instructions in shared programs : 5894114 -> 5887031 (-0.12%)
total gprs used in shared programs    : 666558 -> 666514 (-0.01%)
total shared used in shared programs  : 520416 -> 520416 (0.00%)
total local used in shared programs   : 53524 -> 53572 (0.09%)
total bytes used in shared programs   : 54006744 -> 53942072 (-0.12%)

                local     shared        gpr       inst      bytes
    helped           3           0          36         936         936
      hurt          10           0           5           0           0

increase in local use is related to a bug in the spilling code

Signed-off-by: Karol Herbst <karolherbst at gmail.com>
---
 .../drivers/nouveau/codegen/nv50_ir_peephole.cpp   | 32 +++++++++++++++++++---
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index 48cf74950df..18d5456b8fd 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -636,11 +636,35 @@ ConstantFolding::expr(Instruction *i,
          return;
       }
       break;
-   case OP_SLCT:
-      if (a->data.u32 != b->data.u32)
+   case OP_SLCT: {
+      CmpInstruction *slct = i->asCmp();
+      // slct(a, a, c) -> a
+      if (a->data.u32 == b->data.u32) {
+         res.data.u32 = a->data.u32;
+         break;
+      }
+      // slct(-1, 0, c) -> set(c, 0)
+      if (a->data.u32 == 0xffffffff &&
+          b->data.u32 == 0x0) {
+         i->op = OP_SET;
+         i->setSrc(0, i->getSrc(2));
+         i->setSrc(2, NULL);
+         i->dType = TYPE_U32;
          return;
-      res.data.u32 = a->data.u32;
-      break;
+      }
+      // slct(0, -1, c) -> !set(c, 0)
+      if (a->data.u32 == 0x0 &&
+          b->data.u32 == 0xffffffff) {
+         i->op = OP_SET;
+         i->swapSources(0, 1);
+         i->setSrc(0, i->getSrc(2));
+         i->setSrc(2, NULL);
+         i->dType = TYPE_U32;
+         slct->setCondition(inverseCondCode(slct->getCondition()));
+         return;
+      }
+      return;
+   }
    case OP_EXTBF: {
       int offset = b->data.u32 & 0xff;
       int width = (b->data.u32 >> 8) & 0xff;
-- 
2.14.3



More information about the mesa-dev mailing list