Skip to content

Commit 47615dd

Browse files
authored
[AMDGPU][MC] Add GFX12 VFLAT, VSCRATCH and VGLOBAL encodings (#75193)
1 parent 50e78de commit 47615dd

File tree

11 files changed

+4376
-13
lines changed

11 files changed

+4376
-13
lines changed

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,11 +4195,12 @@ bool AMDGPUAsmParser::validateFlatOffset(const MCInst &Inst,
41954195
return false;
41964196
}
41974197

4198-
// For FLAT segment the offset must be positive;
4198+
// For pre-GFX12 FLAT instructions the offset must be positive;
41994199
// MSB is ignored and forced to zero.
42004200
unsigned OffsetSize = AMDGPU::getNumFlatOffsetBits(getSTI());
42014201
bool AllowNegative =
4202-
TSFlags & (SIInstrFlags::FlatGlobal | SIInstrFlags::FlatScratch);
4202+
(TSFlags & (SIInstrFlags::FlatGlobal | SIInstrFlags::FlatScratch)) ||
4203+
isGFX12Plus();
42034204
if (!isIntN(OffsetSize, Op.getImm()) || (!AllowNegative && Op.getImm() < 0)) {
42044205
Error(getFlatOffsetLoc(Operands),
42054206
Twine("expected a ") +

llvm/lib/Target/AMDGPU/FLATInstructions.td

Lines changed: 257 additions & 2 deletions
Large diffs are not rendered by default.

llvm/lib/Target/AMDGPU/GCNSubtarget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,8 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
12121212
// \returns true if FP8/BF8 VOP1 form of conversion to F32 is unreliable.
12131213
bool hasCvtFP8VOP1Bug() const { return true; }
12141214

1215-
// \returns true is CSUB atomics support a no-return form.
1215+
// \returns true if CSUB (a.k.a. SUB_CLAMP on GFX12) atomics support a
1216+
// no-return form.
12161217
bool hasAtomicCSubNoRtnInsts() const { return HasAtomicCSubNoRtnInsts; }
12171218

12181219
// \returns true if the target has DX10_CLAMP kernel descriptor mode bit

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,19 @@ void AMDGPUInstPrinter::printOffset(const MCInst *MI, unsigned OpNo,
114114
void AMDGPUInstPrinter::printFlatOffset(const MCInst *MI, unsigned OpNo,
115115
const MCSubtargetInfo &STI,
116116
raw_ostream &O) {
117-
uint16_t Imm = MI->getOperand(OpNo).getImm();
117+
uint32_t Imm = MI->getOperand(OpNo).getImm();
118118
if (Imm != 0) {
119119
O << " offset:";
120120

121121
const MCInstrDesc &Desc = MII.get(MI->getOpcode());
122-
bool IsFlatSeg = !(Desc.TSFlags &
123-
(SIInstrFlags::FlatGlobal | SIInstrFlags::FlatScratch));
122+
bool AllowNegative = (Desc.TSFlags & (SIInstrFlags::FlatGlobal |
123+
SIInstrFlags::FlatScratch)) ||
124+
AMDGPU::isGFX12(STI);
124125

125-
if (IsFlatSeg) // Unsigned offset
126-
printU16ImmDecOperand(MI, OpNo, O);
127-
else // Signed offset
126+
if (AllowNegative) // Signed offset
128127
O << formatDec(SignExtend32(Imm, AMDGPU::getNumFlatOffsetBits(STI)));
128+
else // Unsigned offset
129+
printU16ImmDecOperand(MI, OpNo, O);
129130
}
130131
}
131132

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2691,10 +2691,11 @@ std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
26912691
}
26922692

26932693
unsigned getNumFlatOffsetBits(const MCSubtargetInfo &ST) {
2694-
// Address offset is 12-bit signed for GFX10, 13-bit for GFX9 and GFX11+.
26952694
if (AMDGPU::isGFX10(ST))
26962695
return 12;
26972696

2697+
if (AMDGPU::isGFX12(ST))
2698+
return 24;
26982699
return 13;
26992700
}
27002701

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST,
13341334
std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST,
13351335
int64_t ByteOffset);
13361336

1337-
/// For FLAT segment the offset must be positive;
1337+
/// For pre-GFX12 FLAT instructions the offset must be positive;
13381338
/// MSB is ignored and forced to zero.
13391339
///
13401340
/// \return The number of bits available for the signed offset field in flat

llvm/test/MC/AMDGPU/gfx11_asm_err.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,9 @@ v_fmac_f32_e64_dpp v5, v2, 0x1234 quad_perm:[3,2,1,0]
152152

153153
s_load_dword s1, s[2:3], s0 0x1
154154
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
155+
156+
scratch_store_b128 off, v[2:5], s0 offset:8000000
157+
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: expected a 13-bit signed offset
158+
159+
flat_atomic_add_f32 v1, v[0:1], v2 offset:-1
160+
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: expected a 12-bit unsigned offset

llvm/test/MC/AMDGPU/gfx11_unsupported.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,15 @@ buffer_atomic_max_num_f32 v5, off, s[8:11], s3 offset:4095
19931993
buffer_atomic_min_num_f32 v5, off, s[8:11], s3 offset:4095
19941994
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
19951995

1996+
global_atomic_sub_clamp_u32 v5, v[1:2], v2, off glc
1997+
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
1998+
1999+
flat_atomic_csub_u32 v1, v[0:1], v2 offset:64 th:TH_ATOMIC_RETURN
2000+
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
2001+
2002+
flat_atomic_sub_clamp_u32 v1, v[0:1], v2 offset:64 th:TH_ATOMIC_RETURN
2003+
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
2004+
19962005
ds_sub_clamp_rtn_u32 v5, v1, v2
19972006
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
19982007

0 commit comments

Comments
 (0)