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

JIT: OSR is not conservative enough about exposing struct locals #83783

Closed
jakobbotsch opened this issue Mar 22, 2023 · 1 comment · Fixed by #83910
Closed

JIT: OSR is not conservative enough about exposing struct locals #83783

jakobbotsch opened this issue Mar 22, 2023 · 1 comment · Fixed by #83910
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@jakobbotsch
Copy link
Member

using System;
using System.Runtime.CompilerServices;

public class MissingExposure
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Bar()
    {
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Foo(int n)
    {
        S s = new S { F = 1234 };
        ref int foo = ref s.F;

        for (int i = 0; i < n; i++)
        {
            Bar();
        }

        int abc = s.F * 3 + 4;
        foo = 25;
        int def = s.F * 3 + 4;
        Console.WriteLine("abc = {0} (expected {1}), def = {2} (expected {3})", abc, 1234 * 3 + 4, def, 25 * 3 + 4);
    }

    public static void Main()
    {
        Foo(50000);
    }

    public struct S
    {
        public int F;
    }
}

Output with OSR enabled: abc = 3706 (expected 3706), def = 3706 (expected 79)

cc @AndyAyersMS

@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 Mar 22, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 22, 2023
@ghost
Copy link

ghost commented Mar 22, 2023

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

Issue Details
using System;
using System.Runtime.CompilerServices;

public class MissingExposure
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Bar()
    {
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Foo(int n)
    {
        S s = new S { F = 1234 };
        ref int foo = ref s.F;

        for (int i = 0; i < n; i++)
        {
            Bar();
        }

        int abc = s.F * 3 + 4;
        foo = 25;
        int def = s.F * 3 + 4;
        Console.WriteLine("abc = {0} (expected {1}), def = {2} (expected {3})", abc, 1234 * 3 + 4, def, 25 * 3 + 4);
    }

    public static void Main()
    {
        Foo(50000);
    }

    public struct S
    {
        public int F;
    }
}

Output with OSR enabled: abc = 3706 (expected 3706), def = 3706 (expected 79)

cc @AndyAyersMS

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS AndyAyersMS removed the untriaged New issue has not been triaged by the area owner label Mar 24, 2023
@AndyAyersMS AndyAyersMS self-assigned this Mar 24, 2023
@AndyAyersMS AndyAyersMS added this to the 8.0.0 milestone Mar 24, 2023
AndyAyersMS added a commit to AndyAyersMS/runtime that referenced this issue Mar 24, 2023
For OSR compiles, always import from the original entry point in addtion
to the OSR entry point. This gives the OSR compiler a chance
to see all of the method and so properly compute address exposure,
instead of relying on the Tier0
analysis.

Once address exposure has been determined, revoke special protection
for the original entry and try and prune away blocks that are no longer
needed.

Fixes dotnet#83783.

May also fix some of the cases where OSR perf is lagging (though
don't expect this to fix them all).
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 24, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 26, 2023
AndyAyersMS added a commit that referenced this issue Mar 26, 2023
For OSR compiles, always import from the original entry point in addition
to the OSR entry point. This gives the OSR compiler a chance
to see all of the method and so properly compute address exposure,
instead of relying on the Tier0
analysis.

Once address exposure has been determined, revoke special protection
for the original entry and try and prune away blocks that are no longer
needed (we actually wait until morph).

Fixes #83783.

May also fix some of the cases where OSR perf is lagging (though
don't expect this to fix them all).
@ghost ghost locked as resolved and limited conversation to collaborators Apr 25, 2023
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants