[Mesa-dev] [PATCH 4/6] nv50/ir: rework postraconstantfolding pass

Samuel Pitoiset samuel.pitoiset at gmail.com
Sat Oct 8 16:36:25 UTC 2016


"rework" is not the right term in my opinion. :)

On 10/08/2016 05:43 PM, Karol Herbst wrote:
> we might want to add more folding passes here, so make it a bit more generic
>
> Signed-off-by: Karol Herbst <karolherbst at gmail.com>
> ---
>  .../drivers/nouveau/codegen/nv50_ir_peephole.cpp   | 124 ++++++++++-----------
>  1 file changed, 62 insertions(+), 62 deletions(-)
>
> diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
> index 3fcadd9..f2ada55 100644
> --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
> +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
> @@ -2952,79 +2952,79 @@ FlatteningPass::tryPredicateConditional(BasicBlock *bb)
>
>  // =============================================================================
>
> -// Fold Immediate into MAD; must be done after register allocation due to
> -// constraint SDST == SSRC2
> -// TODO:
> -// Does NVC0+ have other situations where this pass makes sense?

I know you are going to improve that situation, but I would suggest to 
not remove that comment in this patch. Remove it later please.

Except this minor thing, that one looks fine.

> -class NV50PostRaConstantFolding : public Pass
> +class PostRaConstantFolding : public Pass
>  {
>  private:
> -   virtual bool visit(BasicBlock *);
> +   virtual bool visit(Instruction *);
> +   void handleMAD(Instruction *);
>  };
>
> -bool
> -NV50PostRaConstantFolding::visit(BasicBlock *bb)
> +// Fold Immediate into MAD; must be done after register allocation due to
> +// constraint SDST == SSRC2
> +void
> +PostRaConstantFolding::handleMAD(Instruction *i)
>  {
> -   Value *vtmp;
> -   Instruction *def;
> -
> -   for (Instruction *i = bb->getFirst(); i; i = i->next) {
> -      switch (i->op) {
> -      case OP_MAD:
> -         if (i->def(0).getFile() != FILE_GPR ||
> -             i->src(0).getFile() != FILE_GPR ||
> -             i->src(1).getFile() != FILE_GPR ||
> -             i->src(2).getFile() != FILE_GPR ||
> -             i->getDef(0)->reg.data.id != i->getSrc(2)->reg.data.id)
> -            break;
> -
> -         if (i->getDef(0)->reg.data.id >= 64 ||
> -             i->getSrc(0)->reg.data.id >= 64)
> -            break;
> +   if (i->def(0).getFile() != FILE_GPR ||
> +       i->src(0).getFile() != FILE_GPR ||
> +       i->src(1).getFile() != FILE_GPR ||
> +       i->src(2).getFile() != FILE_GPR ||
> +       i->getDef(0)->reg.data.id != i->getSrc(2)->reg.data.id)
> +      return;
>
> -         if (i->flagsSrc >= 0 && i->getSrc(i->flagsSrc)->reg.data.id != 0)
> -            break;
> +   if (i->getDef(0)->reg.data.id >= 64 ||
> +       i->getSrc(0)->reg.data.id >= 64)
> +      return;
>
> -         if (i->getPredicate())
> -            break;
> +   if (i->flagsSrc >= 0 && i->getSrc(i->flagsSrc)->reg.data.id != 0)
> +      return;
>
> -         def = i->getSrc(1)->getInsn();
> -         if (def && def->op == OP_SPLIT && typeSizeof(def->sType) == 4)
> -            def = def->getSrc(0)->getInsn();
> -         if (def && def->op == OP_MOV && def->src(0).getFile() == FILE_IMMEDIATE) {
> -            vtmp = i->getSrc(1);
> -            if (isFloatType(i->sType)) {
> -               i->setSrc(1, def->getSrc(0));
> -            } else {
> -               ImmediateValue val;
> -               bool ret = def->src(0).getImmediate(val);
> -               assert(ret);
> -               if (i->getSrc(1)->reg.data.id & 1)
> -                  val.reg.data.u32 >>= 16;
> -               val.reg.data.u32 &= 0xffff;
> -               i->setSrc(1, new_ImmediateValue(bb->getProgram(), val.reg.data.u32));
> -            }
> +   if (i->getPredicate())
> +      return;
>
> -            /* There's no post-RA dead code elimination, so do it here
> -             * XXX: if we add more code-removing post-RA passes, we might
> -             *      want to create a post-RA dead-code elim pass */
> -            if (vtmp->getInsn()->isDead(true)) {
> -               Value *src = vtmp->getInsn()->getSrc(0);
> -               // Careful -- splits will have already been removed from the
> -               // functions. Don't double-delete.
> -               if (vtmp->getInsn()->bb)
> -                  delete_Instruction(prog, vtmp->getInsn());
> -               if (src->getInsn() && src->getInsn()->isDead(true))
> -                  delete_Instruction(prog, src->getInsn());
> -            }
> +   Value *vtmp;
> +   Instruction *def = i->getSrc(1)->getInsn();
> +
> +   if (def && def->op == OP_SPLIT && typeSizeof(def->sType) == 4)
> +      def = def->getSrc(0)->getInsn();
> +   if (def && def->op == OP_MOV && def->src(0).getFile() == FILE_IMMEDIATE) {
> +      vtmp = i->getSrc(1);
> +      if (isFloatType(i->sType)) {
> +         i->setSrc(1, def->getSrc(0));
> +      } else {
> +         ImmediateValue val;
> +         bool ret = def->src(0).getImmediate(val);
> +         assert(ret);
> +         if (i->getSrc(1)->reg.data.id & 1)
> +            val.reg.data.u32 >>= 16;
> +         val.reg.data.u32 &= 0xffff;
> +         i->setSrc(1, new_ImmediateValue(prog, val.reg.data.u32));
> +      }
>
> -            break;
> -         }
> -         break;
> -      default:
> -         break;
> +      /* There's no post-RA dead code elimination, so do it here
> +       * XXX: if we add more code-removing post-RA passes, we might
> +       *      want to create a post-RA dead-code elim pass */
> +      if (vtmp->getInsn()->isDead(true)) {
> +         Value *src = vtmp->getInsn()->getSrc(0);
> +         // Careful -- splits will have already been removed from the
> +         // functions. Don't double-delete.
> +         if (vtmp->getInsn()->bb)
> +            delete_Instruction(prog, vtmp->getInsn());
> +         if (src->getInsn() && src->getInsn()->isDead(true))
> +            delete_Instruction(prog, src->getInsn());
>        }
>     }
> +}
> +
> +bool
> +PostRaConstantFolding::visit(Instruction *i)
> +{
> +   switch (i->op) {
> +   case OP_MAD:
> +      handleMAD(i);
> +      break;
> +   default:
> +      break;
> +   }
>
>     return true;
>  }
> @@ -3555,7 +3555,7 @@ Program::optimizePostRA(int level)
>  {
>     RUN_PASS(2, FlatteningPass, run);
>     if (getTarget()->getChipset() < 0xc0)
> -      RUN_PASS(2, NV50PostRaConstantFolding, run);
> +      RUN_PASS(2, PostRaConstantFolding, run);
>
>     return true;
>  }
>


More information about the mesa-dev mailing list