-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Extend the "skip-test" optimization to all instructions that modify the #120876
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -758,19 +758,29 @@ bool emitter::DoesWriteSignFlag(instruction ins) | |
| } | ||
|
|
||
| //------------------------------------------------------------------------ | ||
| // DoesResetOverflowAndCarryFlags: check if the instruction resets the | ||
| // OF and CF flag to 0. | ||
| // DoesModifySameFlagsAsTESTInst: check if the instruction modifies | ||
| // the same flags as a "TEST" instruction, which allows some optims | ||
| // | ||
| // Arguments: | ||
| // ins - instruction to test | ||
| // | ||
| // Return Value: | ||
| // true if instruction resets the OF and CF flag, false otherwise. | ||
| // true if instruction modifies the same flags as "TEST" instruction | ||
| // | ||
| bool emitter::DoesResetOverflowAndCarryFlags(instruction ins) | ||
| // Note: | ||
| // "TEST" instruction: | ||
| // - Resets OF and CF flags to zero | ||
| // - Sets SF, ZF, PF flags from the result | ||
| // - Leaves AF undefined | ||
|
Author
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. Unsure here whether it makes sense to add a condition on |
||
| // | ||
| bool emitter::DoesModifySameFlagsAsTESTInst(instruction ins) | ||
| { | ||
| insFlags flags = CodeGenInterface::instInfo[ins]; | ||
| return (flags & (Resets_OF | Resets_CF)) == (Resets_OF | Resets_CF); | ||
| return (flags & (Resets_OF | Writes_OF)) != 0 && | ||
| (flags & (Resets_CF | Writes_CF)) != 0 && | ||
| (flags & (Resets_SF | Writes_SF)) != 0 && | ||
| (flags & (Resets_ZF | Writes_ZF)) != 0 && | ||
| (flags & (Resets_PF | Writes_PF)) != 0; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------ | ||
|
|
@@ -1457,9 +1467,7 @@ 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) && DoesWriteSignFlag(lastIns) && DoesWriteZeroFlag(lastIns) && | ||
| DoesWriteParityFlag(lastIns)) | ||
| if (DoesModifySameFlagsAsTESTInst(lastIns)) | ||
|
Member
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. This previously checked specifically that the OF and CF were reset but now it's sufficient to write them instead of reset them, which means they might be nonzero. But this method is named
Author
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. Not too sure what you expect here or how I could improve the code to make it more readable. Perhaps renaming
Member
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 old code was |
||
| { | ||
| return id->idOpSize() == opSize; | ||
| } | ||
|
|
||
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 we provide more detail on what it allows, if it's not too verbose?
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.
Hi @kg thans for the review, very appreciated 🙂
Yes sure I can add more info and point out that this allows to potentially skip a test instruction.