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

x86: Assertion failed '!"Too many unreachable block removal loops"' during 'Global local var liveness' #70786

Closed
EgorBo opened this issue Jun 15, 2022 · 5 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@EgorBo
Copy link
Member

EgorBo commented Jun 15, 2022

Fuzzlyn found it in #70749

Reproduces on 32bit alt jit x86

// Generated by Fuzzlyn v1.5 on 2022-06-15 12:29:54
// Run on X86 Windows
// Seed: 5780366890582234972
// Reduced from 39.2 KiB to 2.6 KiB in 00:03:56
// Hits JIT assert in Release:
// Assertion failed '!"Too many unreachable block removal loops"' in 'Program:M0()' during 'Global local var liveness' (IL size 257; hash 0xaf50ff37; FullOpts)
// 
//     File: D:\a\_work\1\s\src\coreclr\jit\fgopt.cpp Line: 747
// 
public interface I0
{
}

public interface I1
{
}

public struct S0 : I0, I1
{
    public int F0;
    public sbyte F1;
    public byte F2;
    public bool F3;
    public byte F4;
    public sbyte F5;
    public byte F6;
    public uint F7;
    public ulong F8;
    public byte F9;
    public S0(int f0, sbyte f1, byte f2, bool f3, byte f4, sbyte f5, byte f6, uint f7, ulong f8, byte f9): this()
    {
        F0 = f0;
        F1 = f1;
        F2 = f2;
        F3 = f3;
        F4 = f4;
        F5 = f5;
        F6 = f6;
        F7 = f7;
        F8 = f8;
        F9 = f9;
    }
}

public class Program
{
    public static I0 s_3;
    public static S0 s_5;
    public static long s_8;
    public static short s_10;
    public static int[] s_12;
    public static I1 s_21;
    public static void Main()
    {
        M0();
    }

    public static void M0()
    {
        int var0 = default(int);
        uint var1 = default(uint);
        bool var43 = default(bool);
        for (int var6 = 0; var6 < 1; var6++)
        {
            return;
        }

        try
        {
            var0 = -var0;
        }
        finally
        {
            I1 vr2 = s_5;
            short vr3 = default(short);
            if (0 < vr3)
            {
                var vr0 = new S0(0, 0, 0, true, 1, 0, 0, 0, 0, 0);
            }
            else
            {
                short var10 = (short)var1;
            }
        }

        System.Console.WriteLine(var0);
        try
        {
            s_8 = s_5.F4;
        }
        finally
        {
            var vr1 = new S0(0, 0, 0, false, 1, 0, 0, 0, 0, 0);
        }

        try
        {
            var0 <<= s_10;
        }
        finally
        {
            s_3 = new S0(0, 0, 0, true, 0, 0, 0, 0, 0, 0);
        }

        s_8 = 0;
        try
        {
            var0--;
        }
        finally
        {
            var1 = 0;
        }

        S0 var17 = new S0(0, 0, 0, false, 0, -1, 0, 0, 0, 0);
        try
        {
            System.Console.WriteLine(1);
        }
        finally
        {
            int var14 = s_12[0];
        }

        try
        {
            M2();
        }
        finally
        {
            System.Console.WriteLine(var43);
        }

        try
        {
            M1();
        }
        finally
        {
            s_21 = var17;
        }
    }

    public static long M1()
    {
        return 0;
    }

    public static short M2()
    {
        return default(short);
    }
}

cc @jakobbotsch in case if you already filed this

category:implementation
theme:flowgraph
skill-level:intermediate
cost:small
impact:small

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

ghost commented Jun 15, 2022

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

Issue Details

Fuzzlyn found it in #67981

Reproduces on 32bit alt jit x86

// Generated by Fuzzlyn v1.5 on 2022-06-15 12:29:54
// Run on X86 Windows
// Seed: 5780366890582234972
// Reduced from 39.2 KiB to 2.6 KiB in 00:03:56
// Hits JIT assert in Release:
// Assertion failed '!"Too many unreachable block removal loops"' in 'Program:M0()' during 'Global local var liveness' (IL size 257; hash 0xaf50ff37; FullOpts)
// 
//     File: D:\a\_work\1\s\src\coreclr\jit\fgopt.cpp Line: 747
// 
public interface I0
{
}

public interface I1
{
}

public struct S0 : I0, I1
{
    public int F0;
    public sbyte F1;
    public byte F2;
    public bool F3;
    public byte F4;
    public sbyte F5;
    public byte F6;
    public uint F7;
    public ulong F8;
    public byte F9;
    public S0(int f0, sbyte f1, byte f2, bool f3, byte f4, sbyte f5, byte f6, uint f7, ulong f8, byte f9): this()
    {
        F0 = f0;
        F1 = f1;
        F2 = f2;
        F3 = f3;
        F4 = f4;
        F5 = f5;
        F6 = f6;
        F7 = f7;
        F8 = f8;
        F9 = f9;
    }
}

public class Program
{
    public static I0 s_3;
    public static S0 s_5;
    public static long s_8;
    public static short s_10;
    public static int[] s_12;
    public static I1 s_21;
    public static void Main()
    {
        M0();
    }

    public static void M0()
    {
        int var0 = default(int);
        uint var1 = default(uint);
        bool var43 = default(bool);
        for (int var6 = 0; var6 < 1; var6++)
        {
            return;
        }

        try
        {
            var0 = -var0;
        }
        finally
        {
            I1 vr2 = s_5;
            short vr3 = default(short);
            if (0 < vr3)
            {
                var vr0 = new S0(0, 0, 0, true, 1, 0, 0, 0, 0, 0);
            }
            else
            {
                short var10 = (short)var1;
            }
        }

        System.Console.WriteLine(var0);
        try
        {
            s_8 = s_5.F4;
        }
        finally
        {
            var vr1 = new S0(0, 0, 0, false, 1, 0, 0, 0, 0, 0);
        }

        try
        {
            var0 <<= s_10;
        }
        finally
        {
            s_3 = new S0(0, 0, 0, true, 0, 0, 0, 0, 0, 0);
        }

        s_8 = 0;
        try
        {
            var0--;
        }
        finally
        {
            var1 = 0;
        }

        S0 var17 = new S0(0, 0, 0, false, 0, -1, 0, 0, 0, 0);
        try
        {
            System.Console.WriteLine(1);
        }
        finally
        {
            int var14 = s_12[0];
        }

        try
        {
            M2();
        }
        finally
        {
            System.Console.WriteLine(var43);
        }

        try
        {
            M1();
        }
        finally
        {
            s_21 = var17;
        }
    }

    public static long M1()
    {
        return 0;
    }

    public static short M2()
    {
        return default(short);
    }
}

cc @jakobbotsch in case if you already filed this

Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member

It started happening occasionally after #69421 I believe, but it's similar in spirit to the other "dead code" issues so I didn't bother opening an issue. Let's set this to .NET 8.
cc @kunalspathak

@jakobbotsch jakobbotsch added this to the 8.0.0 milestone Jun 15, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jun 15, 2022
@kunalspathak
Copy link
Member

Agree.

@JulieLeeMSFT JulieLeeMSFT added the Priority:2 Work that is important, but not critical for the release label Apr 13, 2023
@kunalspathak kunalspathak modified the milestones: 8.0.0, Future Apr 24, 2023
@BruceForstall
Copy link
Member

Here's a Fuzzlyn generated test case that exposes this assert on win-x64 with today's main:

// Generated by Fuzzlyn v1.5 on 2023-04-26 17:58:23
// Run on X64 Windows
// Seed: 9637554856640891414
// Reduced from 237.7 KiB to 4.9 KiB in 00:04:12
// Hits JIT assert in Release:
// Assertion failed '!"Too many unreachable block removal loops"' in 'Program:M0()' during 'Compute blocks reachability' (IL size 1344; hash 0xaf50ff37; FullOpts)
//
//     File: C:\gh\runtime\src\coreclr\jit\fgopt.cpp Line: 575
//
public interface I0
{
}

public interface I1
{
}

public class C0
{
    public short F0;
    public uint F1;
    public ushort F2;
    public bool F3;
    public uint F4;
    public int F5;
    public C0(short f0, ushort f2, bool f3, uint f4, int f5)
    {
    }

    public ref S0 M1(ref short arg0)
    {
        return ref Program.s_6;
    }
}

public struct S0 : I0, I1
{
    public C0 F0;
    public ulong F1;
    public uint F2;
    public long F3;
    public uint F4;
    public C0 F5;
    public byte F6;
    public int F7;
    public bool F8;
    public S0(C0 f0, ulong f1, uint f2, long f3, uint f4, C0 f5, byte f6, int f7, bool f8): this()
    {
        F0 = f0;
        F1 = f1;
        F2 = f2;
        F3 = f3;
        F4 = f4;
        F5 = f5;
        F6 = f6;
        F7 = f7;
        F8 = f8;
    }
}

public struct S1 : I0
{
    public short F0;
    public long F3;
    public byte F4;
    public short F5;
    public ushort F6;
}

public struct S2
{
    public long F0;
}

public class C1 : I0
{
    public S0 F0;
    public S2 F3;
    public S0 F4;
    public C1(S2 f3, S0 f4)
    {
    }
}

public class Program
{
    public static IRuntime s_rt;
    public static S0 s_6;
    public static C1[] s_11;
    public static bool[] s_17;
    public static void Main()
    {
        M0();
    }

    public static void M0()
    {
        S0 var40 = default(S0);
        C1[] var56 = default(C1[]);
        C0 var66 = default(C0);
        bool var0 = true;
        I1[] var1 = new I1[]{new S0(new C0(0, 0, true, 0, 0), 0, 0, 0, 0, new C0(0, 0, true, 0, 0), 0, 0, false)};
        S0 var2 = new S0(new C0(0, 1, false, 0, 0), 0, 0, 0, 0, new C0(0, 1, false, 0, 0), 0, 0, false);
        if (var0)
        {
            return;
        }

        try
        {
            s_6.F1 = s_6.F1;
        }
        finally
        {
            C0 var8 = new C0(var2.F5.F0, var2.F0.F2, s_6.F5.F3, s_6.F5.F1++, var2.F0.F5);
            s_rt.WriteLine(var8.F1);
            s_rt.WriteLine(var8.F4);
        }

        try
        {
            new C0(0, 0, true, 0, 0).M1(ref var2.F5.F0);
        }
        finally
        {
            C1 var13 = new C1(new S2(), new S0(new C0(0, 1, false, 0, 1), 0, 0, 0, 0, new C0(0, 0, false, 0, 0), 0, 0, false));
        }

        S1 var19 = new S1();
        try
        {
            M2();
        }
        finally
        {
            s_rt.WriteLine(var19.F0);
            s_rt.WriteLine(var19.F3);
            s_rt.WriteLine(var19.F4);
            s_rt.WriteLine(var19.F5);
            s_rt.WriteLine(var19.F6);
        }

        try
        {
            byte var33 = s_6.F6;
        }
        finally
        {
            var2.F0.F2 += 0;
            var2.F5.M1(ref var2.F5.F0);
            s_rt.WriteLine(s_11[0].F0.F1);
            s_rt.WriteLine(s_11[0].F0.F5.F5);
            s_rt.WriteLine(s_11[0].F3.F0);
        }

        try
        {
            I1 var41 = var1[0];
        }
        finally
        {
            var vr0 = new S0(new C0(0, 0, true, 0, 0), 0, 0, 0, 0, new C0(0, 0, false, 0, 0), 1, 0, false);
            M2();
        }

        try
        {
            s_17 = s_17;
        }
        finally
        {
            I1 vr1 = var1[0];
            long vr2 = default(long);
            s_6.F0.F1 = (uint)vr2;
            s_rt.WriteLine(var56[0].F0.F5.F1);
            s_rt.WriteLine(var56[0].F4.F5.F3);
            s_rt.WriteLine(var56[0].F4.F5.F5);
            s_rt.WriteLine(var56[0].F4.F6);
        }

        try
        {
            I1 vr3 = var1[0];
        }
        finally
        {
            s_rt.WriteLine(var66.F0);
            s_rt.WriteLine(var66.F1);
            s_rt.WriteLine(var66.F3);
            s_rt.WriteLine(var66.F4);
            s_rt.WriteLine(var66.F5);
        }

        try
        {
            var2.F2 = 0;
        }
        finally
        {
            I0[] var67 = new I0[]{new S1(), new C1(new S2(), new S0(new C0(0, 0, true, 0, 0), 0, 0, 0, 0, new C0(0, 1, false, 0, 0), 0, 0, true)), new S0(new C0(0, 0, false, 0, -1), 0, 0, 0, 0, new C0(0, 1, false, 0, 1), 0, 0, false), new C1(new S2(), new S0(new C0(0, 0, true, 0, 0), 0, 0, 0, 0, new C0(0, 0, false, 0, 1), 0, 0, false)), new S1(), new S1(), new S1(), new S1(), new S0(new C0(1, 1, false, 0, 0), 0, 0, 0, 0, new C0(0, 1, true, 0, 0), 0, 1, false)};
        }

        try
        {
            uint var75 = var40.F2;
            s_rt.WriteLine(var75);
        }
        finally
        {
            I0[] var77 = new I0[]{new S0(new C0(0, 0, false, 0, 0), 0, 0, 0, 0, new C0(0, 0, false, 0, 0), 0, 0, false)};
        }
    }

    public static S1 M2()
    {
        return default(S1);
    }
}

public interface IRuntime
{
    void WriteLine<T>(T value);
}

public class Runtime : IRuntime
{
    public void WriteLine<T>(T value) => System.Console.WriteLine(value);
}

@jakobbotsch jakobbotsch modified the milestones: Future, 9.0.0 Aug 9, 2023
@kunalspathak kunalspathak removed the Priority:2 Work that is important, but not critical for the release label Jun 24, 2024
@jakobbotsch
Copy link
Member

The old block removal that had this assert was removed in #103809.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2024
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

No branches or pull requests

5 participants