Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Make Unsafe.AsRef inlineable #14547

Merged
merged 1 commit into from
Dec 16, 2016
Merged

Make Unsafe.AsRef inlineable #14547

merged 1 commit into from
Dec 16, 2016

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Dec 15, 2016

The JIT inliner chokes on type mismatch on return. Make the method inlineable by round-tripping the value via local that avoids the type mismatch on return.

The JIT inliner chokes on type mismatch on return. Make the method inlineable by round-tripping the value via local that avoids the type mismatch on return.
@jkotas
Copy link
Member Author

jkotas commented Dec 15, 2016

@AndyAyersMS PTLA

@jkotas
Copy link
Member Author

jkotas commented Dec 15, 2016

[MethodImpl(MethodImplOptions.NoInlining)]
static void Test(void * p)
{
    Unsafe.AsRef<int>(p) = 1;
}

Before:

push    ebp
mov     ebp,esp
call    dword ptr ds:[9754ECh] (System.Runtime.CompilerServices.Unsafe.AsRef[[System.Int32, mscorlib]](Void*), mdToken: 06000010)
mov     dword ptr [eax],1
pop     ebp
ret

After

push    ebp
mov     ebp,esp
mov     eax,ecx
mov     dword ptr [eax],1
pop     ebp
ret

@jkotas jkotas merged commit a0e1d73 into dotnet:master Dec 16, 2016
@AndyAyersMS
Copy link
Member

LGTM too, fwiw...

@karelz karelz modified the milestone: 2.0.0 Dec 16, 2016
@jkotas jkotas deleted the unsafe-asref-fix branch December 17, 2016 01:18
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
The JIT inliner chokes on type mismatch on return. Make the method inlineable by round-tripping the value via local that avoids the type mismatch on return.

Commit migrated from dotnet/corefx@a0e1d73
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants