Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33828,15 +33828,35 @@ GenTree* Compiler::gtFoldExprHWIntrinsic(GenTreeHWIntrinsic* tree)
case FloatComparisonMode::OrderedFalseNonSignaling:
case FloatComparisonMode::OrderedFalseSignaling:
{
resultNode = gtNewZeroConNode(retType);
if (ni == NI_AVX_CompareScalar)
{
// CompareScalar preserves upper elements from op1,
// so we can't fold to a full zero vector
break;
}
// CompareMask returns TYP_MASK which gtNewZeroConNode doesn't handle,
// so use the SIMD vector type instead; the mask conversion at the end
// of this function will wrap it with CvtVectorToMask
resultNode = gtNewZeroConNode(varTypeIsMask(retType) ? getSIMDTypeForSize(simdSize)
: retType);
resultNode = gtWrapWithSideEffects(resultNode, tree, GTF_ALL_EFFECT);
break;
}

case FloatComparisonMode::UnorderedTrueNonSignaling:
case FloatComparisonMode::UnorderedTrueSignaling:
{
resultNode = gtNewAllBitsSetConNode(retType);
if (ni == NI_AVX_CompareScalar)
{
// CompareScalar preserves upper elements from op1,
// so we can't fold to a full AllBitsSet vector
break;
}
// CompareMask returns TYP_MASK which gtNewAllBitsSetConNode doesn't handle,
// so use the SIMD vector type instead; the mask conversion at the end
// of this function will wrap it with CvtVectorToMask
resultNode = gtNewAllBitsSetConNode(varTypeIsMask(retType) ? getSIMDTypeForSize(simdSize)
: retType);
resultNode = gtWrapWithSideEffects(resultNode, tree, GTF_ALL_EFFECT);
break;
}
Expand Down
69 changes: 69 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_125160/Runtime_125160.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using Xunit;

public class Runtime_125160
{
[ConditionalFact(typeof(Avx), nameof(Avx.IsSupported))]
public static void TestEntryPoint()
{
Assert.Equal(Vector128.Create(0f, 1f, 1f, 1f), CompareFalseFloat(Vector128<float>.One, Vector128<float>.Zero));
Assert.Equal(Vector128.Create(0d, 1d), CompareFalseDouble(Vector128<double>.One, Vector128<double>.Zero));

Vector128<float> trueFloat = CompareTrueFloat(Vector128<float>.One, Vector128<float>.Zero);
Assert.Equal(BitConverter.UInt32BitsToSingle(0xFFFFFFFF), trueFloat.GetElement(0));
Assert.Equal(1f, trueFloat.GetElement(1));
Assert.Equal(1f, trueFloat.GetElement(2));
Assert.Equal(1f, trueFloat.GetElement(3));

Vector128<double> trueDouble = CompareTrueDouble(Vector128<double>.One, Vector128<double>.Zero);
Assert.Equal(BitConverter.UInt64BitsToDouble(0xFFFFFFFFFFFFFFFF), trueDouble.GetElement(0));
Assert.Equal(1d, trueDouble.GetElement(1));
}

[ConditionalFact(typeof(Avx512F), nameof(Avx512F.IsSupported))]
public static void TestCompareMask()
{
Assert.Equal(Vector512<float>.Zero, CompareMaskFalseFloat(Vector512<float>.One, Vector512<float>.Zero));
Assert.Equal(Vector512<double>.Zero, CompareMaskFalseDouble(Vector512<double>.One, Vector512<double>.Zero));
Assert.Equal(Vector512<float>.AllBitsSet, CompareMaskTrueFloat(Vector512<float>.One, Vector512<float>.Zero));
Assert.Equal(Vector512<double>.AllBitsSet, CompareMaskTrueDouble(Vector512<double>.One, Vector512<double>.Zero));
}

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector128<float> CompareFalseFloat(Vector128<float> x, Vector128<float> y)
=> Avx.CompareScalar(x, y, FloatComparisonMode.OrderedFalseSignaling);

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector128<double> CompareFalseDouble(Vector128<double> x, Vector128<double> y)
=> Avx.CompareScalar(x, y, FloatComparisonMode.OrderedFalseNonSignaling);

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector128<float> CompareTrueFloat(Vector128<float> x, Vector128<float> y)
=> Avx.CompareScalar(x, y, FloatComparisonMode.UnorderedTrueSignaling);

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector128<double> CompareTrueDouble(Vector128<double> x, Vector128<double> y)
=> Avx.CompareScalar(x, y, FloatComparisonMode.UnorderedTrueNonSignaling);

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector512<float> CompareMaskFalseFloat(Vector512<float> x, Vector512<float> y)
=> Avx512F.Compare(x, y, FloatComparisonMode.OrderedFalseSignaling);

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector512<double> CompareMaskFalseDouble(Vector512<double> x, Vector512<double> y)
=> Avx512F.Compare(x, y, FloatComparisonMode.OrderedFalseNonSignaling);

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector512<float> CompareMaskTrueFloat(Vector512<float> x, Vector512<float> y)
=> Avx512F.Compare(x, y, FloatComparisonMode.UnorderedTrueSignaling);

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector512<double> CompareMaskTrueDouble(Vector512<double> x, Vector512<double> y)
=> Avx512F.Compare(x, y, FloatComparisonMode.UnorderedTrueNonSignaling);
}
1 change: 1 addition & 0 deletions src/tests/JIT/Regression/Regression_ro_2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="JitBlue\Runtime_123790\Runtime_123790.cs" />
<Compile Include="JitBlue\Runtime_124082\Runtime_124082.cs" />
<Compile Include="JitBlue\Runtime_125041\Runtime_125041.cs" />
<Compile Include="JitBlue\Runtime_125160\Runtime_125160.cs" />
</ItemGroup>
<Import Project="$(TestSourceDir)MergedTestRunner.targets" />
</Project>