-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XARCH: Remove redudant tests for GT_LT/GT_GE relops. #61152
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,21 @@ bool emitter::DoesWriteZeroFlag(instruction ins) | |
return (CodeGenInterface::instInfo[ins] & Writes_ZF) != 0; | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
// DoesWriteSignFlag: check if the instruction writes the | ||
// SF flag. | ||
// | ||
// Arguments: | ||
// ins - instruction to test | ||
// | ||
// Return Value: | ||
// true if instruction writes the SF flag, false otherwise. | ||
// | ||
bool emitter::DoesWriteSignFlag(instruction ins) | ||
{ | ||
return (CodeGenInterface::instInfo[ins] & Writes_SF) != 0; | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
// DoesResetOverflowAndCarryFlags: check if the instruction resets the | ||
// OF and CF flag to 0. | ||
|
@@ -338,6 +353,11 @@ bool emitter::AreFlagsSetToZeroCmp(regNumber reg, emitAttr opSize, genTreeOps tr | |
{ | ||
assert(reg != REG_NA); | ||
|
||
if (!emitComp->opts.OptimizationEnabled()) | ||
{ | ||
return false; | ||
} | ||
|
||
// Don't look back across IG boundaries (possible control flow) | ||
if (emitCurIGinsCnt == 0 && ((emitCurIG->igFlags & IGF_EXTEND) == 0)) | ||
{ | ||
|
@@ -393,6 +413,79 @@ bool emitter::AreFlagsSetToZeroCmp(regNumber reg, emitAttr opSize, genTreeOps tr | |
return false; | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
// AreFlagsSetToForSignJumpOpt: checks if the previous instruction set the SF if the tree | ||
// node qualifies for a jg/jle to jns/js optimization | ||
// | ||
// Arguments: | ||
// reg - register of interest | ||
// opSize - size of register | ||
// relop - relational tree node | ||
// | ||
// Return Value: | ||
// true if the tree node qualifies for the jg/jle to jns/js optimization | ||
// false if not, or if we can't safely determine | ||
// | ||
// Notes: | ||
// Currently only looks back one instruction. | ||
bool emitter::AreFlagsSetForSignJumpOpt(regNumber reg, emitAttr opSize, GenTree* relop) | ||
{ | ||
assert(reg != REG_NA); | ||
|
||
if (!emitComp->opts.OptimizationEnabled()) | ||
{ | ||
return false; | ||
} | ||
|
||
// Don't look back across IG boundaries (possible control flow) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a check like if (!emitComp->opts.OptimizationEnabled())
{
return false;
} (or else assert we're optimizing) I realize this is also guaranteed by the way the current caller sets (and add similar to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in both spots. Thanks! |
||
if (emitCurIGinsCnt == 0 && ((emitCurIG->igFlags & IGF_EXTEND) == 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am ok to have a follow-up PR as Andy pointed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I can do this with a follow-up PR. Happy to help. |
||
{ | ||
return false; | ||
} | ||
|
||
instrDesc* id = emitLastIns; | ||
instruction lastIns = id->idIns(); | ||
insFormat fmt = id->idInsFmt(); | ||
|
||
// make sure op1 is a reg | ||
switch (fmt) | ||
{ | ||
case IF_RWR_CNS: | ||
case IF_RRW_CNS: | ||
case IF_RRW_SHF: | ||
case IF_RWR_RRD: | ||
case IF_RRW_RRD: | ||
case IF_RWR_MRD: | ||
case IF_RWR_SRD: | ||
case IF_RRW_SRD: | ||
case IF_RWR_ARD: | ||
case IF_RRW_ARD: | ||
case IF_RWR: | ||
case IF_RRD: | ||
case IF_RRW: | ||
break; | ||
default: | ||
return false; | ||
} | ||
|
||
if (id->idReg1() != reg) | ||
{ | ||
return false; | ||
} | ||
Comment on lines
+448
to
+474
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should think about extracting things that are common as helper methods. But maybe do this as a zero-diff follow up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, happy to do a follow up refactor. |
||
|
||
// If we have a GT_GE/GT_LT which generates an jge/jl, and the previous instruction | ||
// sets the SF, we can omit a test instruction and check for jns/js. | ||
if ((relop->OperGet() == GT_GE || relop->OperGet() == GT_LT) && !GenCondition::FromRelop(relop).IsUnsigned()) | ||
{ | ||
if (DoesWriteSignFlag(lastIns) && IsFlagsAlwaysModified(id)) | ||
{ | ||
return id->idOpSize() == opSize; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
// IsDstSrcImmAvxInstruction: Checks if the instruction has a "reg, reg/mem, imm" or | ||
// "reg/mem, reg, imm" form for the legacy, VEX, and EVEX | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you either always clear this new flag up above before the
if
on line 6231, or assert there that it's not set?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the assertion next to the other ones. Please let me know if the comment needs to change or if its good enough.