Skip to content

Conversation

@jwanggit86
Copy link
Contributor

The ds_gws_* instructions require gds as an operand. However, when nogds is given, it is treated the same as gds. This patch fixes this to disallow nogds.

@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Jun Wang (jwanggit86)

Changes

The ds_gws_* instructions require gds as an operand. However, when nogds is given, it is treated the same as gds. This patch fixes this to disallow nogds.


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

6 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp (+6)
  • (added) llvm/test/MC/AMDGPU/gfx10_asm_ds_err.s (+38)
  • (added) llvm/test/MC/AMDGPU/gfx11_asm_ds_err.s (+37)
  • (added) llvm/test/MC/AMDGPU/gfx7_asm_ds_err.s (+37)
  • (added) llvm/test/MC/AMDGPU/gfx8_asm_ds_err.s (+37)
  • (added) llvm/test/MC/AMDGPU/gfx9_asm_ds_err.s (+37)
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 09338c533fdf2..6a2b0c558da1e 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -7043,6 +7043,12 @@ ParseStatus AMDGPUAsmParser::parseNamedBit(StringRef Name,
   if (Name == "a16" && !hasA16())
     return Error(S, "a16 modifier is not supported on this GPU");
 
+  if (Bit == 0 && Name == "gds") {
+    StringRef Mnemo = ((AMDGPUOperand &)*Operands[0]).getToken();
+    if (Mnemo.starts_with("ds_gws"))
+      return Error(S, "nogds is not allowed");
+  }
+
   if (isGFX9() && ImmTy == AMDGPUOperand::ImmTyA16)
     ImmTy = AMDGPUOperand::ImmTyR128A16;
 
diff --git a/llvm/test/MC/AMDGPU/gfx10_asm_ds_err.s b/llvm/test/MC/AMDGPU/gfx10_asm_ds_err.s
new file mode 100644
index 0000000000000..dcf3f1be4139f
--- /dev/null
+++ b/llvm/test/MC/AMDGPU/gfx10_asm_ds_err.s
@@ -0,0 +1,38 @@
+// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx1010 -mattr=+wavefrontsize32 %s 2>&1 | FileCheck --implicit-check-not=error: %s
+// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx1010 -mattr=+wavefrontsize64 %s 2>&1 | FileCheck --implicit-check-not=error: %s
+
+ds_gws_sema_release_all nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_release_all offset:4660 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v0 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v0 offset:0 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v0 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v0 offset:4660 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p offset:0 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_barrier v0 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_barrier v0 offset:0 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
diff --git a/llvm/test/MC/AMDGPU/gfx11_asm_ds_err.s b/llvm/test/MC/AMDGPU/gfx11_asm_ds_err.s
new file mode 100644
index 0000000000000..c7c92fe51238a
--- /dev/null
+++ b/llvm/test/MC/AMDGPU/gfx11_asm_ds_err.s
@@ -0,0 +1,37 @@
+// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx1100 %s 2>&1 | FileCheck --implicit-check-not=error: %s
+
+ds_gws_barrier v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_barrier v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_release_all nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_release_all offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
diff --git a/llvm/test/MC/AMDGPU/gfx7_asm_ds_err.s b/llvm/test/MC/AMDGPU/gfx7_asm_ds_err.s
new file mode 100644
index 0000000000000..5596bf5b6ea30
--- /dev/null
+++ b/llvm/test/MC/AMDGPU/gfx7_asm_ds_err.s
@@ -0,0 +1,37 @@
+// RUN: not llvm-mc -triple=amdgcn -mcpu=bonaire %s 2>&1 | FileCheck --implicit-check-not=error: %s
+
+ds_gws_sema_release_all offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_release_all nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_barrier v255 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_barrier v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
diff --git a/llvm/test/MC/AMDGPU/gfx8_asm_ds_err.s b/llvm/test/MC/AMDGPU/gfx8_asm_ds_err.s
new file mode 100644
index 0000000000000..27df0b8eacf43
--- /dev/null
+++ b/llvm/test/MC/AMDGPU/gfx8_asm_ds_err.s
@@ -0,0 +1,37 @@
+// RUN: not llvm-mc -triple=amdgcn -mcpu=tonga %s 2>&1 | FileCheck --implicit-check-not=error: %s
+
+ds_gws_sema_release_all offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_release_all nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_barrier v255 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_barrier v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
diff --git a/llvm/test/MC/AMDGPU/gfx9_asm_ds_err.s b/llvm/test/MC/AMDGPU/gfx9_asm_ds_err.s
new file mode 100644
index 0000000000000..e9c71cc3d000c
--- /dev/null
+++ b/llvm/test/MC/AMDGPU/gfx9_asm_ds_err.s
@@ -0,0 +1,37 @@
+// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx900 %s 2>&1 | FileCheck --implicit-check-not=error: %s
+
+ds_gws_sema_release_all offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_release_all nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_init v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_v nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_br v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_sema_p nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_barrier v1 offset:65535 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed
+
+ds_gws_barrier v1 nogds
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: nogds is not allowed

@jwanggit86
Copy link
Contributor Author

jwanggit86 commented Nov 7, 2025

This is an alternative solution to PR 166438. In PR 166438, the problem is detected in post-parsing validation. Here the detection occurs earlier during parsing, so there's no need for post-parsing checking. I'd like to get reviewers' opinions on which one is preferred.

@shiltian
Copy link
Contributor

shiltian commented Nov 7, 2025

I think this one is better, since we don't construct the MCInst in the first place if there is anything wrong.


if (Bit == 0 && Name == "gds") {
StringRef Mnemo = ((AMDGPUOperand &)*Operands[0]).getToken();
if (Mnemo.starts_with("ds_gws"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be a lot better to operate off of a parsed opcode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If do the check after parsing, then it can only be done during validation, as in PR 166438.

@jwanggit86 jwanggit86 requested a review from arsenm November 7, 2025 18:41
The ds_gws_* instructions require gds as an operand. However, when
nogds is given, it is treated the same as gds. This patch fixes
this to disallow nogds.
@jwanggit86 jwanggit86 force-pushed the disallow-nogds-in-ds_gws-instructions-fix2 branch from 737dc4f to 03e23ed Compare November 11, 2025 00:28
@jwanggit86
Copy link
Contributor Author

I think this one is better, since we don't construct the MCInst in the first place if there is anything wrong.

Yes, I also think this is better because it skips instruction matching and construction of MCInst. Any other comments?

@jwanggit86 jwanggit86 merged commit 306f49a into llvm:main Nov 14, 2025
10 checks passed
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