This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU][MC] Warn when disassembling v_cmpx instructions
AbandonedPublic

Authored by gandhi21299 on Sep 5 2022, 9:33 PM.

Details

Reviewers
dp
Joe_Nash
foad
Summary

Based on the discussions in D130345,
AMDGPUDisassembler should emit warnings when v_cmpx*
instructions are disassembled with a non-exec destination,
except when the source is an immediate zero operand.

Diff Detail

Event Timeline

gandhi21299 created this revision.Sep 5 2022, 9:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2022, 9:33 PM
gandhi21299 requested review of this revision.Sep 5 2022, 9:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2022, 9:33 PM
foad added a comment.Sep 6 2022, 1:14 AM

It seems like target disassemblers in general do not emit warnings, and are lacking the machinery to emit them as proper diagnostics with location information.

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

Warnings should go to errs() shouldn't they?

llvm/test/MC/Disassembler/AMDGPU/gfx10_vop3cx.txt
1071

Might be better to do this by changing the RUN lines to use FileCheck --implicit-check-not="Warning:", to catch all unexpected warnings.

kosarev added inline comments.Sep 6 2022, 2:30 AM
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
720

What if to instead say what is expected?

Also, I guess it may be helpful if we emit the instruction itself and maybe its address as well? Might save the user some time and nerves locating the problematic instruction, especially if the warning doesn't go to that same stream we direct disassembled code to.

dp added inline comments.Sep 6 2022, 4:57 AM
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
717–718

We could reuse isVCMPX64 here. It may be defined in AMDGPUBaseInfo and reused where necessary.

718

Why is MI.getNumOperands() >= 5 important?

719

This code checks operands of decoded MCInst, but decoded instruction does not provide any information about what dst was encoded in the original binary representation. To check the dst value, we have to work with the original binary code.

llvm/test/MC/Disassembler/AMDGPU/gfx10_vop3cx.txt
1071

I agree. Also, I suggest creating a separate file gfx10_vop3cx_errs.txt and add new tests for this feature there. The tests should include regular dst values (0x7e and 0), as well as a couple of values that trigger the warning.

dp added a comment.EditedSep 6 2022, 5:21 AM

The summary should be corrected.

except when the source is an immediate zero operand

We should allow dst=EXEC and dst=0. The latter encoding has been used for a while for historical reasons, and we should not warn in this case.

gandhi21299 added inline comments.Sep 7 2022, 2:17 PM
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
719

Do you mean use Bytes instead?

dp added inline comments.Sep 7 2022, 2:35 PM
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
719

Yes, we should use Bytes.

I cannot quite parse 64-bit v_cmpx* instructions after reading the ISA docs several times. I need to implement checks for the source and destination operands. Any pointers?

gandhi21299 planned changes to this revision.Jan 18 2023, 2:46 PM
gandhi21299 marked 7 inline comments as done.
gandhi21299 abandoned this revision.Mar 30 2023, 9:55 AM