-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[AMDGPU] Classify FLAT instructions as VMEM #137148
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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 |
---|---|---|
|
@@ -183,10 +183,7 @@ GCNHazardRecognizer::getHazardType(SUnit *SU, int Stalls) { | |
if (ST.hasNoDataDepHazard()) | ||
return NoHazard; | ||
|
||
// FIXME: Should flat be considered vmem? | ||
if ((SIInstrInfo::isVMEM(*MI) || | ||
SIInstrInfo::isFLAT(*MI)) | ||
&& checkVMEMHazards(MI) > 0) | ||
if (SIInstrInfo::isVMEM(*MI) && checkVMEMHazards(MI) > 0) | ||
return HazardType; | ||
|
||
if (SIInstrInfo::isVALU(*MI) && checkVALUHazards(MI) > 0) | ||
|
@@ -202,8 +199,8 @@ GCNHazardRecognizer::getHazardType(SUnit *SU, int Stalls) { | |
return HazardType; | ||
|
||
if ((SIInstrInfo::isVALU(*MI) || SIInstrInfo::isVMEM(*MI) || | ||
SIInstrInfo::isFLAT(*MI) || SIInstrInfo::isDS(*MI) || | ||
SIInstrInfo::isEXP(*MI)) && checkMAIVALUHazards(MI) > 0) | ||
SIInstrInfo::isDS(*MI) || SIInstrInfo::isEXP(*MI)) && | ||
checkMAIVALUHazards(MI) > 0) | ||
return HazardType; | ||
|
||
if (isSGetReg(MI->getOpcode()) && checkGetRegHazards(MI) > 0) | ||
|
@@ -229,9 +226,8 @@ GCNHazardRecognizer::getHazardType(SUnit *SU, int Stalls) { | |
if (SIInstrInfo::isMAI(*MI) && checkMAIHazards(MI) > 0) | ||
return HazardType; | ||
|
||
if ((SIInstrInfo::isVMEM(*MI) || | ||
SIInstrInfo::isFLAT(*MI) || | ||
SIInstrInfo::isDS(*MI)) && checkMAILdStHazards(MI) > 0) | ||
if ((SIInstrInfo::isVMEM(*MI) || SIInstrInfo::isDS(*MI)) && | ||
checkMAILdStHazards(MI) > 0) | ||
return HazardType; | ||
|
||
if (MI->isInlineAsm() && checkInlineAsmHazards(MI) > 0) | ||
|
@@ -324,7 +320,7 @@ unsigned GCNHazardRecognizer::PreEmitNoopsCommon(MachineInstr *MI) { | |
if (ST.hasNoDataDepHazard()) | ||
return WaitStates; | ||
|
||
if (SIInstrInfo::isVMEM(*MI) || SIInstrInfo::isFLAT(*MI)) | ||
if (SIInstrInfo::isVMEM(*MI)) | ||
WaitStates = std::max(WaitStates, checkVMEMHazards(MI)); | ||
|
||
if (SIInstrInfo::isVALU(*MI)) | ||
|
@@ -340,8 +336,8 @@ unsigned GCNHazardRecognizer::PreEmitNoopsCommon(MachineInstr *MI) { | |
WaitStates = std::max(WaitStates, checkRWLaneHazards(MI)); | ||
|
||
if ((SIInstrInfo::isVALU(*MI) || SIInstrInfo::isVMEM(*MI) || | ||
SIInstrInfo::isFLAT(*MI) || SIInstrInfo::isDS(*MI) || | ||
SIInstrInfo::isEXP(*MI)) && checkMAIVALUHazards(MI) > 0) | ||
SIInstrInfo::isDS(*MI) || SIInstrInfo::isEXP(*MI)) && | ||
checkMAIVALUHazards(MI) > 0) | ||
WaitStates = std::max(WaitStates, checkMAIVALUHazards(MI)); | ||
|
||
if (MI->isInlineAsm()) | ||
|
@@ -369,9 +365,7 @@ unsigned GCNHazardRecognizer::PreEmitNoopsCommon(MachineInstr *MI) { | |
if (SIInstrInfo::isMAI(*MI)) | ||
return std::max(WaitStates, checkMAIHazards(MI)); | ||
|
||
if (SIInstrInfo::isVMEM(*MI) || | ||
SIInstrInfo::isFLAT(*MI) || | ||
SIInstrInfo::isDS(*MI)) | ||
if (SIInstrInfo::isVMEM(*MI) || SIInstrInfo::isDS(*MI)) | ||
return std::max(WaitStates, checkMAILdStHazards(MI)); | ||
|
||
if (ST.hasGFX950Insts() && isPermlane(*MI)) | ||
|
@@ -598,7 +592,7 @@ static bool breaksSMEMSoftClause(MachineInstr *MI) { | |
} | ||
|
||
static bool breaksVMEMSoftClause(MachineInstr *MI) { | ||
return !SIInstrInfo::isVMEM(*MI) && !SIInstrInfo::isFLAT(*MI); | ||
return !SIInstrInfo::isVMEM(*MI); | ||
} | ||
|
||
int GCNHazardRecognizer::checkSoftClauseHazards(MachineInstr *MEM) { | ||
|
@@ -1250,8 +1244,7 @@ bool GCNHazardRecognizer::fixVMEMtoScalarWriteHazards(MachineInstr *MI) { | |
const SIRegisterInfo *TRI = ST.getRegisterInfo(); | ||
|
||
auto IsHazardFn = [TRI, MI](const MachineInstr &I) { | ||
if (!SIInstrInfo::isVMEM(I) && !SIInstrInfo::isDS(I) && | ||
!SIInstrInfo::isFLAT(I)) | ||
if (!SIInstrInfo::isVMEM(I) && !SIInstrInfo::isDS(I)) | ||
return false; | ||
|
||
for (const MachineOperand &Def : MI->defs()) { | ||
|
@@ -1425,8 +1418,8 @@ static bool shouldRunLdsBranchVmemWARHazardFixup(const MachineFunction &MF, | |
for (auto &MBB : MF) { | ||
for (auto &MI : MBB) { | ||
HasLds |= SIInstrInfo::isDS(MI); | ||
HasVmem |= | ||
SIInstrInfo::isVMEM(MI) || SIInstrInfo::isSegmentSpecificFLAT(MI); | ||
HasVmem |= (SIInstrInfo::isVMEM(MI) && !SIInstrInfo::isFLAT(MI)) || | ||
SIInstrInfo::isSegmentSpecificFLAT(MI); | ||
Comment on lines
+1421
to
+1422
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 looks wrong, it's ignoring FLAT_ instructions 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 is addressed by #137170 because otherwise this PR wouldn't be NFC anymore |
||
if (HasLds && HasVmem) | ||
return true; | ||
} | ||
|
@@ -1450,7 +1443,8 @@ bool GCNHazardRecognizer::fixLdsBranchVmemWARHazard(MachineInstr *MI) { | |
auto IsHazardInst = [](const MachineInstr &MI) { | ||
if (SIInstrInfo::isDS(MI)) | ||
return 1; | ||
if (SIInstrInfo::isVMEM(MI) || SIInstrInfo::isSegmentSpecificFLAT(MI)) | ||
if ((SIInstrInfo::isVMEM(MI) && !SIInstrInfo::isFLAT(MI)) || | ||
SIInstrInfo::isSegmentSpecificFLAT(MI)) | ||
return 2; | ||
return 0; | ||
}; | ||
|
@@ -1517,8 +1511,8 @@ bool GCNHazardRecognizer::fixLdsDirectVALUHazard(MachineInstr *MI) { | |
if (WaitStates >= NoHazardWaitStates) | ||
return true; | ||
// Instructions which cause va_vdst==0 expire hazard | ||
return SIInstrInfo::isVMEM(I) || SIInstrInfo::isFLAT(I) || | ||
SIInstrInfo::isDS(I) || SIInstrInfo::isEXP(I); | ||
return SIInstrInfo::isVMEM(I) || SIInstrInfo::isDS(I) || | ||
SIInstrInfo::isEXP(I); | ||
}; | ||
auto GetWaitStatesFn = [](const MachineInstr &MI) { | ||
return SIInstrInfo::isVALU(MI) ? 1 : 0; | ||
|
@@ -1549,8 +1543,7 @@ bool GCNHazardRecognizer::fixLdsDirectVMEMHazard(MachineInstr *MI) { | |
const Register VDSTReg = VDST->getReg(); | ||
|
||
auto IsHazardFn = [this, VDSTReg](const MachineInstr &I) { | ||
if (!SIInstrInfo::isVMEM(I) && !SIInstrInfo::isFLAT(I) && | ||
!SIInstrInfo::isDS(I)) | ||
if (!SIInstrInfo::isVMEM(I) && !SIInstrInfo::isDS(I)) | ||
return false; | ||
return I.readsRegister(VDSTReg, &TRI) || I.modifiesRegister(VDSTReg, &TRI); | ||
}; | ||
|
@@ -1635,8 +1628,8 @@ bool GCNHazardRecognizer::fixVALUPartialForwardingHazard(MachineInstr *MI) { | |
return HazardExpired; | ||
|
||
// Instructions which cause va_vdst==0 expire hazard | ||
if (SIInstrInfo::isVMEM(I) || SIInstrInfo::isFLAT(I) || | ||
SIInstrInfo::isDS(I) || SIInstrInfo::isEXP(I) || | ||
if (SIInstrInfo::isVMEM(I) || SIInstrInfo::isDS(I) || | ||
SIInstrInfo::isEXP(I) || | ||
(I.getOpcode() == AMDGPU::S_WAITCNT_DEPCTR && | ||
AMDGPU::DepCtr::decodeFieldVaVdst(I.getOperand(0).getImm()) == 0)) | ||
return HazardExpired; | ||
|
@@ -1772,8 +1765,8 @@ bool GCNHazardRecognizer::fixVALUTransUseHazard(MachineInstr *MI) { | |
return HazardExpired; | ||
|
||
// Instructions which cause va_vdst==0 expire hazard | ||
if (SIInstrInfo::isVMEM(I) || SIInstrInfo::isFLAT(I) || | ||
SIInstrInfo::isDS(I) || SIInstrInfo::isEXP(I) || | ||
if (SIInstrInfo::isVMEM(I) || SIInstrInfo::isDS(I) || | ||
SIInstrInfo::isEXP(I) || | ||
(I.getOpcode() == AMDGPU::S_WAITCNT_DEPCTR && | ||
I.getOperand(0).getImm() == 0x0fff)) | ||
return HazardExpired; | ||
|
@@ -2003,7 +1996,7 @@ int GCNHazardRecognizer::checkFPAtomicToDenormModeHazard(MachineInstr *MI) { | |
return 0; | ||
|
||
auto IsHazardFn = [](const MachineInstr &I) { | ||
if (!SIInstrInfo::isVMEM(I) && !SIInstrInfo::isFLAT(I)) | ||
if (!SIInstrInfo::isVMEM(I)) | ||
return false; | ||
return SIInstrInfo::isFPAtomic(I); | ||
}; | ||
|
@@ -2625,9 +2618,7 @@ int GCNHazardRecognizer::checkMAIVALUHazards(MachineInstr *MI) { | |
|
||
int WaitStatesNeeded = 0; | ||
|
||
bool IsMem = SIInstrInfo::isVMEM(*MI) || | ||
SIInstrInfo::isFLAT(*MI) || | ||
SIInstrInfo::isDS(*MI); | ||
bool IsMem = SIInstrInfo::isVMEM(*MI) || SIInstrInfo::isDS(*MI); | ||
bool IsMemOrExport = IsMem || SIInstrInfo::isEXP(*MI); | ||
bool IsVALU = SIInstrInfo::isVALU(*MI); | ||
|
||
|
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
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
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
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
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
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.
Am I right in thinking that the isDS test was redundant, since no instructions are both FLAT and DS? @kerbowa
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.
Otherwise, it should check for
!isLDSDMA
if we specifically want to avoid DS accesses, I think