Skip to content

Commit 31a8c84

Browse files
jwanggit86yuxuanchen1997
authored andcommitted
[AMDGPU][MC] Improve error message for missing dim operand (#96588)
Summary: For GFX10+, the MIMG instrucitons generally require a dim operand. However, when dim is missing, the assembler produces the error message "operands are not valid for this GPU or mode" (See issue #47585). This patch fixes the issue by producing a more direct error message. --------- Co-authored-by: Jun Wang <[email protected]> Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251483
1 parent fac2d84 commit 31a8c84

File tree

8 files changed

+867
-6
lines changed

8 files changed

+867
-6
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
17461746
bool validateMIMGDataSize(const MCInst &Inst, const SMLoc &IDLoc);
17471747
bool validateMIMGAddrSize(const MCInst &Inst, const SMLoc &IDLoc);
17481748
bool validateMIMGD16(const MCInst &Inst);
1749+
bool validateMIMGDim(const MCInst &Inst, const OperandVector &Operands);
17491750
bool validateMIMGMSAA(const MCInst &Inst);
17501751
bool validateOpSel(const MCInst &Inst);
17511752
bool validateNeg(const MCInst &Inst, int OpName);
@@ -4011,6 +4012,29 @@ bool AMDGPUAsmParser::validateMIMGGatherDMask(const MCInst &Inst) {
40114012
return DMask == 0x1 || DMask == 0x2 || DMask == 0x4 || DMask == 0x8;
40124013
}
40134014

4015+
bool AMDGPUAsmParser::validateMIMGDim(const MCInst &Inst,
4016+
const OperandVector &Operands) {
4017+
if (!isGFX10Plus())
4018+
return true;
4019+
4020+
const unsigned Opc = Inst.getOpcode();
4021+
const MCInstrDesc &Desc = MII.get(Opc);
4022+
4023+
if ((Desc.TSFlags & MIMGFlags) == 0)
4024+
return true;
4025+
4026+
// image_bvh_intersect_ray instructions do not have dim
4027+
if (AMDGPU::getMIMGBaseOpcode(Opc)->BVH)
4028+
return true;
4029+
4030+
for (unsigned i = 1, e = Operands.size(); i != e; ++i) {
4031+
AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
4032+
if (Op.isDim())
4033+
return true;
4034+
}
4035+
return false;
4036+
}
4037+
40144038
bool AMDGPUAsmParser::validateMIMGMSAA(const MCInst &Inst) {
40154039
const unsigned Opc = Inst.getOpcode();
40164040
const MCInstrDesc &Desc = MII.get(Opc);
@@ -5099,6 +5123,10 @@ bool AMDGPUAsmParser::validateInstruction(const MCInst &Inst,
50995123
"d16 modifier is not supported on this GPU");
51005124
return false;
51015125
}
5126+
if (!validateMIMGDim(Inst, Operands)) {
5127+
Error(IDLoc, "missing dim operand");
5128+
return false;
5129+
}
51025130
if (!validateMIMGMSAA(Inst)) {
51035131
Error(getImmLoc(AMDGPUOperand::ImmTyDim, Operands),
51045132
"invalid dim; must be MSAA type");

llvm/lib/Target/AMDGPU/SIInstrInfo.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,8 @@ def exp_vm : NamedBitOperand<"vm", "ExpVM">;
11041104
def FORMAT : CustomOperand<i8>;
11051105

11061106
def DMask : NamedIntOperand<i16, "dmask">;
1107-
def Dim : CustomOperand<i8>;
1107+
1108+
def Dim : CustomOperand<i8, /*optional=*/1>;
11081109

11091110
def dst_sel : SDWAOperand<"dst_sel", "SDWADstSel">;
11101111
def src0_sel : SDWAOperand<"src0_sel", "SDWASrc0Sel">;

llvm/test/MC/AMDGPU/gfx1030_err.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,7 @@ image_bvh_intersect_ray v[4:7], v[9:16], s[4:7] noa16
207207

208208
image_bvh_intersect_ray v[39:42], [v50, v46, v23, v17, v16, v15, v21, v20], s[12:15] noa16
209209
// GFX10: :[[@LINE-1]]:{{[0-9]+}}: error: image address size does not match a16
210+
211+
// missing dim
212+
image_msaa_load v[1:4], v[5:7], s[8:15] dmask:0xf glc
213+
// GFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand

0 commit comments

Comments
 (0)