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: Assertion failed '!(checkUnusedValues && def->IsUnusedValue()) && "operands should never be marked as unused values"' during 'Lowering nodeinfo' #106480

Closed
amanasifkhalid opened this issue Aug 15, 2024 · 8 comments · Fixed by #106555
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@amanasifkhalid
Copy link
Member

On windows x64:

// Found by Antigen
// Reduced from 339 KB to 5.65 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 S2
    {
    }
    static char s_char_4 = 'F';
    static int s_int_8 = -5;
    static sbyte s_sbyte_10 = 0;
    static Vector512<sbyte> s_v512_sbyte_38 = Vector512.Create(-2, -5, 1, 0, -1, 1, 0, 6, 0, 0, 0, 1, -2, 0, 5, 6, -2, -8, -1, -1, 0, 2, 26, -1, 5, 2, 0, -1, -1, 1, -7, -5, -2, 0, 0, 5, 0, -1, 0, -1, 0, 26, -5, -5, -7, -5, -5, 26, -1, -5, 2, 26, 1, 0, -7, -1, -5, -5, -1, -5, 0, -2, -1, -5);
    static S2 s_s2_61 = new S2();
    char char_64 = '9';
    Vector512<sbyte> v512_sbyte_98 = Vector512.Create((sbyte)2);
    static int s_loopInvariant = 9;
    private static List<string> toPrint = new List<string>();
    public sbyte Method1(S2 p_s2_122, ref S2 p_s2_123)
    {
        unchecked
        {
            byte byte_125 = 5;
            switch (s_int_8 <<= 15^4)
            {
                case -5:
                {
                    int __loopvar16 = s_loopInvariant;
                    for (; s_int_8 < 15+4; __loopvar16 -= 3, char_64 = char_64 = s_char_4 = char_64 = s_char_4)
                    {
                        for (;;)
                        {
                            switch (char_64)
                            {
                                case '8':
                                {
                                    break;
                                }
                                case 'L':
                                {
                                    break;
                                }
                                case 'K':
                                {
                                    break;
                                }
                                case 'C':
                                {
                                    break;
                                }
                                case 'O':
                                {
                                    break;
                                }
                                case 'Q':
                                {
                                    break;
                                }
                                case 'D':
                                {
                                    switch (15/4)
                                    {
                                        case -5:
                                        {
                                            break;
                                        }
                                        case -1:
                                        {
                                            break;
                                        }
                                        case 0:
                                        {
                                            break;
                                        }
                                        case 1:
                                        {
                                            break;
                                        }
                                        case 5:
                                        {
                                            break;
                                        }
                                        case -2:
                                        {
                                            break;
                                        }
                                        case -2147483648:
                                        {
                                            break;
                                        }
                                        default:
                                        {
                                            for (;;)
                                            {
                                                try
                                                {
                                                    v512_sbyte_98 += s_v512_sbyte_38 ^ s_v512_sbyte_38 + s_v512_sbyte_38& Avx512F.TernaryLogic(s_v512_sbyte_38, v512_sbyte_98, Vector512<sbyte>.Zero, byte_125);
                                                }
                                                finally
{}
                                            }
                                            break;
                                        }
                                    }
                                    break;
                                }
                                default:
                                {
                                    break;
                                }
                            }
                        }
                    }
                    break;
                }
                case -1:
                {
                    break;
                }
                case 0:
                {
                    break;
                }
                case 2:
                {
                    break;
                }
                case 1:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            return 15|4;
        }
    }
    public void Method0()
    {
        unchecked
        {
            s_sbyte_10 = Method1(s_s2_61, ref s_s2_61);
            return;
        }
    }
    public static void Main(string[] args)
    {
    }
    public static int Antigen()
    {
        new TestClass().Method0();
        return string.Join(Environment.NewLine, toPrint).GetHashCode();
    }
}
/*
Environment:

set DOTNET_JitForceControlFlowGuard=1
set DOTNET_JitRandomOnStackReplacement=10
set DOTNET_ReadyToRun=1
set DOTNET_TC_OnStackReplacement=1
set DOTNET_TC_PartialCompilation=1
set DOTNET_TC_QuickJitForLoops=1
set DOTNET_TieredCompilation=0
set DOTNET_JitStress=0
set DOTNET_JitThrowOnAssertionFailure=1
set DOTNET_LegacyExceptionHandling=1

Debug: 1629887734

Release: 0
JIT assert failed:
Assertion failed '!(checkUnusedValues && def->IsUnusedValue()) && "operands should never be marked as unused values"' in 'TestClass:Method1(TestClass+S2,byref):byte:this' during 'Lowering nodeinfo' (IL size 228; hash 0xd9d268b0; FullOpts)

    File: D:\a\_work\1\s\src\coreclr\jit\lir.cpp Line: 1649


*/

Also hit on Windows x86. 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 Aug 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Aug 15, 2024
Copy link
Contributor

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

@amanasifkhalid amanasifkhalid changed the title JIT: Assertion failed JIT: Assertion failed '!(checkUnusedValues && def->IsUnusedValue()) && "operands should never be marked as unused values"' during 'Lowering nodeinfo' Aug 15, 2024
@AndyAyersMS
Copy link
Member

I'll take a look.

@AndyAyersMS AndyAyersMS self-assigned this Aug 16, 2024
@AndyAyersMS AndyAyersMS removed the untriaged New issue has not been triaged by the area owner label Aug 16, 2024
@AndyAyersMS
Copy link
Member

I'm not able to repro this -- @amanasifkhalid which hash did this run against?

@amanasifkhalid
Copy link
Member Author

@AndyAyersMS It's from this run; hash is 03969786.

@amanasifkhalid
Copy link
Member Author

Antigen hit it again with this repro:

// Found by Antigen
// Reduced from 121.36 KB to 3.38 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 struct S2
    {
    }
    static int s_int_10 = 0;
    static uint s_uint_16 = 0;
    static Vector512<ushort> s_v512_ushort_42 = Vector512<ushort>.AllBitsSet;
    static Vector512<float> s_v512_float_47 = Vector512<float>.AllBitsSet;
    bool bool_64 = true;
    Vector512<ushort> v512_ushort_102 = Vector512.Create((ushort)0, 0, 2, 0, 2, 0, 0, 2, 2, 1, 5, 99, 2, 99, 5, 5, 5, 2, 2, 99, 5, 32767, 2, 2, 5, 2, 32767, 1, 99, 32766, 5, 2);
    Vector512<float> v512_float_107 = Vector512<float>.Zero;
    static int s_loopInvariant = 2;
    private static List<string> toPrint = new List<string>();
    public double Method1(out Vector512<float> p_v512_float_124)
    {
        unchecked
        {
            bool bool_125 = true;
            byte byte_126 = 5;
            ushort ushort_136 = 0;
            p_v512_float_124 = s_v512_float_47 *= Vector512.Max(v512_float_107 ^ s_v512_float_47, s_v512_float_47);
            try
            {
                if ((bool_64 = ((((s_uint_16 = ((15-4)))) > ((s_int_10 / ((15|4))))))))
{}                else
                {
                    if (((((s_uint_16 = ((15-4)))) > ((s_int_10 / ((15|4)))))))
                    {
                    }
                    else
                    {
                        try
                        {
                            if (bool_125)
                            {
                            }
                            else
                            {
                            }
                        }
                        catch (System.MissingMethodException)
                        {
                            for (int __loopvar9 = 15+4; s_int_10 < (((15/4))); s_int_10++)
                            {
                                if (15<4)
                                    break;
                                int __loopvar5 = s_loopInvariant;
                                do
                                {
                                    Avx512F.TernaryLogic(((((Avx512F.TernaryLogic(v512_ushort_102, v512_ushort_102, v512_ushort_102, byte_126) | ((v512_ushort_102 | v512_ushort_102)))) + ((v512_ushort_102 | v512_ushort_102)))), ((v512_ushort_102 += ((s_v512_ushort_42 *= ((v512_ushort_102 *= v512_ushort_102)))))), ((((v512_ushort_102 * ((15|4)))) ^ ((v512_ushort_102 *= v512_ushort_102)))), byte_126);
                                }
                                while ((((15!=4))) && ((15<4)));
                                ;
                            }
                        }
                        finally
                        {
                        }
                    }
                }
            }
            finally
            {
            }
            return ((15/4));
        }
    }
    public void Method0()
    {
        unchecked
        {
            double double_175 = 99.08695652173913;
            double_175 = Method1(out s_v512_float_47);
            return;
        }
    }
    public static void Main(string[] args)
    {
    }
    public static int Antigen()
    {
        new TestClass().Method0();
        return string.Join(Environment.NewLine, toPrint).GetHashCode();
    }
}
/*
Environment:

set DOTNET_JitRLCSEGreedy=1
set DOTNET_TailcallStress=1
set DOTNET_JitForceControlFlowGuard=1
set DOTNET_HeapVerify=1
set DOTNET_ReadyToRun=1
set DOTNET_JitRandomOnStackReplacement=5
set DOTNET_TieredCompilation=0
set DOTNET_PreferredVectorBitWidth=512
set DOTNET_EnableHWIntrinsic=1
set DOTNET_JitStress=2
set DOTNET_JitStressRegs=3
set DOTNET_JitThrowOnAssertionFailure=1
set DOTNET_LegacyExceptionHandling=1

Debug: -1650517093

Release: 0
JIT assert failed:
Assertion failed '!(checkUnusedValues && def->IsUnusedValue()) && "operands should never be marked as unused values"' in 'TestClass:Method1(byref):double:this' during 'Lowering nodeinfo' (IL size 345; hash 0x05298471; FullOpts)

    File: D:\a\_work\1\s\src\coreclr\jit\lir.cpp Line: 1649


*/

You might have more luck with that one.

@AndyAyersMS
Copy link
Member

Ah, keep forgetting the reduced repros don't actually call the failing methods... eg

    public static void Main(string[] args)
    {
    }

When I fix that I can repro.

@AndyAyersMS
Copy link
Member

Second repro only needs DOTNET_TieredCompilation=0, so possible product issue.

@AndyAyersMS
Copy link
Member

Simplified repro

using System;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
public class TestClass
{
    Vector512<ushort> v512_ushort_102 = Vector512<ushort>.AllBitsSet;

    public void Method0()
    {
        byte byte_126 = 5;
        Avx512F.TernaryLogic(v512_ushort_102, v512_ushort_102, v512_ushort_102, byte_126);
    }
    public static void Main(string[] args)
    {
        new TestClass().Method0();
    }
}

In LowerHWIntrinsicTernaryLogic we do some operand swapping and don't account for this when marking operands as unused.

AndyAyersMS added a commit to AndyAyersMS/runtime that referenced this issue Aug 16, 2024
In `LowerHWIntrinsicTernaryLogic` we do some operand swapping and replacing,
and were not accounting for this when marking operands as unused.

Fixes dotnet#106480.
@AndyAyersMS AndyAyersMS added this to the 9.0.0 milestone Aug 16, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Aug 16, 2024
github-actions bot pushed a commit that referenced this issue Aug 17, 2024
In `LowerHWIntrinsicTernaryLogic` we do some operand swapping and replacing,
and were not accounting for this when marking operands as unused.

Fixes #106480.
carlossanlop pushed a commit that referenced this issue Aug 19, 2024
…TernaryLogic (#106574)

* JIT: fix unused operand marking in LowerHWIntrinsicTernaryLogic

In `LowerHWIntrinsicTernaryLogic` we do some operand swapping and replacing,
and were not accounting for this when marking operands as unused.

Fixes #106480.

* review feedback

---------

Co-authored-by: Andy Ayers <andya@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Sep 17, 2024
mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this issue Dec 10, 2024
…et#106555)

In `LowerHWIntrinsicTernaryLogic` we do some operand swapping and replacing,
and were not accounting for this when marking operands as unused.

Fixes dotnet#106480.
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 in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants