This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Lower inserts into identity shuffles as v{,f}slide1ups
Needs ReviewPublic

Authored by luke on May 30 2023, 10:17 AM.

Details

Summary

Inserting an element at index 0, into a shuffle that's an identity shuffle past the first
element, can be achieved with a single v{,f}slide1up. This patch detects such shuffles with
the isIdentityMask logic and lowers it to said vslide1up.

Diff Detail

Event Timeline

luke created this revision.May 30 2023, 10:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2023, 10:17 AM
luke requested review of this revision.May 30 2023, 10:17 AM
frasercrmck added inline comments.May 30 2023, 10:29 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
6189

This function seems to assert that the mask is not empty. Is it all possible we could end up triggering this assert with one-element vectors? Would we better be moving the VecVT.getVectorNumElements() > 1 check before calling isIdentityMask?

Could we try and add testing for the above case?

Description wise, calling an slideup-by-one mask an identity mask feels very odd to me. It took me a bit reading the code to figure out what you meant by that, and I'd suggest rewording. I'd suggest something along the lines of "would be identity mask if shifted down by one position" or something along those lines.

Did you look at the alternative of adding a DAG combine to reverse the shuffle+insert form into the insert+shuffle form? That'd been what I'd been tentatively thinking about, but I hadn't explored it past idea phase.

llvm/test/CodeGen/RISCV/rvv/fixed-vector-shuffle-vslide1up.ll
318

You can go ahead and precommit these tests without further review.

luke added a comment.May 31 2023, 2:19 AM

Did you look at the alternative of adding a DAG combine to reverse the shuffle+insert form into the insert+shuffle form? That'd been what I'd been tentatively thinking about, but I hadn't explored it past idea phase.

Not yet, but I'd like to explore that option before returning to this patch. This combine feels very specific and doesn't seem to be catch any cases in the benchmarks I've been looking at.

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

Good catch, definitely meant to move the`VecVT.getVectorNumElements() > 1` first.