This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Use vmv.s.x to build one element splat vector.
ClosedPublic

Authored by jacquesguan on Dec 25 2021, 2:12 AM.

Details

Summary

When we want to create an splat vector that only the first element is initialized, we could use vmv.x.s to build it.

Diff Detail

Event Timeline

jacquesguan created this revision.Dec 25 2021, 2:12 AM
jacquesguan requested review of this revision.Dec 25 2021, 2:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 25 2021, 2:12 AM

Do you have a particular microarchitecture where this is a faster sequence?

Why only integer and not FP?

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
2258

benefited->benefit

Do you have a particular microarchitecture where this is a faster sequence?

Why only integer and not FP?

I think that vmv.s.x has less demand on VL and VTYPE, so using vmv.s.x instead vmv.v.x might reduce the amount of VSETVLI instructions that we will insert.

I missed the floating point scalar move instruction, if you think it make sense, I will add it.

Do you have a particular microarchitecture where this is a faster sequence?

Why only integer and not FP?

I think that vmv.s.x has less demand on VL and VTYPE, so using vmv.s.x instead vmv.v.x might reduce the amount of VSETVLI instructions that we will insert.

I missed the floating point scalar move instruction, if you think it make sense, I will add it.

Can this prevent .vx instructions from being recognized from an arithmetic operation plus a splat?

Do you have a particular microarchitecture where this is a faster sequence?

Why only integer and not FP?

I think that vmv.s.x has less demand on VL and VTYPE, so using vmv.s.x instead vmv.v.x might reduce the amount of VSETVLI instructions that we will insert.

I missed the floating point scalar move instruction, if you think it make sense, I will add it.

Can this prevent .vx instructions from being recognized from an arithmetic operation plus a splat?

I think it won't, and all RISCV CodeGen test cases could pass with this change.

Add the same change for the floating point scalar move instruction.

craig.topper retitled this revision from [RISCV] Use vmv.x.s to build one element splat vector. to [RISCV] Use vmv.s.x to build one element splat vector..Dec 28 2021, 8:50 AM
craig.topper added inline comments.
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-fp.ll
191

The CHECK lines here disappeared

230

And here

266

This might be a regresson some microarchitectures.

rebase main and update test.

jacquesguan added inline comments.Dec 30 2021, 3:54 AM
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-fp.ll
191

Done

230

Done

266

Done

jacquesguan added inline comments.Dec 30 2021, 3:56 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
2258

Done

frasercrmck added inline comments.Jan 3 2022, 3:57 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
2258

I'm not sure what "benefit from immediate" is saying. Is this a workaround to keep immediate patterns like vadd.vi matching?

khchen added inline comments.Jan 3 2022, 9:32 AM
llvm/test/CodeGen/RISCV/rvv/vreductions-int-rv32.ll
1599

Spec said If SEW > XLEN, the value is sign-extended to SEW bits.
Does it mean we could also use vmv.s.x here?

This patch only seems to handle reductions and vmv.v.x intrinsics. A single element BUILD_VECTOR would still produce a vmv.v.x.

I think that vmv.s.x has less demand on VL and VTYPE, so using vmv.s.x instead vmv.v.x might reduce the amount of VSETVLI instructions that we will insert.

Do any of the test cases show this benefit? If not, can you create one?

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
2258

It's preventing vmv.v.i from becoming li+vmv.s.x. Splat matching isn't affected because this patch doesn't change the behavior of BUILD_VECTOR handling.

Address comment and rebase main.

This patch only seems to handle reductions and vmv.v.x intrinsics. A single element BUILD_VECTOR would still produce a vmv.v.x.

I think that vmv.s.x has less demand on VL and VTYPE, so using vmv.s.x instead vmv.v.x might reduce the amount of VSETVLI instructions that we will insert.

Do any of the test cases show this benefit? If not, can you create one?

Yes, there are serval cases that already show the changes, for example, llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-fp.ll and llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-fp.ll.

llvm/test/CodeGen/RISCV/rvv/vreductions-int-rv32.ll
1599

Done, thanks.

craig.topper added inline comments.Jan 7 2022, 1:49 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
2257

Use bool and isa instead of dyn_cast since you don't care about the value.

Address comment.

jacquesguan added inline comments.Jan 10 2022, 1:26 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
2257

I add a check if the constant could be an immediate in the below if condition.

This revision is now accepted and ready to land.Jan 10 2022, 10:14 AM