Skip to content

Convert STORE_BLK into STORIND for SIMD #116265

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 6 commits into from
Jun 5, 2025
Merged
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
53 changes: 28 additions & 25 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11123,11 +11123,6 @@ void Lowering::LowerBlockStoreCommon(GenTreeBlk* blkNode)
// Return value:
// true if the replacement was made, false otherwise.
//
// Notes:
// TODO-CQ: this method should do the transformation when possible
// and STOREIND should always generate better or the same code as
// STORE_BLK for the same copy.
//
bool Lowering::TryTransformStoreObjAsStoreInd(GenTreeBlk* blkNode)
{
assert(blkNode->OperIs(GT_STORE_BLK));
Expand All @@ -11143,12 +11138,6 @@ bool Lowering::TryTransformStoreObjAsStoreInd(GenTreeBlk* blkNode)
}

GenTree* src = blkNode->Data();
if (varTypeIsSIMD(regType) && src->IsConstInitVal())
{
// TODO-CQ: support STORE_IND SIMD16(SIMD16, CNT_INT 0).
return false;
}

if (varTypeIsGC(regType))
{
// TODO-CQ: STOREIND does not try to contain src if we need a barrier,
Expand All @@ -11161,29 +11150,43 @@ bool Lowering::TryTransformStoreObjAsStoreInd(GenTreeBlk* blkNode)
return false;
}

JITDUMP("Replacing STORE_BLK with STOREIND for [%06u]\n", blkNode->gtTreeID);
blkNode->ChangeOper(GT_STOREIND);
blkNode->ChangeType(regType);
if (src->IsConstInitVal())
{
#if !defined(TARGET_XARCH)
if (varTypeIsSIMD(regType))
{
// Platforms with zero-regs may produce better/more compact codegen
return false;
}
#endif

assert(!blkNode->ContainsReferences());
if (src->OperIsInitVal())
{
BlockRange().Remove(src);
src = src->gtGetOp1();
}

if (varTypeIsStruct(src))
uint8_t initVal = static_cast<uint8_t>(src->AsIntCon()->IconValue());
GenTree* cnsVec = comp->gtNewConWithPattern(regType, initVal);
BlockRange().InsertAfter(src, cnsVec);
BlockRange().Remove(src);
blkNode->SetData(cnsVec);
}
else if (varTypeIsStruct(src))
{
src->ChangeType(regType);
LowerNode(blkNode->Data());
}
else if (src->OperIsInitVal())
{
GenTreeUnOp* initVal = src->AsUnOp();
src = src->gtGetOp1();
assert(src->IsCnsIntOrI());
src->AsIntCon()->FixupInitBlkValue(regType);
blkNode->SetData(src);
BlockRange().Remove(initVal);
}
else
{
assert(src->TypeIs(regType) || src->IsCnsIntOrI() || src->IsCall());
unreached();
}

JITDUMP("Replacing STORE_BLK with STOREIND for [%06u]\n", blkNode->gtTreeID);
blkNode->ChangeOper(GT_STOREIND);
blkNode->ChangeType(regType);

#if defined(TARGET_XARCH)
if (varTypeIsSmall(regType) && src->OperIs(GT_IND, GT_LCL_FLD))
{
Expand Down
Loading