-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AMDGPU] Ensure positive InstOffset for buffer operations #145504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[AMDGPU] Ensure positive InstOffset for buffer operations #145504
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mc @llvm/pr-subscribers-backend-amdgpu Author: Aleksandar Spasojevic (aleksandar-amd) ChangesGFX12+ buffer ops require positive InstOffset per AMD hardware spec. Modified assembler/disassembler to reject negative buffer offsets. Full diff: https://github.com/llvm/llvm-project/pull/145504.diff 4 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 30dcd6d81f16d..2f759eb2609f1 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -4464,12 +4464,13 @@ bool AMDGPUAsmParser::validateOffset(const MCInst &Inst,
return validateSMEMOffset(Inst, Operands);
const auto &Op = Inst.getOperand(OpNum);
+ // GFX12+ buffer ops: InstOffset is signed 24, but must be positive
if (isGFX12Plus() &&
(TSFlags & (SIInstrFlags::MUBUF | SIInstrFlags::MTBUF))) {
const unsigned OffsetSize = 24;
- if (!isIntN(OffsetSize, Op.getImm())) {
+ if (!isUIntN(OffsetSize - 1, Op.getImm())) {
Error(getFlatOffsetLoc(Operands),
- Twine("expected a ") + Twine(OffsetSize) + "-bit signed offset");
+ Twine("expected a ") + Twine(OffsetSize - 1) + "-bit positive offset for buffer ops");
return false;
}
} else {
@@ -4547,6 +4548,16 @@ bool AMDGPUAsmParser::validateSMEMOffset(const MCInst &Inst,
uint64_t Offset = Op.getImm();
bool IsBuffer = AMDGPU::getSMEMIsBuffer(Opcode);
+ // GFX12+ S_BUFFER_*: InstOffset is signed 24, but must be positive
+ if (isGFX12Plus() && IsBuffer) {
+ const unsigned OffsetSize = 24;
+ if (!isUIntN(OffsetSize, Offset)) {
+ Error(getSMEMOffsetLoc(Operands),
+ Twine("expected a ") + Twine(OffsetSize - 1) + "-bit positive offset for S_BUFFER ops");
+ return false;
+ }
+ return true;
+ }
if (AMDGPU::isLegalSMRDEncodedUnsignedOffset(getSTI(), Offset) ||
AMDGPU::isLegalSMRDEncodedSignedOffset(getSTI(), Offset, IsBuffer))
return true;
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index 07a4292ef28bc..567d3e4ab6203 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -803,6 +803,21 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
}
}
+ // Validate buffer offset for GFX12+ - must be positive
+ if ((MCII->get(MI.getOpcode()).TSFlags &
+ (SIInstrFlags::MTBUF | SIInstrFlags::MUBUF)) &&
+ AMDGPU::isGFX12Plus(STI)) {
+ int OffsetIdx =
+ AMDGPU::getNamedOperandIdx(MI.getOpcode(), AMDGPU::OpName::offset);
+ if (OffsetIdx != -1) {
+ uint32_t Imm = MI.getOperand(OffsetIdx).getImm();
+ int64_t SignedOffset = SignExtend64<24>(Imm);
+ if (SignedOffset < 0) {
+ return MCDisassembler::Fail;
+ }
+ }
+ }
+
if (MCII->get(MI.getOpcode()).TSFlags &
(SIInstrFlags::MTBUF | SIInstrFlags::MUBUF)) {
int SWZOpIdx =
diff --git a/llvm/test/MC/AMDGPU/gfx12_err.s b/llvm/test/MC/AMDGPU/gfx12_err.s
index 9ddb91e25afe6..89278feb43ac3 100644
--- a/llvm/test/MC/AMDGPU/gfx12_err.s
+++ b/llvm/test/MC/AMDGPU/gfx12_err.s
@@ -125,3 +125,261 @@ s_alloc_vgpr exec
s_alloc_vgpr vcc
// GFX12-ERR: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
+
+buffer_load_dword v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_dword v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_dwordx2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_dwordx3 v[0:2], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_dwordx4 v[0:3], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_short_d16 v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_format_d16_x v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_format_d16_xy v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_format_d16_xyz v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_format_d16_xyzw v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_short_d16_hi v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_format_d16_hi_x v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_sbyte_d16_hi v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_ubyte_d16_hi v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_sbyte_d16 v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_ubyte_d16 v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_sbyte v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_sshort v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_ubyte v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_load_ushort v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_byte v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_short v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_dword v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_dwordx2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_dwordx3 v[0:2], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_dwordx4 v[0:3], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_format_d16_x v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_format_d16_xy v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_format_d16_xyz v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_format_d16_xyzw v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_byte_d16_hi v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_short_d16_hi v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_store_format_d16_hi_x v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_add v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_add_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_and v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_and_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_cmpswap v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_cmpswap_x2 v[0:3], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_csub v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_dec v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_dec_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_inc v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_inc_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_fmax v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_smax v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_smax_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_umax v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_umax_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_fmin v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_smin v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_smin_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_umin v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_umin_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_or v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_or_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_sub v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_sub_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_swap v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_swap_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_xor v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+buffer_atomic_xor_x2 v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_load_format_d16_x v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_load_format_d16_xy v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_load_format_d16_xyz v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_load_format_d16_xyzw v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_load_format_x v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_load_format_xy v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_load_format_xyz v[0:2], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_load_format_xyzw v[0:3], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_store_format_d16_x v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_store_format_d16_xy v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_store_format_d16_xyz v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_store_format_d16_xyzw v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_store_format_x v0, off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_store_format_xy v[0:1], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_store_format_xyz v[0:2], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+tbuffer_store_format_xyzw v[0:3], off, s[4:7], s8 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for buffer ops
+
+s_buffer_load_b32 s5, s[4:7], s0 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops
+
+s_buffer_load_b64 s[10:11], s[4:7], s0 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops
+
+s_buffer_load_b96 s[20:22], s[4:7], s0 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops
+
+s_buffer_load_i8 s5, s[4:7], s0 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops
+
+s_buffer_load_u8 s5, s[4:7], s0 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops
+
+s_buffer_load_i16 s5, s[4:7], s0 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops
+
+s_buffer_load_u16 s5, s[4:7], s0 offset:-1
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops
+
+s_buffer_prefetch_data s[20:23], -1, s10, 7
+// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops
\ No newline at end of file
diff --git a/llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_buffer_err.txt b/llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_buffer_err.txt
new file mode 100644
index 0000000000000..d58a7e9b6116a
--- /dev/null
+++ b/llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_buffer_err.txt
@@ -0,0 +1,25 @@
+# RUN: not llvm-mc -disassemble -triple=amdgcn -mcpu=gfx1200 -show-encoding %s 2>&1 | FileCheck --implicit-check-not=warning: --check-prefix=GFX12 %s
+
+# buffer_load_b32 v1, off, s[0:3], s4 offset:-1
+# GFX12: warning: invalid instruction encoding
+[0x04,0x00,0x05,0xc4,0x01,0x00,0x80,0x00,0xff,0xff,0xff,0xff]
+
+# buffer_load_b32 v0, off, s[4:7], s8 offset:-1
+# GFX12: warning: invalid instruction encoding
+[0x08,0x00,0x05,0xc4,0x00,0x08,0x80,0x00,0xff,0xff,0xff,0xff]
+
+# buffer_load_b64 v[0:1], off, s[4:7], s8 offset:-1
+# GFX12: warning: invalid instruction encoding
+[0x08,0x40,0x05,0xc4,0x00,0x08,0x80,0x00,0xff,0xff,0xff,0xff]
+
+# buffer_store_b32 v0, off, s[4:7], s8 offset:-1
+# GFX12: warning: invalid instruction encoding
+[0x08,0x80,0x06,0xc4,0x00,0x08,0x80,0x00,0xff,0xff,0xff,0xff]
+
+# buffer_atomic_add v0, off, s[4:7], s8 offset:-1
+# GFX12: warning: invalid instruction encoding
+[0x08,0x40,0x0d,0xc4,0x00,0x08,0x80,0x00,0xff,0xff,0xff,0xff]
+
+# tbuffer_load_format_x v0, off, s[4:7], s8 format:0 offset:-1
+# GFX12: warning: invalid instruction encoding
+[0x08,0x00,0x20,0xc4,0x00,0x08,0x00,0x00,0xff,0xff,0xff,0xff]
\ No newline at end of file
|
// Validate buffer offset for GFX12+ - must be positive | ||
if ((MCII->get(MI.getOpcode()).TSFlags & | ||
(SIInstrFlags::MTBUF | SIInstrFlags::MUBUF)) && | ||
AMDGPU::isGFX12Plus(STI)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid generation checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this check is only required for GFX12+ as the task specifies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property is not gfx12+, the property is this specific opcode supports the offset or not.
@@ -4547,6 +4548,16 @@ bool AMDGPUAsmParser::validateSMEMOffset(const MCInst &Inst, | |||
|
|||
uint64_t Offset = Op.getImm(); | |||
bool IsBuffer = AMDGPU::getSMEMIsBuffer(Opcode); | |||
// GFX12+ S_BUFFER_*: InstOffset is signed 24, but must be positive | |||
if (isGFX12Plus() && IsBuffer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be neater to put this logic inside isLegalSMRDEncodedSignedOffset?
@@ -4547,6 +4548,16 @@ bool AMDGPUAsmParser::validateSMEMOffset(const MCInst &Inst, | |||
|
|||
uint64_t Offset = Op.getImm(); | |||
bool IsBuffer = AMDGPU::getSMEMIsBuffer(Opcode); | |||
// GFX12+ S_BUFFER_*: InstOffset is signed 24, but must be positive | |||
if (isGFX12Plus() && IsBuffer) { | |||
const unsigned OffsetSize = 24; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
const unsigned OffsetSize = 24; | |
constexpr const unsigned OffsetSize = 24; |
if (SignedOffset < 0) { | ||
return MCDisassembler::Fail; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (SignedOffset < 0) { | |
return MCDisassembler::Fail; | |
} | |
if (SignedOffset < 0) | |
return MCDisassembler::Fail; |
llvm/test/MC/AMDGPU/gfx12_err.s
Outdated
// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops | ||
|
||
s_buffer_prefetch_data s[20:23], -1, s10, 7 | ||
// GFX12-ERR: [[@LINE-1]]:{{[0-9]+}}: error: expected a 23-bit positive offset for S_BUFFER ops |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing the empty line at EOF
GFX12+ buffer ops require positive InstOffset per AMD hardware spec. Modified assembler/disassembler to reject negative buffer offsets.
Resolving comments from review.
8cb7b4f
to
3470988
Compare
Error(getFlatOffsetLoc(Operands), | ||
Twine("expected a ") + Twine(OffsetSize) + "-bit signed offset"); | ||
Twine("expected a ") + Twine(OffsetSize - 1) + "-bit positive offset for buffer ops"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"non-negative" is more correct than "positive", since 0 is OK. Same in the rest of the patch.
// 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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor to choose the correct error string first, and then have a single call to Error
.
if (IsBuffer) { | ||
constexpr const unsigned OffsetSize = 23; | ||
return isUIntN(OffsetSize, EncodedOffset); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation looks wrong here. Also this is simpler:
if (IsBuffer) { | |
constexpr const unsigned OffsetSize = 23; | |
return isUIntN(OffsetSize, EncodedOffset); | |
} | |
if (IsBuffer && EncodedOffset < 0) | |
return false; |
GFX12+ buffer ops require positive InstOffset per AMD hardware spec. Modified assembler/disassembler to reject negative buffer offsets.