diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index bbec675a6f07a1..f288fcf0386960 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -25982,9 +25982,6 @@ GenTree* Compiler::gtNewSimdMinMaxNode(var_types type, needsFixup = cnsNode->IsFloatNegativeZero(); } else - { - needsFixup = cnsNode->IsVectorZero(); - } { needsFixup = cnsNode->IsVectorNegativeZero(simdBaseType); } @@ -31103,7 +31100,7 @@ genTreeOps GenTreeHWIntrinsic::GetOperForHWIntrinsicId(bool* isScalar, bool getE { oper = GT_NEG; } - else if (isScalar && op1->IsCnsVec() && op1->AsVecCon()->IsScalarZero(simdBaseType)) + else if (*isScalar && op1->IsCnsVec() && op1->AsVecCon()->IsScalarZero(simdBaseType)) { oper = GT_NEG; } diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_130830/Runtime_130830.cs b/src/tests/JIT/Regression/JitBlue/Runtime_130830/Runtime_130830.cs new file mode 100644 index 00000000000000..a9d09d08828f84 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_130830/Runtime_130830.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Runtime_130830; + +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; +using Xunit; + +public static class Runtime_130830 +{ + [Fact] + public static void TestEntryPoint() + { + Vector128 result = Test(Vector128.Create(10), Vector128.Create(100)); + Assert.Equal(Vector128.Create(90, 91, 92, 93), result); + } + + // The low lane of the constant is zero but the constant is not all-zero, so the + // subtract must not be treated as a negate; otherwise the constant is dropped and + // the result collapses to <90, 90, 90, 90>. + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + private static Vector128 Test(Vector128 v1, Vector128 v2) + { + return (Vector128.Create(0, 1, 2, 3) - v1) + v2; + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_130831/Runtime_130831.cs b/src/tests/JIT/Regression/JitBlue/Runtime_130831/Runtime_130831.cs new file mode 100644 index 00000000000000..37597d88bc61ea --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_130831/Runtime_130831.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Runtime_130831; + +using System; +using System.Runtime.CompilerServices; +using Xunit; + +public static class Runtime_130831 +{ + // Compare the exact bit pattern: Double/Single.Equals treat -0.0 and +0.0 as equal, + // so a plain Assert.Equal would not observe a wrong-signed-zero result. + [Fact] + [SkipOnMono("https://github.com/dotnet/runtime/issues/131130", TestPlatforms.Any)] + public static void TestEntryPoint() + { + Assert.Equal(BitConverter.DoubleToInt64Bits(-0.0), BitConverter.DoubleToInt64Bits(MinNegZeroConst(+0.0))); + Assert.Equal(BitConverter.DoubleToInt64Bits(-0.0), BitConverter.DoubleToInt64Bits(MinNumberZeroConst(-0.0))); + + Assert.Equal(BitConverter.SingleToInt32Bits(-0.0f), BitConverter.SingleToInt32Bits(MinNegZeroConst(+0.0f))); + Assert.Equal(BitConverter.SingleToInt32Bits(-0.0f), BitConverter.SingleToInt32Bits(MinNumberZeroConst(-0.0f))); + } + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + private static double MinNegZeroConst(double value) => double.Min(value, -0.0); + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + private static double MinNumberZeroConst(double value) => double.MinNumber(value, +0.0); + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + private static float MinNegZeroConst(float value) => float.Min(value, -0.0f); + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + private static float MinNumberZeroConst(float value) => float.MinNumber(value, +0.0f); +} diff --git a/src/tests/JIT/Regression/Regression_ro_2.csproj b/src/tests/JIT/Regression/Regression_ro_2.csproj index f37653b74cbc16..690df1246b734d 100644 --- a/src/tests/JIT/Regression/Regression_ro_2.csproj +++ b/src/tests/JIT/Regression/Regression_ro_2.csproj @@ -114,6 +114,8 @@ + +