@@ -887,21 +887,30 @@ bool emitter::AreFlagsSetToZeroCmp(regNumber reg, emitAttr opSize, GenCondition
887887 return false;
888888 }
889889
890- // Only consider if safe
891- //
892890 if (!emitCanPeepholeLastIns())
893891 {
892+ // Don't consider if not safe
894893 return false;
895894 }
896895
897896 instrDesc* id = emitLastIns;
898897 instruction lastIns = id->idIns();
899898
900- if (!id->idHasReg1 () || (id->idReg1() != reg))
899+ if (!id->idIsReg1Write () || (id->idReg1() != reg))
901900 {
901+ // Don't consider instructions which didn't write a register
902902 return false;
903903 }
904904
905+ if (id->idHasMemWrite() || id->idIsReg2Write())
906+ {
907+ // Don't consider instructions which also wrote a mem location or second register
908+ return false;
909+ }
910+
911+ assert(!id->idIsReg3Write());
912+ assert(!id->idIsReg4Write());
913+
905914 // Certain instruction like and, or and xor modifies exactly same flags
906915 // as "test" instruction.
907916 // They reset OF and CF to 0 and modifies SF, ZF and PF.
@@ -956,8 +965,15 @@ bool emitter::AreFlagsSetForSignJumpOpt(regNumber reg, emitAttr opSize, GenCondi
956965 instruction lastIns = id->idIns();
957966 insFormat fmt = id->idInsFmt();
958967
959- if (!id->idHasReg1() || (id->idReg1() != reg))
968+ if (!id->idIsReg1Write() || (id->idReg1() != reg))
969+ {
970+ // Don't consider instructions which didn't write a register
971+ return false;
972+ }
973+
974+ if (id->idHasMemWrite() || id->idIsReg2Write())
960975 {
976+ // Don't consider instructions which also wrote a mem location or second register
961977 return false;
962978 }
963979
0 commit comments