This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Implement assembler support for XTHeadVdot
ClosedPublic

Authored by JojoR on Dec 5 2022, 6:37 PM.

Details

Summary

This patch implements the T-Head vendor extensions (XTHeadVdot),
which is documented here, it's based on standard vector extension v1.0:

https://github.com/T-head-Semi/thead-extension-spec

Diff Detail

Event Timeline

JojoR created this revision.Dec 5 2022, 6:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 5 2022, 6:37 PM
JojoR requested review of this revision.Dec 5 2022, 6:37 PM
JojoR edited the summary of this revision. (Show Details)Dec 5 2022, 6:58 PM
jrtc27 added a comment.Dec 5 2022, 7:01 PM

Aside from the maintainability question of having two similar but conflicting scalable vector extensions in the backend, this needs splitting up into separate MC, CodeGen and Clang patches like any other extension.

clang/include/clang/Basic/riscvTHEAD_vector.td
1 ↗(On Diff #480309)

You have a lot of files with a blank first line and no header

clang/include/clang/Basic/riscv_vector.td
65 ↗(On Diff #480309)

Maybe this "only" has some clear meaning to those familiar to V but I have no clue from reading this how it differs from "q". From reading the code it seems to just be q without affecting LMUL; maybe that should be a non-primitive type transformer or something so we don't end up expanding out the whole orthogonal space.

2396 ↗(On Diff #480309)

riscv_thead_vector maybe? This is really ugly

clang/test/CodeGen/RISCV/Vendor/THEAD/vdot-intrinsics-overloaded/vmaqa.c
3 ↗(On Diff #480309)

These tests are using +v not +xtheadvdot and demonstrates that your intrinsics aren't predicted on the right thing, since this should give an error

5 ↗(On Diff #480309)

I don't think T-Head intrinsics belong in riscv_vector.h, that's for V

llvm/include/llvm/IR/IntrinsicsRISCVxTHEAD.td
1 ↗(On Diff #480309)

Xthead is the standard capitalisation for extensions when not doing lowercase

4 ↗(On Diff #480309)

TH_ given it's "th."

llvm/lib/Target/RISCV/CMakeLists.txt
74 ↗(On Diff #480309)

Do we really need this? It's only a handful of TableGen files, all of which should have the extension (or family) name in them. Hopefully we're not going to have so many that we'll need this...

llvm/lib/Target/RISCV/RISCV.td
539

We already have a block in this file for vendor extensions

llvm/lib/Target/RISCV/RISCVInstrInfoV.td
1715 ↗(On Diff #480309)

Put this at the top level, don't tie it to V

1717 ↗(On Diff #480309)

Include this in the InstrInfo file

llvm/lib/Target/RISCV/RISCVSubtarget.h
36 ↗(On Diff #480309)

... no

llvm/lib/Target/RISCV/Vendor/CMakeLists.txt
2 ↗(On Diff #480309)

As for the Vendor directory itself... seems wholly unnecessary

llvm/lib/Target/RISCV/Vendor/THEAD/THEAD.td
2 ↗(On Diff #480309)

VDot seems more natural

llvm/lib/Target/RISCV/Vendor/THEAD/THEADInstrInfoV.td
1 ↗(On Diff #480309)

This isn't V, don't call it V

5 ↗(On Diff #480309)

Unclear if it should be tied to V or use its own classes

llvm/lib/Target/RISCV/Vendor/THEAD/THEADSubtarget.h
6 ↗(On Diff #480309)

Fix

llvm/test/CodeGen/RISCV/Vendor/THEAD/attributes.ll
5 ↗(On Diff #480309)

xventanacondops is being tested in the normal attributes.ll

llvm/test/CodeGen/RISCV/Vendor/THEAD/vdot/vmaqa.ll
2 ↗(On Diff #480309)

+v should be incompatible

craig.topper added inline comments.Dec 5 2022, 7:37 PM
llvm/lib/Target/RISCV/Vendor/THEAD/THEADInstrInfoV.td
5 ↗(On Diff #480309)

Need a DecoderNamespace

craig.topper added inline comments.Dec 5 2022, 7:43 PM
llvm/lib/Target/RISCV/Vendor/THEAD/THEAD.td
3 ↗(On Diff #480309)

Probably need to imply at least Zve32x. Here and in RISCVISAInfo.cpp

reames added a subscriber: reames.Dec 6 2022, 8:04 AM

I have not looked at the change at all (yet), but a couple of high level points.

  1. Please link not to the repository, but a specific version of the PDF. We need to know exactly what version of the specification is being implemented. For instance, I was looking at https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.2.0/xthead-2022-12-04-2.2.0.pdf. Please update RISCVUsage.rst to contain the same information. This will form the user focused documentation.
  1. Can you clarify whether the extension is based on v1.0 or a prior vector specification revision? From the document, it looks like this might be based on v1.0. Getting an extension based off v1.0 into tree will be much easier than one based on v0.7, so being clear is in your interest here. Ideally, you'd revise the specification document to be explicit here as well.
  1. Please split the patch. The first patch for review should add the MC (assembly) part only.
  1. I very strongly encourage you to attend the riscv sync up call happening on Thursday of this week. This will be a likely topic of discussion.
JojoR updated this revision to Diff 481237.Dec 8 2022, 4:21 AM
JojoR updated this revision to Diff 481241.Dec 8 2022, 4:25 AM
JojoR marked 3 inline comments as done.Dec 8 2022, 4:28 AM
JojoR added inline comments.Dec 8 2022, 5:14 AM
clang/test/CodeGen/RISCV/Vendor/THEAD/vdot-intrinsics-overloaded/vmaqa.c
5 ↗(On Diff #480309)

Thanks for your comments :)

from our ISAs spec if you have seen it, they are designed based on vector v1.0,
and most rules of that like mc or intrinsic derive from RVV code, so I could copy whole from that,
but I think RISCV is base code for vendor's function if they want to reuse them like llvm code is base code for all backend. we should encourage vendor to reuse RISCV base code if they are stable and help vendor construct function easily or quickly, alright ?

What header file should we supply for this ? any suggestion ?

llvm/lib/Target/RISCV/CMakeLists.txt
74 ↗(On Diff #480309)

Thanks for your comments :)

We should make the long term planning because of RISCV ISAs allow vendor to extend their personal ISAs, alright ? :)

And for another hand, we should also help or guide vendor put their code in the the individual root space, I think it's convenience for vendor and RISCV, you can say one step to create customer's extension: "just copy a skeleton from Vendor sub-directory" :)

I believe that RISCV is open and most of vendors want to put their ISAs into community :)
you think about if there are more than 20 vendors ? is it possible ?

llvm/lib/Target/RISCV/RISCV.td
539

Like my consideration is described above, there will be much more vendors ?
they should maintain their stuffs in some one root place ?

llvm/lib/Target/RISCV/RISCVSubtarget.h
36 ↗(On Diff #480309)

Like my consideration is described above, there will be much more vendors ?
they should maintain their stuffs in some one root place ?

llvm/lib/Target/RISCV/Vendor/THEAD/THEADInstrInfoV.td
1 ↗(On Diff #480309)

I think I explain reason clearly above, do you agree ?

JojoR added a comment.Dec 8 2022, 5:19 AM

I have not looked at the change at all (yet), but a couple of high level points.

  1. Please link not to the repository, but a specific version of the PDF. We need to know exactly what version of the specification is being implemented. For instance, I was looking at https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.2.0/xthead-2022-12-04-2.2.0.pdf. Please update RISCVUsage.rst to contain the same information. This will form the user focused documentation.
  1. Can you clarify whether the extension is based on v1.0 or a prior vector specification revision? From the document, it looks like this might be based on v1.0. Getting an extension based off v1.0 into tree will be much easier than one based on v0.7, so being clear is in your interest here. Ideally, you'd revise the specification document to be explicit here as well.
  1. Please split the patch. The first patch for review should add the MC (assembly) part only.
  1. I very strongly encourage you to attend the riscv sync up call happening on Thursday of this week. This will be a likely topic of discussion.

Thanks for your comments and I will attend if I am free at that time :)

asb added a comment.Dec 9 2022, 2:37 AM

Just to document the discussion we had in the RISC-V sync call yesterday, my understanding is that we concluded there aren't objections to reviewing and merging support for this extension once reviewers are happy with code quality, on the basis that the extension is relatively small, there are people willing to support it, and it's based on v1.0 vector ISA rather than 0.7 (which would trigger a much larger discussion).

craig.topper added inline comments.Dec 9 2022, 4:15 PM
llvm/lib/Target/RISCV/Vendor/THEAD/THEADSubtarget.h
1 ↗(On Diff #481241)

I have a patch up to auto generate this from tablegen.

https://reviews.llvm.org/D139746

craig.topper added inline comments.Dec 9 2022, 4:18 PM
llvm/lib/Target/RISCV/RISCV.td
539

Line 438 already created a section called "Vendor extensions" that contains vendor subtarget features.

JojoR updated this revision to Diff 482339.Dec 12 2022, 7:07 PM
JojoR edited the summary of this revision. (Show Details)
JojoR marked an inline comment as done.Dec 12 2022, 7:10 PM
JojoR added inline comments.
llvm/test/CodeGen/RISCV/Vendor/THEAD/vdot/vmaqa.ll
2 ↗(On Diff #480309)

Where is the incompatibility ?

craig.topper added inline comments.Dec 12 2022, 7:16 PM
llvm/lib/Target/RISCV/RISCV.td
450

I think THEAD should be T-Head in the description since that is user visible?

JojoR updated this revision to Diff 482344.Dec 12 2022, 7:33 PM
JojoR added inline comments.Dec 12 2022, 7:35 PM
llvm/lib/Target/RISCV/RISCV.td
450

Good point, I will refine this in the next version, thanks :)

JojoR updated this revision to Diff 482364.Dec 12 2022, 11:02 PM
JojoR marked 4 inline comments as done.
JojoR updated this revision to Diff 482371.Dec 12 2022, 11:45 PM
JojoR updated this revision to Diff 482417.Dec 13 2022, 2:51 AM
JojoR added a comment.Dec 13 2022, 6:04 PM

I am confused about the failures of CI testing and checked that is AddressSanitizer-Unit of x86,
it looks there is no relation between AddressSanitizer and this patch,
could anyone give me some hints for the failures ? thanks :)

I am confused about the failures of CI testing and checked that is AddressSanitizer-Unit of x86,
it looks there is no relation between AddressSanitizer and this patch,
could anyone give me some hints for the failures ? thanks :)

If these failures are apparently irrelevant to your changes, you can just ignore them since they may be caused by other landed patches.
A rebasing on main branch may help.

If this is some new T-Head extension based on the ratified V 1.0 rather than the 0.7.1 draft implemented in existing T-Head hardware then the compatibility points I made can be ignored. I would prefer that llvm/test remain flatter though and not have Vendor/THEAD/vdot, just use a single level with xtheadvdot as the name. In the case of MC I'd go one step further and say, given it's just a single file (that should conform to the -(in)valid.s convention that already exists there) it should be xtheadvdot-valid.s or whatever (just copy the Ventana approach).

jrtc27 added inline comments.Dec 13 2022, 6:36 PM
llvm/include/llvm/IR/IntrinsicsRISCV.td
1589 ↗(On Diff #482417)

IntrinsicsRISCVXThead?

JojoR updated this revision to Diff 482717.Dec 13 2022, 10:00 PM
JojoR marked an inline comment as done.

It seems we have split Clang changes off, but this patch still mix MC and CodeGen changes.
I think we can do further splitting to make it easier to review (separate MC and CodeGen). :-)

llvm/lib/Target/RISCV/RISCVInstrInfoXTHeadV.td
1 ↗(On Diff #482717)

RISCVInstrInfoXTHeadV.td -> RISCVInstrInfoXTHeadVdot.td?

llvm/lib/Target/RISCV/RISCVInstrInfoXTHeadVPseudo.td
1 ↗(On Diff #482717)

RISCVInstrInfoXTHeadVPseudo.td -> RISCVInstrInfoXTHeadVdotPseudo.td?

llvm/lib/Target/RISCV/RISCVInstrInfoXTHeadVPseudo.td
1 ↗(On Diff #482717)

Pseudo->Pseudos

craig.topper added inline comments.Dec 15 2022, 12:39 AM
llvm/lib/Target/RISCV/RISCVInstrInfoXTHeadV.td
29 ↗(On Diff #482717)

Missing DecoderNamespace?

61 ↗(On Diff #482717)

Merge these into a single let?

llvm/lib/Target/RISCV/RISCVInstrInfoXTHeadVPseudo.td
21 ↗(On Diff #482717)

Quadenable -> QuadWidenable.

59 ↗(On Diff #482717)

indent this 4 more spaces

72 ↗(On Diff #482717)

indent this 4 more spaces

Next step to make progress here is to strip out everything which isn't related to MC (assembler and disassembler). The intrinsic codegen changes should be a separate patch.

llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td
2

Minor: Splitting this off into three different files seems to have little value to me. I would merge all the contents of XTHead* into the root file. If we add further extensions where the division becomes worthwhile, we can split at that time.

llvm/test/CodeGen/RISCV/xtheadvdot/vmaqa.ll
1 ↗(On Diff #482717)

Minor: These dependent on vector, so they should be in the rvv subtree.

Naming wise, I'd stop the xtheadvdot directory, and just prefix the paths.

Ex: test/CodeGen/RISCV/rvv/xtheadvdot-vmaqa.ll

JojoR updated this revision to Diff 483863.Dec 18 2022, 11:33 PM
JojoR retitled this revision from [RISCV][THEAD] Vendor extensions: Add 'XTheadVdot' T-Head vendor extensions to [RISCV] Implement assembler support for XTHeadVdot.
JojoR edited the summary of this revision. (Show Details)
JojoR marked an inline comment as done.
JojoR updated this revision to Diff 483866.Dec 18 2022, 11:52 PM
llvm/test/MC/RISCV/XTHeadVdot-valid.s
1

Change the file name to lower case?

JojoR added inline comments.Dec 19 2022, 12:06 AM
llvm/test/MC/RISCV/XTHeadVdot-valid.s
1

We would like this could be align with other vendors like Ventana,
you can see "XVentanaCondOps-valid.s"

JojoR marked an inline comment as done.Dec 19 2022, 12:07 AM
eopXD accepted this revision.Dec 20 2022, 2:16 AM

Looks good to me.

This revision is now accepted and ready to land.Dec 20 2022, 2:16 AM
asb added a comment.Feb 7 2023, 2:35 AM

Reverse ping on this - @JojoR are there outstanding changes you have planned for this, or is it ready to go on from your perspective. I _think_ the review comments were all addressed and of course it got a LGTM from eop.

llvm/docs/RISCVUsage.rst
164

riscv-toolchai-convention => riscv-toolchain-convention