Skip to content
Merged
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
32 changes: 30 additions & 2 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7734,10 +7734,38 @@ ValueNum ValueNumStore::EvalHWIntrinsicFunBinary(var_types type,
}

#ifdef TARGET_ARM64
case NI_AdvSimd_Multiply:
case NI_AdvSimd_MultiplyByScalar:
case NI_AdvSimd_Arm64_Multiply:
case NI_AdvSimd_Arm64_MultiplyByScalar:
{
if (!varTypeIsFloating(baseType))
{
// Handle `x * 0 == 0` and `0 * x == 0`
// Not safe for floating-point when x == -0.0, NaN, +Inf, -Inf
ValueNum zeroVN = VNZeroForType(TypeOfVN(cnsVN));

if (cnsVN == zeroVN)
{
return VNZeroForType(type);
}
}

assert((TypeOfVN(arg0VN) == type) && (TypeOfVN(arg1VN) == TYP_SIMD8));

// Handle x * 1 => x, but only if the scalar RHS is <1, ...>.
if (IsVNConstant(arg1VN))
{
if (EvaluateSimdGetElement(this, TYP_SIMD8, baseType, arg1VN, 0) == VNOneForType(baseType))
{
return arg0VN;
}
}
break;
}
#endif

#ifdef TARGET_ARM64
case NI_AdvSimd_Multiply:
case NI_AdvSimd_Arm64_Multiply:
#else
case NI_SSE_Multiply:
case NI_SSE2_Multiply:
Expand Down
25 changes: 25 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_93876/Runtime_93876.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

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

public static class Runtime_93876
{
[Fact]
public static void Problem()
{
Vector4 v = Mul(0, 1);
Assert.Equal(Vector4.One, v);
Vector64<float> v64 = Mul64(0, 1);
Assert.Equal(Vector64<float>.One, v64);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static Vector4 Mul(float a, float b) => Vector4.Multiply(a + b, Vector4.One);

[MethodImpl(MethodImplOptions.NoInlining)]
private static Vector64<float> Mul64(float a, float b) => Vector64.Multiply(a + b, Vector64<float>.One);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>