Skip to content

Bad codegen with Vector64<int> and ^ leads to wrong output #91252

Closed
@kunalspathak

Description

@kunalspathak
// Found by Antigen

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using System.Numerics;
public class TestClass
{
    static long s_long_11 = 43;
    static Vector64<int> s_v64_int_22 = Vector64.Create(-5);
    bool bool_54 = false;
    long long_61 = -2;
    Vector64<int> v64_int_72 = Vector64.Create(-1);
    static int s_loopInvariant = 5;
    private static List<string> toPrint = new List<string>();
    public void Method0()
    {
        unchecked
        {
            long long_154 = -1;
            int __loopvar23 = 15+4;
            for (;;)
            {
                if (__loopvar23 == s_loopInvariant)
                    break;
                __loopvar23 -= 2;
                int __loopvar4 = s_loopInvariant, __loopSecondaryVar4_0 = s_loopInvariant;
                for (;;)
                {
                    __loopvar4--;
                    if (__loopvar4 <= s_loopInvariant - 4)
                        break;
                    if (bool_54)
{}                    else
                    {
                        try
                        {
                            long_61 >>= Vector64.Dot(v64_int_72 -= v64_int_72 ^ v64_int_72, v64_int_72 | v64_int_72+ s_v64_int_22 | s_v64_int_22);
                        }
                        catch (System.NotSupportedException)
                        {
                        }
                        catch (System.TimeZoneNotFoundException)
                        {
                        }
                        finally
                        {
                        }
                    }
                }
                long_154 += long_154 |= long_154 ^ long_61 - s_long_11;
            }
            Log("long_154", long_154);
            return;
        }
    }
    public static void Main(string[] args)
    {
        new TestClass().Method0();
        PrintLog();
    }
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static void Log(string varName, object varValue)
    {
        toPrint.Add($"{varName}={varValue}");
    }
    public static void PrintLog()
    {
        foreach (var entry in toPrint)
        {
            Console.WriteLine(entry);
        }
    }
}
/*
Got output diff:
--------- Baseline ---------  

Environment:

set COMPlus_JITMinOpts=1
set COMPlus_TieredCompilation=1

long_154=-40
--------- Test ---------  

Environment:

set COMPlus_TieredCompilation=0

long_154=-20
*/

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions