Skip to content

No inline of method on value type injected to generic method: Fail Reason: noinline per IL/cached result #35791

Closed
@nietras

Description

@nietras

I have a rather simple value type wrapping a Comparison<object> like below.

        readonly struct OpenDelegateObjectComparer : IComparer<object>
        {
            readonly Comparison<object> m_compare;

            public OpenDelegateObjectComparer(Comparison<object> compare) =>
                m_compare = compare;

            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public int Compare(object x, object y) => m_compare(x, y);
        }

This is called in a method similar to below:

    public class Sample<T, TComparer>
        where TComparer : IComparer<T>
    {
        public int Do(Span<T> s, T value, TComparer comparer)
        {
            int count = 0;
            foreach (var v in s)
            {
                if (comparer.Compare(v, value) < 0)
                {
                    ++count;
                }
            }
            return count;
        }
    }

where TComparer is the above mentioned value type comparer.

The project in question is defined as below, and hence tiered compilation should be off.

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp5.0</TargetFrameworks>
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <LangVersion>7.3</LangVersion>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <TieredCompilation>false</TieredCompilation>
  </PropertyGroup>

This fails to inline the comparer.Compare(v, value) call with:

Fail Reason: noinline per IL/cached result

And I don't understand why?

This is for running with and InliningDiagnoser and T being a reference type:

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.720 (1909/November2018Update/19H2)
Intel Core i7-8700 CPU 3.20GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.100-preview.2.20176.6
  [Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.16006, CoreFX 5.0.20.16006), X64 RyuJIT

The most similar question I could find was:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions