-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Promote 32bit pseudo instr that infer extsw removal to 64bit in PPCMIPeephole #85451
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
Changes from 15 commits
79aaf13
d4b4abc
affb9bf
75494c3
489cccc
1ece68c
56b04f5
692138b
95267f5
4482b29
8e98ab8
9b0b9c8
8550317
9a4e4d0
3798b03
34b52bb
f0cdc75
1de4b40
9ae473b
910b1b5
095acfc
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -5234,6 +5234,224 @@ bool PPCInstrInfo::isTOCSaveMI(const MachineInstr &MI) const { | |||||||
| // We limit the max depth to track incoming values of PHIs or binary ops | ||||||||
| // (e.g. AND) to avoid excessive cost. | ||||||||
| const unsigned MAX_BINOP_DEPTH = 1; | ||||||||
|
|
||||||||
| // This function will promote the instruction which defines the register `Reg` | ||||||||
| // in the parameter from a 32-bit to a 64-bit instruction if needed. The logic | ||||||||
| // used to check whether an instruction needs to be promoted or not is similar | ||||||||
| // to the logic used to check whether or not a defined register is sign or zero | ||||||||
| // extended within the function PPCInstrInfo::isSignOrZeroExtended. | ||||||||
| // Additionally, the `promoteInstr32To64ForElimEXTSW` function is recursive. | ||||||||
| // BinOpDepth does not count all of the recursions. The parameter BinOpDepth is | ||||||||
| // incremented only when `promoteInstr32To64ForElimEXTSW` calls itself more | ||||||||
|
Contributor
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. From what I can see below,
Contributor
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. Good Catch for AND8 . the logic of BinOpDepth is come from function isSignOrZeroExtended(), when the instructions(e.g., AND, PHI, OR) which has two or more source registers , the instructions which defines these source registers also need to be promoted and so on , without increase the BinOpDepth , it maybe have 2 * 2 * 2 * 2.... recursions of promoteInstr32To64ForElimEXTSW. |
||||||||
| // than once. This is done to prevent exponential recursion. | ||||||||
| void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg, | ||||||||
| MachineRegisterInfo *MRI, | ||||||||
| unsigned BinOpDepth, | ||||||||
| LiveVariables *LV) const { | ||||||||
| if (!Reg.isVirtual()) | ||||||||
| return; | ||||||||
|
|
||||||||
| MachineInstr *MI = MRI->getVRegDef(Reg); | ||||||||
| if (!MI) | ||||||||
| return; | ||||||||
|
|
||||||||
| unsigned Opcode = MI->getOpcode(); | ||||||||
| bool IsNonSignedExtInstrNeedPromoted = false; | ||||||||
|
||||||||
| int NewOpcode = -1; | ||||||||
|
|
||||||||
| auto CheckAndSetNewOpcode = [&](int NewOpc) { | ||||||||
| if (!IsNonSignedExtInstrNeedPromoted) { | ||||||||
| NewOpcode = NewOpc; | ||||||||
| IsNonSignedExtInstrNeedPromoted = true; | ||||||||
| } | ||||||||
| }; | ||||||||
|
|
||||||||
|
Contributor
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. nit: remove empty line |
||||||||
| switch (Opcode) { | ||||||||
lei137 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| case PPC::OR: | ||||||||
| CheckAndSetNewOpcode(PPC::OR8); | ||||||||
| [[fallthrough]]; | ||||||||
| case PPC::ISEL: | ||||||||
| CheckAndSetNewOpcode(PPC::ISEL8); | ||||||||
| [[fallthrough]]; | ||||||||
| case PPC::OR8: | ||||||||
| case PPC::PHI: | ||||||||
| if (BinOpDepth < MAX_BINOP_DEPTH) { | ||||||||
|
||||||||
| if (BinOpDepth < MAX_BINOP_DEPTH) { | |
| if (BinOpDepth >= MAX_BINOP_DEPTH) | |
| break; |
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.
We should copy the explanation comments for these conditions from issignorzeroextended() as well
Outdated
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.
This big switch stmt makes things a bit confusing. See comment above about replacing the lambda func CheckAndSetNewOpcode with a static helper function.
Outdated
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.
no need for tmp var. Can inline into call.
Outdated
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.
brace not needed here.
Outdated
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.
Not needed since it doesn't do anything.
amy-kwan marked this conversation as resolved.
Show resolved
Hide resolved
amy-kwan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
opt for early exit
if (! TII->isSExt32To64(Opcode) && ! IsNonSignedExtInstrNeedPromoted)
return;
Outdated
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.
early exit
| if (Operand.isReg()) { | |
| if (!Operand.isReg()) | |
| continue; |
Outdated
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.
I think the indentation from here to return is a bit off.
Outdated
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.
opt for early exit
Uh oh!
There was an error while loading. Please reload this page.