Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 13 additions & 2 deletions src/coreclr/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,20 @@ void CodeGen::genSpillVar(GenTree* tree)
// but we will kill the var in the reg (below).
if (!varDsc->IsAlwaysAliveInMemory())
{
instruction storeIns = ins_Store(lclType, compiler->isSIMDTypeLocalAligned(varNum));
assert(varDsc->GetRegNum() == tree->GetRegNum());
inst_TT_RV(storeIns, size, tree, tree->GetRegNum());
#if defined(FEATURE_SIMD)
if ((lclType == TYP_SIMD12) && !compiler->lvaMapSimd12ToSimd16(varDsc))
{
// Store SIMD12 to stack as 12 bytes
GetEmitter()->emitStoreSimd12ToLclOffset(varNum, tree->AsLclVarCommon()->GetLclOffs(),
tree->GetRegNum(), nullptr);
}
else
#endif
{
instruction storeIns = ins_Store(lclType, compiler->isSIMDTypeLocalAligned(varNum));
inst_TT_RV(storeIns, size, tree, tree->GetRegNum());
}
}

// We should only have both GTF_SPILL (i.e. the flag causing this method to be called) and
Expand Down
17 changes: 15 additions & 2 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5620,7 +5620,7 @@ void emitter::emitIns_R(instruction ins, emitAttr attr, regNumber reg)
// varNum - the variable on the stack to use as a base;
// offset - the offset from the varNum;
// dataReg - the src reg with SIMD12 value;
// tmpRegProvider - a tree to grab a tmp reg from if needed.
// tmpRegProvider - a tree to grab a tmp reg from if needed (can be null).
//
void emitter::emitStoreSimd12ToLclOffset(unsigned varNum, unsigned offset, regNumber dataReg, GenTree* tmpRegProvider)
{
Expand All @@ -5635,7 +5635,7 @@ void emitter::emitStoreSimd12ToLclOffset(unsigned varNum, unsigned offset, regNu
// Extract and store upper 4 bytes
emitIns_S_R_I(INS_extractps, EA_16BYTE, varNum, offset + 8, dataReg, 2);
}
else
else if (tmpRegProvider != nullptr)
{
regNumber tmpReg = codeGen->internalRegisters.GetSingle(tmpRegProvider);
assert(isFloatReg(tmpReg));
Expand All @@ -5646,6 +5646,19 @@ void emitter::emitStoreSimd12ToLclOffset(unsigned varNum, unsigned offset, regNu
// Store upper 4 bytes
emitIns_S_R(INS_movss, EA_4BYTE, tmpReg, varNum, offset + 8);
}
else
{
// We don't have temp regs - let's do two shuffles then

// [0,1,2,3] -> [2,3,0,1]
emitIns_R_R_I(INS_pshufd, EA_16BYTE, dataReg, dataReg, 78);

// Store upper 4 bytes
emitIns_S_R(INS_movss, EA_4BYTE, dataReg, varNum, offset + 8);

// Restore dataReg to its previous state: [2,3,0,1] -> [0,1,2,3]
emitIns_R_R_I(INS_pshufd, EA_16BYTE, dataReg, dataReg, 78);
}
}
#endif // FEATURE_SIMD

Expand Down
37 changes: 37 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_95043/Runtime_95043.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.Numerics;
using System.Runtime.CompilerServices;
using Xunit;

public unsafe class Runtime_95043
{
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Sweep(int ecx, int* edx, Vector3 stack12)
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine(ecx);
if (ecx == -1)
{
ecx = edx[0];
}
else if (!float.IsNaN(stack12.X))
{
edx[0] = -1;
ecx = -1;
}
}
}

[Fact]
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Test()
{
int x = 42;
Sweep(1, &x, Vector3.Zero);
Assert.Equal(-1, x);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>