Skip to content
Open
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
26 changes: 12 additions & 14 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4240,15 +4240,6 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree)
//
void CodeGen::genCodeForStoreInd(GenTreeStoreInd* tree)
{
#ifdef FEATURE_SIMD
// Storing Vector3 of size 12 bytes through indirection
if (tree->TypeIs(TYP_SIMD12))
{
genStoreIndTypeSimd12(tree);
return;
}
#endif // FEATURE_SIMD

GenTree* data = tree->Data();
GenTree* addr = tree->Addr();

Expand Down Expand Up @@ -4321,6 +4312,15 @@ void CodeGen::genCodeForStoreInd(GenTreeStoreInd* tree)
}
}

#ifdef FEATURE_SIMD
// Storing Vector3 of size 12 bytes through indirection
if (tree->TypeIs(TYP_SIMD12))
{
genStoreIndTypeSimd12(tree);
return;
}
#endif // FEATURE_SIMD

GetEmitter()->emitInsLoadStoreOp(ins, attr, dataReg, tree);

// If store was to a variable, update variable liveness after instruction was emitted.
Expand Down Expand Up @@ -5438,8 +5438,8 @@ void CodeGen::genStoreIndTypeSimd12(GenTreeStoreInd* treeNode)
GenTree* data = treeNode->Data();
assert(!data->isContained());

regNumber addrReg = genConsumeReg(addr);
regNumber dataReg = genConsumeReg(data);
regNumber addrReg = addr->GetRegNum();
regNumber dataReg = data->GetRegNum();

// Need an additional integer register to extract upper 4 bytes from data.
regNumber tmpReg = internalRegisters.GetSingle(treeNode);
Expand Down Expand Up @@ -5474,7 +5474,7 @@ void CodeGen::genLoadIndTypeSimd12(GenTreeIndir* treeNode)
assert(!addr->isContained());

regNumber tgtReg = treeNode->GetRegNum();
regNumber addrReg = genConsumeReg(addr);
regNumber addrReg = addr->GetRegNum();

// Need an additional int register to read upper 4 bytes, which is different from targetReg
regNumber tmpReg = internalRegisters.GetSingle(treeNode);
Expand All @@ -5487,8 +5487,6 @@ void CodeGen::genLoadIndTypeSimd12(GenTreeIndir* treeNode)

// Insert upper 4-bytes into data
GetEmitter()->emitIns_R_R_I(INS_mov, EA_4BYTE, tgtReg, tmpReg, 2);

genProduceReg(treeNode);
}

//-----------------------------------------------------------------------------
Expand Down
21 changes: 11 additions & 10 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,15 +1749,6 @@ void CodeGen::genCodeForIndir(GenTreeIndir* tree)
{
assert(tree->OperIs(GT_IND));

#ifdef FEATURE_SIMD
// Handling of Vector3 type values loaded through indirection.
if (tree->TypeIs(TYP_SIMD12))
{
genLoadIndTypeSimd12(tree);
return;
}
#endif // FEATURE_SIMD

var_types type = tree->TypeGet();
instruction ins = ins_Load(type);
regNumber targetReg = tree->GetRegNum();
Expand All @@ -1780,7 +1771,17 @@ void CodeGen::genCodeForIndir(GenTreeIndir* tree)
}
#endif // TARGET_ARM64

GetEmitter()->emitInsLoadStoreOp(ins, attr, targetReg, tree);
#ifdef FEATURE_SIMD
// Handling of Vector3 type values loaded through indirection.
if (tree->TypeIs(TYP_SIMD12))
{
genLoadIndTypeSimd12(tree);
}
else
#endif // FEATURE_SIMD
{
GetEmitter()->emitInsLoadStoreOp(ins, attr, targetReg, tree);
}

if (emitBarrier)
{
Expand Down
40 changes: 40 additions & 0 deletions src/tests/JIT/Regression_2/Runtime_137964/Runtime_137964.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

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

public class Runtime_137964
{
[MethodImpl(MethodImplOptions.NoInlining)]
private static Vector3 VolatileLoad(ref Vector3 source)
{
// ARM64: ldr {{d[0-9]+}}, [x0]
// ARM64-NEXT: ldr {{w[0-9]+}}, [x0, #0x08]
// ARM64-FULL-LINE: dmb ishld
return Vector3VolatileHelpers.Load(ref source);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void VolatileStore(ref Vector3 destination, Vector3 value)
{
// ARM64-FULL-LINE: dmb ish
// ARM64-NEXT: str {{d[0-9]+}}, [x0]
// ARM64: str {{w[0-9]+}}, [x0, #0x08]
Vector3VolatileHelpers.Store(ref destination, value);
}

[Theory]
[InlineData(0.0f, 0.0f, 0.0f)]
[InlineData(1.25f, -2.5f, 3.75f)]
public static void TestEntryPoint(float x, float y, float z)
{
Vector3 source = new Vector3(x, y, z);
Assert.Equal(source, VolatileLoad(ref source));

Vector3 destination = new Vector3(-1.0f);
VolatileStore(ref destination, source);
Assert.Equal(source, destination);
}
}
16 changes: 16 additions & 0 deletions src/tests/JIT/Regression_2/Runtime_137964/Runtime_137964.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<Optimize>True</Optimize>
<DebugType>None</DebugType>
<CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs">
<HasDisasmCheck>true</HasDisasmCheck>
</Compile>
<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" />
<CLRTestEnvironmentVariable Include="DOTNET_JITMinOpts" Value="0" />
<ProjectReference Include="Vector3VolatileHelpers.ilproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

.assembly extern System.Runtime { .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A) }
.assembly extern System.Numerics.Vectors { .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A) }
.assembly Vector3VolatileHelpers { }

.class public abstract sealed Vector3VolatileHelpers extends [System.Runtime]System.Object
{
.method public hidebysig static valuetype [System.Numerics.Vectors]System.Numerics.Vector3
Load(valuetype [System.Numerics.Vectors]System.Numerics.Vector3& source) cil managed aggressiveinlining
{
ldarg.0
volatile.
ldobj [System.Numerics.Vectors]System.Numerics.Vector3
ret
}

.method public hidebysig static void
Store(valuetype [System.Numerics.Vectors]System.Numerics.Vector3& destination,
valuetype [System.Numerics.Vectors]System.Numerics.Vector3 'value') cil managed aggressiveinlining
{
ldarg.0
ldarg.1
volatile.
stobj [System.Numerics.Vectors]System.Numerics.Vector3
ret
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.IL">
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).il" />
</ItemGroup>
</Project>
Loading