diff --git a/llvm/lib/Target/AMDGPU/SMInstructions.td b/llvm/lib/Target/AMDGPU/SMInstructions.td --- a/llvm/lib/Target/AMDGPU/SMInstructions.td +++ b/llvm/lib/Target/AMDGPU/SMInstructions.td @@ -515,7 +515,8 @@ // VI supports 20-bit unsigned offsets while GFX9+ supports 21-bit signed. // Offset value is corrected accordingly when offset is encoded/decoded. - let Inst{52-32} = !if(ps.has_offset, offset{20-0}, ?); + let Inst{38-32} = !if(ps.has_offset, offset{6-0}, ?); + let Inst{52-39} = !if(ps.has_offset, !if(imm, offset{20-7}, ?), ?); } multiclass SM_Real_Loads_vi op, string ps, diff --git a/llvm/test/MC/Disassembler/AMDGPU/smem_gfx9.txt b/llvm/test/MC/Disassembler/AMDGPU/smem_gfx9.txt --- a/llvm/test/MC/Disassembler/AMDGPU/smem_gfx9.txt +++ b/llvm/test/MC/Disassembler/AMDGPU/smem_gfx9.txt @@ -291,3 +291,16 @@ # GFX9: s_atc_probe_buffer 1, s[8:11], -0x1 ; encoding: [0x44,0x00,0x9e,0xc0,0xff,0xff,0x1f,0x00] 0x44,0x00,0x9e,0xc0,0xff,0xff,0x1f,0x00 + +#===------------------------------------------------------------------------===# +# Decoding of OFFSET>127 with IMM=0 +#===------------------------------------------------------------------------===# + +# GFX9: s_atomic_or s5, s[2:3], s15 ; encoding: [0x41,0x01,0x24,0xc2,0x0f,0x00,0x00,0x00] +0x41,0x01,0x24,0xc2,0x8f,0x00,0x00,0x00 + +# GFX9: s_atomic_or s5, s[2:3], exec_hi ; encoding: [0x41,0x01,0x24,0xc2,0x7f,0x00,0x00,0x00] +0x41,0x01,0x24,0xc2,0xff,0xff,0x00,0x00 + +# GFX9: s_atomic_add_x2 s[34:35], exec, s11 glc ; encoding: [0xbf,0x08,0x89,0xc2,0x0b,0x00,0x00,0x00] +0xbf,0x08,0x89,0xc2,0x0b,0x00,0x00,0x00