Skip to content

Fix contained LCL_VAR_ADDR in RMW. #50669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2021
Merged
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
28 changes: 22 additions & 6 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3094,7 +3094,7 @@ void emitter::emitInsLoadInd(instruction ins, emitAttr attr, regNumber dstReg, G
return;
}

if (addr->OperIs(GT_LCL_VAR_ADDR, GT_LCL_FLD_ADDR))
if (addr->OperIsLocalAddr())
{
GenTreeLclVarCommon* varNode = addr->AsLclVarCommon();
unsigned offset = varNode->GetLclOffs();
Expand Down Expand Up @@ -3152,7 +3152,7 @@ void emitter::emitInsStoreInd(instruction ins, emitAttr attr, GenTreeStoreInd* m
return;
}

if (addr->OperIs(GT_LCL_VAR_ADDR, GT_LCL_FLD_ADDR))
if (addr->OperIsLocalAddr())
{
GenTreeLclVarCommon* varNode = addr->AsLclVarCommon();
unsigned offset = varNode->GetLclOffs();
Expand Down Expand Up @@ -3688,10 +3688,19 @@ void emitter::emitInsRMW(instruction ins, emitAttr attr, GenTreeStoreInd* storeI
break;
}

id = emitNewInstrAmdCns(attr, offset, iconVal);
emitHandleMemOp(storeInd, id, IF_ARW_CNS, ins);
id->idIns(ins);
sz = emitInsSizeAM(id, insCodeMI(ins), iconVal);
if (addr->isContained() && addr->OperIsLocalAddr())
{
GenTreeLclVarCommon* lclVar = addr->AsLclVarCommon();
emitIns_S_I(ins, attr, lclVar->GetLclNum(), lclVar->GetLclOffs(), iconVal);
return;
}
else
{
id = emitNewInstrAmdCns(attr, offset, iconVal);
emitHandleMemOp(storeInd, id, IF_ARW_CNS, ins);
id->idIns(ins);
sz = emitInsSizeAM(id, insCodeMI(ins), iconVal);
}
}
else
{
Expand Down Expand Up @@ -3745,6 +3754,13 @@ void emitter::emitInsRMW(instruction ins, emitAttr attr, GenTreeStoreInd* storeI
offset = storeInd->Offset();
}

if (addr->isContained() && addr->OperIsLocalAddr())
{
GenTreeLclVarCommon* lclVar = addr->AsLclVarCommon();
emitIns_S(ins, attr, lclVar->GetLclNum(), lclVar->GetLclOffs());
return;
}

instrDesc* id = emitNewInstrAmd(attr, offset);
emitHandleMemOp(storeInd, id, IF_ARW, ins);
id->idIns(ins);
Expand Down
66 changes: 66 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_41073/Runtime_41073.il
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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
{
}

.assembly extern System.Runtime.CompilerServices.Unsafe
{
}

.assembly extern System.Console
{
}

.assembly Runtime_41073
{
}

.class private auto ansi beforefieldinit Runtime_41073
extends [System.Runtime]System.Object
{
.method private hidebysig static float32
PassNullByref(float32 f) cil managed noinlining
{
// Code size 20 (0x14)
.maxstack 8
IL_0000: ldarga.s f
IL_0007: ldarga.s f
IL_000e: ldind.i8
IL_000f: ldc.i8 123
IL_0010: add
IL_0011: stind.i8
IL_0012: ldarg.0
IL_0013: ret
} // end of method Runtime_41073::PassNullByref

.method public hidebysig static int32 Main() cil managed
{
.entrypoint
// Code size 27 (0x1b)
.maxstack 1
.locals init (float32 V_0)
IL_0000: ldc.r4 0.0
IL_0005: call float32 Runtime_41073::PassNullByref(float32)
IL_000a: stloc.0
IL_000b: ldloca.s V_0
IL_000d: call !!1& [System.Runtime.CompilerServices.Unsafe]System.Runtime.CompilerServices.Unsafe::As<float32,int32>(!!0&)
IL_0012: ldind.i4
IL_0013: call void [System.Console]System.Console::WriteLine(int32)
IL_0018: ldc.i4.s 100
IL_001a: ret
} // end of method Runtime_41073::Main

.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: ret
} // end of method Runtime_41073::.ctor

} // end of class Runtime_41073
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.IL">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).il" />
</ItemGroup>
</Project>