-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[AMDGPU][MC] Improve error message for missing dim operand #96588
[AMDGPU][MC] Improve error message for missing dim operand #96588
Conversation
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 llvm#47585). This patch fixes the issure by producing a more direct error message.
@llvm/pr-subscribers-backend-amdgpu Author: Jun Wang (jwanggit86) ChangesFor 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 issure by producing a more direct error message. Patch is 42.34 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96588.diff 8 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 8c7b33fd0194a..e4ed6dc1fb713 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -1739,6 +1739,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
bool validateMIMGDataSize(const MCInst &Inst, const SMLoc &IDLoc);
bool validateMIMGAddrSize(const MCInst &Inst, const SMLoc &IDLoc);
bool validateMIMGD16(const MCInst &Inst);
+ bool validateMIMGDim(const MCInst &Inst, const OperandVector &Operands);
bool validateMIMGMSAA(const MCInst &Inst);
bool validateOpSel(const MCInst &Inst);
bool validateNeg(const MCInst &Inst, int OpName);
@@ -4006,6 +4007,52 @@ bool AMDGPUAsmParser::validateMIMGGatherDMask(const MCInst &Inst) {
return DMask == 0x1 || DMask == 0x2 || DMask == 0x4 || DMask == 0x8;
}
+bool AMDGPUAsmParser::validateMIMGDim(const MCInst &Inst,
+ const OperandVector &Operands) {
+ const unsigned Opc = Inst.getOpcode();
+ const MCInstrDesc &Desc = MII.get(Opc);
+
+ if ((Desc.TSFlags & MIMGFlags) == 0)
+ return true;
+
+ if (!isGFX10Plus())
+ return true;
+
+ switch (Opc) {
+ case IMAGE_BVH64_INTERSECT_RAY_a16_gfx12:
+ case IMAGE_BVH64_INTERSECT_RAY_a16_nsa_gfx10:
+ case IMAGE_BVH64_INTERSECT_RAY_a16_nsa_gfx11:
+ case IMAGE_BVH64_INTERSECT_RAY_a16_sa_gfx10:
+ case IMAGE_BVH64_INTERSECT_RAY_a16_sa_gfx11:
+ case IMAGE_BVH64_INTERSECT_RAY_gfx12:
+ case IMAGE_BVH64_INTERSECT_RAY_nsa_gfx10:
+ case IMAGE_BVH64_INTERSECT_RAY_nsa_gfx11:
+ case IMAGE_BVH64_INTERSECT_RAY_sa_gfx10:
+ case IMAGE_BVH64_INTERSECT_RAY_sa_gfx11:
+
+ case IMAGE_BVH_INTERSECT_RAY_a16_gfx12:
+ case IMAGE_BVH_INTERSECT_RAY_a16_nsa_gfx10:
+ case IMAGE_BVH_INTERSECT_RAY_a16_nsa_gfx11:
+ case IMAGE_BVH_INTERSECT_RAY_a16_sa_gfx10:
+ case IMAGE_BVH_INTERSECT_RAY_a16_sa_gfx11:
+ case IMAGE_BVH_INTERSECT_RAY_gfx12:
+ case IMAGE_BVH_INTERSECT_RAY_nsa_gfx10:
+ case IMAGE_BVH_INTERSECT_RAY_nsa_gfx11:
+ case IMAGE_BVH_INTERSECT_RAY_sa_gfx10:
+ case IMAGE_BVH_INTERSECT_RAY_sa_gfx11:
+ return true;
+ default:
+ break;
+ }
+
+ for (unsigned i = 1, e = Operands.size(); i != e; ++i) {
+ AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
+ if (Op.isDim())
+ return true;
+ }
+ return false;
+}
+
bool AMDGPUAsmParser::validateMIMGMSAA(const MCInst &Inst) {
const unsigned Opc = Inst.getOpcode();
const MCInstrDesc &Desc = MII.get(Opc);
@@ -5094,6 +5141,10 @@ bool AMDGPUAsmParser::validateInstruction(const MCInst &Inst,
"d16 modifier is not supported on this GPU");
return false;
}
+ if (!validateMIMGDim(Inst, Operands)) {
+ Error(IDLoc, "missing dim operand");
+ return false;
+ }
if (!validateMIMGMSAA(Inst)) {
Error(getImmLoc(AMDGPUOperand::ImmTyDim, Operands),
"invalid dim; must be MSAA type");
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.td b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
index 80c623514bda1..9a01da2812386 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.td
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
@@ -1089,7 +1089,7 @@ def exp_vm : NamedBitOperand<"vm", "ExpVM">;
def FORMAT : CustomOperand<i8>;
def DMask : NamedIntOperand<i16, "dmask">;
-def Dim : CustomOperand<i8>;
+def Dim : CustomOperand<i8, 1>;
def dst_sel : SDWAOperand<"dst_sel", "SDWADstSel">;
def src0_sel : SDWAOperand<"src0_sel", "SDWASrc0Sel">;
diff --git a/llvm/test/MC/AMDGPU/gfx1030_err.s b/llvm/test/MC/AMDGPU/gfx1030_err.s
index f4ab5fe5b14a9..51498d3c86d7f 100644
--- a/llvm/test/MC/AMDGPU/gfx1030_err.s
+++ b/llvm/test/MC/AMDGPU/gfx1030_err.s
@@ -207,3 +207,7 @@ image_bvh_intersect_ray v[4:7], v[9:16], s[4:7] noa16
image_bvh_intersect_ray v[39:42], [v50, v46, v23, v17, v16, v15, v21, v20], s[12:15] noa16
// GFX10: :[[@LINE-1]]:{{[0-9]+}}: error: image address size does not match a16
+
+// missing dim
+image_msaa_load v[1:4], v[5:7], s[8:15] dmask:0xf glc
+// GFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
diff --git a/llvm/test/MC/AMDGPU/gfx10_asm_mimg_err.s b/llvm/test/MC/AMDGPU/gfx10_asm_mimg_err.s
index 8deb16ebeb204..bd61ad3908d21 100644
--- a/llvm/test/MC/AMDGPU/gfx10_asm_mimg_err.s
+++ b/llvm/test/MC/AMDGPU/gfx10_asm_mimg_err.s
@@ -1,8 +1,331 @@
// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx1010 %s 2>&1 | FileCheck --check-prefixes=NOGFX10 --implicit-check-not=error: %s
-// TODO: more helpful error message for missing dim operand
+image_atomic_add v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_and v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_cmpswap v[5:6], v1, s[8:15] dmask:0x3 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_dec v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_fcmpswap v[1:2], v2, s[12:19] dmask:0x3 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_fmax v4, v32, s[96:103] dmask:0x1 glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_fmin v4, v32, s[96:103] dmask:0x1 glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_inc v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_or v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_smax v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_smin v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_sub v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_swap v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_umax v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_umin v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_xor v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4 v[5:8], v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_b v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_b_cl v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_b_cl_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_b_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_b v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_b_cl v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_b_cl_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_b_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_cl v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_cl_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_l v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_cl v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_l_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_cl_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_lz v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_lz_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4h v[254:255], v[254:255], ttmp[8:15], ttmp[12:15] dmask:0x4 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_l v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_l_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_lz v[5:8], v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_lz_o v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_o v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_get_lod v5, v1, s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_get_resinfo v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
image_load v[0:3], v0, s[0:7] dmask:0xf unorm
-// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: operands are not valid for this GPU or mode
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_mip v[5:6], v1, s[8:15] dmask:0x3 a16
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_pck v[5:6], v1, s[8:15] dmask:0x1 tfe
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_pck_sgn v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_mip_pck v5, v[1:2], s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_mip_pck_sgn v5, v[1:2], s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample v[5:6], v1, s[8:15], s[12:15] dmask:0x1 tfe
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_b v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_b_cl v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_b_cl_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_b_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_b v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_b_cl v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_b_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_b_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_cl v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_cl_g16 v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_cl_o_g16 v[5:6], v[1:6], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_g16 v[5:6], v[1:4], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_o_g16 v[5:6], v[1:5], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cl v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cl_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_cl v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_cl v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_cl_g16 v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_cl_g16 v[0:3], v[0:3], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_cl_o_g16 v[5:6], v[1:6], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_cl_o_g16 v[5:6], v[1:5], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_g16 v[0:3], v[0:3], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_g16 v[0:3], v[0:2], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_o_g16 v0, [v0, v1, v2, v4, v6, v7, v8], s[0:7], s[8:11] dmask:0x4
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_o_g16 v[5:6], v[1:4], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_l v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cl v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_l_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cl_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_lz v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_lz_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_cl v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_cl_g16 v[0:3], v[0:3], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_cl_o_g16 v[5:6], v[1:5], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_g16 v[0:3], v[0:2], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_o_g16 v[5:6], v[1:4], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_l v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_l_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_lz v5, v1, s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_lz_o v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_o v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_store v1, v2, s[12:19] dmask:0x0 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_store_mip v1, v[2:3], s[12:19] dmask:0x0 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_store_pck v1, v[2:3], s[12:19] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_store_mip_pck v1, v[2:3], s[12:19] dmask:0x0 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
image_load v[0:3], v0, s[0:7] dmask:0xf dim:SQ_RSRC_IMG_1D da
// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
diff --git a/llvm/test/MC/AMDGPU/gfx10_err_pos.s b/llvm/test/MC/AMDGPU/gfx10_err_pos.s
index c2679db3b2acf..7113bb17de99c 100644
--- a/llvm/test/MC/AMDGPU/gfx10_err_pos.s
+++ b/llvm/test/MC/AMDGPU/gfx10_err_pos.s
@@ -4,7 +4,7 @@
// operands are not valid for this GPU or mode
image_atomic_add v252, v2, s[8:15]
-// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: operands are not valid for this GPU or mode
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
// CHECK-NEXT:{{^}}image_atomic_add v252, v2, s[8:15]
// CHECK-NEXT:{{^}}^
diff --git a/llvm/test/MC/AMDGPU/gfx11_asm_mimg_err.s b/llvm/test/MC/AMDGPU/gfx11_asm_mimg_err.s
index 9dc88690d9562..9bf72a11e5eed 100644
--- a/llvm/test/MC/AMDGPU/gfx11_asm_mimg_err.s
+++ b/llvm/test/MC/AMDGPU/gfx11_asm_mimg_err.s
@@ -152,3 +152,251 @@ image_bvh_intersect_ray v[4:7], v[9:16], s[4:7] noa16
image_bvh_intersect_ray v[39:42], [v50, v46, v[20:22], v[40:42]], s[12:15] noa16
// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: image address size does not match a16
+
+// missing dim
+image_atomic_add v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_and v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_cmpswap v[5:6], v1, s[8:15] dmask:0x3 unorm glc
+// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_dec v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: ...
[truncated]
|
@llvm/pr-subscribers-mc Author: Jun Wang (jwanggit86) ChangesFor 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 issure by producing a more direct error message. Patch is 42.34 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96588.diff 8 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 8c7b33fd0194a..e4ed6dc1fb713 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -1739,6 +1739,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
bool validateMIMGDataSize(const MCInst &Inst, const SMLoc &IDLoc);
bool validateMIMGAddrSize(const MCInst &Inst, const SMLoc &IDLoc);
bool validateMIMGD16(const MCInst &Inst);
+ bool validateMIMGDim(const MCInst &Inst, const OperandVector &Operands);
bool validateMIMGMSAA(const MCInst &Inst);
bool validateOpSel(const MCInst &Inst);
bool validateNeg(const MCInst &Inst, int OpName);
@@ -4006,6 +4007,52 @@ bool AMDGPUAsmParser::validateMIMGGatherDMask(const MCInst &Inst) {
return DMask == 0x1 || DMask == 0x2 || DMask == 0x4 || DMask == 0x8;
}
+bool AMDGPUAsmParser::validateMIMGDim(const MCInst &Inst,
+ const OperandVector &Operands) {
+ const unsigned Opc = Inst.getOpcode();
+ const MCInstrDesc &Desc = MII.get(Opc);
+
+ if ((Desc.TSFlags & MIMGFlags) == 0)
+ return true;
+
+ if (!isGFX10Plus())
+ return true;
+
+ switch (Opc) {
+ case IMAGE_BVH64_INTERSECT_RAY_a16_gfx12:
+ case IMAGE_BVH64_INTERSECT_RAY_a16_nsa_gfx10:
+ case IMAGE_BVH64_INTERSECT_RAY_a16_nsa_gfx11:
+ case IMAGE_BVH64_INTERSECT_RAY_a16_sa_gfx10:
+ case IMAGE_BVH64_INTERSECT_RAY_a16_sa_gfx11:
+ case IMAGE_BVH64_INTERSECT_RAY_gfx12:
+ case IMAGE_BVH64_INTERSECT_RAY_nsa_gfx10:
+ case IMAGE_BVH64_INTERSECT_RAY_nsa_gfx11:
+ case IMAGE_BVH64_INTERSECT_RAY_sa_gfx10:
+ case IMAGE_BVH64_INTERSECT_RAY_sa_gfx11:
+
+ case IMAGE_BVH_INTERSECT_RAY_a16_gfx12:
+ case IMAGE_BVH_INTERSECT_RAY_a16_nsa_gfx10:
+ case IMAGE_BVH_INTERSECT_RAY_a16_nsa_gfx11:
+ case IMAGE_BVH_INTERSECT_RAY_a16_sa_gfx10:
+ case IMAGE_BVH_INTERSECT_RAY_a16_sa_gfx11:
+ case IMAGE_BVH_INTERSECT_RAY_gfx12:
+ case IMAGE_BVH_INTERSECT_RAY_nsa_gfx10:
+ case IMAGE_BVH_INTERSECT_RAY_nsa_gfx11:
+ case IMAGE_BVH_INTERSECT_RAY_sa_gfx10:
+ case IMAGE_BVH_INTERSECT_RAY_sa_gfx11:
+ return true;
+ default:
+ break;
+ }
+
+ for (unsigned i = 1, e = Operands.size(); i != e; ++i) {
+ AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
+ if (Op.isDim())
+ return true;
+ }
+ return false;
+}
+
bool AMDGPUAsmParser::validateMIMGMSAA(const MCInst &Inst) {
const unsigned Opc = Inst.getOpcode();
const MCInstrDesc &Desc = MII.get(Opc);
@@ -5094,6 +5141,10 @@ bool AMDGPUAsmParser::validateInstruction(const MCInst &Inst,
"d16 modifier is not supported on this GPU");
return false;
}
+ if (!validateMIMGDim(Inst, Operands)) {
+ Error(IDLoc, "missing dim operand");
+ return false;
+ }
if (!validateMIMGMSAA(Inst)) {
Error(getImmLoc(AMDGPUOperand::ImmTyDim, Operands),
"invalid dim; must be MSAA type");
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.td b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
index 80c623514bda1..9a01da2812386 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.td
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
@@ -1089,7 +1089,7 @@ def exp_vm : NamedBitOperand<"vm", "ExpVM">;
def FORMAT : CustomOperand<i8>;
def DMask : NamedIntOperand<i16, "dmask">;
-def Dim : CustomOperand<i8>;
+def Dim : CustomOperand<i8, 1>;
def dst_sel : SDWAOperand<"dst_sel", "SDWADstSel">;
def src0_sel : SDWAOperand<"src0_sel", "SDWASrc0Sel">;
diff --git a/llvm/test/MC/AMDGPU/gfx1030_err.s b/llvm/test/MC/AMDGPU/gfx1030_err.s
index f4ab5fe5b14a9..51498d3c86d7f 100644
--- a/llvm/test/MC/AMDGPU/gfx1030_err.s
+++ b/llvm/test/MC/AMDGPU/gfx1030_err.s
@@ -207,3 +207,7 @@ image_bvh_intersect_ray v[4:7], v[9:16], s[4:7] noa16
image_bvh_intersect_ray v[39:42], [v50, v46, v23, v17, v16, v15, v21, v20], s[12:15] noa16
// GFX10: :[[@LINE-1]]:{{[0-9]+}}: error: image address size does not match a16
+
+// missing dim
+image_msaa_load v[1:4], v[5:7], s[8:15] dmask:0xf glc
+// GFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
diff --git a/llvm/test/MC/AMDGPU/gfx10_asm_mimg_err.s b/llvm/test/MC/AMDGPU/gfx10_asm_mimg_err.s
index 8deb16ebeb204..bd61ad3908d21 100644
--- a/llvm/test/MC/AMDGPU/gfx10_asm_mimg_err.s
+++ b/llvm/test/MC/AMDGPU/gfx10_asm_mimg_err.s
@@ -1,8 +1,331 @@
// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx1010 %s 2>&1 | FileCheck --check-prefixes=NOGFX10 --implicit-check-not=error: %s
-// TODO: more helpful error message for missing dim operand
+image_atomic_add v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_and v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_cmpswap v[5:6], v1, s[8:15] dmask:0x3 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_dec v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_fcmpswap v[1:2], v2, s[12:19] dmask:0x3 unorm glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_fmax v4, v32, s[96:103] dmask:0x1 glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_fmin v4, v32, s[96:103] dmask:0x1 glc
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_inc v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_or v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_smax v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_smin v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_sub v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_swap v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_umax v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_umin v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_xor v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4 v[5:8], v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_b v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_b_cl v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_b_cl_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_b_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_b v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_b_cl v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_b_cl_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_b_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_cl v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_cl_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_l v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_cl v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_l_o v[5:8], v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_cl_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_lz v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_lz_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_c_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4h v[254:255], v[254:255], ttmp[8:15], ttmp[12:15] dmask:0x4 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_l v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_l_o v[5:8], v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_lz v[5:8], v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_lz_o v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_gather4_o v[5:8], v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_get_lod v5, v1, s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_get_resinfo v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
image_load v[0:3], v0, s[0:7] dmask:0xf unorm
-// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: operands are not valid for this GPU or mode
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_mip v[5:6], v1, s[8:15] dmask:0x3 a16
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_pck v[5:6], v1, s[8:15] dmask:0x1 tfe
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_pck_sgn v5, v1, s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_mip_pck v5, v[1:2], s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_load_mip_pck_sgn v5, v[1:2], s[8:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample v[5:6], v1, s[8:15], s[12:15] dmask:0x1 tfe
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_b v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_b_cl v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_b_cl_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_b_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_b v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_b_cl v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_b_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_b_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_cl v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_cl_g16 v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_cl_o_g16 v[5:6], v[1:6], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_g16 v[5:6], v[1:4], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cd_o_g16 v[5:6], v[1:5], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cl v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_cl_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_cl v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_cl v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_cl_g16 v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_cl_g16 v[0:3], v[0:3], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_cl_o_g16 v[5:6], v[1:6], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_cl_o_g16 v[5:6], v[1:5], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_g16 v[0:3], v[0:3], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_g16 v[0:3], v[0:2], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_d_o_g16 v0, [v0, v1, v2, v4, v6, v7, v8], s[0:7], s[8:11] dmask:0x4
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cd_o_g16 v[5:6], v[1:4], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_l v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cl v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_l_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_cl_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_lz v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_lz_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_c_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_cl v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_cl_g16 v[0:3], v[0:3], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_cl_o v5, v[1:8], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_cl_o_g16 v[5:6], v[1:5], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_g16 v[0:3], v[0:2], s[0:7], s[8:11] dmask:0xf
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_o v5, v[1:4], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_d_o_g16 v[5:6], v[1:4], s[8:15], s[12:15] dmask:0x3
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_l v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_l_o v5, v[1:3], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_lz v5, v1, s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_lz_o v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_sample_o v5, v[1:2], s[8:15], s[12:15] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_store v1, v2, s[12:19] dmask:0x0 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_store_mip v1, v[2:3], s[12:19] dmask:0x0 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_store_pck v1, v[2:3], s[12:19] dmask:0x1 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_store_mip_pck v1, v[2:3], s[12:19] dmask:0x0 unorm
+// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
image_load v[0:3], v0, s[0:7] dmask:0xf dim:SQ_RSRC_IMG_1D da
// NOGFX10: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
diff --git a/llvm/test/MC/AMDGPU/gfx10_err_pos.s b/llvm/test/MC/AMDGPU/gfx10_err_pos.s
index c2679db3b2acf..7113bb17de99c 100644
--- a/llvm/test/MC/AMDGPU/gfx10_err_pos.s
+++ b/llvm/test/MC/AMDGPU/gfx10_err_pos.s
@@ -4,7 +4,7 @@
// operands are not valid for this GPU or mode
image_atomic_add v252, v2, s[8:15]
-// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: operands are not valid for this GPU or mode
+// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
// CHECK-NEXT:{{^}}image_atomic_add v252, v2, s[8:15]
// CHECK-NEXT:{{^}}^
diff --git a/llvm/test/MC/AMDGPU/gfx11_asm_mimg_err.s b/llvm/test/MC/AMDGPU/gfx11_asm_mimg_err.s
index 9dc88690d9562..9bf72a11e5eed 100644
--- a/llvm/test/MC/AMDGPU/gfx11_asm_mimg_err.s
+++ b/llvm/test/MC/AMDGPU/gfx11_asm_mimg_err.s
@@ -152,3 +152,251 @@ image_bvh_intersect_ray v[4:7], v[9:16], s[4:7] noa16
image_bvh_intersect_ray v[39:42], [v50, v46, v[20:22], v[40:42]], s[12:15] noa16
// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: image address size does not match a16
+
+// missing dim
+image_atomic_add v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_and v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_cmpswap v[5:6], v1, s[8:15] dmask:0x3 unorm glc
+// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: missing dim operand
+
+image_atomic_dec v5, v1, s[8:15] dmask:0x1 unorm glc
+// NOGFX11: :[[@LINE-1]]:{{[0-9]+}}: error: ...
[truncated]
|
This looks like an improvement over the status quo, but why did you choose to do this rather than replicate sp3's behavior? You should probably update #47585 to explain your thought process. |
Please see my summary in 47585 where I listed 4 options. No. 2 is to mimic sp3 and to make dim optional, but colleagues raised questions about whether the sp3 default value for dim was suitable. |
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.
OK, thanks! LGTM
@@ -1089,7 +1089,7 @@ def exp_vm : NamedBitOperand<"vm", "ExpVM">; | |||
def FORMAT : CustomOperand<i8>; | |||
|
|||
def DMask : NamedIntOperand<i16, "dmask">; | |||
def Dim : CustomOperand<i8>; | |||
def Dim : CustomOperand<i8, 1>; |
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.
Can you comment the parameter name here? I have to look to see what this does
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.
Done.
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.
I mean like /OperandName=/ not exposition before the definition
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.
also can call it true instead of 1
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.
Updated comment as suggested.
return true; | ||
|
||
switch (Opc) { | ||
case IMAGE_BVH64_INTERSECT_RAY_a16_gfx12: |
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.
Can we avoid this hardcoded switch of specific opcodes?
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.
It seems this can be done by checking the boolean AMDGPU::getMIMGBaseOpcode(Opc)->BVH
. See latest commit.
@arsenm ping. |
@@ -4006,6 +4007,29 @@ bool AMDGPUAsmParser::validateMIMGGatherDMask(const MCInst &Inst) { | |||
return DMask == 0x1 || DMask == 0x2 || DMask == 0x4 || DMask == 0x8; | |||
} | |||
|
|||
bool AMDGPUAsmParser::validateMIMGDim(const MCInst &Inst, | |||
const OperandVector &Operands) { | |||
if (!isGFX10Plus()) |
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.
can this be a named feature instead of a generation check
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.
I was not able to find a named feature for "dim". Note that isGFX10Plus()
etc are defined as member functions of the class AMDGPUAsmParser
and are used throughout the file. For example, the first few lines of parseDim()
include a call of isGFX10Plus()
:
ParseStatus AMDGPUAsmParser::parseDim(OperandVector &Operands) {
if (!isGFX10Plus())
return ParseStatus::NoMatch;
...
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.
Right, you would need to add it. Or at least hide this in an alias that shows why the version matters
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 <jun.wang7@amd.com> Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251483
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 issure by producing a more direct error message.