From d018afa90151ee43078ffc617734ec198ea17aa6 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Fri, 21 Jul 2023 08:31:28 -0700 Subject: [PATCH 1/2] Block inlining of IntroSort With PGO and (via #88749) one level of recursive inlining enabled, the jit sees the recursive call made by `IntroSort` as an attractive inline candidate, but it isn't. Fixes #89106. --- src/libraries/System.Private.CoreLib/src/System/Array.cs | 2 ++ .../src/System/Collections/Generic/ArraySortHelper.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Array.cs b/src/libraries/System.Private.CoreLib/src/System/Array.cs index 313b064fc9e676..5ba66adf90c18b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Array.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Array.cs @@ -2207,6 +2207,7 @@ private void IntrospectiveSort(int left, int length) } } + [MethodImpl(MethodImplOptions.NoInlining)] private void IntroSort(int lo, int hi, int depthLimit) { Debug.Assert(hi >= lo); @@ -2421,6 +2422,7 @@ private void IntrospectiveSort(int left, int length) } } + [MethodImpl(MethodImplOptions.NoInlining)] private void IntroSort(int lo, int hi, int depthLimit) { Debug.Assert(hi >= lo); diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs index cf481d8999649a..5a65f6e5a97245 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs @@ -128,6 +128,7 @@ internal static void IntrospectiveSort(Span keys, Comparison comparer) } } + [MethodImpl(MethodImplOptions.NoInlining)] private static void IntroSort(Span keys, int depthLimit, Comparison comparer) { Debug.Assert(!keys.IsEmpty); @@ -402,6 +403,7 @@ private static void Swap(ref T i, ref T j) j = t; } + [MethodImpl(MethodImplOptions.NoInlining)] private static void IntroSort(Span keys, int depthLimit) { Debug.Assert(!keys.IsEmpty); From e15846f347997698dc75c7fb6647784aa622ca74 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Fri, 21 Jul 2023 09:39:52 -0700 Subject: [PATCH 2/2] add comment --- src/libraries/System.Private.CoreLib/src/System/Array.cs | 4 ++++ .../src/System/Collections/Generic/ArraySortHelper.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Array.cs b/src/libraries/System.Private.CoreLib/src/System/Array.cs index 5ba66adf90c18b..cecfcf12ccf9aa 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Array.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Array.cs @@ -2207,6 +2207,8 @@ private void IntrospectiveSort(int left, int length) } } + // IntroSort is recursive; block it from being inlined into itself as + // this is currenly not profitable. [MethodImpl(MethodImplOptions.NoInlining)] private void IntroSort(int lo, int hi, int depthLimit) { @@ -2422,6 +2424,8 @@ private void IntrospectiveSort(int left, int length) } } + // IntroSort is recursive; block it from being inlined into itself as + // this is currenly not profitable. [MethodImpl(MethodImplOptions.NoInlining)] private void IntroSort(int lo, int hi, int depthLimit) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs index 5a65f6e5a97245..1d937f4b853369 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs @@ -128,6 +128,8 @@ internal static void IntrospectiveSort(Span keys, Comparison comparer) } } + // IntroSort is recursive; block it from being inlined into itself as + // this is currenly not profitable. [MethodImpl(MethodImplOptions.NoInlining)] private static void IntroSort(Span keys, int depthLimit, Comparison comparer) { @@ -403,6 +405,8 @@ private static void Swap(ref T i, ref T j) j = t; } + // IntroSort is recursive; block it from being inlined into itself as + // this is currenly not profitable. [MethodImpl(MethodImplOptions.NoInlining)] private static void IntroSort(Span keys, int depthLimit) {