-
Notifications
You must be signed in to change notification settings - Fork 15k
[AMDGPU][NFC]:: Minor Unpacking Fixes. #163992
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
jrbyrnes
merged 5 commits into
llvm:main
from
akadutta:users/akadutta/amdgpu/remove_redundant_checks_unpacking
Oct 17, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,9 +47,6 @@ class SIPreEmitPeephole { | |
| const MachineBasicBlock &From, | ||
| const MachineBasicBlock &To) const; | ||
| bool removeExeczBranch(MachineInstr &MI, MachineBasicBlock &SrcMBB); | ||
| // Check if the machine instruction being processed is a supported packed | ||
| // instruction. | ||
| bool isUnpackingSupportedInstr(MachineInstr &MI) const; | ||
| // Creates a list of packed instructions following an MFMA that are suitable | ||
| // for unpacking. | ||
| void collectUnpackingCandidates(MachineInstr &BeginMI, | ||
|
|
@@ -454,23 +451,6 @@ bool SIPreEmitPeephole::removeExeczBranch(MachineInstr &MI, | |
| return true; | ||
| } | ||
|
|
||
| // If support is extended to new operations, add tests in | ||
| // llvm/test/CodeGen/AMDGPU/unpack-non-coissue-insts-post-ra-scheduler.mir. | ||
| bool SIPreEmitPeephole::isUnpackingSupportedInstr(MachineInstr &MI) const { | ||
| if (!TII->isNeverCoissue(MI)) | ||
| return false; | ||
| unsigned Opcode = MI.getOpcode(); | ||
| switch (Opcode) { | ||
| case AMDGPU::V_PK_ADD_F32: | ||
| case AMDGPU::V_PK_MUL_F32: | ||
| case AMDGPU::V_PK_FMA_F32: | ||
| return true; | ||
| default: | ||
| return false; | ||
| } | ||
| llvm_unreachable("Fully covered switch"); | ||
| } | ||
|
|
||
| bool SIPreEmitPeephole::canUnpackingClobberRegister(const MachineInstr &MI) { | ||
| unsigned OpCode = MI.getOpcode(); | ||
| Register DstReg = MI.getOperand(0).getReg(); | ||
|
|
@@ -612,10 +592,12 @@ void SIPreEmitPeephole::collectUnpackingCandidates( | |
|
|
||
| for (auto I = std::next(BeginMI.getIterator()); I != E; ++I) { | ||
| MachineInstr &Instr = *I; | ||
| uint16_t UnpackedOpCode = mapToUnpackedOpcode(Instr); | ||
| if (Instr.isMetaInstruction()) | ||
| continue; | ||
| if ((Instr.isTerminator()) || | ||
| (TII->isNeverCoissue(Instr) && !isUnpackingSupportedInstr(Instr)) || | ||
| (TII->isNeverCoissue(Instr) && | ||
| (UnpackedOpCode == std::numeric_limits<uint16_t>::max())) || | ||
| (SIInstrInfo::modifiesModeRegister(Instr) && | ||
| Instr.modifiesRegister(AMDGPU::EXEC, TRI))) | ||
| return; | ||
|
|
@@ -639,7 +621,7 @@ void SIPreEmitPeephole::collectUnpackingCandidates( | |
| if (TRI->regsOverlap(MFMADef, InstrMO.getReg())) | ||
| return; | ||
| } | ||
| if (!isUnpackingSupportedInstr(Instr)) | ||
| if (UnpackedOpCode == std::numeric_limits<uint16_t>::max()) | ||
| continue; | ||
|
|
||
| if (canUnpackingClobberRegister(Instr)) | ||
|
|
@@ -687,8 +669,8 @@ MachineInstrBuilder SIPreEmitPeephole::createUnpackedMI(MachineInstr &I, | |
| bool IsHiBits) { | ||
| MachineBasicBlock &MBB = *I.getParent(); | ||
| const DebugLoc &DL = I.getDebugLoc(); | ||
| const MachineOperand *SrcMO1 = TII->getNamedOperand(I, AMDGPU::OpName::src0); | ||
| const MachineOperand *SrcMO2 = TII->getNamedOperand(I, AMDGPU::OpName::src1); | ||
| const MachineOperand *SrcMO0 = TII->getNamedOperand(I, AMDGPU::OpName::src0); | ||
| const MachineOperand *SrcMO1 = TII->getNamedOperand(I, AMDGPU::OpName::src1); | ||
| Register DstReg = I.getOperand(0).getReg(); | ||
| unsigned OpCode = I.getOpcode(); | ||
| Register UnpackedDstReg = IsHiBits ? TRI->getSubReg(DstReg, AMDGPU::sub1) | ||
|
|
@@ -702,15 +684,15 @@ MachineInstrBuilder SIPreEmitPeephole::createUnpackedMI(MachineInstr &I, | |
|
|
||
| MachineInstrBuilder NewMI = BuildMI(MBB, I, DL, TII->get(UnpackedOpcode)); | ||
| NewMI.addDef(UnpackedDstReg); // vdst | ||
| addOperandAndMods(NewMI, Src0Mods, IsHiBits, *SrcMO1); | ||
| addOperandAndMods(NewMI, Src1Mods, IsHiBits, *SrcMO2); | ||
| addOperandAndMods(NewMI, Src0Mods, IsHiBits, *SrcMO0); | ||
| addOperandAndMods(NewMI, Src1Mods, IsHiBits, *SrcMO1); | ||
|
|
||
| if (AMDGPU::hasNamedOperand(OpCode, AMDGPU::OpName::src2)) { | ||
| const MachineOperand *SrcMO3 = | ||
| const MachineOperand *SrcMO2 = | ||
| TII->getNamedOperand(I, AMDGPU::OpName::src2); | ||
| unsigned Src2Mods = | ||
| TII->getNamedOperand(I, AMDGPU::OpName::src2_modifiers)->getImm(); | ||
| addOperandAndMods(NewMI, Src2Mods, IsHiBits, *SrcMO3); | ||
| addOperandAndMods(NewMI, Src2Mods, IsHiBits, *SrcMO2); | ||
| } | ||
| NewMI.addImm(ClampVal); // clamp | ||
| // Packed instructions do not support output modifiers. safe to assign them 0 | ||
|
|
@@ -787,22 +769,26 @@ bool SIPreEmitPeephole::run(MachineFunction &MF) { | |
|
|
||
| // TODO: Fold this into previous block, if possible. Evaluate and handle any | ||
| // side effects. | ||
| for (MachineBasicBlock &MBB : MF) { | ||
| // Unpack packed instructions overlapped by MFMAs. This allows the compiler | ||
| // to co-issue unpacked instructions with MFMA | ||
| auto SchedModel = TII->getSchedModel(); | ||
| SetVector<MachineInstr *> InstrsToUnpack; | ||
| for (auto &MI : make_early_inc_range(MBB.instrs())) { | ||
| if (!SIInstrInfo::isMFMA(MI)) | ||
| continue; | ||
| const MCSchedClassDesc *SchedClassDesc = | ||
| SchedModel.resolveSchedClass(&MI); | ||
| uint16_t NumMFMACycles = | ||
| SchedModel.getWriteProcResBegin(SchedClassDesc)->ReleaseAtCycle; | ||
| collectUnpackingCandidates(MI, InstrsToUnpack, NumMFMACycles); | ||
| } | ||
| for (MachineInstr *MI : InstrsToUnpack) { | ||
| performF32Unpacking(*MI); | ||
|
|
||
| // Perform the extra MF scans only for supported archs | ||
| if (ST.hasGFX950Insts() || ST.hasGFX940Insts()) { | ||
|
||
| for (MachineBasicBlock &MBB : MF) { | ||
| // Unpack packed instructions overlapped by MFMAs. This allows the | ||
| // compiler to co-issue unpacked instructions with MFMA | ||
| auto SchedModel = TII->getSchedModel(); | ||
| SetVector<MachineInstr *> InstrsToUnpack; | ||
| for (auto &MI : make_early_inc_range(MBB.instrs())) { | ||
| if (!SIInstrInfo::isMFMA(MI)) | ||
| continue; | ||
| const MCSchedClassDesc *SchedClassDesc = | ||
| SchedModel.resolveSchedClass(&MI); | ||
| uint16_t NumMFMACycles = | ||
| SchedModel.getWriteProcResBegin(SchedClassDesc)->ReleaseAtCycle; | ||
| collectUnpackingCandidates(MI, InstrsToUnpack, NumMFMACycles); | ||
| } | ||
| for (MachineInstr *MI : InstrsToUnpack) { | ||
| performF32Unpacking(*MI); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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 you use a local variable --
IsUnpackable = UnpackedOpCode == std::numeric_limits<uint16_t>::max()