This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU/MC: Make VReg and VISrc decoders more strict
AbandonedPublic

Authored by Petar.Avramovic on Dec 6 2022, 9:32 AM.

Details

Summary

These are operands that use 9 bit src operand encoding
but still don't allow sgprs and inline immediates.
Report decoding fail when operands are invalid values.

Diff Detail

Event Timeline

Petar.Avramovic created this revision.Dec 6 2022, 9:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 9:32 AM
Petar.Avramovic requested review of this revision.Dec 6 2022, 9:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 9:32 AM
dp added a comment.Dec 7 2022, 1:55 AM

By design, disassembler should be able to decode invalid code when possible. It is much more helpful for the user to see something like this:

v_wmma_f32_16x16x16_f16  … s[0:7], …

or

v_wmma_f32_16x16x16_f16  … /*invalid immediate*/, …

than this:

warning: invalid instruction encoding

Would it be possible to modify your patch and decode invalid operands with a comment stating that they are incorrect?

In most cases if instruction can't use some bits in encoding of an operand, those bits are set to default value in td file. Disassembler fails (in generic way) in this cases and does not print e.g. "instruction must use glc" (assembler prints such verbose warnings)

This is the corner case where some combinations of bits in the operand encoding are not allowed. Those cases are too complicated to be implemented in tablegen encoding so I moved it to decoder.

Would it be possible to modify your patch and decode invalid operands with a comment stating that they are incorrect?

I don't know where would be the best place to implement it, but as far I am aware it is not done for any other instruction.
Maybe return errOperand instead of MCOperand() but it does not seem to make any difference.
Another option would be to make new OperandType and write some error msg in InstPrinter (I would print normal src operand + msg that operand value is invalid and reason why(e.g. not vgpr/not vgpr or inline imm)).

dp added a comment.Dec 7 2022, 6:07 AM

In most cases if instruction can't use some bits in encoding of an operand, those bits are set to default value in td file.

AFAIK, we use ? as a default value to allow disassembler ignore these bits.

Another option would be to make new OperandType and write some error msg in InstPrinter (I would print normal src operand + msg that operand value is invalid and reason why(e.g. not vgpr/not vgpr or inline imm)).

I think that would be perfect!

Another attempt in D139646, I could to get anything better with tools available in InstPrinter.
OperandType would not make much difference (maybe for printing more verbose error for /*invalid immediate*/), I skipped adding it for now since it was possible to print some meaningful msg without it.

As for better dissasembler diagnostic when sgpr/imm was used in VReg_* and VISrc_*, /*invalid immediate*/ and D139646 address them in good enough way.
It would probably be better if we could make more verbose warning than warning: invalid instruction encoding in some place before InstrPrinter.

arsenm requested changes to this revision.Dec 13 2022, 2:26 PM

Is this still relevant with D139646 committed?

This revision now requires changes to proceed.Dec 13 2022, 2:26 PM
Petar.Avramovic abandoned this revision.Dec 14 2022, 2:22 AM

Implemented D139646 instead.