Skip to content

Commit

Permalink
Diagnostic change only, to confirm whether a theory is correct or
Browse files Browse the repository at this point in the history
not when chasing an error.
  • Loading branch information
AndyJGraham committed Dec 9, 2022
1 parent ed4d070 commit 4b0e51e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
15 changes: 14 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9122,11 +9122,22 @@ void emitter::emitNxtIG(bool extend)
// NOTE: It is expected that the GC effect of the removed instruction will be handled by the newly
// generated replacement(s).
//
void emitter::emitRemoveLastInstruction()
bool emitter::emitRemoveLastInstruction()
{
assert(emitLastIns != nullptr);
assert(emitLastInsIG != nullptr);

#ifdef TARGET_ARM64
// AJG - This is a temporary change, to prevent the first
// instruction in a group to be optimised away.
// This is for diagnostic and test purposes only.

if (emitCurIGinsCnt == 1)
{
return false;
}
#endif

JITDUMP("Removing saved instruction in %s:\n> ", emitLabelString(emitLastInsIG));
JITDUMPEXEC(dispIns(emitLastIns))

Expand Down Expand Up @@ -9175,6 +9186,8 @@ void emitter::emitRemoveLastInstruction()

emitLastIns = nullptr;
emitLastInsIG = nullptr;

return true;
}

/*****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ class emitter
insGroup* emitSavIG(bool emitAdd = false);
void emitNxtIG(bool extend = false);

void emitRemoveLastInstruction();
bool emitRemoveLastInstruction();

bool emitCurIGnonEmpty()
{
Expand Down
40 changes: 24 additions & 16 deletions src/coreclr/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16219,24 +16219,32 @@ bool emitter::TryReplaceLdrStrWithPairInstr(
}

// Remove the last instruction written.
emitRemoveLastInstruction();

// We need to scale the immediate value by the operand size.
// This is either the "old" immediate (for ascending) or the
// "current" immediate (for descending) register order.
if (optimizationOrder == eRO_ascending)
{
// The FIRST register is at the lower offset
emitIns_R_R_R_I(optIns, oldReg1Attr, oldReg1, reg1, reg2, oldImm * size, INS_OPTS_NONE, reg1Attr);
}
else
// This has been temporarily changed to allow the function
// to "refuse" to remove an instruction for diagnostic purposes only.
if (emitRemoveLastInstruction())
{
// The SECOND register is at the lower offset
emitIns_R_R_R_I(optIns, reg1Attr, reg1, oldReg1, reg2, imm * size, INS_OPTS_NONE, oldReg1Attr);
}
// The above function can refuse to remove an emitted
// instruction, for diagnostic purposes only.

// And now return true, to indicate that the second instruction descriptor is no longer to be emitted.
return true;
// It HAS removed an instruction this time.

// We need to scale the immediate value by the operand size.
// This is either the "old" immediate (for ascending) or the
// "current" immediate (for descending) register order.
if (optimizationOrder == eRO_ascending)
{
// The FIRST register is at the lower offset
emitIns_R_R_R_I(optIns, oldReg1Attr, oldReg1, reg1, reg2, oldImm * size, INS_OPTS_NONE, reg1Attr);
}
else
{
// The SECOND register is at the lower offset
emitIns_R_R_R_I(optIns, reg1Attr, reg1, oldReg1, reg2, imm * size, INS_OPTS_NONE, oldReg1Attr);
}

// And now return true, to indicate that the second instruction descriptor is no longer to be emitted.
return true;
}
}

return false;
Expand Down

0 comments on commit 4b0e51e

Please sign in to comment.