@@ -314,10 +314,9 @@ bool emitter::IsFlagsAlwaysModified(instrDesc* id)
314
314
315
315
bool emitter::AreUpper32BitsZero(regNumber reg)
316
316
{
317
- // If there are no instructions in this IG, we can look back at
318
- // the previous IG's instructions if this IG is an extension.
317
+ // Only consider if safe
319
318
//
320
- if ((emitCurIGinsCnt == 0) && ((emitCurIG->igFlags & IGF_EXTEND) == 0 ))
319
+ if (!emitCanPeepholeLastIns( ))
321
320
{
322
321
return false;
323
322
}
@@ -397,8 +396,9 @@ bool emitter::AreFlagsSetToZeroCmp(regNumber reg, emitAttr opSize, genTreeOps tr
397
396
return false;
398
397
}
399
398
400
- // Don't look back across IG boundaries (possible control flow)
401
- if (emitCurIGinsCnt == 0 && ((emitCurIG->igFlags & IGF_EXTEND) == 0))
399
+ // Only consider if safe
400
+ //
401
+ if (!emitCanPeepholeLastIns())
402
402
{
403
403
return false;
404
404
}
@@ -480,8 +480,9 @@ bool emitter::AreFlagsSetForSignJumpOpt(regNumber reg, emitAttr opSize, GenTree*
480
480
return false;
481
481
}
482
482
483
- // Don't look back across IG boundaries (possible control flow)
484
- if (emitCurIGinsCnt == 0 && ((emitCurIG->igFlags & IGF_EXTEND) == 0))
483
+ // Only consider if safe
484
+ //
485
+ if (!emitCanPeepholeLastIns())
485
486
{
486
487
return false;
487
488
}
@@ -4698,13 +4699,10 @@ bool emitter::IsRedundantMov(
4698
4699
return true;
4699
4700
}
4700
4701
4701
- bool isFirstInstrInBlock = (emitCurIGinsCnt == 0) && ((emitCurIG->igFlags & IGF_EXTEND) == 0);
4702
-
4703
4702
// TODO-XArch-CQ: Certain instructions, such as movaps vs movups, are equivalent in
4704
4703
// functionality even if their actual identifier differs and we should optimize these
4705
4704
4706
- if (isFirstInstrInBlock || // Don't optimize if instruction is the first instruction in IG.
4707
- (emitLastIns == nullptr) || // or if a last instruction doesn't exist
4705
+ if (!emitCanPeepholeLastIns() || // Don't optimize if unsafe
4708
4706
(emitLastIns->idIns() != ins) || // or if the instruction is different from the last instruction
4709
4707
(emitLastIns->idOpSize() != size) || // or if the operand size is different from the last instruction
4710
4708
(emitLastIns->idInsFmt() != fmt)) // or if the format is different from the last instruction
@@ -7343,14 +7341,10 @@ bool emitter::IsRedundantStackMov(instruction ins, insFormat fmt, emitAttr size,
7343
7341
return false;
7344
7342
}
7345
7343
7346
- bool hasSideEffect = HasSideEffect(ins, size);
7347
-
7348
- bool isFirstInstrInBlock = (emitCurIGinsCnt == 0) && ((emitCurIG->igFlags & IGF_EXTEND) == 0);
7349
7344
// TODO-XArch-CQ: Certain instructions, such as movaps vs movups, are equivalent in
7350
7345
// functionality even if their actual identifier differs and we should optimize these
7351
7346
7352
- if (isFirstInstrInBlock || // Don't optimize if instruction is the first instruction in IG.
7353
- (emitLastIns == nullptr) || // or if a last instruction doesn't exist
7347
+ if (!emitCanPeepholeLastIns() || // Don't optimize if unsafe
7354
7348
(emitLastIns->idIns() != ins) || // or if the instruction is different from the last instruction
7355
7349
(emitLastIns->idOpSize() != size)) // or if the operand size is different from the last instruction
7356
7350
{
@@ -7367,6 +7361,8 @@ bool emitter::IsRedundantStackMov(instruction ins, insFormat fmt, emitAttr size,
7367
7361
int varNum = emitLastIns->idAddr()->iiaLclVar.lvaVarNum();
7368
7362
int lastOffs = emitLastIns->idAddr()->iiaLclVar.lvaOffset();
7369
7363
7364
+ const bool hasSideEffect = HasSideEffect(ins, size);
7365
+
7370
7366
// Check if the last instruction and current instructions use the same register and local memory.
7371
7367
if (varNum == varx && lastReg1 == ireg && lastOffs == offs)
7372
7368
{
0 commit comments