Index: llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp =================================================================== --- llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp +++ llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp @@ -90,17 +90,17 @@ // Subtract error margin and bias from register limits and avoid overflow. SGPRCriticalLimit = - std::min(SGPRCriticalLimit - SGPRLimitBias, SGPRCriticalLimit); - SGPRCriticalLimit = - std::min(SGPRCriticalLimit - ErrorMargin, SGPRCriticalLimit); - VGPRCriticalLimit = - std::min(VGPRCriticalLimit - VGPRLimitBias, VGPRCriticalLimit); + SGPRCriticalLimit - + std::clamp(SGPRLimitBias + ErrorMargin, 0u, SGPRCriticalLimit); VGPRCriticalLimit = - std::min(VGPRCriticalLimit - ErrorMargin, VGPRCriticalLimit); - SGPRExcessLimit = std::min(SGPRExcessLimit - SGPRLimitBias, SGPRExcessLimit); - SGPRExcessLimit = std::min(SGPRExcessLimit - ErrorMargin, SGPRExcessLimit); - VGPRExcessLimit = std::min(VGPRExcessLimit - VGPRLimitBias, VGPRExcessLimit); - VGPRExcessLimit = std::min(VGPRExcessLimit - ErrorMargin, VGPRExcessLimit); + VGPRCriticalLimit - + std::clamp(VGPRLimitBias + ErrorMargin, 0u, VGPRCriticalLimit); + SGPRExcessLimit = + SGPRExcessLimit - + std::clamp(SGPRLimitBias + ErrorMargin, 0u, SGPRExcessLimit); + VGPRExcessLimit = + VGPRExcessLimit - + std::clamp(VGPRLimitBias + ErrorMargin, 0u, VGPRExcessLimit); LLVM_DEBUG(dbgs() << "VGPRCriticalLimit = " << VGPRCriticalLimit << ", VGPRExcessLimit = " << VGPRExcessLimit