[llvm-branch-commits] [llvm] [AMDGPU] Fix the packed F32 unpack window in SIPreEmitPeephole (PR #233721)

Akash Dutta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Oct 21 09:52:00 PDT 2026


================
@@ -914,16 +916,17 @@ bool SIPreEmitPeephole::run(MachineFunction &MF, MachineLoopInfo *LoopInfo) {
   for (MachineBasicBlock &MBB : MF) {
     // Unpack packed instructions overlapped by MFMAs. This allows the
     // compiler to co-issue unpacked instructions with MFMA
-    const TargetSchedModel &SchedModel = TII->getSchedModel();
     SetVector<MachineInstr *> InstrsToUnpack;
     for (auto &MI : make_early_inc_range(MBB.instrs())) {
-      if (!SIInstrInfo::isMFMA(MI))
+      // SGEMM/DGEMM hold every VALU back, so only XDL benefits.
+      if (!SIInstrInfo::isMFMA(MI) || !TII->isXDL(MI))
         continue;
-      const MCSchedClassDesc *SchedClassDesc =
-          SchedModel.resolveSchedClass(&MI);
-      uint16_t NumMFMACycles =
-          SchedModel.getWriteProcResBegin(SchedClassDesc)->ReleaseAtCycle;
-      collectUnpackingCandidates(MI, InstrsToUnpack, NumMFMACycles);
+      unsigned PackedCycle =
+          AMDGPU::getPackedVALUIssueCycle(MI, AMDGPU::V_PK_FMA_F32, *TII);
+      unsigned VALUCycle = AMDGPU::getVALUIssueCycle(MI, *TII);
+      assert(PackedCycle >= VALUCycle && "packed VALU issues before VALU");
+      collectUnpackingCandidates(MI, InstrsToUnpack,
----------------
akadutta wrote:

I may be missing something, but I'm confused how (PackedCycle - VALUCycle +1) helps in all cases. I understand it helps unpack insts beyond the old budget that are still blocked, but consider back to back packed instructions and a Write8PassMAI.

A Write8PassMAI probably uses 8 cycles, so the old budget is 7. The new helper says that an unpacked inst can issue at cycle 1 and a packed inst at cycle 6. So the new budget becomes 6.

For back to back packed insts, previously you would have something like this:

first candidate:  Total = 2   → 2 < 7, unpack
second candidate: Total = 4   → 4 < 7, upack
third candidate:  Total = 6   → 6 < 7, unpack 

Under the new budget, the last one won't unpack. Is that by design?

https://github.com/llvm/llvm-project/pull/233721


More information about the llvm-branch-commits mailing list