[AMDGPU][MC] Return fail when it is not a VGPR in the decoder - #215136
Open
shiltian wants to merge 1 commit into
Open
[AMDGPU][MC] Return fail when it is not a VGPR in the decoder#215136shiltian wants to merge 1 commit into
shiltian wants to merge 1 commit into
Conversation
Contributor
Author
|
This stack of pull requests is managed by sgh. |
shiltian
marked this pull request as ready for review
August 9, 2026 19:57
|
@llvm/pr-subscribers-backend-amdgpu Author: Shilei Tian (shiltian) ChangesFixes #215003. This PR was assisted by AI but I reviewed all the changes. Full diff: https://github.com/llvm/llvm-project/pull/215136.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index d05997cacba0a..bf7502f4aec6d 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -265,6 +265,10 @@ static DecodeStatus decodeSrcReg9(MCInst &Inst, unsigned Imm,
template <unsigned OpWidth>
static DecodeStatus decodeSrcA9(MCInst &Inst, unsigned Imm, uint64_t /* Addr */,
const MCDisassembler *Decoder) {
+ // A clear Imm{8} names an SGPR or an inline constant, which this
+ // register-only operand cannot hold.
+ if (!(Imm & AMDGPU::EncValues::IS_VGPR))
+ return MCDisassembler::Fail;
return decodeSrcOp(Inst, 9, OpWidth, Imm, Imm | 512, Decoder);
}
@@ -274,6 +278,10 @@ template <unsigned OpWidth>
static DecodeStatus decodeSrcAV10(MCInst &Inst, unsigned Imm,
uint64_t /* Addr */,
const MCDisassembler *Decoder) {
+ // A clear Imm{8} names an SGPR or an inline constant, which this
+ // register-only operand cannot hold.
+ if (!(Imm & AMDGPU::EncValues::IS_VGPR))
+ return MCDisassembler::Fail;
return decodeSrcOp(Inst, 10, OpWidth, Imm, Imm, Decoder);
}
diff --git a/llvm/test/MC/Disassembler/AMDGPU/gfx9_dasm_mai_err.txt b/llvm/test/MC/Disassembler/AMDGPU/gfx9_dasm_mai_err.txt
new file mode 100644
index 0000000000000..34dd986346bef
--- /dev/null
+++ b/llvm/test/MC/Disassembler/AMDGPU/gfx9_dasm_mai_err.txt
@@ -0,0 +1,26 @@
+# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --version 6
+# RUN: llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx908 -disassemble -show-encoding < %s 2>&1 | FileCheck --implicit-check-not=warning: %s
+# RUN: llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx90a -disassemble -show-encoding < %s 2>&1 | FileCheck --implicit-check-not=warning: %s
+# RUN: llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -disassemble -show-encoding < %s 2>&1 | FileCheck --implicit-check-not=warning: %s
+# RUN: llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx950 -disassemble -show-encoding < %s 2>&1 | FileCheck --implicit-check-not=warning: %s
+
+# The AV and AGPR source operands below only accept vector registers, so an
+# encoding naming an SGPR or an inline constant must be rejected. -show-encoding
+# is required: re-encoding the decoded instruction is what used to assert on the
+# non-register operand.
+
+# This is v_mfma_f32_16x16x1_4b_f32 with s0 as src0.
+0x00,0x00,0xc1,0xd3,0x00,0x00,0x02,0x04
+# CHECK: :[[@LINE-1]]:1: warning: invalid instruction encoding
+
+# This is v_mfma_f32_16x16x1_4b_f32 with the inline constant 0 as src1.
+0x00,0x00,0xc1,0xd3,0x00,0x01,0x01,0x04
+# CHECK: :[[@LINE-1]]:1: warning: invalid instruction encoding
+
+# This is v_accvgpr_read_b32 with s0 as src0.
+0x02,0x40,0xd8,0xd3,0x00,0x00,0x00,0x18
+# CHECK: :[[@LINE-1]]:1: warning: invalid instruction encoding
+
+# This is v_accvgpr_read_b32 with the inline constant 0 as src0.
+0x02,0x40,0xd8,0xd3,0x80,0x00,0x00,0x18
+# CHECK: :[[@LINE-1]]:1: warning: invalid instruction encoding
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #215003.
This PR was assisted by AI but I reviewed all the changes.