forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 77
Wave Transform to generate SSA Exec mask manipulation instrs #789
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
Open
lalaniket8
wants to merge
4
commits into
amd-feature/wave-transform
Choose a base branch
from
amd/dev/lalaniket8/non-ssa-compliant-wave-transform
base: amd-feature/wave-transform
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
10c69e3
Wave Transform should generate non SSA Exec mask manipulation instrs
lalaniket8 54b5f3b
sanitized with git clang format and minor fixes
lalaniket8 7a31f7f
Removed default mode and cleanup
lalaniket8 35f7d2c
Move getDomVRegDefInBasicBlock() into SIRegisterInfo.cpp, replace Mov…
lalaniket8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1839,7 +1839,7 @@ void ControlFlowRewriter::rewrite() { | |
| Opcode = AMDGPU::S_CBRANCH_SCC1; | ||
| } else { | ||
| Register CondReg = Info.OrigCondition; | ||
| if (!LMA.isSubsetOfExec(CondReg, *Node->Block)) { | ||
| if (!LMA.isSubsetOfExec(CondReg, *Node->Block, Node->Block->end())) { | ||
| CondReg = LMU.createLaneMaskReg(); | ||
| BuildMI(*Node->Block, Node->Block->end(), {}, TII.get(LMC.AndOpc), | ||
| CondReg) | ||
|
|
@@ -1876,7 +1876,6 @@ void ControlFlowRewriter::rewrite() { | |
| RegMap; | ||
| GCNLaneMaskUpdater Updater(Function); | ||
| Updater.setLaneMaskAnalysis(&LMA); | ||
| Updater.setAccumulating(true); | ||
|
|
||
| for (WaveNode *LaneTarget : NodeOrder) { | ||
| CFGNodeInfo &LaneTargetInfo = NodeInfo.find(LaneTarget)->second; | ||
|
|
@@ -1937,7 +1936,8 @@ void ControlFlowRewriter::rewrite() { | |
| } | ||
| } else { | ||
| CondReg = LaneOrigin.CondReg; | ||
| if (!LMA.isSubsetOfExec(LaneOrigin.CondReg, *LaneOrigin.Node->Block)) { | ||
| if (!LMA.isSubsetOfExec(LaneOrigin.CondReg, *LaneOrigin.Node->Block, | ||
| LaneOrigin.Node->Block->getFirstTerminator())) { | ||
| Register Prev = CondReg; | ||
| CondReg = LMU.createLaneMaskReg(); | ||
| BuildMI(*LaneOrigin.Node->Block, | ||
|
|
@@ -2033,28 +2033,34 @@ void ControlFlowRewriter::rewrite() { | |
| CFGNodeInfo &PredInfo = NodeInfo.find(Pred)->second; | ||
| Register PrimaryExec = PredInfo.PrimarySuccessorExec; | ||
|
|
||
| MachineInstr *PrimaryExecDef; | ||
| for (;;) { | ||
| PrimaryExecDef = MRI.getVRegDef(PrimaryExec); | ||
| if (PrimaryExecDef->getOpcode() != AMDGPU::COPY) | ||
| break; | ||
| PrimaryExec = PrimaryExecDef->getOperand(1).getReg(); | ||
| } | ||
| // Turning off this copy-chain optimization to retain the Accumulator as | ||
| // the PrimaryExec | ||
|
|
||
| // MachineInstr *PrimaryExecDef; | ||
| // for (;;) { | ||
| // PrimaryExecDef = MRI.getVRegDef(PrimaryExec); | ||
| // if (PrimaryExecDef->getOpcode() != AMDGPU::COPY) | ||
| // break; | ||
| // PrimaryExec = PrimaryExecDef->getOperand(1).getReg(); | ||
| // } | ||
|
|
||
| // Rejoin = EXEC ^ PrimaryExec | ||
| // | ||
| // Fold immediately if PrimaryExec was obtained via XOR as well. | ||
| Register Rejoin; | ||
|
|
||
| if (PrimaryExecDef->getParent() == Pred->Block && | ||
| PrimaryExecDef->getOpcode() == LMC.XorOpc && | ||
| PrimaryExecDef->getOperand(1).isReg() && | ||
| PrimaryExecDef->getOperand(2).isReg()) { | ||
| if (PrimaryExecDef->getOperand(1).getReg() == LMC.ExecReg) | ||
| Rejoin = PrimaryExecDef->getOperand(2).getReg(); | ||
| else if (PrimaryExecDef->getOperand(2).getReg() == LMC.ExecReg) | ||
| Rejoin = PrimaryExecDef->getOperand(1).getReg(); | ||
| } | ||
| // Turning off this XOR optimiztion since buildMergeLaneMasks() will not | ||
|
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. Ditto. |
||
| // introduce XOR instruction for creating the PrimaryExec | ||
|
|
||
| // if (PrimaryExecDef->getParent() == Pred->Block && | ||
| // PrimaryExecDef->getOpcode() == LMC.XorOpc && | ||
| // PrimaryExecDef->getOperand(1).isReg() && | ||
| // PrimaryExecDef->getOperand(2).isReg()) { | ||
| // if (PrimaryExecDef->getOperand(1).getReg() == LMC.ExecReg) | ||
| // Rejoin = PrimaryExecDef->getOperand(2).getReg(); | ||
| // else if (PrimaryExecDef->getOperand(2).getReg() == LMC.ExecReg) | ||
| // Rejoin = PrimaryExecDef->getOperand(1).getReg(); | ||
| // } | ||
|
|
||
| if (!Rejoin) { | ||
| // Try to find a previously generated XOR (or merely masked) value | ||
|
|
@@ -2091,7 +2097,15 @@ void ControlFlowRewriter::rewrite() { | |
|
|
||
| LLVM_DEBUG(Function.dump()); | ||
| } | ||
|
|
||
| Updater.insertAccumulatorResets(); | ||
| // Replace MovTermOpc with MovOpc | ||
| for (MachineBasicBlock &MBB : Function) { | ||
lalaniket8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (MachineInstr &MI : MBB) { | ||
| if (MI.getOpcode() == LMC.MovTermOpc) { | ||
| MI.setDesc(TII.get(LMC.MovOpc)); | ||
lalaniket8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| Updater.cleanup(); | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Code commented out won't look good. Better clean them all. What is the significance of adding the above comment here? Are you planning to implement a similar optimization for ACC based non-SSA form? If yes, leave a strong note mentioning that (still need to clean up the commented code). Otherwise, remove the comment as well.