Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7819,7 +7819,7 @@ ValueNum ValueNumStore::EvalHWIntrinsicFunBinary(var_types type,

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

Expand All @@ -7836,7 +7836,7 @@ ValueNum ValueNumStore::EvalHWIntrinsicFunBinary(var_types type,
oneVN = VNOneForType(baseType);
}

if (cnsVN == oneVN)
if ((cnsVN == oneVN) && (TypeOfVN(argVN) == type))
{
return argVN;
}
Expand Down
19 changes: 19 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,19 @@
// 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.Numerics;
using Xunit;

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

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

@tannergooding tannergooding Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the type of a + b here that causes the issue? Does it become TYP_DOUBLE or something or is the issue that it's TYP_FLOAT and the other operand is TYP_SIMD16?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gtNewSimdBinOpNode creates the following IR on ARM64:

               [000005] -----------                           HWINTRINSIC simd16 float MultiplyByScalar
               [000003] -----------                         ├──▌  CNS_VEC   simd16<0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000>
               [000004] -----------                         └──▌  HWINTRINSIC simd8  float CreateScalarUnsafe
               [000002] -----------                            └──▌  ADD       float 
               [000000] -----------                               ├──▌  LCL_VAR   float  V00 arg0         
               [000001] -----------                               └──▌  LCL_VAR   float  V01 arg1         

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think MultiplyByScalar shouldn't be handled by this path. E.g. Vector64.Multiply(Vector64<float>.One, x) will produce <x, 0> instead of <x, x> because of that. So this needs a bit more work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a change that handles MultiplyByScalar separately, can you take another look?

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<CLRTestEnvironmentVariable Include="DOTNET_JitStressModeNames" Value="STRESS_MAKE_CSE STRESS_SPLIT_TREES_REMOVE_COMMAS" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other tests there are comments that you need process isolation to use CLRTestEnvironmentVariable, is that no longer true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's still true, thanks for noticing. Fixed this and another test.

<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>