[llvm] [AMDGPU] Ensure positive InstOffset for buffer operations (PR #145504)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 02:04:50 PDT 2025


================
@@ -4551,10 +4552,15 @@ bool AMDGPUAsmParser::validateSMEMOffset(const MCInst &Inst,
       AMDGPU::isLegalSMRDEncodedSignedOffset(getSTI(), Offset, IsBuffer))
     return true;
 
-  Error(getSMEMOffsetLoc(Operands),
-        isGFX12Plus()          ? "expected a 24-bit signed offset"
-        : (isVI() || IsBuffer) ? "expected a 20-bit unsigned offset"
-                               : "expected a 21-bit signed offset");
+  // Generate appropriate error message based on generation and buffer type
+  if (isGFX12Plus() && IsBuffer)
+    Error(getSMEMOffsetLoc(Operands),
+          "expected a 23-bit positive offset for S_BUFFER ops");
+  else
+    Error(getSMEMOffsetLoc(Operands),
+          isGFX12Plus()          ? "expected a 24-bit signed offset"
+          : (isVI() || IsBuffer) ? "expected a 20-bit unsigned offset"
+                                 : "expected a 21-bit signed offset");
----------------
jayfoad wrote:

Please refactor to choose the correct error string first, and then have a single call to `Error`.

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


More information about the llvm-commits mailing list