[clang] [llvm] [AMDGPU] Fix monitor-sleep duration validation on GFX12.5 (PR #241042)

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 11 13:02:53 PST 2026


https://github.com/yxsamliu updated https://github.com/llvm/llvm-project/pull/241042

>From 382e32cbb835f4423718d64a728f6fc65651dc98 Mon Sep 17 00:00:00 2001
From: Yaxun Liu <yaxun.liu at amd.com>
Date: Tue, 10 Nov 2026 16:26:07 -0500
Subject: [PATCH 1/3] [AMDGPU] Fix monitor-sleep duration validation on GFX12.5

On GFX12.5, s_monitor_sleep uses only seven bits for the duration.

PR #232561 corrected the fallback for unsupported sleep forever to
127, but that path only handles operands with bit 15 set. Ordinary
durations such as 128 and 200 remained unchecked.

Reject reserved duration bits in builtin calls and assembly, and clamp
invalid durations from direct IR to 127. Model the duration restriction
separately from sleep-forever support so valid sleep-forever operands
remain accepted on targets that support them.
---
 clang/lib/Basic/Targets/AMDGPU.cpp            | 12 +++++
 clang/lib/Sema/SemaAMDGPU.cpp                 | 18 +++++++
 .../SemaCUDA/amdgpu-monitor-sleep-range.cu    | 32 ++++++++++++
 .../builtins-amdgcn-error-gfx1250-param.cl    | 10 ++++
 .../Target/AMDGPU/AMDGPULowerIntrinsics.cpp   | 17 ++++---
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp      | 15 ++++--
 llvm/lib/Target/AMDGPU/GCNFeatures.td         |  7 +++
 .../AMDGPU/llvm.amdgcn.s.monitor.sleep.ll     | 50 ++++++++++++++++++-
 llvm/test/MC/AMDGPU/gfx1250_asm_sopp.s        |  4 +-
 .../MC/AMDGPU/monitor-sleep-duration-err.s    | 27 ++++++++++
 llvm/test/MC/AMDGPU/monitor-sleep-forever.s   | 20 ++++++++
 11 files changed, 197 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/SemaCUDA/amdgpu-monitor-sleep-range.cu
 create mode 100644 llvm/test/MC/AMDGPU/monitor-sleep-duration-err.s
 create mode 100644 llvm/test/MC/AMDGPU/monitor-sleep-forever.s

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index c3e6f8bbcafa8a..de077627d337d8 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -181,6 +181,18 @@ bool AMDGPUTargetInfo::initFeatureMap(
     return false;
   }
 
+  // The target parser does not expose these backend features to Sema.
+  if (getTriple().isAMDGCN()) {
+    llvm::AMDGPU::GPUKind Kind =
+        CPU.empty() ? getGPUKindFromSubArch(getTriple().getSubArch())
+                    : parseArchAMDGCN(CPU);
+    if (Kind == GK_GFX1250 || Kind == GK_GFX1250_STRICT)
+      Features.insert({"no-sleep-forever", true});
+    if (Kind == GK_GFX1250 || Kind == GK_GFX1250_STRICT || Kind == GK_GFX1251 ||
+        Kind == GK_GFX12_5_GENERIC)
+      Features.insert({"monitor-sleep-7-bit-duration", true});
+  }
+
   return true;
 }
 
diff --git a/clang/lib/Sema/SemaAMDGPU.cpp b/clang/lib/Sema/SemaAMDGPU.cpp
index 913c1bfdb30e0b..f639e40eeba959 100644
--- a/clang/lib/Sema/SemaAMDGPU.cpp
+++ b/clang/lib/Sema/SemaAMDGPU.cpp
@@ -169,6 +169,24 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(const TargetInfo &TI,
   case AMDGPU::BI__builtin_amdgcn_s_setreg:
     return SemaRef.BuiltinConstantArgRange(TheCall, /*ArgNum=*/0, /*Low=*/0,
                                            /*High=*/UINT16_MAX);
+  case AMDGPU::BI__builtin_amdgcn_s_monitor_sleep: {
+    bool Has7BitDuration = Builtin::evaluateRequiredTargetFeatures(
+        "monitor-sleep-7-bit-duration", CallerFeatureMap);
+    bool NoSleepForever = Builtin::evaluateRequiredTargetFeatures(
+        "no-sleep-forever", CallerFeatureMap);
+    if (!Has7BitDuration && !NoSleepForever)
+      return false;
+    Expr *ArgExpr = TheCall->getArg(0);
+    if (ArgExpr->isInstantiationDependent())
+      return false;
+    llvm::APSInt Sleep;
+    if (SemaRef.BuiltinConstantArg(TheCall, 0, Sleep))
+      return true;
+    // Bit 15 reaches Sema as the sign bit of the builtin's short argument.
+    int Low = !NoSleepForever && Sleep.isNegative() ? INT16_MIN : 0;
+    int High = Has7BitDuration ? Low + 127 : INT16_MAX;
+    return SemaRef.BuiltinConstantArgRange(TheCall, 0, Low, High);
+  }
   case AMDGPU::BI__builtin_amdgcn_flat_prefetch:
   case AMDGPU::BI__builtin_amdgcn_global_prefetch: {
     // Only th (bits 0-2, not 7), scope (bits 3-4) and nv (bit 5) may be set.
diff --git a/clang/test/SemaCUDA/amdgpu-monitor-sleep-range.cu b/clang/test/SemaCUDA/amdgpu-monitor-sleep-range.cu
new file mode 100644
index 00000000000000..8517935eeff6a9
--- /dev/null
+++ b/clang/test/SemaCUDA/amdgpu-monitor-sleep-range.cu
@@ -0,0 +1,32 @@
+// NOTE: Do not autogenerate. -verify checks target-specific diagnostics.
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgpu12.50-amd-amdhsa -fcuda-is-device -x hip -DNO_SLEEP_FOREVER -fsyntax-only -verify=range,forever %s
+// RUN: %clang_cc1 -triple amdgpu12.50s-amd-amdhsa -fcuda-is-device -x hip -DNO_SLEEP_FOREVER -fsyntax-only -verify=range,forever %s
+// RUN: %clang_cc1 -triple amdgpu12.51-amd-amdhsa -fcuda-is-device -x hip -fsyntax-only -verify=range,negative %s
+// RUN: %clang_cc1 -triple amdgpu12.50-amd-amdhsa -target-feature -no-sleep-forever -fcuda-is-device -x hip -fsyntax-only -verify=range,negative %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple amdgpu12.50-amd-amdhsa -x hip -DNO_SLEEP_FOREVER -fsyntax-only -verify=host %s
+// RUN: %clang_cc1 -triple amdgpu12.5-amd-amdhsa -fcuda-is-device -x hip -fsyntax-only -verify=range,negative %s
+// host-no-diagnostics
+
+#include "Inputs/cuda.h"
+
+__device__ void monitor_sleep_range() {
+  __builtin_amdgcn_s_monitor_sleep(0);
+  __builtin_amdgcn_s_monitor_sleep(127);
+  __builtin_amdgcn_s_monitor_sleep(128); // range-error {{argument value 128 is outside the valid range [0, 127]}}
+  __builtin_amdgcn_s_monitor_sleep(200); // range-error {{argument value 200 is outside the valid range [0, 127]}}
+  __builtin_amdgcn_s_monitor_sleep(32767); // range-error {{argument value 32767 is outside the valid range [0, 127]}}
+#ifdef NO_SLEEP_FOREVER
+  __builtin_amdgcn_s_monitor_sleep(-32768); // forever-error {{argument value -32768 is outside the valid range [0, 127]}}
+#else
+  __builtin_amdgcn_s_monitor_sleep(-32768);
+  __builtin_amdgcn_s_monitor_sleep(-32641);
+  __builtin_amdgcn_s_monitor_sleep(-32640); // negative-error {{argument value -32640 is outside the valid range [-32768, -32641]}}
+  __builtin_amdgcn_s_monitor_sleep(-1); // negative-error {{argument value -1 is outside the valid range [-32768, -32641]}}
+#endif
+}
+
+template <short Duration> __device__ void monitor_sleep_template() {
+  __builtin_amdgcn_s_monitor_sleep(Duration);
+}
+template __device__ void monitor_sleep_template<127>();
diff --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
index 75b0bec29baffa..ebef28f6fe77c6 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
@@ -1,5 +1,7 @@
+// NOTE: Do not autogenerate. -verify checks target-specific diagnostics.
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgpu12.50-- -verify -S -o - %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx1250-strict -verify -S -o - %s
 
 typedef unsigned int uint;
 typedef unsigned short int ushort;
@@ -36,6 +38,14 @@ void test_s_monitor_sleep(short a) {
   __builtin_amdgcn_s_monitor_sleep(a); // expected-error {{'__builtin_amdgcn_s_monitor_sleep' must be a constant integer}}
 }
 
+void test_s_monitor_sleep_range() {
+  __builtin_amdgcn_s_monitor_sleep(0);
+  __builtin_amdgcn_s_monitor_sleep(127);
+  __builtin_amdgcn_s_monitor_sleep(128); // expected-error {{argument value 128 is outside the valid range}}
+  __builtin_amdgcn_s_monitor_sleep(200); // expected-error {{argument value 200 is outside the valid range}}
+  __builtin_amdgcn_s_monitor_sleep(0x7fff); // expected-error {{argument value 32767 is outside the valid range}}
+}
+
 void test_s_wait_asynccnt(short a) {
   __builtin_amdgcn_s_wait_asynccnt(a); // expected-error {{'__builtin_amdgcn_s_wait_asynccnt' must be a constant integer}}
 }
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
index 1403b5b3fc6995..2f18eabb364343 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
@@ -248,17 +248,18 @@ bool AMDGPULowerIntrinsicsImpl::visitMonitorSleep(IntrinsicInst &I) {
   assert(I.getIntrinsicID() == Intrinsic::amdgcn_s_monitor_sleep);
 
   const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(*I.getFunction());
-  if (!ST.hasNoSleepForever())
-    return false;
-
-  int Sleep = cast<ConstantInt>(I.getArgOperand(0))->getSExtValue();
-  if (!(Sleep & 0x8000))
+  unsigned Sleep = cast<ConstantInt>(I.getArgOperand(0))->getZExtValue();
+  unsigned NewSleep;
+  if (ST.hasNoSleepForever() && (Sleep & 0x8000)) {
+    NewSleep = 127;
+  } else if (ST.hasMonitorSleep7BitDuration() && (Sleep & 0x7f80)) {
+    NewSleep = (Sleep & 0x8000) | 127;
+  } else {
     return false;
+  }
 
   IRBuilder<> B(&I);
-  Value *NewSleep = B.getInt16(127); // Maximum
-  I.setArgOperand(0, NewSleep);
-
+  I.setArgOperand(0, B.getInt16(NewSleep));
   return true;
 }
 
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 8ee55807ebb4b5..1505454d274820 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -5554,16 +5554,25 @@ bool AMDGPUAsmParser::validateWMMA(const MCInst &Inst,
 bool AMDGPUAsmParser::validateMonitorSleep(const MCInst &Inst,
                                            const OperandVector &Operands) {
   unsigned Opc = Inst.getOpcode();
-  if (Opc != AMDGPU::S_MONITOR_SLEEP_gfx12 ||
-      !getSTI().hasFeature(AMDGPU::FeatureNoSleepForever))
+  if (Opc != AMDGPU::S_MONITOR_SLEEP_gfx12)
     return true;
 
   int ImmIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::simm16);
-  if (Inst.getOperand(ImmIdx).getImm() & 0x8000) {
+  int64_t Sleep = Inst.getOperand(ImmIdx).getImm();
+  // Accept the sign-extended spelling emitted for negative i16 operands.
+  if (isUInt<32>(Sleep) && isInt<16>(SignExtend64<32>(Sleep)))
+    Sleep = SignExtend64<32>(Sleep);
+  if (getSTI().hasFeature(AMDGPU::FeatureNoSleepForever) && (Sleep & 0x8000)) {
     Error(getOperandLoc(Operands, ImmIdx),
           "sleep forever is unsuported on the target");
     return false;
   }
+  if (getSTI().hasFeature(AMDGPU::FeatureMonitorSleep7BitDuration) &&
+      (Sleep < INT16_MIN || Sleep > UINT16_MAX || (Sleep & 0x7f80))) {
+    Error(getOperandLoc(Operands, ImmIdx),
+          "sleep duration must be in range [0, 127] on this target");
+    return false;
+  }
 
   return true;
 }
diff --git a/llvm/lib/Target/AMDGPU/GCNFeatures.td b/llvm/lib/Target/AMDGPU/GCNFeatures.td
index 313f67ea31e22f..b59d1af6017b66 100644
--- a/llvm/lib/Target/AMDGPU/GCNFeatures.td
+++ b/llvm/lib/Target/AMDGPU/GCNFeatures.td
@@ -1690,6 +1690,12 @@ defm NeedsAligned2addrDS : AMDGPUSubtargetFeature<"needs-aligned-2addr-lds",
   /*GenPredicate=*/1
 >;
 
+defm MonitorSleep7BitDuration : AMDGPUSubtargetFeature<
+  "monitor-sleep-7-bit-duration",
+  "s_monitor_sleep uses a 7-bit duration",
+  /*GenPredicate=*/0
+>;
+
 defm NoSleepForever : AMDGPUSubtargetFeature<"no-sleep-forever",
   "s_monitor_sleep should not use sleep_forever",
   /*GenPredicate=*/1
@@ -2493,6 +2499,7 @@ def FeatureISAVersion12 : FeatureSet<
 
 def FeatureISAVersion12_50_Common : FeatureSet<
   [FeatureGFX12,
+   FeatureMonitorSleep7BitDuration,
    FeatureGFX1250Insts,
    FeatureBackOffBarrier,
    FeatureRequiresAlignedVGPRs,
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.monitor.sleep.ll b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.monitor.sleep.ll
index 9a56b8655962a7..67966843c1edae 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.monitor.sleep.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.monitor.sleep.ll
@@ -1,7 +1,16 @@
+; NOTE: Do not autogenerate. Full function checks obscure the target-dependent immediate.
 ; RUN: llc -global-isel=0 -mtriple=amdgpu12.50 < %s | FileCheck --check-prefixes=GCN,GFX1250 %s
-; RUN: llc -global-isel=1 -mtriple=amdgpu12.50 < %s | FileCheck --check-prefixes=GCN,GFX1250 %s
+; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu12.50 < %s | FileCheck --check-prefixes=GCN,GFX1250 %s
+; RUN: llc -global-isel=0 -mtriple=amdgpu12.50s < %s | FileCheck --check-prefixes=GCN,GFX1250 %s
+; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu12.50s < %s | FileCheck --check-prefixes=GCN,GFX1250 %s
 ; RUN: llc -global-isel=0 -mtriple=amdgpu12.51 < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
-; RUN: llc -global-isel=1 -mtriple=amdgpu12.51 < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
+; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu12.51 < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
+
+; RUN: llc -global-isel=0 -mtriple=amdgpu12.50 -mattr=-no-sleep-forever < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
+; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu12.50 -mattr=-no-sleep-forever < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
+
+; RUN: llc -global-isel=0 -mtriple=amdgpu12.5 < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
+; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu12.5 < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
 
 declare void @llvm.amdgcn.s.monitor.sleep(i16)
 
@@ -12,6 +21,27 @@ define amdgpu_ps void @test_monitor_sleep_1() {
   ret void
 }
 
+; GCN-LABEL: {{^}}test_monitor_sleep_127:
+; GCN: s_monitor_sleep 0x7f
+define amdgpu_ps void @test_monitor_sleep_127() {
+  call void @llvm.amdgcn.s.monitor.sleep(i16 127)
+  ret void
+}
+
+; GCN-LABEL: {{^}}test_monitor_sleep_128:
+; GCN: s_monitor_sleep 0x7f
+define amdgpu_ps void @test_monitor_sleep_128() {
+  call void @llvm.amdgcn.s.monitor.sleep(i16 128)
+  ret void
+}
+
+; GCN-LABEL: {{^}}test_monitor_sleep_200:
+; GCN: s_monitor_sleep 0x7f
+define amdgpu_ps void @test_monitor_sleep_200() {
+  call void @llvm.amdgcn.s.monitor.sleep(i16 200)
+  ret void
+}
+
 ; FIXME: 0x8000 would look better
 
 ; GCN-LABEL: {{^}}test_monitor_sleep_forever:
@@ -21,3 +51,19 @@ define amdgpu_ps void @test_monitor_sleep_forever() {
   call void @llvm.amdgcn.s.monitor.sleep(i16 32768)
   ret void
 }
+
+; GCN-LABEL: {{^}}test_monitor_sleep_forever_max_duration:
+; GFX1250: s_monitor_sleep 0x7f
+; GFX1251: s_monitor_sleep 0xffff807f
+define amdgpu_ps void @test_monitor_sleep_forever_max_duration() {
+  call void @llvm.amdgcn.s.monitor.sleep(i16 32895)
+  ret void
+}
+
+; GCN-LABEL: {{^}}test_monitor_sleep_forever_reserved:
+; GFX1250: s_monitor_sleep 0x7f
+; GFX1251: s_monitor_sleep 0xffff807f
+define amdgpu_ps void @test_monitor_sleep_forever_reserved() {
+  call void @llvm.amdgcn.s.monitor.sleep(i16 -1)
+  ret void
+}
diff --git a/llvm/test/MC/AMDGPU/gfx1250_asm_sopp.s b/llvm/test/MC/AMDGPU/gfx1250_asm_sopp.s
index 4a94d9063b5c0c..6e72cd629e1a28 100644
--- a/llvm/test/MC/AMDGPU/gfx1250_asm_sopp.s
+++ b/llvm/test/MC/AMDGPU/gfx1250_asm_sopp.s
@@ -54,9 +54,9 @@ s_monitor_sleep 1
 // GFX12-ERR: :[[@LINE-1]]:1: error: instruction not supported on this GPU (gfx1200): s_monitor_sleep
 // GFX1250: s_monitor_sleep 1                       ; encoding: [0x01,0x00,0x84,0xbf]
 
-s_monitor_sleep 0x2000
+s_monitor_sleep 0x7f
 // GFX12-ERR: :[[@LINE-1]]:1: error: instruction not supported on this GPU (gfx1200): s_monitor_sleep
-// GFX1250: s_monitor_sleep 0x2000                  ; encoding: [0x00,0x20,0x84,0xbf]
+// GFX1250: s_monitor_sleep 0x7f                    ; encoding: [0x7f,0x00,0x84,0xbf]
 
 s_monitor_sleep 0
 // GFX12-ERR: :[[@LINE-1]]:1: error: instruction not supported on this GPU (gfx1200): s_monitor_sleep
diff --git a/llvm/test/MC/AMDGPU/monitor-sleep-duration-err.s b/llvm/test/MC/AMDGPU/monitor-sleep-duration-err.s
new file mode 100644
index 00000000000000..5aa4d39343c313
--- /dev/null
+++ b/llvm/test/MC/AMDGPU/monitor-sleep-duration-err.s
@@ -0,0 +1,27 @@
+// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --unique --sort --version 6
+// RUN: not llvm-mc -triple=amdgpu12.5 -filetype=null %s 2>&1 | FileCheck --check-prefixes=ERR,FOREVER --implicit-check-not=error: -strict-whitespace %s
+
+// RUN: not llvm-mc -triple=amdgpu12.50 -filetype=null %s 2>&1 | FileCheck --check-prefixes=ERR,NO-FOREVER --implicit-check-not=error: -strict-whitespace %s
+// RUN: not llvm-mc -triple=amdgpu12.50s -filetype=null %s 2>&1 | FileCheck --check-prefixes=ERR,NO-FOREVER --implicit-check-not=error: -strict-whitespace %s
+// RUN: not llvm-mc -triple=amdgpu12.51 -filetype=null %s 2>&1 | FileCheck --check-prefixes=ERR,FOREVER --implicit-check-not=error: -strict-whitespace %s
+// RUN: not llvm-mc -triple=amdgpu12.50 -mattr=-no-sleep-forever -filetype=null %s 2>&1 | FileCheck --check-prefixes=ERR,FOREVER --implicit-check-not=error: -strict-whitespace %s
+
+s_monitor_sleep -1
+// FOREVER: :[[@LINE-1]]:17: error: sleep duration must be in range [0, 127] on this target
+// NO-FOREVER: :[[@LINE-2]]:17: error: sleep forever is unsuported on the target
+
+s_monitor_sleep 0x10000
+// ERR: :[[@LINE-1]]:17: error: sleep duration must be in range [0, 127] on this target
+
+s_monitor_sleep 0x7fff
+// ERR: :[[@LINE-1]]:17: error: sleep duration must be in range [0, 127] on this target
+
+s_monitor_sleep 0x80
+// ERR: :[[@LINE-1]]:17: error: sleep duration must be in range [0, 127] on this target
+
+s_monitor_sleep 0x8080
+// FOREVER: :[[@LINE-1]]:17: error: sleep duration must be in range [0, 127] on this target
+// NO-FOREVER: :[[@LINE-2]]:17: error: sleep forever is unsuported on the target
+
+s_monitor_sleep 0xc8
+// ERR: :[[@LINE-1]]:17: error: sleep duration must be in range [0, 127] on this target
diff --git a/llvm/test/MC/AMDGPU/monitor-sleep-forever.s b/llvm/test/MC/AMDGPU/monitor-sleep-forever.s
new file mode 100644
index 00000000000000..c2f52a8af7b105
--- /dev/null
+++ b/llvm/test/MC/AMDGPU/monitor-sleep-forever.s
@@ -0,0 +1,20 @@
+// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --version 6
+// RUN: llvm-mc -triple=amdgpu12.51 -show-encoding %s | FileCheck %s
+// RUN: llvm-mc -triple=amdgpu12.50 -mattr=-no-sleep-forever -show-encoding %s | FileCheck %s
+// RUN: llvm-mc -triple=amdgpu12.50s -mattr=-no-sleep-forever -show-encoding %s | FileCheck %s
+
+// RUN: llvm-mc -triple=amdgpu12.5 -show-encoding %s | FileCheck %s
+
+s_monitor_sleep 0x8000
+// CHECK: s_monitor_sleep 0x8000                  ; encoding: [0x00,0x80,0x84,0xbf]
+s_monitor_sleep 0x807f
+// CHECK: s_monitor_sleep 0x807f                  ; encoding: [0x7f,0x80,0x84,0xbf]
+s_monitor_sleep -32768
+// CHECK: s_monitor_sleep 0xffff8000              ; encoding: [0x00,0x80,0x84,0xbf]
+s_monitor_sleep -32641
+// CHECK: s_monitor_sleep 0xffff807f              ; encoding: [0x7f,0x80,0x84,0xbf]
+
+s_monitor_sleep 0xffff8000
+// CHECK: s_monitor_sleep 0xffff8000              ; encoding: [0x00,0x80,0x84,0xbf]
+s_monitor_sleep 0xffff807f
+// CHECK: s_monitor_sleep 0xffff807f              ; encoding: [0x7f,0x80,0x84,0xbf]

>From c45d07a0aa9238d37ed46f1c47e686b89aafe0c3 Mon Sep 17 00:00:00 2001
From: Yaxun Liu <yaxun.liu at amd.com>
Date: Wed, 11 Nov 2026 12:43:39 +0000
Subject: [PATCH 2/3] [AMDGPU] Address monitor-sleep review feedback

Expose the monitor-sleep features through the shared frontend feature table
and remove manual architecture parsing. Check the extracted duration
against its target range, with the sleep-forever bit handled separately.

Reject invalid durations in target instruction verification for both
pseudo and encoded monitor-sleep instructions. Preserve the existing
sleep-forever fallback and the wider durations supported by GFX13.
Add direct-IR and MIR coverage for rejection and valid boundaries.
---
 clang/lib/Basic/Targets/AMDGPU.cpp            | 12 ---
 .../builtins-amdgcn-error-gfx1250-param.cl    |  2 +-
 .../Target/AMDGPU/AMDGPULowerIntrinsics.cpp   | 17 ++--
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp      |  2 +-
 llvm/lib/Target/AMDGPU/GCNFeatures.td         |  3 +-
 llvm/lib/Target/AMDGPU/SIInstrInfo.cpp        | 20 +++++
 .../AMDGPU/llvm.amdgcn.s.monitor.sleep.ll     | 25 +-----
 .../CodeGen/AMDGPU/monitor-sleep-gfx13.ll     | 14 ++++
 .../AMDGPU/monitor-sleep-invalid-forever.ll   | 18 +++++
 .../CodeGen/AMDGPU/monitor-sleep-invalid.ll   | 25 ++++++
 .../CodeGen/AMDGPU/monitor-sleep-invalid.mir  | 77 +++++++++++++++++++
 11 files changed, 169 insertions(+), 46 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/monitor-sleep-gfx13.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid-forever.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.mir

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index de077627d337d8..c3e6f8bbcafa8a 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -181,18 +181,6 @@ bool AMDGPUTargetInfo::initFeatureMap(
     return false;
   }
 
-  // The target parser does not expose these backend features to Sema.
-  if (getTriple().isAMDGCN()) {
-    llvm::AMDGPU::GPUKind Kind =
-        CPU.empty() ? getGPUKindFromSubArch(getTriple().getSubArch())
-                    : parseArchAMDGCN(CPU);
-    if (Kind == GK_GFX1250 || Kind == GK_GFX1250_STRICT)
-      Features.insert({"no-sleep-forever", true});
-    if (Kind == GK_GFX1250 || Kind == GK_GFX1250_STRICT || Kind == GK_GFX1251 ||
-        Kind == GK_GFX12_5_GENERIC)
-      Features.insert({"monitor-sleep-7-bit-duration", true});
-  }
-
   return true;
 }
 
diff --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
index ebef28f6fe77c6..3701d0d1639df2 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
@@ -1,7 +1,7 @@
 // NOTE: Do not autogenerate. -verify checks target-specific diagnostics.
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgpu12.50-- -verify -S -o - %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx1250-strict -verify -S -o - %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgpu12.50s-amd-amdhsa -verify -S -o - %s
 
 typedef unsigned int uint;
 typedef unsigned short int ushort;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
index 2f18eabb364343..1403b5b3fc6995 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerIntrinsics.cpp
@@ -248,18 +248,17 @@ bool AMDGPULowerIntrinsicsImpl::visitMonitorSleep(IntrinsicInst &I) {
   assert(I.getIntrinsicID() == Intrinsic::amdgcn_s_monitor_sleep);
 
   const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(*I.getFunction());
-  unsigned Sleep = cast<ConstantInt>(I.getArgOperand(0))->getZExtValue();
-  unsigned NewSleep;
-  if (ST.hasNoSleepForever() && (Sleep & 0x8000)) {
-    NewSleep = 127;
-  } else if (ST.hasMonitorSleep7BitDuration() && (Sleep & 0x7f80)) {
-    NewSleep = (Sleep & 0x8000) | 127;
-  } else {
+  if (!ST.hasNoSleepForever())
+    return false;
+
+  int Sleep = cast<ConstantInt>(I.getArgOperand(0))->getSExtValue();
+  if (!(Sleep & 0x8000))
     return false;
-  }
 
   IRBuilder<> B(&I);
-  I.setArgOperand(0, B.getInt16(NewSleep));
+  Value *NewSleep = B.getInt16(127); // Maximum
+  I.setArgOperand(0, NewSleep);
+
   return true;
 }
 
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 1505454d274820..42898e8b5d59a6 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -5568,7 +5568,7 @@ bool AMDGPUAsmParser::validateMonitorSleep(const MCInst &Inst,
     return false;
   }
   if (getSTI().hasFeature(AMDGPU::FeatureMonitorSleep7BitDuration) &&
-      (Sleep < INT16_MIN || Sleep > UINT16_MAX || (Sleep & 0x7f80))) {
+      (Sleep < INT16_MIN || Sleep > UINT16_MAX || (Sleep & 0x7fff) > 127)) {
     Error(getOperandLoc(Operands, ImmIdx),
           "sleep duration must be in range [0, 127] on this target");
     return false;
diff --git a/llvm/lib/Target/AMDGPU/GCNFeatures.td b/llvm/lib/Target/AMDGPU/GCNFeatures.td
index b59d1af6017b66..b70c244e6a0bff 100644
--- a/llvm/lib/Target/AMDGPU/GCNFeatures.td
+++ b/llvm/lib/Target/AMDGPU/GCNFeatures.td
@@ -2847,7 +2847,8 @@ def AMDGPUFrontendVisibleFeatures {
   FeatureGFX940Insts, FeatureGFX950Insts, FeatureGFX9Insts,
   FeatureGWS, FeatureImageInsts, FeatureLdsBarrierArriveAtomic,
   FeatureLerpInst, FeatureLoadMonitorInsts, FeatureMAIInsts, FeatureMcastLoadInsts,
-  FeatureMqsadInsts, FeatureMqsadPkInsts, FeatureMsadInsts,
+  FeatureMonitorSleep7BitDuration, FeatureMqsadInsts, FeatureMqsadPkInsts,
+  FeatureMsadInsts, FeatureNoSleepForever,
   FeatureOCPFP8ConversionInsts, FeaturePermlane16Insts, FeaturePermlane16Swap,
   FeaturePermlane32Swap, FeaturePkAddMinMaxInsts, FeaturePrngInst,
   FeatureQsadInsts, FeatureSMemRealTime, FeatureSMemTimeInst,
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 1e75f208608904..235401f4ace6a6 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -5605,6 +5605,26 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
     return false;
   }
 
+  if (Opcode == AMDGPU::S_MONITOR_SLEEP ||
+      Opcode == AMDGPU::S_MONITOR_SLEEP_gfx12 ||
+      Opcode == AMDGPU::S_MONITOR_SLEEP_gfx13) {
+    const MachineOperand &Sleep = MI.getOperand(0);
+    if (!Sleep.isImm()) {
+      ErrInfo = "sleep duration must be an immediate";
+      return false;
+    }
+    int64_t Value = Sleep.getImm();
+    if (ST.hasNoSleepForever() && (Value & 0x8000)) {
+      ErrInfo = "sleep forever is unsupported on this target";
+      return false;
+    }
+    if (ST.hasMonitorSleep7BitDuration() &&
+        ((!isInt<16>(Value) && !isUInt<16>(Value)) || (Value & 0x7fff) > 127)) {
+      ErrInfo = "sleep duration must be in range [0, 127] on this target";
+      return false;
+    }
+  }
+
   if (MI.isInlineAsm()) {
     // Verify register classes for inlineasm constraints.
     for (unsigned I = InlineAsm::MIOp_FirstOperand, E = MI.getNumOperands();
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.monitor.sleep.ll b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.monitor.sleep.ll
index 67966843c1edae..c9119129b9ff06 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.monitor.sleep.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.monitor.sleep.ll
@@ -9,6 +9,9 @@
 ; RUN: llc -global-isel=0 -mtriple=amdgpu12.50 -mattr=-no-sleep-forever < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
 ; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu12.50 -mattr=-no-sleep-forever < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
 
+; RUN: llc -global-isel=0 -mtriple=amdgpu13 < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
+; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu13 < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
+
 ; RUN: llc -global-isel=0 -mtriple=amdgpu12.5 < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
 ; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu12.5 < %s | FileCheck --check-prefixes=GCN,GFX1251 %s
 
@@ -28,20 +31,6 @@ define amdgpu_ps void @test_monitor_sleep_127() {
   ret void
 }
 
-; GCN-LABEL: {{^}}test_monitor_sleep_128:
-; GCN: s_monitor_sleep 0x7f
-define amdgpu_ps void @test_monitor_sleep_128() {
-  call void @llvm.amdgcn.s.monitor.sleep(i16 128)
-  ret void
-}
-
-; GCN-LABEL: {{^}}test_monitor_sleep_200:
-; GCN: s_monitor_sleep 0x7f
-define amdgpu_ps void @test_monitor_sleep_200() {
-  call void @llvm.amdgcn.s.monitor.sleep(i16 200)
-  ret void
-}
-
 ; FIXME: 0x8000 would look better
 
 ; GCN-LABEL: {{^}}test_monitor_sleep_forever:
@@ -59,11 +48,3 @@ define amdgpu_ps void @test_monitor_sleep_forever_max_duration() {
   call void @llvm.amdgcn.s.monitor.sleep(i16 32895)
   ret void
 }
-
-; GCN-LABEL: {{^}}test_monitor_sleep_forever_reserved:
-; GFX1250: s_monitor_sleep 0x7f
-; GFX1251: s_monitor_sleep 0xffff807f
-define amdgpu_ps void @test_monitor_sleep_forever_reserved() {
-  call void @llvm.amdgcn.s.monitor.sleep(i16 -1)
-  ret void
-}
diff --git a/llvm/test/CodeGen/AMDGPU/monitor-sleep-gfx13.ll b/llvm/test/CodeGen/AMDGPU/monitor-sleep-gfx13.ll
new file mode 100644
index 00000000000000..92de1c9582fbf1
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/monitor-sleep-gfx13.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -global-isel=0 -mtriple=amdgpu13 < %s | FileCheck %s
+; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu13 < %s | FileCheck %s
+
+declare void @llvm.amdgcn.s.monitor.sleep(i16)
+
+define amdgpu_ps void @sleep_duration() {
+; CHECK-LABEL: sleep_duration:
+; CHECK:       ; %bb.0:
+; CHECK-NEXT:    s_monitor_sleep 0x1234
+; CHECK-NEXT:    s_endpgm
+  call void @llvm.amdgcn.s.monitor.sleep(i16 4660)
+  ret void
+}
diff --git a/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid-forever.ll b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid-forever.ll
new file mode 100644
index 00000000000000..1cc9feb06ba452
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid-forever.ll
@@ -0,0 +1,18 @@
+; NOTE: Do not autogenerate. Check diagnostics for reserved duration bits with sleep forever enabled.
+; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
+
+; CHECK: error: Illegal instruction detected: sleep duration must be in range [0, 127] on this target
+; CHECK: error: Illegal instruction detected: sleep duration must be in range [0, 127] on this target
+
+declare void @llvm.amdgcn.s.monitor.sleep(i16)
+
+define amdgpu_ps void @sleep_forever_128() {
+  call void @llvm.amdgcn.s.monitor.sleep(i16 -32640)
+  ret void
+}
+
+define amdgpu_ps void @sleep_forever_reserved() {
+  call void @llvm.amdgcn.s.monitor.sleep(i16 -1)
+  ret void
+}
diff --git a/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.ll b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.ll
new file mode 100644
index 00000000000000..18314d88a9bdb8
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.ll
@@ -0,0 +1,25 @@
+; NOTE: Do not autogenerate. Check the diagnostic from normal instruction emission.
+; The target verifier must reject direct IR even when MachineVerifier is disabled.
+; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.50 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.50 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.50s < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.50s < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.5 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.5 < %s 2>&1 | FileCheck %s
+
+; CHECK: error: Illegal instruction detected: sleep duration must be in range [0, 127] on this target
+; CHECK: error: Illegal instruction detected: sleep duration must be in range [0, 127] on this target
+
+declare void @llvm.amdgcn.s.monitor.sleep(i16)
+
+define amdgpu_ps void @sleep_128() {
+  call void @llvm.amdgcn.s.monitor.sleep(i16 128)
+  ret void
+}
+
+define amdgpu_ps void @sleep_200() {
+  call void @llvm.amdgcn.s.monitor.sleep(i16 200)
+  ret void
+}
diff --git a/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.mir b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.mir
new file mode 100644
index 00000000000000..8f2acb416713c4
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.mir
@@ -0,0 +1,77 @@
+# NOTE: Do not autogenerate. Check the target's MachineVerifier diagnostics.
+# RUN: split-file %s %t
+# RUN: llc -mtriple=amdgpu12.50 -run-pass=none -verify-machineinstrs -filetype=null %t/valid-duration.mir
+# RUN: llc -mtriple=amdgpu12.51 -run-pass=none -verify-machineinstrs -filetype=null %t/valid-duration.mir
+# RUN: llc -mtriple=amdgpu12.51 -run-pass=none -verify-machineinstrs -filetype=null %t/valid-forever.mir
+# RUN: llc -mtriple=amdgpu13 -run-pass=none -verify-machineinstrs -filetype=null %t/gfx13.mir
+# RUN: not --crash llc -mtriple=amdgpu12.51 -run-pass=none -verify-machineinstrs -filetype=null %t/duration.mir 2>&1 | FileCheck %s --check-prefix=DURATION
+# RUN: not --crash llc -mtriple=amdgpu12.50 -run-pass=none -verify-machineinstrs -filetype=null %t/forever.mir 2>&1 | FileCheck %s --check-prefix=FOREVER
+
+# DURATION: Bad machine code: sleep duration must be in range [0, 127] on this target
+# DURATION: S_MONITOR_SLEEP 200
+# DURATION: Bad machine code: sleep duration must be in range [0, 127] on this target
+# DURATION: S_MONITOR_SLEEP 65536
+# DURATION: Bad machine code: sleep duration must be in range [0, 127] on this target
+# DURATION: S_MONITOR_SLEEP_gfx12 200
+# DURATION: Bad machine code: sleep duration must be in range [0, 127] on this target
+# DURATION: S_MONITOR_SLEEP_gfx12 65536
+# FOREVER: Bad machine code: sleep forever is unsupported on this target
+# FOREVER: S_MONITOR_SLEEP 32768
+# FOREVER: Bad machine code: sleep forever is unsupported on this target
+# FOREVER: S_MONITOR_SLEEP_gfx12 32768
+
+#--- duration.mir
+---
+name: sleep_200
+body: |
+  bb.0:
+    S_MONITOR_SLEEP 200
+    S_MONITOR_SLEEP 65536
+    S_MONITOR_SLEEP_gfx12 200
+    S_MONITOR_SLEEP_gfx12 65536
+    S_ENDPGM 0
+...
+
+#--- forever.mir
+---
+name: sleep_forever
+body: |
+  bb.0:
+    S_MONITOR_SLEEP 32768
+    S_MONITOR_SLEEP_gfx12 32768
+    S_ENDPGM 0
+...
+
+#--- valid-duration.mir
+---
+name: valid_duration
+body: |
+  bb.0:
+    S_MONITOR_SLEEP 0
+    S_MONITOR_SLEEP 127
+    S_MONITOR_SLEEP_gfx12 0
+    S_MONITOR_SLEEP_gfx12 127
+    S_ENDPGM 0
+...
+
+#--- valid-forever.mir
+---
+name: valid_forever
+body: |
+  bb.0:
+    S_MONITOR_SLEEP_gfx12 32768
+    S_MONITOR_SLEEP_gfx12 32895
+    S_MONITOR_SLEEP_gfx12 -32768
+    S_MONITOR_SLEEP_gfx12 -32641
+    S_ENDPGM 0
+...
+
+#--- gfx13.mir
+---
+name: wider_duration
+body: |
+  bb.0:
+    S_MONITOR_SLEEP 4660
+    S_MONITOR_SLEEP_gfx13 4660
+    S_ENDPGM 0
+...

>From 0376f61e23c9b3ab3020777b554a9aa95a17545c Mon Sep 17 00:00:00 2001
From: Yaxun Liu <yaxun.liu at amd.com>
Date: Wed, 11 Nov 2026 21:02:09 +0000
Subject: [PATCH 3/3] [AMDGPU] Simplify monitor-sleep tests

Remove redundant GlobalISel abort options and intrinsic declarations.
Clarify that disabling MachineVerifier tests duration checks during code
emission. Preserve the existing inputs and assertions.
---
 llvm/test/CodeGen/AMDGPU/monitor-sleep-gfx13.ll    |  4 +---
 .../AMDGPU/monitor-sleep-invalid-forever.ll        |  4 +---
 llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.ll  | 14 ++++++--------
 3 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/llvm/test/CodeGen/AMDGPU/monitor-sleep-gfx13.ll b/llvm/test/CodeGen/AMDGPU/monitor-sleep-gfx13.ll
index 92de1c9582fbf1..413aee985c3024 100644
--- a/llvm/test/CodeGen/AMDGPU/monitor-sleep-gfx13.ll
+++ b/llvm/test/CodeGen/AMDGPU/monitor-sleep-gfx13.ll
@@ -1,8 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
 ; RUN: llc -global-isel=0 -mtriple=amdgpu13 < %s | FileCheck %s
-; RUN: llc -global-isel=1 -global-isel-abort=1 -mtriple=amdgpu13 < %s | FileCheck %s
-
-declare void @llvm.amdgcn.s.monitor.sleep(i16)
+; RUN: llc -global-isel=1 -mtriple=amdgpu13 < %s | FileCheck %s
 
 define amdgpu_ps void @sleep_duration() {
 ; CHECK-LABEL: sleep_duration:
diff --git a/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid-forever.ll b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid-forever.ll
index 1cc9feb06ba452..9d583e08953eaa 100644
--- a/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid-forever.ll
+++ b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid-forever.ll
@@ -1,12 +1,10 @@
 ; NOTE: Do not autogenerate. Check diagnostics for reserved duration bits with sleep forever enabled.
 ; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
-; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
 
 ; CHECK: error: Illegal instruction detected: sleep duration must be in range [0, 127] on this target
 ; CHECK: error: Illegal instruction detected: sleep duration must be in range [0, 127] on this target
 
-declare void @llvm.amdgcn.s.monitor.sleep(i16)
-
 define amdgpu_ps void @sleep_forever_128() {
   call void @llvm.amdgcn.s.monitor.sleep(i16 -32640)
   ret void
diff --git a/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.ll b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.ll
index 18314d88a9bdb8..34cd15a760115f 100644
--- a/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.ll
+++ b/llvm/test/CodeGen/AMDGPU/monitor-sleep-invalid.ll
@@ -1,19 +1,17 @@
-; NOTE: Do not autogenerate. Check the diagnostic from normal instruction emission.
-; The target verifier must reject direct IR even when MachineVerifier is disabled.
+; NOTE: Do not autogenerate. Check diagnostics rather than assembly.
+; Disable MachineVerifier to exercise the check during code emission.
 ; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.50 < %s 2>&1 | FileCheck %s
-; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.50 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -verify-machineinstrs=0 -mtriple=amdgpu12.50 < %s 2>&1 | FileCheck %s
 ; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.50s < %s 2>&1 | FileCheck %s
-; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.50s < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -verify-machineinstrs=0 -mtriple=amdgpu12.50s < %s 2>&1 | FileCheck %s
 ; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
-; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -verify-machineinstrs=0 -mtriple=amdgpu12.51 < %s 2>&1 | FileCheck %s
 ; RUN: not llc -global-isel=0 -verify-machineinstrs=0 -mtriple=amdgpu12.5 < %s 2>&1 | FileCheck %s
-; RUN: not llc -global-isel=1 -global-isel-abort=1 -verify-machineinstrs=0 -mtriple=amdgpu12.5 < %s 2>&1 | FileCheck %s
+; RUN: not llc -global-isel=1 -verify-machineinstrs=0 -mtriple=amdgpu12.5 < %s 2>&1 | FileCheck %s
 
 ; CHECK: error: Illegal instruction detected: sleep duration must be in range [0, 127] on this target
 ; CHECK: error: Illegal instruction detected: sleep duration must be in range [0, 127] on this target
 
-declare void @llvm.amdgcn.s.monitor.sleep(i16)
-
 define amdgpu_ps void @sleep_128() {
   call void @llvm.amdgcn.s.monitor.sleep(i16 128)
   ret void



More information about the cfe-commits mailing list