dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

linux/arm: Assertion failed 'kind == Overwrite' during 'VN-based dead store removal' #108850

Open kunalspathak opened 3 weeks ago

kunalspathak commented 3 weeks ago
// Found by Antigen
// Reduced from 14.8 KB to 4.54 KB.

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86;
using System.Numerics;
public class TestClass
{
    public struct S1
    {
        public uint uint_0;
    }
    public struct S2
    {
        public Vector2 v2_2;
    }
    static char s_char_5 = 'K';
    static decimal s_decimal_6 = -2147483647.9333333333333333333m;
    static int s_int_9 = 2;
    static long s_long_10 = -5;
    static Vector<ushort> s_v_ushort_21 = Vector.Create((ushort)5);
    static Vector<long> s_v_long_24 = Vector.Create((long)0);
    static Vector<ulong> s_v_ulong_25 = Vector<ulong>.AllBitsSet;
    static Vector<float> s_v_float_26 = Vector<float>.Zero;
    static Vector3 s_v3_29 = Vector3.Create(2.125f, 2.3636365f, 2.0857143f);
    decimal decimal_36 = 5m;
    int int_39 = -2;
    long long_40 = 1;
    ushort ushort_44 = 1;
    ulong ulong_46 = 2;
    SveMaskPattern SveMaskPattern_47 = SveMaskPattern.LargestPowerOf2;
    Vector<ushort> v_ushort_51 = Vector.Create((ushort)1);
    Vector<long> v_long_54 = Vector.Create((long)2147483646);
    Vector<float> v_float_56 = Vector<float>.Zero;
    Vector3 v3_59 = Vector3.Create(-4.9690723f);
    S2 s2_62 = new S2();
    static int s_loopInvariant = 6;
    private static List<string> toPrint = new List<string>();
    [MethodImpl(MethodImplOptions.NoInlining)]
    public int LeafMethod6()
    {
        unchecked
        {
            return 15<<4;
        }
    }
    public long Method1(S2 p_s2_63, out ushort p_ushort_64)
    {
        unchecked
        {
            bool bool_65 = false;
            decimal decimal_68 = -1.9736842105263157894736842105m;
            double double_69 = 75.16666666666667;
            int int_71 = -2;
            sbyte sbyte_73 = 5;
            string string_75 = "333H54N";
            ushort ushort_76 = 2;
            SveMaskPattern SveMaskPattern_79 = SveMaskPattern_47;
            S1 s1_80 = new S1();
            S2 s2_81 = new S2();
            p_ushort_64 = 15*4;
            int __loopvar1 = 15+4, __loopSecondaryVar1_0 = s_loopInvariant;
            for (; int_39 < int_39; __loopSecondaryVar1_0++, s_char_5 = s_char_5 = s_char_5 = s_char_5 = s_char_5)
            {
                if (__loopvar1 <= 15-4)
                    break;
                Vector.Negate(s_v_ushort_21 ^ v_ushort_51 * s_v_ushort_21^ s_v_ushort_21);
                try
                {
                    v3_59 *= v3_59 *= s_v3_29 * v3_59* (s_v3_29 += Vector3.Zero)+ v3_59 - v3_59- Vector3.Log2(s_v3_29);
                }
                catch (System.InvalidOperationException)
                {
                    v_float_56 += v_float_56 & (s_v_float_26 -= v_float_56 += v_float_56)^ v_float_56;
                }
                catch (System.IndexOutOfRangeException)
                {
                    v_long_54 -= s_v_long_24 + (s_v_long_24 *= v_long_54)& Vector.AsVectorInt64(s_v_ulong_25)+ Vector.ShiftRightArithmetic(v_long_54, int_39) | s_v_long_24 + (s_v_long_24 *= v_long_54);
                }
                catch (System.NotFiniteNumberException)
                {
                    int __loopvar0 = 15-4;
                    while ((decimal_36 *= s_int_9 /= 15|4)- 15%4>= s_decimal_6)
                    {
                        if (__loopvar0 == s_loopInvariant)
                            break;
                        sbyte_73 >>= int_71 + int_39<< LeafMethod6()* (int_71 -= 15&4)| s_int_9;
                    }
                }
                finally
                {
                    ulong_46 >>= int_39 | (int_39 ^= 15^4)+ (int_71 *= int_39)<< int_71;
                }
            }
            Log("bool_65", bool_65);
            Log("decimal_68", decimal_68);
            Log("double_69", double_69);
            Log("string_75", string_75);
            Log("ushort_76", ushort_76);
            Log("p_ushort_6", p_ushort_64);
            Log("s1_80.uint", s1_80.uint_0);
            Log("SveMaskPat", SveMaskPattern_79);
            Log("s2_81.v2_2", s2_81.v2_2);
            return s_long_10 &= long_40;
        }
    }
    public void Method0()
    {
        unchecked
        {
            s_long_10 = Method1(s2_62, out ushort_44);
            return;
        }
    }
    public static void Main(string[] args)
   {
     Antigen();
   }
    public static int Antigen()
    {
        new TestClass().Method0();
        return string.Join(Environment.NewLine, toPrint).GetHashCode();
    }
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static void Log(string varName, object varValue)
    {
    }
}
/*
Environment:

set DOTNET_JitAlignLoops=1
set DOTNET_JitDoReversePostOrderLayout=1
set DOTNET_TieredPGO_InstrumentedTierAlwaysOptimized=1
set DOTNET_HeapVerify=1
set DOTNET_ReadyToRun=1
set DOTNET_TieredCompilation=0
set DOTNET_MaxVectorTBitWidth=128
set DOTNET_PreferredVectorBitWidth=0
set DOTNET_JitStressRegs=0x80
set DOTNET_JitThrowOnAssertionFailure=1
set DOTNET_LegacyExceptionHandling=1

Debug: -513242532

Release: 0
JIT assert failed:
Assertion failed 'kind == Overwrite' in 'TestClass:Method1(TestClass+S2,byref):long:this' during 'VN-based dead store removal' (IL size 895; hash 0x13bd25b0; FullOpts)

    File: /__w/1/s/src/coreclr/jit/jithashtable.h Line: 339

*/
dotnet-policy-service[bot] commented 3 weeks ago

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

kunalspathak commented 3 weeks ago

I have seen failures on win/x86 as well, but this was the shortest repro on linux/arm