[llvm] [AMDGPU] Add hint for MFMA Dst and OpC (PR #185218)

Josh Hutton via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 12:43:50 PDT 2026


================
@@ -245,6 +246,69 @@ bool GCNPreRAOptimizationsImpl::run(MachineFunction &MF) {
   TRI = ST.getRegisterInfo();
 
   bool Changed = false;
+  if (ST.hasMAIInsts()) {
+    EquivalenceClasses<Register> MFMAHints;
+    for (const MachineBasicBlock &MBB : MF) {
+      for (const MachineInstr &MI : MBB) {
+        if (!SIInstrInfo::isMFMA(MI))
+          continue;
+        const MachineOperand *DstMO =
+            TII->getNamedOperand(MI, AMDGPU::OpName::vdst);
+        const MachineOperand *Src2MO =
+            TII->getNamedOperand(MI, AMDGPU::OpName::src2);
+        if (!DstMO || !Src2MO || !DstMO->isReg() || !Src2MO->isReg())
+          continue;
+        Register Dst = DstMO->getReg();
+        Register Src2 = Src2MO->getReg();
+        if (!Dst.isVirtual() || !Src2.isVirtual())
+          continue;
+        LLVM_DEBUG(dbgs() << "Setting hint for "; MI.dump());
+        LLVM_DEBUG(dbgs() << " Dst: "; DstMO->dump(); dbgs() << " Src2: ";
+                   Src2MO->dump());
+        MFMAHints.unionSets(Dst, Src2);
+      }
+    }
+
+    auto CheckAllCompatibleRC =
----------------
JoshHuttonCode wrote:

To make sure I understand, is your suggestion to still create the equivalence classes and add the hints where I currently have it, and then to do the checking of compatible register classes in greedy?

To not change the behavior for regular hints, I think this would require a new type of hint with this specific behavior (not applying any hints in the equivalence class if any of the hinted registers are incompatible). Then, before calling `selectOrSplit()`, check through all hints of this type and apply the rule by removing the hints if needed. Is this the intent of your suggestion?

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


More information about the llvm-commits mailing list