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: RBO's utilization of liberal VNs is illegal #102158

Open
jakobbotsch opened this issue May 13, 2024 · 1 comment
Open

JIT: RBO's utilization of liberal VNs is illegal #102158

jakobbotsch opened this issue May 13, 2024 · 1 comment
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

jakobbotsch commented May 13, 2024

The following program hits the assert when run with DOTNET_JitNoCSE=1.

using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;

public unsafe class Program
{
    public static void Main()
    {
        C c = new C();
        new Thread(_ => { while (true) { c.X = 0; c.X = 1; } }) { IsBackground = true }.Start();

        while (true)
        {
            IllegalRBO(c, 0);
        }
    }

    public class C
    {
        public int X;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void IllegalRBO(C c, int k)
    {
        int y = c.X;

        if (c.X == k + 1)
        {
            if (y == k + 1)
            {
                if (Id(y) != k + 1)
                {
                    Trace.Fail("Impossible");
                }
            }
        }
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static int Id(int x) => x;
}

RBO eliminates the y == k + 1 branch because it is dominated by c.X == k + 1 with the same liberal VN. However, this is not legal since y and c.X evaluated in the dominating test may not have the same value under data races.

The example requires DOTNET_JitNoCSE because otherwise CSE removes one of the loads of c.X, but naturally CSE could decide not to CSE these for any number of reasons (like register pressure).

cc @dotnet/jit-contrib

@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 May 13, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 13, 2024
Copy link
Contributor

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

@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label May 13, 2024
@JulieLeeMSFT JulieLeeMSFT added this to the 9.0.0 milestone May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

No branches or pull requests

3 participants