[PATCH] D142262: [AMDGPU] Use std::clamp to avoid overflow in the scheduler
Stanislav Mekhanoshin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 15:22:57 PST 2023
rampitec created this revision.
rampitec added a reviewer: kerbowa.
Herald added subscribers: kosarev, foad, hiraditya, tpr, dstuttard, yaxunl, jvesely, kzhuravl, arsenm.
Herald added a project: All.
rampitec requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
Using std::clamp() from c++17 is a more consistent way to avoid
overflow when calculating SGPR and VGPR pressure limits.
https://reviews.llvm.org/D142262
Files:
llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142262.490988.patch
Type: text/x-patch
Size: 1569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230120/7190d8a0/attachment.bin>
More information about the llvm-commits
mailing list