@@ -146,7 +146,7 @@ inline bool OptimizeLdrStr(instruction ins,
146
146
{
147
147
assert (ins == INS_ldr || ins == INS_str);
148
148
149
- if (!emitCanPeepholeLastIns ())
149
+ if (!emitCanPeepholeLastIns () || (emitLastIns-> idIns () != ins) )
150
150
{
151
151
return false ;
152
152
}
@@ -161,9 +161,21 @@ inline bool OptimizeLdrStr(instruction ins,
161
161
reg2 = encodingZRtoSP (reg2);
162
162
163
163
// 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))
167
179
{
168
180
return true ;
169
181
}
0 commit comments