Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fc78e6

Browse files
authored
Perform ldr to ldp peephole optimization (#84399)
* Perform ldr to ldp peephole optimization * jit format * handle non-gc str cases * Add the comment
1 parent 6ca0784 commit 0fc78e6

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/coreclr/jit/emitarm64.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ inline bool OptimizeLdrStr(instruction ins,
146146
{
147147
assert(ins == INS_ldr || ins == INS_str);
148148

149-
if (!emitCanPeepholeLastIns())
149+
if (!emitCanPeepholeLastIns() || (emitLastIns->idIns() != ins))
150150
{
151151
return false;
152152
}
@@ -161,9 +161,21 @@ inline bool OptimizeLdrStr(instruction ins,
161161
reg2 = encodingZRtoSP(reg2);
162162

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

0 commit comments

Comments
 (0)