Index: vm/jitrino/src/codegenerator/ia32/Ia32InstCodeSelector.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32InstCodeSelector.cpp (revision 530024) +++ vm/jitrino/src/codegenerator/ia32/Ia32InstCodeSelector.cpp (working copy) @@ -2704,7 +2704,7 @@ Opnd* ecxOpnd = irManager.newOpnd(opnds[2]->getType(), cecx); #else Opnd* eaxOpnd = irManager.getRegOpnd(RegName_EAX); - Opnd* ecxOpnd = irManager.getRegOpnd(RegName_ECX); + Opnd* ecxOpnd = irManager.newOpnd(typeManager.getUInt32Type(), Constraint(OpndKind_GPReg)); #endif Opnd* memOpnd = irManager.newMemOpnd(opnds[1]->getType(), opnds[0]);//use opnd1 type for memopnd appendInsts(irManager.newCopyPseudoInst(Mnemonic_MOV, eaxOpnd, opnds[1])); Index: vm/jitrino/src/codegenerator/ia32/Ia32PeepHole.cpp =================================================================== --- vm/jitrino/src/codegenerator/ia32/Ia32PeepHole.cpp (revision 530024) +++ vm/jitrino/src/codegenerator/ia32/Ia32PeepHole.cpp (working copy) @@ -91,6 +91,7 @@ Changed handleInst_MUL(Inst* inst); Changed handleInst_SSEMov(Inst* inst); Changed handleInst_SSEXor(Inst* inst); + Changed handleInst_CMP(Inst* inst); // // Helpers // @@ -177,6 +179,8 @@ PeepHoleOpt::Changed PeepHoleOpt::handleInst(Inst* inst) { + PeepHoleOpt::Changed temp; + if (isPseudoInst(inst)) { return Changed_Nothing; } @@ -191,9 +195,15 @@ case Mnemonic_AND: case Mnemonic_OR: case Mnemonic_XOR: - case Mnemonic_CMP: case Mnemonic_TEST: return handleInst_ALU(inst); + case Mnemonic_CMP: + temp = handleInst_CMP(inst); + if ( temp == Changed_Nothing ) { + return handleInst_ALU(inst); + } else { + return temp; + } case Mnemonic_IMUL: case Mnemonic_MUL: return handleInst_MUL(inst); @@ -405,6 +417,29 @@ return i; } +PeepHoleOpt::Changed PeepHoleOpt::handleInst_CMP(Inst* inst) { + assert(inst->getMnemonic()==Mnemonic_CMP); + + Inst::Opnds uses(inst, Inst::OpndRole_Explicit | Inst::OpndRole_Use); + Opnd* src1 = inst->getOpnd(uses.begin()); + Opnd* src2 = inst->getOpnd(uses.next(uses.begin())); + assert(src1!=NULL && src2!=NULL); + + if (isImm(src1)) { + Opnd* tmp = src1; src1 = src2; src2 = tmp; + } + + if (isImm(src2) && isReg(src1) && (int)src2->getImmValue() == 0) { + if (Log::isEnabled()) Log::out()<<"I"<getId()<<" -> CMP with 0"<newInst(Mnemonic_TEST, src1, src1)->insertAfter(inst); + inst->unlink(); + return Changed_Inst; + } + return Changed_Nothing; +} + + + PeepHoleOpt::Changed PeepHoleOpt::handleInst_MUL(Inst* inst) { assert(inst->getMnemonic()==Mnemonic_IMUL || inst->getMnemonic()==Mnemonic_MUL); if (inst->getForm() == Inst::Form_Native) {