-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[AMDGPU][True16] si-fold-operand selecting srcidx for v_mov_b16_t16_e64 #162101
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
broxigarchen
wants to merge
1
commit into
llvm:main
Choose a base branch
from
broxigarchen:main-fix-true16-si-fold-1
base: main
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.
+20
−38
Open
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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -932,7 +932,8 @@ static MachineOperand *lookUpCopyChain(const SIInstrInfo &TII, | |||||
for (MachineInstr *SubDef = MRI.getVRegDef(SrcReg); | ||||||
SubDef && TII.isFoldableCopy(*SubDef); | ||||||
SubDef = MRI.getVRegDef(Sub->getReg())) { | ||||||
unsigned SrcIdx = TII.getFoldableCopySrcIdx(*SubDef); | ||||||
const int SrcIdx = | ||||||
(SubDef->getOpcode()) == AMDGPU::V_MOV_B16_t16_e64 ? 2 : 1; | ||||||
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.
Suggested change
|
||||||
MachineOperand &SrcOp = SubDef->getOperand(SrcIdx); | ||||||
|
||||||
if (SrcOp.isImm()) | ||||||
|
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 |
---|---|---|
|
@@ -3408,10 +3408,9 @@ void SIInstrInfo::insertSelect(MachineBasicBlock &MBB, | |
} | ||
} | ||
|
||
bool SIInstrInfo::isFoldableCopy(const MachineInstr &MI) { | ||
bool SIInstrInfo::isFoldableCopy(const MachineInstr &MI) const { | ||
switch (MI.getOpcode()) { | ||
case AMDGPU::V_MOV_B16_t16_e32: | ||
case AMDGPU::V_MOV_B16_t16_e64: | ||
case AMDGPU::V_MOV_B32_e32: | ||
case AMDGPU::V_MOV_B32_e64: | ||
case AMDGPU::V_MOV_B64_PSEUDO: | ||
|
@@ -3428,34 +3427,10 @@ bool SIInstrInfo::isFoldableCopy(const MachineInstr &MI) { | |
case AMDGPU::AV_MOV_B32_IMM_PSEUDO: | ||
case AMDGPU::AV_MOV_B64_IMM_PSEUDO: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
unsigned SIInstrInfo::getFoldableCopySrcIdx(const MachineInstr &MI) { | ||
switch (MI.getOpcode()) { | ||
case AMDGPU::V_MOV_B16_t16_e32: | ||
case AMDGPU::V_MOV_B16_t16_e64: | ||
return 2; | ||
case AMDGPU::V_MOV_B32_e32: | ||
case AMDGPU::V_MOV_B32_e64: | ||
case AMDGPU::V_MOV_B64_PSEUDO: | ||
case AMDGPU::V_MOV_B64_e32: | ||
case AMDGPU::V_MOV_B64_e64: | ||
case AMDGPU::S_MOV_B32: | ||
case AMDGPU::S_MOV_B64: | ||
case AMDGPU::S_MOV_B64_IMM_PSEUDO: | ||
case AMDGPU::COPY: | ||
case AMDGPU::WWM_COPY: | ||
case AMDGPU::V_ACCVGPR_WRITE_B32_e64: | ||
case AMDGPU::V_ACCVGPR_READ_B32_e64: | ||
case AMDGPU::V_ACCVGPR_MOV_B32: | ||
case AMDGPU::AV_MOV_B32_IMM_PSEUDO: | ||
case AMDGPU::AV_MOV_B64_IMM_PSEUDO: | ||
return 1; | ||
return !hasAnyModifiersSet(MI); | ||
default: | ||
llvm_unreachable("MI is not a foldable copy"); | ||
return false; | ||
} | ||
} | ||
|
||
|
@@ -3976,12 +3951,13 @@ bool SIInstrInfo::areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, | |
return false; | ||
} | ||
|
||
static bool getFoldableImm(Register Reg, const MachineRegisterInfo &MRI, | ||
int64_t &Imm, MachineInstr **DefMI = nullptr) { | ||
bool SIInstrInfo::getFoldableImm(Register Reg, const MachineRegisterInfo &MRI, | ||
int64_t &Imm, | ||
MachineInstr **DefMI = nullptr) const { | ||
if (Reg.isPhysical()) | ||
return false; | ||
auto *Def = MRI.getUniqueVRegDef(Reg); | ||
if (Def && SIInstrInfo::isFoldableCopy(*Def) && Def->getOperand(1).isImm()) { | ||
if (Def && isFoldableCopy(*Def) && Def->getOperand(1).isImm()) { | ||
Imm = Def->getOperand(1).getImm(); | ||
if (DefMI) | ||
*DefMI = Def; | ||
|
@@ -3990,8 +3966,8 @@ static bool getFoldableImm(Register Reg, const MachineRegisterInfo &MRI, | |
return false; | ||
} | ||
|
||
static bool getFoldableImm(const MachineOperand *MO, int64_t &Imm, | ||
MachineInstr **DefMI = nullptr) { | ||
bool SIInstrInfo::getFoldableImm(const MachineOperand *MO, int64_t &Imm, | ||
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. I think you can make hasAnyModifiers static instead |
||
MachineInstr **DefMI = nullptr) const { | ||
if (!MO->isReg()) | ||
return false; | ||
const MachineFunction *MF = MO->getParent()->getParent()->getParent(); | ||
|
@@ -10643,10 +10619,11 @@ bool SIInstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, | |
return false; | ||
|
||
int64_t Mask; | ||
const auto isMask = [&Mask, SrcSize](const MachineOperand *MO) -> bool { | ||
const auto isMask = [&Mask, SrcSize, | ||
this](const MachineOperand *MO) -> bool { | ||
if (MO->isImm()) | ||
Mask = MO->getImm(); | ||
else if (!getFoldableImm(MO, Mask)) | ||
else if (!this->getFoldableImm(MO, Mask)) | ||
return false; | ||
Mask &= maxUIntN(SrcSize); | ||
return isPowerOf2_64(Mask); | ||
|
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.
Can we add some unit-tests to make sure this is working as expected ?
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.
test added in previous patch https://github.com/llvm/llvm-project/pull/161764/files#diff-fdc17816dfff25251b0acd60e624921d50180b5c2fd5e1c6673a7a57def7f5e4
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.
Yes, but according to point 1 in the description there was an error which is apparently not covered