This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Combine (vrgather src, vid) -> vmerge
AbandonedPublic

Authored by luke on Mar 22 2023, 6:09 AM.

Details

Summary

If a vrgather is using vid as its index, and they both have the same
mask and VL, then it can be replaced with a vmerge of the source and
passthru vectors.

Diff Detail

Event Timeline

luke created this revision.Mar 22 2023, 6:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2023, 6:09 AM
luke requested review of this revision.Mar 22 2023, 6:09 AM
luke added inline comments.
llvm/test/CodeGen/RISCV/rvv/combine-gather.ll
11

The vmerge gets folded away at the pseudo instruction stage: https://reviews.llvm.org/D133255#inline-1283170

Perhaps the easiest thing to do here is just check for an all ones mask in this combine

luke updated this revision to Diff 507335.Mar 22 2023, 6:13 AM

Update comment

luke marked an inline comment as not done.Mar 22 2023, 6:13 AM
craig.topper added inline comments.Mar 22 2023, 8:30 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
11055

I'm not sure you want VP_MERGE_VL here. VP_MERGE_VL is supposed to be tail undisturbed. I think you want RISCVISD::VSELECT_VL.

llvm/test/CodeGen/RISCV/rvv/combine-gather.ll
18

Shouldn't we be able to implement this shuffle with vslideup/down?

luke added inline comments.Mar 23 2023, 2:28 AM
llvm/test/CodeGen/RISCV/rvv/combine-gather.ll
18

Yes, I think so. I was working on a patch for this, I’ll put it up later today.
It might actually supersede this patch since it prevents the vrgather vid from being generated when lowering vector_shuffle. And I’m not sure if there’s anywhere else where that sequence of nodes is emitted.

luke abandoned this revision.Mar 23 2023, 4:16 AM

Rather than optimise this case, I've uploaded D146711 to try and avoid the gathers in the first place