Skip to content
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

ARM64: Use stlur for volatile stores #91553

Merged
merged 8 commits into from
Sep 8, 2023
Merged
Changes from 3 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
61 changes: 45 additions & 16 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4209,26 +4209,55 @@ void CodeGen::genCodeForStoreInd(GenTreeStoreInd* tree)
{
bool addrIsInReg = addr->isUsedFromReg();
bool addrIsAligned = ((tree->gtFlags & GTF_IND_UNALIGNED) == 0);
bool handledByRcpc = false;

if ((ins == INS_strb) && addrIsInReg)
// On arm64-v8.4+ we can use stlur* instructions with acquire/release semantics
// if the address is LEA with just imm offset (unscaled)
if (compiler->compOpportunisticallyDependsOn(InstructionSet_Rcpc2) && addrIsAligned &&
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
(tree->Addr()->OperIs(GT_LEA) && !tree->HasIndex() && (tree->Scale() == 1) &&
emitter::emitIns_valid_imm_for_unscaled_ldst_offset(tree->Offset())))
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
{
ins = INS_stlrb;
}
else if ((ins == INS_strh) && addrIsInReg && addrIsAligned)
{
ins = INS_stlrh;
}
else if ((ins == INS_str) && genIsValidIntReg(dataReg) && addrIsInReg && addrIsAligned)
{
ins = INS_stlr;
if (ins == INS_strb)
{
ins = INS_stlurb;
handledByRcpc = true;
}
else if (ins == INS_strh)
{
ins = INS_stlurh;
handledByRcpc = true;
}
else if ((ins == INS_str) && genIsValidIntReg(dataReg))
{
ins = INS_stlur;
handledByRcpc = true;
}
}
else

// If the address is in a register we can use the baseline stlr*
// Otherwise, a full memory barrier.
if (!handledByRcpc)
{
// issue a full memory barrier before a volatile StInd
// Note: We cannot issue store barrier ishst because it is a weaker barrier.
// The loads can get rearranged around the barrier causing to read wrong
// value.
instGen_MemoryBarrier();
if ((ins == INS_strb) && addrIsInReg)
{
ins = INS_stlrb;
}
else if ((ins == INS_strh) && addrIsInReg && addrIsAligned)
{
ins = INS_stlrh;
}
else if ((ins == INS_str) && genIsValidIntReg(dataReg) && addrIsInReg && addrIsAligned)
{
ins = INS_stlr;
}
else
{
// issue a full memory barrier before a volatile StInd
// Note: We cannot issue store barrier ishst because it is a weaker barrier.
// The loads can get rearranged around the barrier causing to read wrong
// value.
instGen_MemoryBarrier();
}
}
}

Expand Down