-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[AMDGPU] Remove s_delay_alu for VALU->SGPR->SALU #127212
Merged
Merged
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -47,6 +47,13 @@ class AMDGPUInsertDelayAlu { | |
return false; | ||
} | ||
|
||
static bool instructionWaitsForSGPRWrites(const MachineInstr &MI) { | ||
// These instruction types wait for VA_SDST==0 before issuing. | ||
const uint64_t VA_SDST_0 = SIInstrFlags::SALU | SIInstrFlags::SMRD; | ||
|
||
return MI.getDesc().TSFlags & VA_SDST_0; | ||
} | ||
|
||
// Types of delay that can be encoded in an s_delay_alu instruction. | ||
enum DelayType { VALU, TRANS, SALU, OTHER }; | ||
|
||
|
@@ -227,6 +234,16 @@ class AMDGPUInsertDelayAlu { | |
} | ||
} | ||
|
||
void advanceByVALUNum(unsigned VALUNum) { | ||
iterator Next; | ||
for (auto I = begin(), E = end(); I != E; I = Next) { | ||
Next = std::next(I); | ||
if (I->second.VALUNum >= VALUNum && I->second.VALUCycles > 0) { | ||
erase(I); | ||
} | ||
} | ||
} | ||
|
||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||
void dump(const TargetRegisterInfo *TRI) const { | ||
if (empty()) { | ||
|
@@ -331,6 +348,7 @@ class AMDGPUInsertDelayAlu { | |
bool Changed = false; | ||
MachineInstr *LastDelayAlu = nullptr; | ||
|
||
MCRegUnit LastSGPRFromVALU = 0; | ||
// Iterate over the contents of bundles, but don't emit any instructions | ||
// inside a bundle. | ||
for (auto &MI : MBB.instrs()) { | ||
|
@@ -345,6 +363,15 @@ class AMDGPUInsertDelayAlu { | |
|
||
DelayType Type = getDelayType(MI.getDesc().TSFlags); | ||
|
||
if (instructionWaitsForSGPRWrites(MI)) { | ||
auto It = State.find(LastSGPRFromVALU); | ||
if (It != State.end()) { | ||
DelayInfo Info = It->getSecond(); | ||
State.advanceByVALUNum(Info.VALUNum); | ||
LastSGPRFromVALU = 0; | ||
} | ||
} | ||
|
||
if (instructionWaitsForVALU(MI)) { | ||
// Forget about all outstanding VALU delays. | ||
// TODO: This is overkill since it also forgets about SALU delays. | ||
|
@@ -368,6 +395,17 @@ class AMDGPUInsertDelayAlu { | |
} | ||
} | ||
} | ||
|
||
if (SII->isVALU(MI.getOpcode())) { | ||
for (const auto &Op : MI.defs()) { | ||
Register Reg = Op.getReg(); | ||
if (AMDGPU::isSGPR(Reg, TRI)) { | ||
LastSGPRFromVALU = *TRI->regunits(Reg).begin(); | ||
break; | ||
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. eliminating the outer loop by only taking the first unit of the SGPR operand |
||
} | ||
} | ||
} | ||
|
||
if (Emit && !MI.isBundledWithPred()) { | ||
// TODO: For VALU->SALU delays should we use s_delay_alu or s_nop or | ||
// just ignore them? | ||
|
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
other instructions are already covered by instructionWaitsForVALU function