diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index e657b9dde198f5..55a450d2932478 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -2575,12 +2575,6 @@ ValueNum ValueNumStore::VNForFunc(var_types typ, VNFunc func, ValueNum arg0VN) { *resultVN = funcApp.GetArg(0); } - // NOT(relop(x,y)) ==> Reverse(relop)(x,y) - // - else if (VNFuncIsComparison(funcApp.GetFunc())) - { - *resultVN = GetRelatedRelop(arg0VN, VN_RELATION_KIND::VRK_Reverse); - } } } diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_129076/Runtime_129076.cs b/src/tests/JIT/Regression/JitBlue/Runtime_129076/Runtime_129076.cs new file mode 100644 index 00000000000000..d593f7e4e35f5a --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_129076/Runtime_129076.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// VN was simplifying NOT(relop(x,y)) to Reverse(relop)(x,y). GT_NOT is +// bitwise complement, not logical negation: ~(x relop y) produces -1 or +// -2 for a 0/1 relop result, while Reverse(relop)(x,y) produces 0 or 1, +// so downstream uses comparing the value arithmetically (here `~v3 >= -1`) +// folded the wrong way. + +namespace Runtime_129076; + +using System.Runtime.CompilerServices; +using Xunit; + +public static class Runtime_129076 +{ + private static volatile int Input_p0 = unchecked((int)0x800335C5); + private static volatile int Input_p1 = 0; + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int Func(int p0, int p1) + { + unchecked + { + int v1 = unchecked((int)0x000335C5) & p1; + int v3 = (v1 != p0) ? 1 : 0; + if (v3 == 0) return 99; + int v4 = ~v3; + return (v4 >= -1) ? 1 : 0; + } + } + + [Fact] + public static int TestEntryPoint() + { + return Func(Input_p0, Input_p1) == 0 ? 100 : 1; + } +} diff --git a/src/tests/JIT/Regression/Regression_ro_2.csproj b/src/tests/JIT/Regression/Regression_ro_2.csproj index f8bedd81f9050b..82e13ec3df7e5c 100644 --- a/src/tests/JIT/Regression/Regression_ro_2.csproj +++ b/src/tests/JIT/Regression/Regression_ro_2.csproj @@ -100,6 +100,7 @@ +