Skip to content

Do we still need [AggressiveOptimization] on so many methods? #71261

Closed

Description

@stephentoub

dotnet/coreclr#22191 added a bunch of [AggressiveOptimization] attributes to methods throughout SpanHelpers and elsewhere that make heavy use of intrinsics, e.g.

[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public static bool Contains(ref byte searchSpace, byte value, int length)

After all of the inlining improvements made in .NET 6 and 7, are these still necessary and helping more than they hurt?

category:design
theme:basic-cq
skill-level:beginner
cost:small
impact:small

Activity

  1. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Jun 24, 2022
  2. added this to the 7.0.0 milestone on Jun 24, 2022
  3. jkotas commented on Jun 24, 2022

    @jkotas
    Member

    These [AggressiveOptimization] attributes were added as a workaround for #9120

  4. EgorBo commented on Jun 26, 2022

    @EgorBo
    Member

    I think we can remove them at least from SpanHelpers because SPC.dll is always prejitted (R2R) so e.g. SpanHelpers will never see Tier0 and will be properly instrumented and optimized for current app (in Dynamic PGO mode), e.g. if current app mostly works with large inputs we will re-order "handle small-inputs" blocks, etc.

    However, we might need to check that SpanHelpers is actually fully prejitted due to presence of Vector<T> (see #67398 (comment))

  5. EgorBo commented on Jun 26, 2022

    @EgorBo
    Member

    SpanHelpers members which refuse to precompile (because they use Vector<T> without Vector128 and Vector256 paths)

    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<__Canon>(__Canon&,native uint,__Canon)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.UnalignedCountVector(char&)` was not compiled because `This function is using SIMD intrinsics, their size is machine specific` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.GetCharVectorSpanLength(native int,native int)` was not compiled because `This function is using SIMD intrinsics, their size is machine specific` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.UnalignedCountVectorFromEnd(uint8&,int32)` was not compiled because `This function is using SIMD intrinsics, their size is machine specific` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.UnalignedCountVector(uint8&)` was not compiled because `This function is using SIMD intrinsics, their size is machine specific` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.GetByteVectorSpanLength(native uint,int32)` was not compiled because `This function is using SIMD intrinsics, their size is machine specific` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.LastIndexOfAny(uint8&,uint8,uint8,uint8,int32)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.LastIndexOfAny(uint8&,uint8,uint8,int32)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<char>(char&,native uint,char)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<GuidResult>(GuidResult&,native uint,GuidResult)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<native int>(native int&,native uint,native int)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<int32>(int32&,native uint,int32)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<float32>(float32&,native uint,float32)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<uint16>(uint16&,native uint,uint16)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<uint64>(uint64&,native uint,uint64)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<uint32>(uint32&,native uint,uint32)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<int64>(int64&,native uint,int64)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<int16>(int16&,native uint,int16)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.IndexOfValueType<int32>(int32&,int32,int32)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<int32>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.IndexOfValueType<int64>(int64&,int64,int32)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<int64>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<KeyValuePair`2<__Canon,__Canon>>(KeyValuePair`2<__Canon,__Canon>&,native uint,KeyValuePair`2<__Canon,__Canon>)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<CalendarId>(CalendarId&,native uint,CalendarId)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<float64>(float64&,native uint,float64)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<KeyValuePair`2<SessionInfo,bool>>(KeyValuePair`2<SessionInfo,bool>&,native uint,KeyValuePair`2<SessionInfo,bool>)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<KeyValuePair`2<int32,__Canon>>(KeyValuePair`2<int32,__Canon>&,native uint,KeyValuePair`2<int32,__Canon>)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    Info: Method `[S.P.CoreLib]System.SpanHelpers.Fill<SessionInfo>(SessionInfo&,native uint,SessionInfo)` was not compiled because `[S.P.CoreLib]System.Numerics.Vector`1<uint8>` requires runtime JIT
    
  6. EgorBo commented on Jul 6, 2022

    @EgorBo
    Member

    Moving to 8.0.0 as it depends on the planned change to make crossgen avx2-aware by default.

  7. modified the milestones: 7.0.0, 8.0.0 on Jul 6, 2022
  8. modified the milestones: 8.0.0, Future on Apr 10, 2023
  9. EgorBo commented on May 6, 2023

    @EgorBo
    Member

    I assume we can close this one as we now have only 3 [AO] in BCL:

    1. AsyncTaskMethodBuilder<TResult>.AwaitUnsafeOnCompleted the comment states that it allocates in T0 (presumably, when R2R doesn't hande a specific generic instance)
    2. (and 3) CastHelper's StelemRef and LdelemaRef -- these have to be [AO] because VM special case them to be direct calls (so there is no call counting in between) - we can make them indirect just like 99% of other methods but VSadov claimed it is needed for perf.
  10. modified the milestones: Future, 8.0.0 on May 6, 2023
  11. ghost locked as resolved and limited conversation to collaborators on Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions