[llvm] [AMDGPU] Register allocation anti-hints to reduce MFMA hazard NOPs (PR #156943)
Syadus Sefat via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 7 18:53:56 PDT 2025
================
@@ -248,6 +254,95 @@ bool GCNPreRAOptimizationsImpl::run(MachineFunction &MF) {
bool Changed = false;
+ // Single pass implementation
+ if (EnableAntiHintsForMFMARegs && ST.hasMAIInsts()) {
+ // Max lookback window for RAW or WAW hazard
+ constexpr unsigned MaxLookbackWindow = 19;
+ for (const MachineBasicBlock &MBB : MF) {
+
+ SmallVector<std::pair<SlotIndex, SmallVector<Register, 4>>, 16>
+ RecentMFMAs;
+ for (const MachineInstr &MI : MBB) {
+ if (MI.isDebugInstr())
+ continue;
+ const SlotIndex CurrentSlot = LIS->getInstructionIndex(MI).getRegSlot();
+ // Handle MFMA instructions
+ if (SIInstrInfo::isMFMA(MI)) {
+ SmallVector<Register, 4> MFMARegisters;
+ // Helper to get named operand
+ auto collectNamedOperand = [&](AMDGPU::OpName OpName,
+ const char *OpNameStr) {
+ unsigned Opc = MI.getOpcode();
+ int OpIdx = AMDGPU::getNamedOperandIdx(Opc, OpName);
+ if (OpIdx == -1) {
+ LLVM_DEBUG(dbgs() << " Named operand " << OpNameStr
+ << " not found\n");
+ return;
+ }
+ const MachineOperand &MO = MI.getOperand(OpIdx);
----------------
mssefat wrote:
Fixed it. Please check.
https://github.com/llvm/llvm-project/pull/156943
More information about the llvm-commits
mailing list