Skip to content

Commit bc91acc

Browse files
authored
[AMDGPU][MC] Disassembler warning for v_cmpx instructions (#127925)
For GFX10+ the destination reg of v_cmpx instructions is implicitly EXEC, which is encoded as 0x7E. However, the disassembler does not check this field, thus allowing any value. With this patch, if the field is not EXEC a warning is issued.
1 parent d91e5c3 commit bc91acc

File tree

4 files changed

+1126
-1
lines changed

4 files changed

+1126
-1
lines changed

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
664664
return MCDisassembler::Fail;
665665
} while (false);
666666

667+
DecodeStatus Status = MCDisassembler::Success;
668+
667669
if (MCII->get(MI.getOpcode()).TSFlags & SIInstrFlags::DPP) {
668670
if (isMacDPP(MI))
669671
convertMacDPPInst(MI);
@@ -802,8 +804,18 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
802804
if (ImmLitIdx != -1 && !IsSOPK)
803805
convertFMAanyK(MI, ImmLitIdx);
804806

807+
// Some VOPC instructions, e.g., v_cmpx_f_f64, use VOP3 encoding and
808+
// have EXEC as implicit destination. Issue a warning if encoding for
809+
// vdst is not EXEC.
810+
if ((MCII->get(MI.getOpcode()).TSFlags & SIInstrFlags::VOP3) &&
811+
MCII->get(MI.getOpcode()).hasImplicitDefOfPhysReg(AMDGPU::EXEC)) {
812+
auto ExecEncoding = MRI.getEncodingValue(AMDGPU::EXEC_LO);
813+
if (Bytes_[0] != ExecEncoding)
814+
Status = MCDisassembler::SoftFail;
815+
}
816+
805817
Size = MaxInstBytesNum - Bytes.size();
806-
return MCDisassembler::Success;
818+
return Status;
807819
}
808820

809821
void AMDGPUDisassembler::convertEXPInst(MCInst &MI) const {

0 commit comments

Comments
 (0)