Skip to content

Commit

Permalink
[release/9.0] Fix Issue #105820 (#106656)
Browse files Browse the repository at this point in the history
* Check for writing sign flag for skipping test condition in compare to zero

* Only skip test instruction in case Writes_PF, Writes ZF, WritesSF, ResetsCF and ResetsOF are true

---------

Co-authored-by: Khushal Modi <[email protected]>
Co-authored-by: Jeff Schwartz <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2024
1 parent 84e8aa4 commit a80d1c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,22 @@ bool emitter::DoesWriteZeroFlag(instruction ins)
return (flags & Writes_ZF) != 0;
}

//------------------------------------------------------------------------
// DoesWriteParityFlag: check if the instruction write the
// PF flag.
//
// Arguments:
// ins - instruction to test
//
// Return Value:
// true if instruction writes the PF flag, false otherwise.
//
bool emitter::DoesWriteParityFlag(instruction ins)
{
insFlags flags = CodeGenInterface::instInfo[ins];
return (flags & Writes_PF) != 0;
}

//------------------------------------------------------------------------
// DoesWriteSignFlag: check if the instruction writes the
// SF flag.
Expand Down Expand Up @@ -979,7 +995,8 @@ bool emitter::AreFlagsSetToZeroCmp(regNumber reg, emitAttr opSize, GenCondition
// Certain instruction like and, or and xor modifies exactly same flags
// as "test" instruction.
// They reset OF and CF to 0 and modifies SF, ZF and PF.
if (DoesResetOverflowAndCarryFlags(lastIns))
if (DoesResetOverflowAndCarryFlags(lastIns) && DoesWriteSignFlag(lastIns) && DoesWriteZeroFlag(lastIns) &&
DoesWriteParityFlag(lastIns))
{
return id->idOpSize() == opSize;
}
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/emitxarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ bool IsThreeOperandAVXInstruction(instruction ins) const;
static bool HasRegularWideForm(instruction ins);
static bool HasRegularWideImmediateForm(instruction ins);
static bool DoesWriteZeroFlag(instruction ins);
static bool DoesWriteParityFlag(instruction ins);
static bool DoesWriteSignFlag(instruction ins);
static bool DoesResetOverflowAndCarryFlags(instruction ins);
bool IsFlagsAlwaysModified(instrDesc* id);
Expand Down

0 comments on commit a80d1c1

Please sign in to comment.