Skip to content

Commit

Permalink
Ensure that Arm64 correctly handles multiplication of simd by a 64-bi…
Browse files Browse the repository at this point in the history
…t scalar
  • Loading branch information
tannergooding committed Aug 22, 2024
1 parent 615a2e2 commit 6dc65e1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21258,22 +21258,26 @@ GenTree* Compiler::gtNewSimdBinOpNode(
#elif defined(TARGET_ARM64)
if (varTypeIsLong(simdBaseType))
{
GenTree** op1ToDup = &op1;
GenTree** op2ToDup = &op2;
GenTree** op2ToDup = nullptr;

assert(!varTypeIsArithmetic(op1));
assert(varTypeIsSIMD(op1));
op1 = gtNewSimdToScalarNode(TYP_LONG, op1, simdBaseJitType, simdSize);
op1ToDup = &op1->AsHWIntrinsic()->Op(1);
GenTree** op1ToDup = &op1->AsHWIntrinsic()->Op(1);

if (!varTypeIsArithmetic(op2))
if (varTypeIsSIMD(op2))
{
op2 = gtNewSimdToScalarNode(TYP_LONG, op2, simdBaseJitType, simdSize);
op2ToDup = &op2->AsHWIntrinsic()->Op(1);
}

// lower = op1.GetElement(0) * op2.GetElement(0)
GenTree* lower = gtNewOperNode(GT_MUL, TYP_LONG, op1, op2);
lower = gtNewSimdCreateScalarUnsafeNode(type, lower, simdBaseJitType, simdSize);

if (op2ToDup == nullptr)
{
op2ToDup = &lower->AsOp()->gtOp2;
}
lower = gtNewSimdCreateScalarUnsafeNode(type, lower, simdBaseJitType, simdSize);

if (simdSize == 8)
{
Expand Down
20 changes: 20 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_106838/Runtime_106838.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 Xunit;

public class Runtime_106838
{
[MethodImpl(MethodImplOptions.NoInlining)]
private Vector128<ulong> Problem(Vector128<ulong> vector) => vector * 5UL;

[Fact]
public static void TestEntryPoint()
{
Vector128<ulong> result = Problem(Vector128.Create<ulong>(5));
Assert.Equal(Vector128.Create<ulong>(25), result);
}
}
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>

0 comments on commit 6dc65e1

Please sign in to comment.