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
32 changes: 22 additions & 10 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8950,22 +8950,34 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Memcpy // Copying memory from src to dst
};

unsigned int getUnrollThreshold(UnrollKind type)
unsigned int getUnrollThreshold(UnrollKind type, bool canUseSimd = true)
{
unsigned threshold = TARGET_POINTER_SIZE;

#if defined(FEATURE_SIMD)
threshold = maxSIMDStructBytes();
if (canUseSimd)
{
threshold = maxSIMDStructBytes();
#if defined(TARGET_ARM64)
// ldp/stp instructions can load/store two 16-byte vectors at once, e.g.:
//
// ldp q0, q1, [x1]
// stp q0, q1, [x0]
//
threshold *= 2;
// ldp/stp instructions can load/store two 16-byte vectors at once, e.g.:
//
// ldp q0, q1, [x1]
// stp q0, q1, [x0]
//
threshold *= 2;
#elif defined(TARGET_XARCH)
// Ignore AVX-512 for now
threshold = max(threshold, YMM_REGSIZE_BYTES);
// Ignore AVX-512 for now
threshold = max(threshold, YMM_REGSIZE_BYTES);
#endif
}
#if defined(TARGET_XARCH)
else
{
// Compatibility with previous logic: we used to allow memset:128/memcpy:64
// on AMD64 (and 64/32 on x86) for cases where we don't use SIMD
// see https://github.com/dotnet/runtime/issues/83297
threshold *= 2;
}
#endif
#endif

Expand Down
13 changes: 10 additions & 3 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode)
}
else
{
blkNode->gtBlkOpKind = GenTreeBlk::BlkOpKindUnroll;

// The fill value of an initblk is interpreted to hold a
// value of (unsigned int8) however a constant of any size
Expand All @@ -357,6 +356,10 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode)
{
src->SetContained();
}
else if (size > comp->getUnrollThreshold(Compiler::UnrollKind::Memset, /*canUseSimd*/ false))
{
goto TOO_BIG_TO_UNROLL;
}
}
}
#ifdef TARGET_AMD64
Expand All @@ -371,13 +374,15 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode)
fill *= 0x01010101;
}

blkNode->gtBlkOpKind = GenTreeBlk::BlkOpKindUnroll;
src->AsIntCon()->SetIconValue(fill);

ContainBlockStoreAddress(blkNode, size, dstAddr, nullptr);
}
}
else
{
TOO_BIG_TO_UNROLL:
#ifdef TARGET_AMD64
blkNode->gtBlkOpKind = GenTreeBlk::BlkOpKindHelper;
#else
Expand Down Expand Up @@ -412,7 +417,8 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode)
blkNode->SetOper(GT_STORE_BLK);
}
#ifndef JIT32_GCENCODER
else if (dstAddr->OperIsLocalAddr() && (size <= comp->getUnrollThreshold(Compiler::UnrollKind::Memcpy)))
else if (dstAddr->OperIsLocalAddr() &&
(size <= comp->getUnrollThreshold(Compiler::UnrollKind::Memcpy, false)))
{
// If the size is small enough to unroll then we need to mark the block as non-interruptible
// to actually allow unrolling. The generated code does not report GC references loaded in the
Expand Down Expand Up @@ -472,7 +478,8 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode)
blkNode->gtBlkOpKind = GenTreeBlk::BlkOpKindUnroll;
}
}
else if (blkNode->OperIs(GT_STORE_BLK) && (size <= comp->getUnrollThreshold(Compiler::UnrollKind::Memcpy)))
else if (blkNode->OperIs(GT_STORE_BLK) &&
(size <= comp->getUnrollThreshold(Compiler::UnrollKind::Memcpy, !blkNode->GetLayout()->HasGCPtr())))
{
blkNode->gtBlkOpKind = GenTreeBlk::BlkOpKindUnroll;

Expand Down