[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:49 PDT 2025


================
@@ -2945,8 +2945,14 @@ bool isLegalSMRDEncodedUnsignedOffset(const MCSubtargetInfo &ST,
 
 bool isLegalSMRDEncodedSignedOffset(const MCSubtargetInfo &ST,
                                     int64_t EncodedOffset, bool IsBuffer) {
-  if (isGFX12Plus(ST))
+  if (isGFX12Plus(ST)) {
+          // GFX12+ S_BUFFER_*: InstOffset is signed 24, but must be positive (23-bit)
+      if (IsBuffer) {
+        constexpr const unsigned OffsetSize = 23;
+        return isUIntN(OffsetSize, EncodedOffset);
+      }
----------------
jayfoad wrote:

Indentation looks wrong here. Also this is simpler:
```suggestion
    if (IsBuffer && EncodedOffset < 0)
      return false;
```

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


More information about the llvm-commits mailing list