-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AMDGPU] Fix undefined scc register in successor block of SI_KILL terminators #134718
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 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b98e163
[AMDGPU] Fix undefined $scc in successor blocks of SI_KILL terminators
mssefat 2f04569
[AMDGPU] Fix undefined $scc in successor blocks of SI_KILL terminators
mssefat b058b0e
[AMDGPU] Fix undefined scc register in successor block of SI_KILL ter…
mssefat 2b8d661
Update llvm/lib/Target/AMDGPU/SIISelLowering.cpp
mssefat 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 |
---|---|---|
|
@@ -4516,6 +4516,38 @@ SITargetLowering::splitKillBlock(MachineInstr &MI, | |
MachineBasicBlock *SplitBB = BB->splitAt(MI, false /*UpdateLiveIns*/); | ||
const SIInstrInfo *TII = getSubtarget()->getInstrInfo(); | ||
MI.setDesc(TII->getKillTerminatorFromPseudo(MI.getOpcode())); | ||
|
||
// Check if SCC register is used in the successor block | ||
bool IsSCCUsedInSuccessor = false; | ||
for (const MachineInstr &SuccMI : *SplitBB) { | ||
// Check for uses of SCC in the instruction's operands | ||
for (const MachineOperand &MO : SuccMI.operands()) { | ||
if (MO.isReg() && MO.getReg() == AMDGPU::SCC && !MO.isDef()) { | ||
IsSCCUsedInSuccessor = true; | ||
break; | ||
} | ||
} | ||
|
||
// Also check for implicit uses of SCC | ||
if(!IsSCCUsedInSuccessor){ | ||
const MCInstrDesc &Desc = SuccMI.getDesc(); | ||
if (Desc.hasImplicitUseOfPhysReg(AMDGPU::SCC)) { | ||
IsSCCUsedInSuccessor = true; | ||
break; | ||
} | ||
} | ||
|
||
if (IsSCCUsedInSuccessor) | ||
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. If you move this code to a helper function we would end up with less awkward branching: for (const MachineInstr &SuccMI : *SplitBB) {
// Check for uses of SCC in the instruction's operands
for (const MachineOperand &MO : SuccMI.operands())
if (MO.isReg() && MO.getReg() == AMDGPU::SCC && !MO.isDef())
return true;
// Also check for implicit uses of SCC
const MCInstrDesc &Desc = SuccMI.getDesc();
if (Desc.hasImplicitUseOfPhysReg(AMDGPU::SCC))
return true;
} |
||
|
||
// Add SCC as implicit def and live-in SCC if used in successor | ||
if (IsSCCUsedInSuccessor) { | ||
MI.addOperand( | ||
MachineOperand::CreateReg(AMDGPU::SCC, true, true, false, false)); | ||
SplitBB->addLiveIn(AMDGPU::SCC); | ||
} | ||
|
||
return SplitBB; | ||
} | ||
|
||
|
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.
What if we set
UpdateLiveIns
to true ? Wouldn't that cover the case we're trying to cover here ?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've pushed the updates, where UpdateLiveIns is now set to true. To support this change, I moved the call to finalizeLowering to the beginning of FinalizeISel::runImpl. This ensures that reserved registers are frozen before live-ins are added. Without this change, llvm::addLiveIns() triggers an assertion failure due to the check for reservedRegsFrozen() when reserved registers are not yet finalized. Please review.