Skip to content
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

riscv64: Implement iadd_pairwise #6568

Merged
merged 4 commits into from
Jun 16, 2023

Conversation

afonso360
Copy link
Contributor

👋 Hey,

This PR implements both the move instruction for vector registers and iadd_pairwise.

We can't really implement iadd_pairwise in the best way possible, since that requires supporting LMUL > 1 which dynamically changes how many registers are available. (At least as far as I know, If regalloc supports this it would be nice to start using it)

@afonso360 afonso360 added the cranelift:area:riscv64 Issues related to the RISC-V 64 backend. label Jun 12, 2023
@afonso360 afonso360 requested review from a team as code owners June 12, 2023 23:47
@afonso360 afonso360 requested review from fitzgen and removed request for a team June 12, 2023 23:47
Comment on lines 660 to 666
if op.forbids_src_dst_overlaps() {
collector.reg_late_use(vd_src);
} else {
collector.reg_use(vd_src);
}

collector.reg_reuse_def(vd, 1); // `vd` == `vd_src`.
Copy link
Contributor Author

@afonso360 afonso360 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vslideup instruction both modifies the destination register and also has the requirement that none of the input registers must be the same as the destination register.

I've used reg_late_use and reg_reuse_def to model this (and it seems to work), but this always emits a move before the instruction even when the register is otherwise unused, so there's probably a better way of expressing this which I'm not entirely sure how

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the intended semantics here: src and dst (vd_src and vd, rather) must not overlap, but vd is also a reuse of vd_src? Or is the non-overlap constraint between vs2 and vd?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I could have written that better. vd must be the same as vd_src (since they are encoded in the same field), and none of the other inputs (vs2 and vm) must be the same register as vd.

vm (The mask register) is slightly hidden here since it's not always applicable, but when it is, it's a fixed_use(v0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, OK. The right way to encode that is probably to use a late-use on vs2 (and on vm when present), rather than on vd_src, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'm not entirely sure I did the right thing. I also couldn't find something along the lines of reg_fixed_late_use for vm, does regalloc support encoding multiple constraints by calling reg_fixed_use and reg_late_use on the same VReg?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it should be possible to do that -- if it's not on the OperandCollector API we can add it. The early/late ("position"), use/def ("kind"), and fixed/any/reg/stack ("constraint") are all orthogonal fields of the Operand.

@jameysharp
Copy link
Contributor

This looks good to me; I'd just like @cfallin to review the regalloc bits and then approve this if that part looks okay.

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. labels Jun 13, 2023
@elliottt elliottt removed the request for review from a team June 14, 2023 00:05
@afonso360 afonso360 force-pushed the riscv-simd-iadd-pairwise branch from 239e348 to e1aeee9 Compare June 14, 2023 11:40
@afonso360 afonso360 requested a review from cfallin June 16, 2023 15:18
@cfallin cfallin added this pull request to the merge queue Jun 16, 2023
Merged via the queue into bytecodealliance:main with commit 62019b2 Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:riscv64 Issues related to the RISC-V 64 backend. cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants