Skip to content

Conversation

@jayfoad
Copy link
Contributor

@jayfoad jayfoad commented Aug 18, 2025

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Aug 18, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Jay Foad (jayfoad)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp (+4-32)
  • (modified) llvm/lib/Target/AMDGPU/SIInstrInfo.h (+1-1)
diff --git a/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp b/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
index 49a681efc79c7..a3b64aee297b2 100644
--- a/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
@@ -1357,17 +1357,10 @@ bool GCNHazardRecognizer::fixSMEMtoVectorWriteHazards(MachineInstr *MI) {
         // DsCnt corresponds to LGKMCnt here.
         return (Decoded.DsCnt == 0);
       }
-      case AMDGPU::S_WAIT_STORECNT:
-      case AMDGPU::S_WAIT_STORECNT_DSCNT:
-      case AMDGPU::S_WAIT_LOADCNT:
-      case AMDGPU::S_WAIT_LOADCNT_DSCNT:
-      case AMDGPU::S_WAIT_SAMPLECNT:
-      case AMDGPU::S_WAIT_BVHCNT:
-      case AMDGPU::S_WAIT_DSCNT:
-      case AMDGPU::S_WAIT_EXPCNT:
-      case AMDGPU::S_WAIT_KMCNT:
-        llvm_unreachable("unexpected wait count instruction");
       default:
+        assert((!SIInstrInfo::isWaitcnt(MI.getOpcode()) ||
+                MI.getOpcode() == AMDGPU::S_WAIT_IDLE) &&
+               "unexpected wait count instruction");
         // SOPP instructions cannot mitigate the hazard.
         if (TII->isSOPP(MI))
           return false;
@@ -2257,28 +2250,7 @@ int GCNHazardRecognizer::checkFPAtomicToDenormModeHazard(MachineInstr *MI) {
     if (WaitStates >= 3 || SIInstrInfo::isVALU(MI))
       return true;
 
-    switch (MI.getOpcode()) {
-    case AMDGPU::S_WAITCNT:
-    case AMDGPU::S_WAITCNT_VSCNT:
-    case AMDGPU::S_WAITCNT_VMCNT:
-    case AMDGPU::S_WAITCNT_EXPCNT:
-    case AMDGPU::S_WAITCNT_LGKMCNT:
-    case AMDGPU::S_WAIT_IDLE:
-    case AMDGPU::S_WAIT_LOADCNT:
-    case AMDGPU::S_WAIT_LOADCNT_DSCNT:
-    case AMDGPU::S_WAIT_SAMPLECNT:
-    case AMDGPU::S_WAIT_BVHCNT:
-    case AMDGPU::S_WAIT_STORECNT:
-    case AMDGPU::S_WAIT_STORECNT_DSCNT:
-    case AMDGPU::S_WAIT_EXPCNT:
-    case AMDGPU::S_WAIT_DSCNT:
-    case AMDGPU::S_WAIT_KMCNT:
-      return true;
-    default:
-      break;
-    }
-
-    return false;
+    return SIInstrInfo::isWaitcnt(MI.getOpcode());
   };
 
   return FPAtomicToDenormModeWaitStates -
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 18f0e5b9b56bc..5cbf6f5ab0459 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -1056,7 +1056,7 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
     }
   }
 
-  bool isWaitcnt(unsigned Opcode) const {
+  static bool isWaitcnt(unsigned Opcode) {
     switch (getNonSoftWaitcntOpcode(Opcode)) {
     case AMDGPU::S_WAITCNT:
     case AMDGPU::S_WAITCNT_VSCNT:

Copy link
Collaborator

@rovka rovka 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 f15c6ff into llvm:main Aug 18, 2025
11 checks passed
@jayfoad jayfoad deleted the use-iswaitcnt branch August 18, 2025 15:18
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.

4 participants