Skip to content

Commit fc92d11

Browse files
committed
[AMDGPU][MC] Add GFX12 VBUFFER encoding
1 parent 554e4df commit fc92d11

12 files changed

+12297
-207
lines changed

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class AMDGPUOperand : public MCParsedAsmOperand {
373373
bool isOffen() const { return isImmTy(ImmTyOffen); }
374374
bool isIdxen() const { return isImmTy(ImmTyIdxen); }
375375
bool isAddr64() const { return isImmTy(ImmTyAddr64); }
376-
bool isOffset() const { return isImmTy(ImmTyOffset) && isUInt<16>(getImm()); }
376+
bool isOffset() const { return isImmTy(ImmTyOffset); }
377377
bool isOffset0() const { return isImmTy(ImmTyOffset0) && isUInt<8>(getImm()); }
378378
bool isOffset1() const { return isImmTy(ImmTyOffset1) && isUInt<8>(getImm()); }
379379
bool isSMEMOffsetMod() const { return isImmTy(ImmTySMEMOffsetMod); }
@@ -1666,6 +1666,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
16661666
SMLoc getInstLoc(const OperandVector &Operands) const;
16671667

16681668
bool validateInstruction(const MCInst &Inst, const SMLoc &IDLoc, const OperandVector &Operands);
1669+
bool validateOffset(const MCInst &Inst, const OperandVector &Operands);
16691670
bool validateFlatOffset(const MCInst &Inst, const OperandVector &Operands);
16701671
bool validateSMEMOffset(const MCInst &Inst, const OperandVector &Operands);
16711672
bool validateSOPLiteral(const MCInst &Inst) const;
@@ -4143,6 +4144,40 @@ SMLoc AMDGPUAsmParser::getFlatOffsetLoc(const OperandVector &Operands) const {
41434144
return getLoc();
41444145
}
41454146

4147+
bool AMDGPUAsmParser::validateOffset(const MCInst &Inst,
4148+
const OperandVector &Operands) {
4149+
auto Opcode = Inst.getOpcode();
4150+
auto OpNum = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::offset);
4151+
if (OpNum == -1)
4152+
return true;
4153+
4154+
uint64_t TSFlags = MII.get(Inst.getOpcode()).TSFlags;
4155+
if ((TSFlags & SIInstrFlags::FLAT))
4156+
return validateFlatOffset(Inst, Operands);
4157+
4158+
if ((TSFlags & SIInstrFlags::SMRD))
4159+
return validateSMEMOffset(Inst, Operands);
4160+
4161+
const auto &Op = Inst.getOperand(OpNum);
4162+
if (isGFX12Plus() &&
4163+
(TSFlags & (SIInstrFlags::MUBUF | SIInstrFlags::MTBUF))) {
4164+
const unsigned OffsetSize = 24;
4165+
if (!isIntN(OffsetSize, Op.getImm())) {
4166+
Error(getFlatOffsetLoc(Operands),
4167+
Twine("expected a ") + Twine(OffsetSize) + "-bit signed offset");
4168+
return false;
4169+
}
4170+
} else {
4171+
const unsigned OffsetSize = 16;
4172+
if (!isUIntN(OffsetSize, Op.getImm())) {
4173+
Error(getFlatOffsetLoc(Operands),
4174+
Twine("expected a ") + Twine(OffsetSize) + "-bit unsigned offset");
4175+
return false;
4176+
}
4177+
}
4178+
return true;
4179+
}
4180+
41464181
bool AMDGPUAsmParser::validateFlatOffset(const MCInst &Inst,
41474182
const OperandVector &Operands) {
41484183
uint64_t TSFlags = MII.get(Inst.getOpcode()).TSFlags;
@@ -4800,10 +4835,7 @@ bool AMDGPUAsmParser::validateInstruction(const MCInst &Inst,
48004835
if (!validateMovrels(Inst, Operands)) {
48014836
return false;
48024837
}
4803-
if (!validateFlatOffset(Inst, Operands)) {
4804-
return false;
4805-
}
4806-
if (!validateSMEMOffset(Inst, Operands)) {
4838+
if (!validateOffset(Inst, Operands)) {
48074839
return false;
48084840
}
48094841
if (!validateMAIAccWrite(Inst, Operands)) {

llvm/lib/Target/AMDGPU/BUFInstructions.td

Lines changed: 440 additions & 198 deletions
Large diffs are not rendered by default.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,17 @@ void AMDGPUInstPrinter::printNamedBit(const MCInst *MI, unsigned OpNo,
9797
void AMDGPUInstPrinter::printOffset(const MCInst *MI, unsigned OpNo,
9898
const MCSubtargetInfo &STI,
9999
raw_ostream &O) {
100-
uint16_t Imm = MI->getOperand(OpNo).getImm();
100+
uint32_t Imm = MI->getOperand(OpNo).getImm();
101101
if (Imm != 0) {
102102
O << " offset:";
103-
printU16ImmDecOperand(MI, OpNo, O);
103+
104+
// GFX12 uses a 24-bit signed offset for VBUFFER.
105+
const MCInstrDesc &Desc = MII.get(MI->getOpcode());
106+
bool IsVBuffer = Desc.TSFlags & (SIInstrFlags::MUBUF | SIInstrFlags::MTBUF);
107+
if (AMDGPU::isGFX12(STI) && IsVBuffer)
108+
O << formatDec(SignExtend32<24>(Imm));
109+
else
110+
printU16ImmDecOperand(MI, OpNo, O);
104111
}
105112
}
106113

llvm/test/MC/AMDGPU/ds-err.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// RUN: not llvm-mc -triple=amdgcn -mcpu=tahiti %s 2>&1 | FileCheck --implicit-check-not=error: %s
33

44
// offset too big
5-
// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: invalid operand for instruction
5+
// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: expected a 16-bit unsigned offset
66
ds_add_u32 v2, v4 offset:1000000000
77

88
// offset too big
9-
// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: invalid operand for instruction
9+
// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: expected a 16-bit unsigned offset
1010
ds_add_u32 v2, v4 offset:0x10000
1111

1212
// offset0 twice

llvm/test/MC/AMDGPU/gfx11_unsupported.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,15 @@ s_cmp_nlt_f16 s1, s2
19841984
s_singleuse_vdst 0x1234
19851985
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
19861986

1987+
buffer_atomic_sub_clamp_u32 v5, off, s[8:11], s3 offset:0 glc
1988+
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
1989+
1990+
buffer_atomic_max_num_f32 v5, off, s[8:11], s3 offset:4095
1991+
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
1992+
1993+
buffer_atomic_min_num_f32 v5, off, s[8:11], s3 offset:4095
1994+
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
1995+
19871996
ds_sub_clamp_rtn_u32 v5, v1, v2
19881997
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
19891998

0 commit comments

Comments
 (0)