This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support immediate vtype of VSETVLI/VSETIVLI in asm parser
ClosedPublic

Authored by Miss_Grape on Dec 5 2021, 10:55 PM.

Diff Detail

Event Timeline

Miss_Grape created this revision.Dec 5 2021, 10:55 PM
Miss_Grape requested review of this revision.Dec 5 2021, 10:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 5 2021, 10:55 PM
Miss_Grape retitled this revision from This patch is to add new syntax at the assembly level for the vsetvli and vsetvli instructions,eg:vsetvli rd, rs1, imm; vsetivli rd to [RISCV] Support immediate vtype of VSETVLI/VSETIVLI in asm parser.Dec 5 2021, 10:59 PM
Miss_Grape changed the repository for this revision from rW llvm-www to rG LLVM Github Monorepo.
benshi001 added a comment.EditedDec 5 2021, 11:01 PM

This patch impements TODOs in https://reviews.llvm.org/D114581

craig.topper added inline comments.Dec 6 2021, 11:29 AM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1673

Does binutils only except literal integers or does it support expressions?

1677

There are no illegal values in the immediate form for vlmul or vsew. The intention was to allow the disassembler to print immediates for reserved encodings. Anything that the disassembler prints must be parseable.

We do need to make sure the immedaite fits in 11 bits for vsetvli and 10 bits for vsetivli.

benshi001 added inline comments.Dec 6 2021, 11:49 PM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1673

I have tested the newest master of binutils,

  1. it does not support vtype being an expression, in fact there is no expression cases in binutils's unit tests.
  1. it still generate wrong dissambly against illegal vtype, for example, larger types such as e128
craig.topper added inline comments.Dec 7 2021, 9:24 AM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1673

Our internal version of bintuils does accept this vsetvli x0, x0, 0xff + 1. I haven't checked binutils compiled with public sources, but I expect they would be the same.

The disassembly bugs have been fixed in our internal branch of binutils. I'll find out when they'll be fixed in publicly available sources.

Support non-canonical syntax:

  1. vsetivli rd, uimm, 0xabc or vsetvli rd, rs1, 0xabc
  2. vsetivli rd, uimm, (0xc << N) or vsetvli rd, rs1, (0xc << N)
Miss_Grape marked an inline comment as done.Dec 9 2021, 11:00 PM
Miss_Grape added inline comments.
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1673

The latest patch already supports this representation.

craig.topper added inline comments.Dec 9 2021, 11:03 PM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
432

Capitalize 'if'

433

Immedidate -> Immediate

435

Drop curly braces

441

Drop curly braces

llvm/test/MC/RISCV/rvv/vsetvl.s
19

Why 2 spaces between each operand?

Miss_Grape added inline comments.Dec 10 2021, 12:16 AM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
432

Done

433

Done

435

Done

441

Done

llvm/test/MC/RISCV/rvv/vsetvl.s
19

Done

craig.topper added inline comments.Dec 15 2021, 1:00 PM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
423–443

This doesn't need to be a template. Just pass the bitwidth and use isUIntN instead of isUint

927

auto *CE Don't hide the * with auto.

Miss_Grape added inline comments.
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
423–443

Done

927

Done

craig.topper added inline comments.Dec 27 2021, 11:30 AM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
927

I think we need to call evaluateConstantImm here. Since we used evaluateConstantImm in isVTypeImm which can find an immediate that isn't from an MCConstantExpr. I think we should assert that evaluateConstantImm returns true since we checked that in isVTypeImm.

Miss_Grape added inline comments.
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
927

Done.

craig.topper added inline comments.Jan 5 2022, 10:36 PM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
928

You can't call evaluateConstantImm from inside the assert. The contents of the assert aren't evaluated in release builds. You'll need to use a variable to capture the result. And cast the variable to void to avoid an unused variable warning in release builds.

Miss_Grape marked an inline comment as done.
Miss_Grape added inline comments.
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
928

done

clang-format

LGTM other than trying to use RenderMethod.

llvm/lib/Target/RISCV/RISCVInstrInfoV.td
25–26

I think you can add

let RenderMethod = "addVTypeIOperands";

And avoid needing addVTypeI10Operands and addVTypeI11Operands in the assembler

craig.topper accepted this revision.Jan 6 2022, 9:06 AM
This revision is now accepted and ready to land.Jan 6 2022, 9:06 AM
benshi001 added inline comments.Jan 6 2022, 3:52 PM
llvm/lib/Target/RISCV/RISCVInstrInfoV.td
25–26

Thanks for your review, I will commit this patch for her. And will correct this when when doing git commit and git push.