From d26a3f1737aa26b7a210262abf4d9ae47eeab4ae Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 30 Jun 2024 21:06:28 -0700 Subject: [PATCH] [NativeAOT] Optimize multicast delegate thunk - Use RawCalli - Use Unsafe cast of invocation list These changes make the codegen of multicast delegate thunk to be more similar to CoreCLR w/ JIT. --- .../tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs | 4 ++-- .../tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs index b12db35c7b59e8..cba7f51a757b6f 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs @@ -323,11 +323,11 @@ public override MethodIL EmitIL() // ldarg.0 (this pointer) // ldfld Delegate._helperObject - // castclass Delegate.Wrapper[] + // castclass Delegate.Wrapper[] (omitted - generate unsafe cast assuming the delegate is well-formed) // stloc delegateArrayLocal codeStream.EmitLdArg(0); codeStream.Emit(ILOpcode.ldfld, emitter.NewToken(HelperObjectField)); - codeStream.Emit(ILOpcode.castclass, emitter.NewToken(invocationListArrayType)); + // codeStream.Emit(ILOpcode.castclass, emitter.NewToken(invocationListArrayType)); codeStream.EmitStLoc(delegateArrayLocal); // Fill in invocationCountLocal diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs index 6a542d8d00a748..8b6bf4a8664698 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs @@ -436,8 +436,12 @@ public bool IsFatPointerCandidate(MethodDesc containingMethod, MethodSignature s return false; // Delegate invocation never needs fat calls - if (owningType.IsDelegate && containingMethod.Name == "Invoke") - return false; + if (owningType.IsDelegate) + { + string methodName = containingMethod.Name; + if (methodName == "Invoke" || methodName == "InvokeMulticastThunk") + return false; + } } return true;