Skip to content

[AMDGPU] Inline two helpers in SIInsertWaitcnts. NFC.#174557

Merged
jayfoad merged 1 commit intollvm:mainfrom
jayfoad:inline-redundant-xcnt
Jan 12, 2026
Merged

[AMDGPU] Inline two helpers in SIInsertWaitcnts. NFC.#174557
jayfoad merged 1 commit intollvm:mainfrom
jayfoad:inline-redundant-xcnt

Conversation

@jayfoad
Copy link
Contributor

@jayfoad jayfoad commented Jan 6, 2026

No description provided.

@jayfoad
Copy link
Contributor Author

jayfoad commented Jan 6, 2026

@RyanRio

@jayfoad jayfoad requested a review from nhaehnle January 6, 2026 09:47
@llvmbot
Copy link
Member

llvmbot commented Jan 6, 2026

@llvm/pr-subscribers-backend-amdgpu

Author: Jay Foad (jayfoad)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp (+9-22)
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index 10138f59ab1b4..8207bd46ea9f7 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -662,8 +662,6 @@ class WaitcntBrackets {
   void simplifyWaitcnt(const AMDGPU::Waitcnt &CheckWait,
                        AMDGPU::Waitcnt &UpdateWait) const;
   void simplifyWaitcnt(InstCounterType T, unsigned &Count) const;
-  bool hasRedundantXCntWithKmCnt(const AMDGPU::Waitcnt &Wait) const;
-  bool canOptimizeXCntWithLoadCnt(const AMDGPU::Waitcnt &Wait) const;
   void simplifyXcnt(const AMDGPU::Waitcnt &CheckWait,
                     AMDGPU::Waitcnt &UpdateWait) const;
 
@@ -1354,23 +1352,6 @@ void WaitcntBrackets::applyWaitcnt(InstCounterType T, unsigned Count) {
   }
 }
 
-bool WaitcntBrackets::hasRedundantXCntWithKmCnt(
-    const AMDGPU::Waitcnt &Wait) const {
-  // Wait on XCNT is redundant if we are already waiting for a load to complete.
-  // SMEM can return out of order, so only omit XCNT wait if we are waiting till
-  // zero.
-  return Wait.KmCnt == 0 && hasPendingEvent(SMEM_GROUP);
-}
-
-bool WaitcntBrackets::canOptimizeXCntWithLoadCnt(
-    const AMDGPU::Waitcnt &Wait) const {
-  // If we have pending store we cannot optimize XCnt because we do not wait for
-  // stores. VMEM loads retun in order, so if we only have loads XCnt is
-  // decremented to the same number as LOADCnt.
-  return Wait.LoadCnt != ~0u && hasPendingEvent(VMEM_GROUP) &&
-         !hasPendingEvent(STORE_CNT);
-}
-
 void WaitcntBrackets::simplifyXcnt(const AMDGPU::Waitcnt &CheckWait,
                                    AMDGPU::Waitcnt &UpdateWait) const {
   // Try to simplify xcnt further by checking for joint kmcnt and loadcnt
@@ -1378,10 +1359,16 @@ void WaitcntBrackets::simplifyXcnt(const AMDGPU::Waitcnt &CheckWait,
   // be pending SMEM and VMEM events active at the same time.
   // In such cases, only clear one active event at a time.
   // TODO: Revisit xcnt optimizations for gfx1250.
-  if (hasRedundantXCntWithKmCnt(CheckWait))
+  // Wait on XCNT is redundant if we are already waiting for a load to complete.
+  // SMEM can return out of order, so only omit XCNT wait if we are waiting till
+  // zero.
+  if (CheckWait.KmCnt == 0 && hasPendingEvent(SMEM_GROUP))
     UpdateWait.XCnt = ~0u;
-  if (canOptimizeXCntWithLoadCnt(CheckWait) &&
-      CheckWait.XCnt >= CheckWait.LoadCnt)
+  // If we have pending store we cannot optimize XCnt because we do not wait for
+  // stores. VMEM loads retun in order, so if we only have loads XCnt is
+  // decremented to the same number as LOADCnt.
+  if (CheckWait.LoadCnt != ~0u && hasPendingEvent(VMEM_GROUP) &&
+      !hasPendingEvent(STORE_CNT) && CheckWait.XCnt >= CheckWait.LoadCnt)
     UpdateWait.XCnt = ~0u;
   simplifyWaitcnt(X_CNT, UpdateWait.XCnt);
 }

@jayfoad
Copy link
Contributor Author

jayfoad commented Jan 6, 2026

The patch was created by an LLM.

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

🪟 Windows x64 Test Results

  • 129123 tests passed
  • 2842 tests skipped
  • 1 test failed

Failed Tests

(click on a test name to see its output)

LLVM

LLVM.CodeGen/RISCV/riscv-macho.ll
Exit Code: 3221225477

Command Output (stdout):
--
# RUN: at line 1
c:\_work\llvm-project\llvm-project\build\bin\llc.exe -mtriple=riscv32-apple-macho C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\RISCV\riscv-macho.ll -o - | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\RISCV\riscv-macho.ll
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\llc.exe' -mtriple=riscv32-apple-macho 'C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\RISCV\riscv-macho.ll' -o -
# note: command had no output on stdout or stderr
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 'C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\RISCV\riscv-macho.ll'
# note: command had no output on stdout or stderr
# RUN: at line 2
c:\_work\llvm-project\llvm-project\build\bin\llc.exe -mtriple=riscv32-apple-macho -filetype=obj C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\RISCV\riscv-macho.ll -o C:\_work\llvm-project\llvm-project\build\test\CodeGen\RISCV\Output\riscv-macho.ll.tmp.o
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\llc.exe' -mtriple=riscv32-apple-macho -filetype=obj 'C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\RISCV\riscv-macho.ll' -o 'C:\_work\llvm-project\llvm-project\build\test\CodeGen\RISCV\Output\riscv-macho.ll.tmp.o'
# .---command stderr------------
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: c:\\_work\\llvm-project\\llvm-project\\build\\bin\\llc.exe -mtriple=riscv32-apple-macho -filetype=obj C:\\_work\\llvm-project\\llvm-project\\llvm\\test\\CodeGen\\RISCV\\riscv-macho.ll -o C:\\_work\\llvm-project\\llvm-project\\build\\test\\CodeGen\\RISCV\\Output\\riscv-macho.ll.tmp.o
# | Exception Code: 0xC0000005
# |  #0 0x00007ffbfc852004 (C:\Windows\SYSTEM32\ntdll.dll+0x12004)
# |  #1 0x00007ffbfc851dda (C:\Windows\SYSTEM32\ntdll.dll+0x11dda)
# |  #2 0x00007ffbec47ff29 (C:\Windows\System32\ucrtbase.dll+0xff29)
# |  #3 0x00007ff700d71429 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x6f1429)
# |  #4 0x00007ff7034cfb73 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x2e4fb73)
# |  #5 0x00007ff702509ee8 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x1e89ee8)
# |  #6 0x00007ff700eef105 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x86f105)
# |  #7 0x00007ff700b419a1 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x4c19a1)
# |  #8 0x00007ff700b39fb1 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x4b9fb1)
# |  #9 0x00007ff700687c0c (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x7c0c)
# | #10 0x00007ff700684e86 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x4e86)
# | #11 0x00007ff704c9a1f4 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x461a1f4)
# | #12 0x00007ffbf0a74cb0 (C:\Windows\System32\KERNEL32.DLL+0x14cb0)
# | #13 0x00007ffbfc8bedcb (C:\Windows\SYSTEM32\ntdll.dll+0x7edcb)
# `-----------------------------
# error: command failed with exit status: 0xc0000005

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

Copy link
Collaborator

@nhaehnle nhaehnle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jayfoad jayfoad merged commit 3b2d14b into llvm:main Jan 12, 2026
11 of 12 checks passed
@jayfoad jayfoad deleted the inline-redundant-xcnt branch January 12, 2026 14:26
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants