[llvm-branch-commits] [llvm] [AMDGPU][SIInsertWaitcnts][NFC] Introduce Counter::setToMax() (PR #193382)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Apr 21 19:05:06 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: vporpo (vporpo)

<details>
<summary>Changes</summary>


---
Previous PRs:

0. https://github.com/llvm/llvm-project/pull/193368
1. https://github.com/llvm/llvm-project/pull/193369
2. https://github.com/llvm/llvm-project/pull/193374
3. https://github.com/llvm/llvm-project/pull/193381


---
Full diff: https://github.com/llvm/llvm-project/pull/193382.diff


1 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp (+13-16) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index 7d9ad6bf38686..baa7f61f471e6 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -775,6 +775,13 @@ class WaitcntBrackets {
       const AMDGPU::HardwareLimits *Limits = nullptr;
       unsigned LB = 0;
       unsigned UB = 0;
+      void setUB(unsigned NewUB) {
+        UB = NewUB;
+        if (CntT == AMDGPU::EXP_CNT) {
+          if (getCount() > getWaitCountMax(*Limits, AMDGPU::EXP_CNT))
+            LB = UB - getWaitCountMax(*Limits, AMDGPU::EXP_CNT);
+        }
+      }
 
     public:
       Counter() = default;
@@ -789,14 +796,6 @@ class WaitcntBrackets {
       // TODO: Make private: we should not provide raw access to the internals.
       void setLB(unsigned NewLB) { LB = NewLB; }
       // TODO: Make private: we should not provide raw access to the internals.
-      void setUB(unsigned NewUB) {
-        UB = NewUB;
-        if (CntT == AMDGPU::EXP_CNT) {
-          if (getCount() > getWaitCountMax(*Limits, AMDGPU::EXP_CNT))
-            LB = UB - getWaitCountMax(*Limits, AMDGPU::EXP_CNT);
-        }
-      }
-      // TODO: Make private: we should not provide raw access to the internals.
       unsigned getUB() const { return UB; }
       // TODO: Make private: we should not provide raw access to the internals.
       unsigned getLB() const { return LB; }
@@ -824,6 +823,11 @@ class WaitcntBrackets {
           report_fatal_error("InsertWaitcnt score wraparound");
         return UB;
       }
+      /// Sets the counter to its maximum value.
+      void setToMax() {
+        unsigned Max = getWaitCountMax(*Limits, CntT);
+        setUB(UB + Max);
+      }
     };
 
     std::array<Counter, AMDGPU::NUM_INST_CNTS> Counters;
@@ -950,9 +954,7 @@ class WaitcntBrackets {
   }
 
   void setStateOnFunctionEntryOrReturn() {
-    setScoreUB(AMDGPU::STORE_CNT,
-               getScoreUB(AMDGPU::STORE_CNT) +
-                   getWaitCountMax(Context->getLimits(), AMDGPU::STORE_CNT));
+    Counters[AMDGPU::STORE_CNT].setToMax();
     PendingEvents |= Context->getWaitEvents(AMDGPU::STORE_CNT);
   }
 
@@ -1005,11 +1007,6 @@ class WaitcntBrackets {
     Counters[T].setLB(Val);
   }
 
-  void setScoreUB(AMDGPU::InstCounterType T, unsigned Val) {
-    assert(T < AMDGPU::NUM_INST_CNTS);
-    Counters[T].setUB(Val);
-  }
-
   void setRegScore(MCPhysReg Reg, AMDGPU::InstCounterType T, unsigned Val) {
     const SIRegisterInfo &TRI = Context->TRI;
     if (Reg == AMDGPU::SCC) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/193382


More information about the llvm-branch-commits mailing list