From c1a0e6cbd3a65da1a4c5aed12adb951fd3ab961a Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 26 May 2022 18:53:38 +0200 Subject: [PATCH 1/4] Enable JitConsumeProfileForCasts by default --- src/coreclr/jit/jitconfigvalues.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/jitconfigvalues.h b/src/coreclr/jit/jitconfigvalues.h index b345c7e4323d1f..def43cab91cce9 100644 --- a/src/coreclr/jit/jitconfigvalues.h +++ b/src/coreclr/jit/jitconfigvalues.h @@ -540,7 +540,7 @@ CONFIG_INTEGER(JitMinimalJitProfiling, W("JitMinimalJitProfiling"), 1) CONFIG_INTEGER(JitMinimalPrejitProfiling, W("JitMinimalPrejitProfiling"), 0) CONFIG_INTEGER(JitProfileCasts, W("JitProfileCasts"), 0) // Profile castclass/isinst -CONFIG_INTEGER(JitConsumeProfileForCasts, W("JitConsumeProfileForCasts"), 0) // Consume profile data (if any) for +CONFIG_INTEGER(JitConsumeProfileForCasts, W("JitConsumeProfileForCasts"), 1) // Consume profile data (if any) for // castclass/isinst CONFIG_INTEGER(JitClassProfiling, W("JitClassProfiling"), 1) // Profile virtual and interface calls From 1682f72974303c786d496e8fead3213152060b2c Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 14 Jun 2022 00:27:12 +0200 Subject: [PATCH 2/4] Fix failing tests --- .../src/System/Runtime/CompilerServices/CastHelpers.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs index a921099356ec3d..782143a654e90d 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs @@ -477,7 +477,12 @@ private static CastResult TryGet(nuint source, nuint target) private static object? ChkCastClassSpecial(void* toTypeHnd, object obj) { MethodTable* mt = RuntimeHelpers.GetMethodTable(obj); - Debug.Assert(mt != toTypeHnd, "The check for the trivial cases should be inlined by the JIT"); + + // Normally, this case is expected to be handled by JIT inline. + // However, with PGO data JIT might decide to check a different type instead + // so this one has to be always checked here + if (toTypeHnd == obj) + goto done; for (; ; ) { From f3ccb3e9b30a7bc2d7a79a667114643c9832508a Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Tue, 14 Jun 2022 19:46:48 +0200 Subject: [PATCH 3/4] Update CastHelpers.cs --- .../src/System/Runtime/CompilerServices/CastHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs index 782143a654e90d..820c43be0578cd 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs @@ -481,7 +481,7 @@ private static CastResult TryGet(nuint source, nuint target) // Normally, this case is expected to be handled by JIT inline. // However, with PGO data JIT might decide to check a different type instead // so this one has to be always checked here - if (toTypeHnd == obj) + if (toTypeHnd == mt) goto done; for (; ; ) From e645a9874ff1ce8174926079d0ff397a765cca56 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Tue, 14 Jun 2022 21:34:13 +0200 Subject: [PATCH 4/4] Update CastHelpers.cs --- .../src/System/Runtime/CompilerServices/CastHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs index 820c43be0578cd..486aeb72faddbc 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs @@ -478,7 +478,7 @@ private static CastResult TryGet(nuint source, nuint target) { MethodTable* mt = RuntimeHelpers.GetMethodTable(obj); - // Normally, this case is expected to be handled by JIT inline. + // Normally, this case is expected to be handled by JIT inline. // However, with PGO data JIT might decide to check a different type instead // so this one has to be always checked here if (toTypeHnd == mt)