Skip to content

Commit 666bb9d

Browse files
authored
Relax unrolling for structs with gc refs (#112227)
1 parent 86dbcbd commit 666bb9d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/coreclr/jit/lowerxarch.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,15 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode)
443443

444444
ClassLayout* layout = blkNode->GetLayout();
445445
bool doCpObj = layout->HasGCPtr();
446-
unsigned copyBlockUnrollLimit = comp->getUnrollThreshold(Compiler::UnrollKind::Memcpy, false);
446+
bool isNotHeap = blkNode->IsAddressNotOnHeap(comp);
447+
bool canUseSimd = !doCpObj || isNotHeap;
448+
unsigned copyBlockUnrollLimit = comp->getUnrollThreshold(Compiler::UnrollKind::Memcpy, canUseSimd);
447449

448450
#ifndef JIT32_GCENCODER
449451
if (doCpObj && (size <= copyBlockUnrollLimit))
450452
{
451-
// No write barriers are needed on the stack.
452-
// If the layout is byref-like, then we know it must live on the stack.
453-
if (blkNode->IsAddressNotOnHeap(comp))
453+
// No write barriers are needed if the destination is known to be outside of the GC heap.
454+
if (isNotHeap)
454455
{
455456
// If the size is small enough to unroll then we need to mark the block as non-interruptible
456457
// to actually allow unrolling. The generated code does not report GC references loaded in the
@@ -515,7 +516,7 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode)
515516
}
516517
}
517518
else if (blkNode->OperIs(GT_STORE_BLK) &&
518-
(size <= comp->getUnrollThreshold(Compiler::UnrollKind::Memcpy, !layout->HasGCPtr())))
519+
(size <= comp->getUnrollThreshold(Compiler::UnrollKind::Memcpy, canUseSimd)))
519520
{
520521
blkNode->gtBlkOpKind = GenTreeBlk::BlkOpKindUnroll;
521522

0 commit comments

Comments
 (0)