This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Don't parse 'vmsltu.vi v0, v1, 0' as 'vmsleu.vi v0, v1, -1'
ClosedPublic

Authored by craig.topper on Jan 4 2021, 3:09 PM.

Details

Summary

vmsltu.vi v0, v1, 0 is always false there is no unsigned number
less than 0. vmsleu.vi v0, v1, -1 on the other hand is always true
since -1 will be considered unsigned max and all numbers are <=
unsigned max.

A similar problem exists for vmsgeu.vi v0, v1, 0 which is always true,
but becomes vmsgtu.vi v0, v1, -1 which is always false.

To match the GNU assembler we'll emit vmsne.vv and vmseq.vv with
the same register for these cases instead.

I'm using AsmParserOnly pseudo instructions here because we can't
match an explicit immediate in an InstAlias. And we can't use a
AsmOperand for the zero because the output we want doesn't use an
immediate so there's nowhere to name the AsmOperand we want to use.

To keep the implementations similar I'm also handling signed with
pseudo instructions even though they don't have this issue. This
way we can avoid the special renderMethod that decremented by 1 so
the immediate we see for the pseudo instruction in processInstruction
is 0 and not -1. Another option might have been to have a different
simm5_plus1 operand for the unsigned case or just live with the
immediate being pre-decremented. I felt this way was clearer, but I'm
open to other opinions.

Diff Detail

Event Timeline

craig.topper created this revision.Jan 4 2021, 3:09 PM
craig.topper requested review of this revision.Jan 4 2021, 3:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 4 2021, 3:09 PM
Herald added a subscriber: MaskRay. · View Herald Transcript
craig.topper retitled this revision from [RISCV] Don't parse 'vsltu.vi v0, v1, 0' as 'vsleu.vi v0, v1, -1' to [RISCV] Don't parse 'vmsltu.vi v0, v1, 0' as 'vmsleu.vi v0, v1, -1'.Jan 4 2021, 5:37 PM
craig.topper edited the summary of this revision. (Show Details)
craig.topper edited the summary of this revision. (Show Details)Jan 4 2021, 7:45 PM
craig.topper edited the summary of this revision. (Show Details)

LGTM too, but pardon my ignorance: I thought we could match an explicit immediate in InstAliases? Or is it that we can't do the decrement? I'm only going by matching vxor -1 as vnot but that's how I interpret the word "match".

LGTM too, but pardon my ignorance: I thought we could match an explicit immediate in InstAliases? Or is it that we can't do the decrement? I'm only going by matching vxor -1 as vnot but that's how I interpret the word "match".

You can match an explicit immediate in the MCInst part of the alias. You can’t match an immediate in the text part. It ends up telling the parser to look for a string token containg “0”, but the lexer would never generate that.

frasercrmck accepted this revision.Jan 5 2021, 2:51 AM
This revision is now accepted and ready to land.Jan 5 2021, 2:51 AM