Skip to content

Commit 7f24e1b

Browse files
committed
Move to lower
1 parent aab8803 commit 7f24e1b

File tree

19 files changed

+127
-26
lines changed

19 files changed

+127
-26
lines changed

src/coreclr/inc/jiteeversionguid.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
4343
#define GUID_DEFINED
4444
#endif // !GUID_DEFINED
4545

46-
constexpr GUID JITEEVersionIdentifier = { /* 32d71f8e-c1f5-41cb-88cc-4e8504cabf40 */
47-
0x32d71f8e,
48-
0xc1f5,
49-
0x41cb,
50-
{0x88, 0xcc, 0x4e, 0x85, 0x04, 0xca, 0xbf, 0x40}
46+
constexpr GUID JITEEVersionIdentifier = { /* bd8c41d4-8531-49c1-a600-0ae9bfe05de1 */
47+
0xbd8c41d4,
48+
0x8531,
49+
0x49c1,
50+
{0xa6, 0x00, 0x0a, 0xe9, 0xbf, 0xe0, 0x5d, 0xe1}
5151
};
5252

5353
//////////////////////////////////////////////////////////////////////////////////////////////////////////

src/coreclr/inc/jithelpers.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@
153153
JITHELPER(CORINFO_HELP_ASSIGN_REF_ENSURE_NONHEAP, JIT_WriteBarrierEnsureNonHeapTarget,CORINFO_HELP_SIG_REG_ONLY)
154154

155155
DYNAMICJITHELPER(CORINFO_HELP_ASSIGN_BYREF, JIT_ByRefWriteBarrier,CORINFO_HELP_SIG_NO_ALIGN_STUB)
156-
157-
JITHELPER(CORINFO_HELP_ASSIGN_STRUCT, JIT_StructWriteBarrier,CORINFO_HELP_SIG_4_STACK)
156+
DYNAMICJITHELPER(CORINFO_HELP_ASSIGN_STRUCT, NULL, CORINFO_HELP_SIG_REG_ONLY)
158157

159158
// Accessing fields
160159
JITHELPER(CORINFO_HELP_GETFIELD8, JIT_GetField8,CORINFO_HELP_SIG_REG_ONLY)

src/coreclr/inc/readytorun.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// If you update this, ensure you run `git grep MINIMUM_READYTORUN_MAJOR_VERSION`
2121
// and handle pending work.
2222
#define READYTORUN_MAJOR_VERSION 0x0009
23-
#define READYTORUN_MINOR_VERSION 0x0002
23+
#define READYTORUN_MINOR_VERSION 0x0003
2424

2525
#define MINIMUM_READYTORUN_MAJOR_VERSION 0x009
2626

@@ -34,6 +34,7 @@
3434
// R2R Version 9.0 adds support for the Vector512 type
3535
// R2R Version 9.1 adds new helpers to allocate objects on frozen segments
3636
// R2R Version 9.2 adds MemZero and NativeMemSet helpers
37+
// R2R Version 9.3 adds AssignStruct helper
3738

3839

3940
struct READYTORUN_CORE_HEADER
@@ -321,6 +322,7 @@ enum ReadyToRunHelper
321322
READYTORUN_HELPER_WriteBarrier = 0x30,
322323
READYTORUN_HELPER_CheckedWriteBarrier = 0x31,
323324
READYTORUN_HELPER_ByRefWriteBarrier = 0x32,
325+
READYTORUN_HELPER_AssignStruct = 0x33,
324326

325327
// Array helpers
326328
READYTORUN_HELPER_Stelem_Ref = 0x38,

src/coreclr/inc/readytorunhelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ HELPER(READYTORUN_HELPER_ThrowDivZero, CORINFO_HELP_THROWDIVZERO,
2424
HELPER(READYTORUN_HELPER_WriteBarrier, CORINFO_HELP_ASSIGN_REF, )
2525
HELPER(READYTORUN_HELPER_CheckedWriteBarrier, CORINFO_HELP_CHECKED_ASSIGN_REF, )
2626
HELPER(READYTORUN_HELPER_ByRefWriteBarrier, CORINFO_HELP_ASSIGN_BYREF, )
27+
HELPER(READYTORUN_HELPER_AssignStruct, CORINFO_HELP_ASSIGN_STRUCT, )
2728

2829
HELPER(READYTORUN_HELPER_Stelem_Ref, CORINFO_HELP_ARRADDR_ST, )
2930
HELPER(READYTORUN_HELPER_Ldelema_Ref, CORINFO_HELP_LDELEMA_REF, )

src/coreclr/jit/compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7803,6 +7803,7 @@ class Compiler
78037803
GenTree* optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, GenTree* tree);
78047804
GenTree* optVNBasedFoldExpr(BasicBlock* block, GenTree* parent, GenTree* tree);
78057805
GenTree* optVNBasedFoldExpr_Call(BasicBlock* block, GenTree* parent, GenTreeCall* call);
7806+
GenTree* optVNBasedFoldExpr_Blk(BasicBlock* block, GenTree* parent, GenTreeBlk* blk);
78067807
GenTree* optExtractSideEffListFromConst(GenTree* tree);
78077808

78087809
AssertionIndex GetAssertionCount()

src/coreclr/jit/lower.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8212,6 +8212,91 @@ void Lowering::ContainCheckBitCast(GenTree* node)
82128212
}
82138213
}
82148214

8215+
bool Lowering::TryLowerBlockStoreAsGcBulkCopyCall(GenTreeBlk* blk)
8216+
{
8217+
if (comp->opts.OptimizationDisabled() || !ISMETHOD("Test"))
8218+
{
8219+
return false;
8220+
}
8221+
8222+
// Replace STORE_BLK (struct copy) with CORINFO_HELP_ASSIGN_STRUCT which performs
8223+
// bulk copy for byrefs.
8224+
const unsigned bulkCopyThreshold = 4;
8225+
if (blk->OperIs(GT_STORE_BLK) && !blk->OperIsInitBlkOp() &&
8226+
(blk->GetLayout()->GetGCPtrCount() >= bulkCopyThreshold))
8227+
{
8228+
GenTree* addr = blk->Addr();
8229+
GenTree* data = blk->Data();
8230+
8231+
const unsigned gcPtrs = blk->GetLayout()->GetGCPtrCount();
8232+
if (!CheckedOps::MulOverflows((int)gcPtrs, TARGET_POINTER_SIZE, true))
8233+
{
8234+
if (data->OperIs(GT_IND))
8235+
{
8236+
// Drop GT_IND nodes
8237+
BlockRange().Remove(data);
8238+
data = data->AsIndir()->Addr();
8239+
}
8240+
else
8241+
{
8242+
assert(data->OperIs(GT_LCL_VAR, GT_LCL_FLD));
8243+
8244+
// Convert local to LCL_ADDR
8245+
unsigned lclOffset = data->AsLclVarCommon()->GetLclOffs();
8246+
data->ChangeOper(GT_LCL_ADDR);
8247+
data->ChangeType(TYP_I_IMPL);
8248+
data->AsLclFld()->SetLclOffs(lclOffset);
8249+
data->ClearContained();
8250+
}
8251+
8252+
// Size is a constant
8253+
GenTreeIntCon* size = comp->gtNewIconNode((ssize_t)gcPtrs * TARGET_POINTER_SIZE, TYP_I_IMPL);
8254+
BlockRange().InsertBefore(data, size);
8255+
8256+
// A hacky way to safely call fgMorphTree in Lower
8257+
GenTree* destPlaceholder = comp->gtNewZeroConNode(addr->TypeGet());
8258+
GenTree* dataPlaceholder = comp->gtNewZeroConNode(genActualType(data));
8259+
GenTree* sizePlaceholder = comp->gtNewZeroConNode(genActualType(size));
8260+
8261+
GenTreeCall* call = comp->gtNewHelperCallNode(CORINFO_HELP_ASSIGN_STRUCT, TYP_VOID, destPlaceholder, dataPlaceholder, sizePlaceholder);
8262+
comp->fgMorphArgs(call);
8263+
8264+
LIR::Range range = LIR::SeqTree(comp, call);
8265+
GenTree* rangeStart = range.FirstNode();
8266+
GenTree* rangeEnd = range.LastNode();
8267+
8268+
BlockRange().InsertBefore(blk, std::move(range));
8269+
blk->gtBashToNOP();
8270+
8271+
LIR::Use destUse;
8272+
LIR::Use sizeUse;
8273+
BlockRange().TryGetUse(destPlaceholder, &destUse);
8274+
BlockRange().TryGetUse(sizePlaceholder, &sizeUse);
8275+
destUse.ReplaceWith(addr);
8276+
sizeUse.ReplaceWith(size);
8277+
destPlaceholder->SetUnusedValue();
8278+
sizePlaceholder->SetUnusedValue();
8279+
8280+
LIR::Use dataUse;
8281+
BlockRange().TryGetUse(dataPlaceholder, &dataUse);
8282+
dataUse.ReplaceWith(data);
8283+
dataPlaceholder->SetUnusedValue();
8284+
8285+
LowerRange(rangeStart, rangeEnd);
8286+
8287+
// Finally move all GT_PUTARG_* nodes
8288+
// Re-use the existing logic for CFG call args here
8289+
MoveCFGCallArgs(call);
8290+
8291+
BlockRange().Remove(destPlaceholder);
8292+
BlockRange().Remove(sizePlaceholder);
8293+
BlockRange().Remove(dataPlaceholder);
8294+
return true;
8295+
}
8296+
}
8297+
return false;
8298+
}
8299+
82158300
//------------------------------------------------------------------------
82168301
// LowerBlockStoreAsHelperCall: Lower a block store node as a memset/memcpy call
82178302
//

src/coreclr/jit/lower.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ class Lowering final : public Phase
334334
void LowerBlockStore(GenTreeBlk* blkNode);
335335
void LowerBlockStoreCommon(GenTreeBlk* blkNode);
336336
void LowerBlockStoreAsHelperCall(GenTreeBlk* blkNode);
337+
bool TryLowerBlockStoreAsGcBulkCopyCall(GenTreeBlk* blkNode);
337338
void LowerLclHeap(GenTree* node);
338339
void ContainBlockStoreAddress(GenTreeBlk* blkNode, unsigned size, GenTree* addr, GenTree* addrParent);
339340
void LowerPutArgStkOrSplit(GenTreePutArgStk* putArgNode);

src/coreclr/jit/lowerxarch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,11 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode)
457457

458458
if (doCpObj)
459459
{
460+
if (TryLowerBlockStoreAsGcBulkCopyCall(blkNode))
461+
{
462+
return;
463+
}
464+
460465
assert((dstAddr->TypeGet() == TYP_BYREF) || (dstAddr->TypeGet() == TYP_I_IMPL));
461466

462467
// If we have a long enough sequence of slots that do not require write barriers then

src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct ReadyToRunHeaderConstants
1212
static const uint32_t Signature = 0x00525452; // 'RTR'
1313

1414
static const uint32_t CurrentMajorVersion = 9;
15-
static const uint32_t CurrentMinorVersion = 2;
15+
static const uint32_t CurrentMinorVersion = 3;
1616
};
1717

1818
struct ReadyToRunHeader

src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal struct ReadyToRunHeaderConstants
1616
public const uint Signature = 0x00525452; // 'RTR'
1717

1818
public const ushort CurrentMajorVersion = 9;
19-
public const ushort CurrentMinorVersion = 2;
19+
public const ushort CurrentMinorVersion = 3;
2020
}
2121
#if READYTORUN
2222
#pragma warning disable 0169

0 commit comments

Comments
 (0)