[llvm] [AMDGPU] Make SGPR occupancy the exact inverse of getMaxNumSGPRs (PR #201342)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 3 05:46:55 PDT 2026
================
@@ -178,12 +183,24 @@ bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res,
if (!Success || !evaluateMCExprs(Args.slice(5, 2), Asm, {NumSGPRs, NumVGPRs}))
return false;
+ // Arguments 8 to 10 carry the SGPR budget of the code-generator's subtarget
+ // (total SGPRs, allocation granule, and the trap-handler reservation). They
+ // let the SGPR-limited occupancy be computed exactly as the code generator
+ // does (in particular trap-handler aware), instead of from the asm printer's
+ // MCSubtargetInfo which does not carry the implicit amdhsa features.
+ if (!evaluateMCExprs(Args.slice(7, 3), Asm,
+ {SGPRTotal, SGPRGranule, SGPRTrapReserve}))
+ return false;
+
unsigned Occupancy = InitOccupancy;
- if (NumSGPRs)
- Occupancy = std::min(
- Occupancy, IsaInfo::getOccupancyWithNumSGPRs(
- NumSGPRs, MaxWaves,
- static_cast<AMDGPUSubtarget::Generation>(Generation)));
+ // Mirror the GFX10+ rule of the getOccupancyWithNumSGPRs(MCSubtargetInfo)
+ // overload: on GFX10+ the SGPR file is large enough that SGPRs never limit
+ // occupancy. The MC layer only has the decoded Generation here, so it tests
+ // that rather than an MCSubtargetInfo.
+ if (NumSGPRs && Generation < AMDGPUSubtarget::GFX10)
----------------
arsenm wrote:
Avoid generation checks
https://github.com/llvm/llvm-project/pull/201342
More information about the llvm-commits
mailing list