@@ -887,21 +887,30 @@ bool emitter::AreFlagsSetToZeroCmp(regNumber reg, emitAttr opSize, GenCondition
887
887
return false;
888
888
}
889
889
890
- // Only consider if safe
891
- //
892
890
if (!emitCanPeepholeLastIns())
893
891
{
892
+ // Don't consider if not safe
894
893
return false;
895
894
}
896
895
897
896
instrDesc* id = emitLastIns;
898
897
instruction lastIns = id->idIns();
899
898
900
- if (!id->idHasReg1 () || (id->idReg1() != reg))
899
+ if (!id->idIsReg1Write () || (id->idReg1() != reg))
901
900
{
901
+ // Don't consider instructions which didn't write a register
902
902
return false;
903
903
}
904
904
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
+
905
914
// Certain instruction like and, or and xor modifies exactly same flags
906
915
// as "test" instruction.
907
916
// 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
956
965
instruction lastIns = id->idIns();
957
966
insFormat fmt = id->idInsFmt();
958
967
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())
960
975
{
976
+ // Don't consider instructions which also wrote a mem location or second register
961
977
return false;
962
978
}
963
979
0 commit comments