@@ -486,10 +486,9 @@ bool emitter::IsFlagsAlwaysModified(instrDesc* id)
486486
487487bool emitter::AreUpper32BitsZero(regNumber reg)
488488{
489- // If there are no instructions in this IG, we can look back at
490- // the previous IG's instructions if this IG is an extension.
489+ // Only consider if safe
491490 //
492- if ((emitCurIGinsCnt == 0) && ((emitCurIG->igFlags & IGF_EXTEND) == 0 ))
491+ if (!emitCanPeepholeLastIns( ))
493492 {
494493 return false;
495494 }
@@ -569,8 +568,9 @@ bool emitter::AreFlagsSetToZeroCmp(regNumber reg, emitAttr opSize, genTreeOps tr
569568 return false;
570569 }
571570
572- // Don't look back across IG boundaries (possible control flow)
573- if (emitCurIGinsCnt == 0 && ((emitCurIG->igFlags & IGF_EXTEND) == 0))
571+ // Only consider if safe
572+ //
573+ if (!emitCanPeepholeLastIns())
574574 {
575575 return false;
576576 }
@@ -652,8 +652,9 @@ bool emitter::AreFlagsSetForSignJumpOpt(regNumber reg, emitAttr opSize, GenTree*
652652 return false;
653653 }
654654
655- // Don't look back across IG boundaries (possible control flow)
656- if (emitCurIGinsCnt == 0 && ((emitCurIG->igFlags & IGF_EXTEND) == 0))
655+ // Only consider if safe
656+ //
657+ if (!emitCanPeepholeLastIns())
657658 {
658659 return false;
659660 }
@@ -5717,13 +5718,10 @@ bool emitter::IsRedundantMov(
57175718 return true;
57185719 }
57195720
5720- bool isFirstInstrInBlock = (emitCurIGinsCnt == 0) && ((emitCurIG->igFlags & IGF_EXTEND) == 0);
5721-
57225721 // TODO-XArch-CQ: Certain instructions, such as movaps vs movups, are equivalent in
57235722 // functionality even if their actual identifier differs and we should optimize these
57245723
5725- if (isFirstInstrInBlock || // Don't optimize if instruction is the first instruction in IG.
5726- (emitLastIns == nullptr) || // or if a last instruction doesn't exist
5724+ if (!emitCanPeepholeLastIns() || // Don't optimize if unsafe
57275725 (emitLastIns->idIns() != ins) || // or if the instruction is different from the last instruction
57285726 (emitLastIns->idOpSize() != size) || // or if the operand size is different from the last instruction
57295727 (emitLastIns->idInsFmt() != fmt)) // or if the format is different from the last instruction
@@ -8410,14 +8408,10 @@ bool emitter::IsRedundantStackMov(instruction ins, insFormat fmt, emitAttr size,
84108408 return false;
84118409 }
84128410
8413- bool hasSideEffect = HasSideEffect(ins, size);
8414-
8415- bool isFirstInstrInBlock = (emitCurIGinsCnt == 0) && ((emitCurIG->igFlags & IGF_EXTEND) == 0);
84168411 // TODO-XArch-CQ: Certain instructions, such as movaps vs movups, are equivalent in
84178412 // functionality even if their actual identifier differs and we should optimize these
84188413
8419- if (isFirstInstrInBlock || // Don't optimize if instruction is the first instruction in IG.
8420- (emitLastIns == nullptr) || // or if a last instruction doesn't exist
8414+ if (!emitCanPeepholeLastIns() || // Don't optimize if unsafe
84218415 (emitLastIns->idIns() != ins) || // or if the instruction is different from the last instruction
84228416 (emitLastIns->idOpSize() != size)) // or if the operand size is different from the last instruction
84238417 {
@@ -8434,6 +8428,8 @@ bool emitter::IsRedundantStackMov(instruction ins, insFormat fmt, emitAttr size,
84348428 int varNum = emitLastIns->idAddr()->iiaLclVar.lvaVarNum();
84358429 int lastOffs = emitLastIns->idAddr()->iiaLclVar.lvaOffset();
84368430
8431+ const bool hasSideEffect = HasSideEffect(ins, size);
8432+
84378433 // Check if the last instruction and current instructions use the same register and local memory.
84388434 if (varNum == varx && lastReg1 == ireg && lastOffs == offs)
84398435 {
0 commit comments