[llvm-branch-commits] [llvm] [AMDGPU] Apply occupancy-aware register allocation anti-hints (PR #218074)
Janek van Oirschot via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Aug 24 08:57:55 PDT 2026
================
@@ -4173,6 +4178,130 @@ bool SIRegisterInfo::getRegAllocationHints(Register VirtReg,
}
}
+bool SIRegisterInfo::shouldApplyAntiHints(
+ const MachineFunction &MF, unsigned NumAllocatedVGPRs,
+ unsigned &MaxVGPRsForCurrentOccupancy) const {
+
+ const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
+ unsigned DynamicVGPRBlockSize = MFI->getDynamicVGPRBlockSize();
+ unsigned TargetOccupancy = MFI->getOccupancy();
+ unsigned CurrentOccupancy =
+ ST.getOccupancyWithNumVGPRs(NumAllocatedVGPRs, DynamicVGPRBlockSize);
+ MaxVGPRsForCurrentOccupancy =
+ ST.getMaxNumVGPRs(CurrentOccupancy, DynamicVGPRBlockSize);
+
+ LLVM_DEBUG(dbgs() << "anti-hints: " << NumAllocatedVGPRs
+ << " VGPRs allocated, target occupancy " << TargetOccupancy
+ << ", current occupancy " << CurrentOccupancy << '\n');
+
+ // If we are already at lowest occupancy, then there is no need to protect
+ // against occupancy regression.
+ if (CurrentOccupancy == 1)
+ return true;
+
+ // Set max VGPRs for target and current occupancy to early bail out if we are
+ // close to the limit.
+ unsigned MaxVGPRsCutOffForTargetOccupancy =
+ (ST.getMaxNumVGPRs(TargetOccupancy, DynamicVGPRBlockSize) * 80) / 100;
+ unsigned MaxVGPRsCutOffForCurrentOccupancy =
+ (MaxVGPRsForCurrentOccupancy * 95) / 100;
----------------
JanekvO wrote:
Can we add some comments on these %s? Even if they're hand-wavey numbers, that's alright but would like to have some sort of acknowledgement of that in comments. Additionally, would these %s be something users might want to play around with? Would these be fit as cli args?
https://github.com/llvm/llvm-project/pull/218074
More information about the llvm-branch-commits
mailing list