-
Notifications
You must be signed in to change notification settings - Fork 44
fix(data): vsetvli/vsetivli: correct assembly and fields #838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
`vsetvli` and `vsetivli` accept the _components_ of VTYPEI as individual parameters, and they are encoded in individual fields. ...with a few additional `0` bits as a result, per the definition of vtype.
I'm a little confused as to why this is failing in CI. It's failing within "regress:smoke" in "test:llvm", complaining about a mismatch with the new (correct) operands and LLVM's apparent expectation of a single "vtype" operand. The RISC-V instruction syntax for
(Here, apparently using a single "vtypei" operand.) However, an example later (30.16.5 "Vector Compress Instruction") shows 6 operands:
The Sail code shows:
(6 operands, with lmul apparently being optional, and defaulting to "m1".) However, LLVM has:
(Not too familiar with this code, but it seems to show a single "vtypei" operand.) and the LLVM TableGen we use in the CI step shows:
Is LLVM wrong here, or is our interpretation of it wrong, or something else? @AFOliveira? @lenary? |
Some additional discussion over in this Sail PR: riscv/sail-riscv#1010. For valid values, the 4-component approach is used, but expressing them as a single immediate is also accepted by the assemblers and is the only way to express reserved values (which in this case does not mean that the instruction itself is reserved). |
For this sequence of instructions:
GCC emits the same encoding for each.
|
What's going on here is that LLVM has a custom parser for the vtype information: https://github.com/llvm/llvm-project/blob/b3873e8aa41be17b6664c918fd6ba30307361d08/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp#L2295 I haven't looked closely at how I would expect that LLVM will want to continue to bundle all the vsetvli operands into a single immediate, but I could be wrong, so this might be somewhere where we need a little gap between the "asmstring" in LLVM (which is using a more complex parser underneath), and the unified db information, when doing the cross-verification. |
Thankfully, @lenary arrived to the issue earlier than me and clarified much better than what I could have :) I see two ways of going forward here: If @ThinkOpenly opens that issue against LLVM:
I don't quite know how fast LLVM is in fixing this if they agree with our view here, but I can really just skip those test for now in a couple minutes if you want me to |
I see. Is there anything in the TableGen JSON that indicates that this instruction has a custom parser, or is weird in some way? (I didn't see anything obvious.) I'm just looking for a programmatic way to separate these two instructions from the herd.
UDB is going to need to accommodate all 3 different syntax possibilities somehow. There is no way to do that at present. Validating those three against the TableGen JSON is perhaps not possible. |
The intent of the vector spec is that the LMUL is not optional. Text saying it was optional was explicitly removed here riscv/riscv-isa-manual@75e857d |
Here's how it works in the tablegen. In the JSON, all "defs" should be available in the JSON, from what I understand. Starting at the Instruction definition for
To find the information about the operand, we find the def of
Which will have fields from its class,
In this case, we care about
It is the presence of the I would take the time to look in the LLVM RISC-V tablegen for Thanks |
Unfortunately, this removal happened years after ratification. So I guess LLVM might need to support it to be compatible with the ratified spec prior to this change? But independent of that, the SAIL code should probably reflect what's in the current text. And we should consider it being optional a historical artifact and not encourage its use. |
I don't see that a fix coming from LLVMland that would help, given our current use of the JSON. I think Sam's awesomely detailed overview of how to interpret the JSON could be used to intelligently skip this class of cases in general:
|
vsetvli
andvsetivli
accept the components of VTYPEI asindividual parameters, and they are encoded in individual fields.
...with a few additional
0
bits as a result, per thedefinition of vtype.