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

Perform ldr to ldp peephole optimization #84399

Merged
merged 5 commits into from
Apr 8, 2023
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
20 changes: 16 additions & 4 deletions src/coreclr/jit/emitarm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ inline bool OptimizeLdrStr(instruction ins,
{
assert(ins == INS_ldr || ins == INS_str);

if (!emitCanPeepholeLastIns())
if (!emitCanPeepholeLastIns() || (emitLastIns->idIns() != ins))
{
return false;
}
Expand All @@ -161,9 +161,21 @@ inline bool OptimizeLdrStr(instruction ins,
reg2 = encodingZRtoSP(reg2);

// If the previous instruction was a matching load/store, then try to replace it instead of emitting.
// Don't do this if either instruction had a local variable.
if ((emitLastIns->idIns() == ins) && !localVar && !emitLastIns->idIsLclVar() &&
ReplaceLdrStrWithPairInstr(ins, reg1Attr, reg1, reg2, imm, size, fmt))
//
bool canReplaceWithPair = true;
if (ins == INS_str)
{
// For INS_str, don't do this if either instruction had a local GC variable.
// For INS_ldr, it is fine to perform this optimization because the output code already handles the code of
// updating the gc refs. We do not need offset tracking for load cases.
if ((localVar && EA_IS_GCREF_OR_BYREF(reg1Attr)) ||
(emitLastIns->idIsLclVar() && (emitLastIns->idGCref() != GCT_NONE)))
{
canReplaceWithPair = false;
}
}

if (canReplaceWithPair && ReplaceLdrStrWithPairInstr(ins, reg1Attr, reg1, reg2, imm, size, fmt))
{
return true;
}
Expand Down