From ef1940dc522fc5d3960a019ca18705bbb6ea399b Mon Sep 17 00:00:00 2001 From: SingleAccretion Date: Thu, 13 Jan 2022 22:09:31 +0300 Subject: [PATCH] Fix MOffset size estimate --- src/coreclr/jit/emitxarch.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index 40eb8d078209f7..1075c4ccd97d0e 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -2565,6 +2565,19 @@ UNATIVE_OFFSET emitter::emitInsSizeAM(instrDesc* id, code_t code) if (reg == REG_NA) { /* The address is of the form "[disp]" */ + CLANG_FORMAT_COMMENT_ANCHOR; + +#ifdef TARGET_X86 + // Special case: "mov eax, [disp]" and "mov [disp], eax" can use a smaller 1-byte encoding. + if ((ins == INS_mov) && (id->idReg1() == REG_EAX) && + ((id->idInsFmt() == IF_RWR_ARD) || (id->idInsFmt() == IF_AWR_RRD))) + { + // Amd64: this is one case where addr can be 64-bit in size. This is currently unused. + // If this ever changes, this code will need to be updated to add "sizeof(INT64)" to "size". + assert((size == 2) || ((size == 3) && (id->idOpSize() == EA_2BYTE))); + size--; + } +#endif size += sizeof(INT32);