Skip to content

Commit

Permalink
JIT: arm64 redundant move peephole must check instruction format (#57016
Browse files Browse the repository at this point in the history
)

Otherwise we may mistake an immediate for a register and do an incorrect
optimization.

Fixes #56689.
  • Loading branch information
AndyAyersMS authored Aug 8, 2021
1 parent a56b5d7 commit 22ae541
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/coreclr/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15581,17 +15581,19 @@ bool emitter::IsRedundantMov(instruction ins, emitAttr size, regNumber dst, regN
regNumber prevSrc = emitLastIns->idReg2();
insFormat lastInsfmt = emitLastIns->idInsFmt();

if ((prevDst == dst) && (prevSrc == src))
// Sometimes emitLastIns can be a mov with single register e.g. "mov reg, #imm". So ensure to
// optimize formats that does vector-to-vector or scalar-to-scalar register movs.
//
const bool isValidLastInsFormats =
((lastInsfmt == IF_DV_3C) || (lastInsfmt == IF_DR_2G) || (lastInsfmt == IF_DR_2E));

if (isValidLastInsFormats && (prevDst == dst) && (prevSrc == src))
{
assert(emitLastIns->idOpSize() == size);
JITDUMP("\n -- suppressing mov because previous instruction already moved from src to dst register.\n");
return true;
}

// Sometimes emitLastIns can be a mov with single register e.g. "mov reg, #imm". So ensure to
// optimize formats that does vector-to-vector or scalar-to-scalar register movs.
bool isValidLastInsFormats = ((lastInsfmt == IF_DV_3C) || (lastInsfmt == IF_DR_2G) || (lastInsfmt == IF_DR_2E));

if ((prevDst == src) && (prevSrc == dst) && isValidLastInsFormats)
{
// For mov with EA_8BYTE, ensure src/dst are both scalar or both vector.
Expand Down

0 comments on commit 22ae541

Please sign in to comment.