Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CorInfoIntrinsics with NamedIntrinsic #62639

Merged
merged 5 commits into from
Dec 12, 2021

Conversation

am11
Copy link
Member

@am11 am11 commented Dec 10, 2021

The remaining legacy CORINFO_INTRINSIC_* are dynamically identified by the runtime (without involving [Intrinsic] attribute mechanism in managed code). They are converted to modern NamedIntrinsic.

In case of array functions, those appear without name, class and namespace in JIT's import, so it continues to rely on runtime support (which in turns relies on array's vtable). In the initial draft, it is hardwired end to end, until a better solution comes up in the review. I have kept that commit separate to easily drop it (if need be).

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Dec 10, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 10, 2021
@ghost
Copy link

ghost commented Dec 10, 2021

Tagging subscribers to this area: @JulieLeeMSFT
See info in area-owners.md if you want to be subscribed.

Issue Details

The remaining legacy CORINFO_INTRINSIC_* are dynamically identified by the runtime (without involving [Intrinsic] attribute mechanism in managed code). They are converted to modern NamedIntrinsic.

In case of array functions, those appear without name, class and namespace in JIT's import, so it continues to rely on runtime support (which in turns relies on array's vtable). In the initial draft, it is hardwired end to end, until a better solution comes up in the review. I have kept that commit separate to easily drop it (if need be).

Author: am11
Assignees: -
Labels:

area-CodeGen-coreclr, community-contribution

Milestone: -

src/coreclr/inc/corinfo.h Outdated Show resolved Hide resolved
src/coreclr/vm/jitinterface.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/jitinterface.cpp Show resolved Hide resolved
src/coreclr/vm/ceeload.cpp Outdated Show resolved Hide resolved
@@ -4671,6 +4670,49 @@ unsigned CEEInfo::getArrayRank(CORINFO_CLASS_HANDLE cls)
return result;
}

/*********************************************************************/
// Get the index of runtime provided array method
CorInfoArrayIntrinsic CEEInfo::getArrayFuncIndex(CORINFO_METHOD_HANDLE ftn)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: getArrayFuncIndex -> getArrayIntrinsicID or something like that

src/coreclr/inc/corinfo.h Outdated Show resolved Hide resolved
@am11
Copy link
Member Author

am11 commented Dec 11, 2021

diff from filtered JIT Dump:

DOTNET_JitDump=* artifacts/bin/testhost/net7.0-Linux-Debug-x64/shared/Microsoft.NETCore.App/7.0.0/corerun \
    $(pwd)/../mdarraytest/bin/Debug/net6.0/mdarraytest.dll | grep -i intrinsic.*recogni > dump.log

mdarraytest code:

var x = new int[2,2];
x[0,0] = 2;
x[1,0] = 1;

unsafe
{
    fixed(int *y = &x[0,0])
    {
        Console.WriteLine("{0}, {1}, {2}, {3}", x.GetLowerBound(0), x.GetUpperBound(1), x[1,0], (IntPtr)y);
    }
}

difff with diff -U1 runtime_base/dump.log runtime_pr/dump.log

--- runtime_base/dump.log
+++ runtime_pr/dump.log
@@ -91,5 +91,2 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.ReadUnaligned: Not recognized
-Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
-Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.As: Not recognized
-Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.ReadUnaligned: Not recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.AddByteOffset: Not recognized
@@ -147,2 +144,5 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.ByteOffset: Not recognized
+Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
+Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.As: Not recognized
+Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.ReadUnaligned: Not recognized
 Named Intrinsic System.StubHelpers.StubHelpers.GetStubContext: Recognized
@@ -213,3 +213,3 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.As: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
 Named Intrinsic System.Type.GetTypeFromHandle: Recognized
@@ -379,3 +379,3 @@
 Named Intrinsic System.Runtime.InteropServices.MemoryMarshal.GetArrayDataReference: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
 Named Intrinsic System.Runtime.CompilerServices.RuntimeHelpers.IsBitwiseEquatable: Not recognized
@@ -384,3 +384,3 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.As: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.AddByteOffset: Not recognized
@@ -419,8 +419,8 @@
 Named Intrinsic System.Collections.Generic.EqualityComparer`1.get_Default: Recognized
-Intrinsic CORINFO_INTRINSIC_Array_Set Recognized
-Intrinsic CORINFO_INTRINSIC_Array_Set Recognized
-Intrinsic CORINFO_INTRINSIC_Array_Address Recognized
+Named Intrinsic ARRAY_FUNC_SET: Recognized
+Named Intrinsic ARRAY_FUNC_SET: Recognized
+Named Intrinsic ARRAY_FUNC_ADDRESS: Recognized
 Named Intrinsic System.Array.GetLowerBound: Recognized
 Named Intrinsic System.Array.GetUpperBound: Recognized
-Intrinsic CORINFO_INTRINSIC_Array_Get Recognized
+Named Intrinsic ARRAY_FUNC_GET: Recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
@@ -443,5 +443,5 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.As: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
 Named Intrinsic System.Type.GetTypeFromHandle: Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic System.StubHelpers.StubHelpers.GetStubContext: Recognized
@@ -449,5 +449,5 @@
 Named Intrinsic System.String.get_Chars: Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
 Named Intrinsic System.Type.GetTypeFromHandle: Recognized
@@ -456,8 +456,8 @@
 Named Intrinsic System.Type.GetTypeFromHandle: Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.As: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic System.ReadOnlySpan`1.get_Item: Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
@@ -500,4 +500,4 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic System.String.get_Length: Recognized
@@ -505,3 +505,3 @@
 Named Intrinsic System.String.get_Length: Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
@@ -570,3 +570,3 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.As: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
 Named Intrinsic System.Type.GetTypeFromHandle: Recognized
@@ -574,6 +574,6 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.AsRef: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.AsRef: Not recognized
@@ -609,3 +609,3 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
 Named Intrinsic System.Object.GetType: Recognized
@@ -632,7 +632,7 @@
 Named Intrinsic System.ReadOnlySpan`1.get_Item: Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.Add: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Ctor Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
+Named Intrinsic System.ByReference`1..ctor: Recognized
 Named Intrinsic System.Threading.Volatile.Read: Not recognized
@@ -650,3 +650,3 @@
 Named Intrinsic Internal.Runtime.CompilerServices.Unsafe.NullRef: Not recognized
-Intrinsic CORINFO_INTRINSIC_ByReference_Value Recognized
+Named Intrinsic System.ByReference`1.get_Value: Recognized
 Named Intrinsic System.StubHelpers.StubHelpers.GetStubContext: Recognized

@am11 am11 marked this pull request as ready for review December 11, 2021 04:04
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you

@jkotas
Copy link
Member

jkotas commented Dec 11, 2021

@dotnet/jit-contrib Could somebody on JIT team please sign-off on this as a well?

@EgorBo
Copy link
Member

EgorBo commented Dec 11, 2021

JIT side LGTM, @am11 I assume you ran jit-utils for this change? (it could be non-empty - this change helps inliner a bit)

It's great to see we got rid of gtIntrinsicId field finally! 🎉 Many thanks!!

I'm going to use your changes in my #62421, e.g. if arg is valuetype or "sealed" then Object_GetType is going to return const something like that.

@am11
Copy link
Member Author

am11 commented Dec 11, 2021

@EgorBo, I offloaded the number crunching to GitHub Action worker, it just completed: https://github.com/am11/CrossRepoCITesting/runs/4493289569?check_suite_focus=true
crossgen2 ones are text only diffs:

0 total methods with Code Size differences (0 improved, 0 regressed), 246076 unchanged.

and pmi has some errors in generating asm for special assemblies like DllImportGenerator.dll (possibly due to same reason that Microsoft.CodeAnalysis is not available. #62518?), so I sprinkled around a few || true in workflow script to continue on those errors. e.g.

Dasm command "jit-dasm-pmi --platform /home/runner/work/CrossRepoCITesting/CrossRepoCITesting/runtime-base/artifacts/tests/coreclr/Linux.x64.Release/Tests/Core_Root --corerun /home/runner/work/CrossRepoCITesting/CrossRepoCITesting/runtime-base/artifacts/tests/coreclr/Linux.x64.Release/Tests/Core_Root/corerun --jit /home/runner/work/CrossRepoCITesting/CrossRepoCITesting/runtime-base/artifacts/bin/coreclr/Linux.x64.Checked/libclrjit.so --nocopy --output /tmp/jit-diffs/pmi/dasmset_1/base /home/runner/work/CrossRepoCITesting/CrossRepoCITesting/runtime-base/artifacts/tests/coreclr/Linux.x64.Release/Tests/Core_Root/Microsoft.Interop.DllImportGenerator.dll" returned with 1 failures
Error running /home/runner/work/CrossRepoCITesting/CrossRepoCITesting/runtime-base/artifacts/tests/coreclr/Linux.x64.Release/Tests/Core_Root/corerun on /home/runner/work/CrossRepoCITesting/CrossRepoCITesting/runtime-base/artifacts/tests/coreclr/Linux.x64.Release/Tests/Core_Root/System.Security.Cryptography.Algorithms.dll
1 errors compiling set.

Here is the pmi verdict:

3 total methods with Code Size differences (0 improved, 3 regressed), 273075 unchanged.

this scenario of gathering pmi diffs when JITEEVersionIdentifier changes is probably not very well handled by jitutils.

I have also added a step in workflow script to upload artifacts (jit-diff directory), this job's artifacts are available here: https://github.com/am11/CrossRepoCITesting/releases/tag/jit-diffs_1567265287 (jit-diffs.tar.gz for further analysis).

@jkotas jkotas merged commit daa2965 into dotnet:main Dec 12, 2021
@am11 am11 deleted the feature/jit/namedintrinsic branch December 12, 2021 17:26
@ghost ghost locked as resolved and limited conversation to collaborators Jan 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants