Skip to content

Commit d38a539

Browse files
authored
Handle contained BITCAST for STORE_LCL_FLD (#55852)
* Do not mark BITCAST as contained for STORE_LCL_FLD * Add unit test * Handle contained BITCAST in STORE_LCL_FLD * Return 100
1 parent 3847790 commit d38a539

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

src/coreclr/jit/codegenxarch.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4425,7 +4425,7 @@ void CodeGen::genCodeForStoreLclFld(GenTreeLclFld* tree)
44254425

44264426
#ifdef FEATURE_SIMD
44274427
// storing of TYP_SIMD12 (i.e. Vector3) field
4428-
if (tree->TypeGet() == TYP_SIMD12)
4428+
if (targetType == TYP_SIMD12)
44294429
{
44304430
genStoreLclTypeSIMD12(tree);
44314431
return;
@@ -4436,7 +4436,32 @@ void CodeGen::genCodeForStoreLclFld(GenTreeLclFld* tree)
44364436
assert(genTypeSize(genActualType(targetType)) == genTypeSize(genActualType(op1->TypeGet())));
44374437

44384438
genConsumeRegs(op1);
4439-
GetEmitter()->emitInsBinary(ins_Store(targetType), emitTypeSize(tree), tree, op1);
4439+
4440+
if (op1->OperIs(GT_BITCAST) && op1->isContained())
4441+
{
4442+
regNumber targetReg = tree->GetRegNum();
4443+
GenTree* bitCastSrc = op1->gtGetOp1();
4444+
var_types srcType = bitCastSrc->TypeGet();
4445+
noway_assert(!bitCastSrc->isContained());
4446+
4447+
if (targetReg == REG_NA)
4448+
{
4449+
unsigned lclNum = tree->GetLclNum();
4450+
LclVarDsc* varDsc = compiler->lvaGetDesc(lclNum);
4451+
4452+
GetEmitter()->emitIns_S_R(ins_Store(srcType, compiler->isSIMDTypeLocalAligned(lclNum)),
4453+
emitTypeSize(targetType), bitCastSrc->GetRegNum(), lclNum, 0);
4454+
varDsc->SetRegNum(REG_STK);
4455+
}
4456+
else
4457+
{
4458+
genBitCast(targetType, targetReg, srcType, bitCastSrc->GetRegNum());
4459+
}
4460+
}
4461+
else
4462+
{
4463+
GetEmitter()->emitInsBinary(ins_Store(targetType), emitTypeSize(tree), tree, op1);
4464+
}
44404465

44414466
// Updating variable liveness after instruction was emitted
44424467
genUpdateLife(tree);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Runtime.CompilerServices;
5+
6+
struct S0
7+
{
8+
public ulong F0;
9+
public ulong F1;
10+
public long F2;
11+
public uint F4;
12+
public uint F6;
13+
}
14+
15+
public class Runtime_55141
16+
{
17+
// UDIV is lowered to the MULHI/BITCAST nodes and they are stored in field (STORE_LCL_FLD).
18+
// BITCAST is marked as contained so the value to be stored can be used from MULHI, but marking
19+
// the containment of BITCAST is not supported in codegen for STORE_LCL_FLD.
20+
public static int Main()
21+
{
22+
return (uint)Run(0) == 0 ? 100 : 0;
23+
}
24+
25+
[MethodImpl(MethodImplOptions.NoInlining)]
26+
public static uint Run(long x)
27+
{
28+
S0 vr1 = default(S0);
29+
vr1.F4 = (uint)x / 254;
30+
return vr1.F6;
31+
}
32+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<Optimize>True</Optimize>
5+
<DebugType>None</DebugType>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="$(MSBuildProjectName).cs" />
9+
</ItemGroup>
10+
</Project>

0 commit comments

Comments
 (0)