Skip to content

Commit 683dc4d

Browse files
committed
[AMDGPU][MC] Disassembler warning for v_cmpx instructions
For GFX10+ the destination reg of v_cmpx instructions and others 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 0x7E a warning is issued.
1 parent 7c104b6 commit 683dc4d

File tree

4 files changed

+425
-2
lines changed

4 files changed

+425
-2
lines changed

llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class MCDisassembler {
194194

195195
private:
196196
MCContext &Ctx;
197+
std::string ErrorOrWarningMsg;
197198

198199
protected:
199200
// Subtarget information, for instruction decoding predicates if required.
@@ -222,6 +223,9 @@ class MCDisassembler {
222223
// Marked mutable because we cache it inside the disassembler, rather than
223224
// having to pass it around as an argument through all the autogenerated code.
224225
mutable raw_ostream *CommentStream = nullptr;
226+
227+
const std::string& getErrorOrWarningMsg() const { return ErrorOrWarningMsg; }
228+
void setErrorOrWarningMsg(const std::string &Msg) { ErrorOrWarningMsg = Msg; }
225229
};
226230

227231
} // end namespace llvm

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

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

666+
DecodeStatus Status = MCDisassembler::Success;
667+
666668
if (MCII->get(MI.getOpcode()).TSFlags & SIInstrFlags::DPP) {
667669
if (isMacDPP(MI))
668670
convertMacDPPInst(MI);
@@ -801,8 +803,17 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
801803
if (ImmLitIdx != -1 && !IsSOPK)
802804
convertFMAanyK(MI, ImmLitIdx);
803805

806+
if ((MCII->get(MI.getOpcode()).TSFlags & SIInstrFlags::VOP3) &&
807+
MCII->get(MI.getOpcode()).hasImplicitDefOfPhysReg(AMDGPU::EXEC)) {
808+
auto ExecEncoding = MRI.getEncodingValue(AMDGPU::EXEC_LO);
809+
if (Bytes_[0] != ExecEncoding) {
810+
const_cast<AMDGPUDisassembler*>(this)->setErrorOrWarningMsg("invalid vdst encoding");
811+
Status = MCDisassembler::SoftFail;
812+
}
813+
}
814+
804815
Size = MaxInstBytesNum - Bytes.size();
805-
return MCDisassembler::Success;
816+
return Status;
806817
}
807818

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

0 commit comments

Comments
 (0)