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

Ensure that Vector<T> is tracked as "optimistic" for crossgen2 #87240

Merged
merged 1 commit into from
Jun 9, 2023

Conversation

tannergooding
Copy link
Member

This resolves #87235

The issue was introduced in #85551 as the InstructionSet_VectorT### was included as part of the supportedInstructionSet and was therefore getting encoded as part of the required ISAs for a given image.

What this meant was that when we hit TryIncrementalLoad for System.Private.Corelib we'd try to apply the EagerFixups, find that the host machine supported InstructionSet_VectorT256 while the image said it required InstructionSet_VectorT128. This caused the entire image to be thrown away as invalid.

By instead tracking the Vector<T> size that's being targeted as the opportunistic set, we get the dependency flagged per method alongside any layout check required for Vector<T>. This allows just the method in question to be thrown away instead.

@tannergooding
Copy link
Member Author

tannergooding commented Jun 8, 2023

This brings the number of jitted methods for a Hello, World application (run from CORE_ROOT) back down to 64:

Assembly listing for method System.Runtime.CompilerServices.CastHelpers:StelemRef(System.Array,long,System.Object)
Assembly listing for method System.Runtime.CompilerServices.CastHelpers:LdelemaRef(System.Array,long,ulong):byref
Assembly listing for method System.SpanHelpers:IndexOfNullCharacter(ulong):int
Assembly listing for method System.SpanHelpers:NonPackedIndexOfValueType[short,System.SpanHelpers+DontNegate`1[short]](byref,short,int):int
Assembly listing for method System.ArgumentOutOfRangeException:ThrowIfNegative[int](int,System.String)
Assembly listing for method System.Text.Unicode.Utf16Utility:GetPointerToFirstInvalidChar(ulong,int,byref,byref):ulong
Assembly listing for method System.Text.Ascii:NarrowUtf16ToAscii(ulong,ulong,ulong):ulong
Assembly listing for method System.SpanHelpers:SequenceEqual(byref,byref,ulong):bool
Assembly listing for method System.Guid:TryFormatCore[ushort](System.Span`1[ushort],byref,int):bool:this
Assembly listing for method System.Diagnostics.Debug:Assert(bool)
Assembly listing for method System.Guid:FormatGuidVector128Utf8(System.Guid,bool):System.ValueTuple`3[System.Runtime.Intrinsics.Vector128`1[ubyte],System.Runtime.Intrinsics.Vector128`1[ubyte],System.Runtime.Intrinsics.Vector128`1[ubyte]]
Assembly listing for method System.HexConverter:AsciiToHexVector128(System.Runtime.Intrinsics.Vector128`1[ubyte],System.Runtime.Intrinsics.Vector128`1[ubyte]):System.ValueTuple`2[System.Runtime.Intrinsics.Vector128`1[ubyte],System.Runtime.Intrinsics.Vector128`1[ubyte]]
Assembly listing for method System.Runtime.Intrinsics.Vector128:ShuffleUnsafe(System.Runtime.Intrinsics.Vector128`1[ubyte],System.Runtime.Intrinsics.Vector128`1[ubyte]):System.Runtime.Intrinsics.Vector128`1[ubyte]
Assembly listing for method System.Number:UInt32ToDecChars[ushort](ulong,uint):ulong
Assembly listing for method System.SpanHelpers:IndexOfNullByte(ulong):int
Assembly listing for method System.RuntimeType+RuntimeTypeCache+MemberInfoCache`1[System.__Canon]:AddMethod(System.RuntimeType,long,int):System.Reflection.MethodBase:this
Assembly listing for method System.PackedSpanHelpers:IndexOf[System.SpanHelpers+DontNegate`1[short]](byref,short,int):int
Assembly listing for method System.PackedSpanHelpers:PackSources(System.Runtime.Intrinsics.Vector256`1[short],System.Runtime.Intrinsics.Vector256`1[short]):System.Runtime.Intrinsics.Vector256`1[ubyte]
Assembly listing for method System.PackedSpanHelpers:ComputeFirstIndexOverlapped(byref,byref,byref,System.Runtime.Intrinsics.Vector256`1[ubyte]):int
Assembly listing for method System.PackedSpanHelpers:FixUpPackedVector256Result(System.Runtime.Intrinsics.Vector256`1[ubyte]):System.Runtime.Intrinsics.Vector256`1[ubyte]
Assembly listing for method System.SpanHelpers:LastIndexOfValueType[short,System.SpanHelpers+DontNegate`1[short]](byref,short,int):int
Assembly listing for method System.Text.Ascii:WidenAsciiToUtf16(ulong,ulong,ulong):ulong
Assembly listing for method (dynamicClass):InvokeStub_EventAttribute.set_Level(System.Object,System.Object,ulong):System.Object
Assembly listing for method (dynamicClass):InvokeStub_EventAttribute.set_Message(System.Object,System.Object,ulong):System.Object
Assembly listing for method (dynamicClass):InvokeStub_EventAttribute.set_Task(System.Object,System.Object,ulong):System.Object
Assembly listing for method (dynamicClass):InvokeStub_EventAttribute.set_Opcode(System.Object,System.Object,ulong):System.Object
Assembly listing for method (dynamicClass):InvokeStub_EventAttribute.set_Version(System.Object,System.Object,ulong):System.Object
Assembly listing for method (dynamicClass):InvokeStub_EventAttribute.set_Keywords(System.Object,System.Object,ulong):System.Object
Assembly listing for method System.Number:Int64ToHexChars[ushort](ulong,ulong,int,int):ulong
Assembly listing for method System.SpanHelpers:IndexOfAnyInRangeUnsignedNumber[ushort,System.SpanHelpers+DontNegate`1[ushort]](byref,ushort,ushort,int):int
Assembly listing for method System.PackedSpanHelpers:IndexOfAnyInRange[System.SpanHelpers+DontNegate`1[short]](byref,short,short,int):int
Assembly listing for method System.SpanHelpers:SequenceCompareTo(byref,int,byref,int):int
Assembly listing for method Program:<Main>$(System.String[])
Assembly listing for method System.Console:WriteLine(System.String)
Assembly listing for method System.Console:get_Out():System.IO.TextWriter
Assembly listing for method System.Console:.cctor()
Assembly listing for method System.Console:<get_Out>g__EnsureInitialized|26_0():System.IO.TextWriter
Assembly listing for method System.ConsolePal:OpenStandardOutput():System.IO.Stream
Assembly listing for method System.Console:get_OutputEncoding():System.Text.Encoding
Assembly listing for method System.ConsolePal:get_OutputEncoding():System.Text.Encoding
Assembly listing for method System.Text.EncodingHelper:GetSupportedConsoleEncoding(int):System.Text.Encoding
Assembly listing for method System.Text.OSEncoding:.ctor(int):this
Assembly listing for method System.ConsolePal:GetStandardFile(int,int,bool):System.IO.Stream
Assembly listing for method System.ConsolePal:get_InvalidHandleValue():long
Assembly listing for method System.ConsolePal:ConsoleHandleIsWritable(long):bool
Assembly listing for method Interop+Kernel32:WriteFile(long,ulong,int,byref,long):int
Assembly listing for method System.ConsolePal+WindowsConsoleStream:.ctor(long,int,bool):this
Assembly listing for method System.IO.ConsoleStream:.ctor(int):this
Assembly listing for method Interop+Kernel32:GetFileType(long):uint
Assembly listing for method System.Console:CreateOutputWriter(System.IO.Stream):System.IO.TextWriter
Assembly listing for method System.Text.EncodingExtensions:RemovePreamble(System.Text.Encoding):System.Text.Encoding
Assembly listing for method System.IO.ConsoleStream:get_CanWrite():bool:this
Assembly listing for method System.ArgumentOutOfRangeException:ThrowIfNegativeOrZero[int](int,System.String)
Assembly listing for method System.Text.OSEncoding:GetEncoder():System.Text.Encoder:this
Assembly listing for method System.Text.OSEncoder:.ctor(System.Text.Encoding):this
Assembly listing for method System.Text.OSEncoder:Reset():this
Assembly listing for method System.IO.ConsoleStream:get_CanSeek():bool:this
Assembly listing for method System.Text.OSEncoding:GetMaxByteCount(int):int:this
Assembly listing for method System.Text.OSEncoder:GetBytes(ulong,int,ulong,int,bool):int:this
Assembly listing for method System.ConsolePal+WindowsConsoleStream:Flush():this
Assembly listing for method System.IO.ConsoleStream:Flush():this
Assembly listing for method System.Text.OSEncoding:WideCharToMultiByte(int,ulong,int,ulong,int):int
Assembly listing for method System.ConsolePal+WindowsConsoleStream:Write(System.ReadOnlySpan`1[ubyte]):this
Assembly listing for method System.ConsolePal+WindowsConsoleStream:WriteFileNative(long,System.ReadOnlySpan`1[ubyte],bool):int

@tannergooding
Copy link
Member Author

An example of the r2rdump differences:

Before:

System.Numerics.Vector`1<ulong> System.Numerics.Vector.WidenUpper(System.Numerics.Vector`1<uint>)
Handle: 0x060029F1
Rid: 10737
EntryPointRuntimeFunctionId: 7433
Number of RuntimeFunctions: 1
Number of fixups: 2
    TableIndex 5, Offset 0ADF: System.Numerics.Vector`1<uint> Flags READYTORUN_LAYOUT_Alignment, READYTORUN_LAYOUT_Alignment_Native, READYTORUN_LAYOUT_GCLayout, READYTORUN_LAYOUT_GCLayout_Empty Size 16 (CHECK_TYPE_LAYOUT)
    TableIndex 5, Offset 0AE0: System.Numerics.Vector`1<ulong> Flags READYTORUN_LAYOUT_Alignment, READYTORUN_LAYOUT_Alignment_Native, READYTORUN_LAYOUT_GCLayout, READYTORUN_LAYOUT_GCLayout_Empty Size 16 (CHECK_TYPE_LAYOUT)

System.Numerics.Vector`1<ulong> System.Numerics.Vector.WidenUpper(System.Numerics.Vector`1<uint>)
Id: 7433
StartAddress: 0x002A1670
Size: 34 bytes
UnwindRVA: 0x0003CAF0
Version:            1
Flags:              0x03 EHANDLER UHANDLER
SizeOfProlog:       0x0004
CountOfUnwindCodes: 1
FrameRegister:      None
FrameOffset:        0x0
PersonalityRVA:     0x5D2F80
UnwindCode[0]: CodeOffset 0x0004 FrameOffset 0x0000 NextOffset 0x0 Op 24

Debug Info
    Bounds:
    Native Offset: 0x0, Prolog, Source Types: StackEmpty
    Native Offset: 0x4, IL Offset: 0x0019, Source Types: StackEmpty
    Native Offset: 0x13, IL Offset: 0x0034, Source Types: StackEmpty
    Native Offset: 0x1D, Epilog, Source Types: StackEmpty

    Variable Locations:
    Variable Number: 4294967294
    Start Offset: 0x0
    End Offset: 0x1A
    Loc Type: VLT_REG
    Register: RCX

    Variable Number: 0
    Start Offset: 0x0
    End Offset: 0xB
    Loc Type: VLT_REG
    Register: RDX

After:

System.Numerics.Vector`1<ulong> System.Numerics.Vector.WidenUpper(System.Numerics.Vector`1<uint>)
Handle: 0x060029F1
Rid: 10737
EntryPointRuntimeFunctionId: 7433
Number of RuntimeFunctions: 1
Number of fixups: 3
    TableIndex 5, Offset 0020: CHECK_InstructionSetSupport X86Base+ Sse+ Sse2+ VectorT128+
    TableIndex 5, Offset 0AE0: System.Numerics.Vector`1<uint> Flags READYTORUN_LAYOUT_Alignment, READYTORUN_LAYOUT_Alignment_Native, READYTORUN_LAYOUT_GCLayout, READYTORUN_LAYOUT_GCLayout_Empty Size 16 (CHECK_TYPE_LAYOUT)
    TableIndex 5, Offset 0AE1: System.Numerics.Vector`1<ulong> Flags READYTORUN_LAYOUT_Alignment, READYTORUN_LAYOUT_Alignment_Native, READYTORUN_LAYOUT_GCLayout, READYTORUN_LAYOUT_GCLayout_Empty Size 16 (CHECK_TYPE_LAYOUT)

System.Numerics.Vector`1<ulong> System.Numerics.Vector.WidenUpper(System.Numerics.Vector`1<uint>)
Id: 7433
StartAddress: 0x002A1790
Size: 34 bytes
UnwindRVA: 0x0003CB18
Version:            1
Flags:              0x03 EHANDLER UHANDLER
SizeOfProlog:       0x0004
CountOfUnwindCodes: 1
FrameRegister:      None
FrameOffset:        0x0
PersonalityRVA:     0x5D30A0
UnwindCode[0]: CodeOffset 0x0004 FrameOffset 0x0000 NextOffset 0x0 Op 24

Debug Info
    Bounds:
    Native Offset: 0x0, Prolog, Source Types: StackEmpty
    Native Offset: 0x4, IL Offset: 0x0019, Source Types: StackEmpty
    Native Offset: 0x13, IL Offset: 0x0034, Source Types: StackEmpty
    Native Offset: 0x1D, Epilog, Source Types: StackEmpty

    Variable Locations:
    Variable Number: 4294967294
    Start Offset: 0x0
    End Offset: 0x1A
    Loc Type: VLT_REG
    Register: RCX

    Variable Number: 0
    Start Offset: 0x0
    End Offset: 0xB
    Loc Type: VLT_REG
    Register: RDX

@tannergooding
Copy link
Member Author

Note that before #85551 the number of jitted methods for Hello, World was 62, the two new methods are:

  • System.SpanHelpers:SequenceEqual(byref,byref,ulong):bool
  • System.SpanHelpers:SequenceCompareTo(byref,int,byref,int):int

These two methods are no longer being used for AOT because they do in fact use Vector<T> along some code path and that causes it to be flagged as VectorT128+.

These code paths are only being kept around for Mono currently and so it may be desirable to #ifdef them out for CoreCLR as the simple fix.

@stephentoub
Copy link
Member

These two methods are no longer being used for AOT because they do in fact use Vector along some code path and that causes it to be flagged as VectorT128+. These code paths are only being kept around for Mono currently and so it may be desirable to #ifdef them out for CoreCLR as the simple fix.

#85916 has been pending to delete those fallbacks entirely. To move things along, I could update it to instead ifdef them to just be for mono.

@tannergooding tannergooding merged commit a7094a5 into dotnet:main Jun 9, 2023
@tannergooding tannergooding deleted the fix-87235 branch June 9, 2023 03:52
@ghost ghost locked as resolved and limited conversation to collaborators Jul 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Performance] Startup regression
3 participants