From 81124dba554ef33a5c75b641505904fc7e9e76c8 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 6 Sep 2023 13:31:46 +0200 Subject: [PATCH 1/4] SPMI: Hacky workaround for coredistools unsupported instructions We currently are unable to get SPMI diffs for methods that use ldapur instructions as our current coredistools does not support this instruction. While we wait for coredistools to be updated (this was blocked on some C++ lib issues) here is a hacky temporary workaround for the problem. It rewrites ldapur* instructions into the corresponding ldur* instruction before passing it to the near differ. --- .../tools/superpmi/superpmi/neardiffer.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/coreclr/tools/superpmi/superpmi/neardiffer.cpp b/src/coreclr/tools/superpmi/superpmi/neardiffer.cpp index 4fa300725cb721..402cade6635fe1 100644 --- a/src/coreclr/tools/superpmi/superpmi/neardiffer.cpp +++ b/src/coreclr/tools/superpmi/superpmi/neardiffer.cpp @@ -1269,6 +1269,28 @@ bool NearDiffer::compare(MethodContext* mc, CompileResult* cr1, CompileResult* c hotCodeSize_1 = nativeSizeOfCode_1; hotCodeSize_2 = nativeSizeOfCode_2; + + auto rewriteUnsupportedInstrs = [](unsigned char* bytes, size_t numBytes) { + for (size_t i = 0; i < numBytes; i += 4) + { + uint32_t inst; + memcpy(&inst, &bytes[i], 4); + + const uint32_t ldapurMask = 0b00111111111000000000110000000000; + const uint32_t ldapurBits = 0b00011001010000000000000000000000; + const uint32_t ldurBits = 0b00111000010000000000000000000000; + if ((inst & ldapurMask) == ldapurBits) + { + inst ^= (ldapurBits ^ ldurBits); + memcpy(&bytes[i], &inst, 4); + } + } + }; + + rewriteUnsupportedInstrs(hotCodeBlock_1, hotCodeSize_1); + rewriteUnsupportedInstrs(coldCodeBlock_1, coldCodeSize_1); + rewriteUnsupportedInstrs(hotCodeBlock_2, hotCodeSize_2); + rewriteUnsupportedInstrs(coldCodeBlock_2, coldCodeSize_2); } LogDebug("HCS1 %d CCS1 %d RDS1 %d xcpnt1 %d flag1 %08X, HCB %p CCB %p RDB %p ohcb %p occb %p odb %p", hotCodeSize_1, From 593fb3a2f6f5092b3b845151d105d2af72480dcd Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 6 Sep 2023 13:35:04 +0200 Subject: [PATCH 2/4] Random JIT change --- src/coreclr/jit/importer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 995068c10aef62..1c43535808e9e5 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -1425,8 +1425,8 @@ bool Compiler::impIsCastHelperMayHaveProfileData(CorInfoHelpFunc helper) switch (helper) { - case CORINFO_HELP_ISINSTANCEOFINTERFACE: case CORINFO_HELP_ISINSTANCEOFARRAY: + case CORINFO_HELP_ISINSTANCEOFINTERFACE: case CORINFO_HELP_ISINSTANCEOFCLASS: case CORINFO_HELP_ISINSTANCEOFANY: case CORINFO_HELP_CHKCASTINTERFACE: From 4e5a3aa6f915f5e13ac978779da142cb5569dbe0 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 7 Sep 2023 15:28:50 +0200 Subject: [PATCH 3/4] Revert "Random JIT change" This reverts commit 593fb3a2f6f5092b3b845151d105d2af72480dcd. --- src/coreclr/jit/importer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 1c43535808e9e5..995068c10aef62 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -1425,8 +1425,8 @@ bool Compiler::impIsCastHelperMayHaveProfileData(CorInfoHelpFunc helper) switch (helper) { - case CORINFO_HELP_ISINSTANCEOFARRAY: case CORINFO_HELP_ISINSTANCEOFINTERFACE: + case CORINFO_HELP_ISINSTANCEOFARRAY: case CORINFO_HELP_ISINSTANCEOFCLASS: case CORINFO_HELP_ISINSTANCEOFANY: case CORINFO_HELP_CHKCASTINTERFACE: From 3378e427727b336359acef5e65ff0fe48a9677dc Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 7 Sep 2023 16:21:52 +0200 Subject: [PATCH 4/4] Add stlur --- src/coreclr/tools/superpmi/superpmi/neardiffer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/coreclr/tools/superpmi/superpmi/neardiffer.cpp b/src/coreclr/tools/superpmi/superpmi/neardiffer.cpp index 402cade6635fe1..4edaba1734f5c1 100644 --- a/src/coreclr/tools/superpmi/superpmi/neardiffer.cpp +++ b/src/coreclr/tools/superpmi/superpmi/neardiffer.cpp @@ -1279,11 +1279,20 @@ bool NearDiffer::compare(MethodContext* mc, CompileResult* cr1, CompileResult* c const uint32_t ldapurMask = 0b00111111111000000000110000000000; const uint32_t ldapurBits = 0b00011001010000000000000000000000; const uint32_t ldurBits = 0b00111000010000000000000000000000; + + const uint32_t stlurMask = 0b00111111111000000000110000000000; + const uint32_t stlurBits = 0b00011001000000000000000000000000; + const uint32_t sturBits = 0b00111000000000000000000000000000; if ((inst & ldapurMask) == ldapurBits) { inst ^= (ldapurBits ^ ldurBits); memcpy(&bytes[i], &inst, 4); } + else if ((inst & stlurMask) == stlurBits) + { + inst ^= (stlurBits ^ sturBits); + memcpy(&bytes[i], &inst, 4); + } } };