Skip to content

Commit

Permalink
Perform ldr to ldp peephole optimization (#84399)
Browse files Browse the repository at this point in the history
* Perform ldr to ldp peephole optimization

* jit format

* handle non-gc str cases

* Add the comment
  • Loading branch information
kunalspathak authored Apr 8, 2023
1 parent 6ca0784 commit 0fc78e6
Showing 1 changed file with 16 additions and 4 deletions.
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

0 comments on commit 0fc78e6

Please sign in to comment.