nv50/ir/opt: optimize u32 MOD by power of 2 into AND
authorChristoph Bumiller <e0425955@student.tuwien.ac.at>
Sat, 7 Jan 2012 17:42:13 +0000 (18:42 +0100)
committerChristoph Bumiller <e0425955@student.tuwien.ac.at>
Mon, 9 Jan 2012 23:37:37 +0000 (00:37 +0100)
src/gallium/drivers/nv50/codegen/nv50_ir_peephole.cpp

index 2a7a981ac6140a1af84c24483d2e532dd64ac1d0..fc025d8767e9c40996f661fc64a33b9b89040432 100644 (file)
@@ -698,6 +698,14 @@ ConstantFolding::opnd(Instruction *i, ImmediateValue *src, int s)
       }
       break;
 
+   case OP_MOD:
+      if (i->sType == TYPE_U32 && imm.isPow2()) {
+         bld.setPosition(i, false);
+         i->op = OP_AND;
+         i->setSrc(1, bld.loadImm(NULL, imm.reg.data.u32 - 1));
+      }
+      break;
+
    case OP_SET: // TODO: SET_AND,OR,XOR
    {
       CmpInstruction *si = findOriginForTestWithZero(i->getSrc(t));