This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Improve codegen for shuffles with LHS/RHS splats
ClosedPublic

Authored by frasercrmck on Aug 4 2021, 5:05 AM.

Details

Summary

Shuffles which are broken into separate halves reveal splats in which
a half is accessed via one index; such operations can be optimized to
use "vrgather.vi".

This optimization could be achieved by adding extra patterns to match
vrgather_vv_vl which uses a splat as an index operand, but this patch
instead identifies splat earlier. This way, future optimizations can
build on top of the data gathered here, e.g., to splat-gather dominant
indices and insert any leftovers.

Diff Detail

Event Timeline

frasercrmck created this revision.Aug 4 2021, 5:05 AM
frasercrmck requested review of this revision.Aug 4 2021, 5:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2021, 5:05 AM
craig.topper added inline comments.Aug 5 2021, 8:47 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1986

Can this just be

++LHSIndexCounts[MaskIndex]

It should default construct a 0 the first time it is accessed.

frasercrmck added inline comments.Aug 5 2021, 9:12 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1986

Yeah I hope I'm being overly cautious here, but I wasn't sure. I couldn't find it explicitly documented in the DenseMap API unlike for std::map and I saw this idiom used elsewhere. From what I can see, the DenseMap implementation is indeed value-initializing (i.e. zero-initializing for unsigned) - is that strong enough to rely on?

craig.topper added inline comments.Aug 5 2021, 9:18 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1986

I think so. I was able to find other places that rely on it.

  • simplify awkward use of DenseMap
frasercrmck marked 2 inline comments as done.Aug 6 2021, 2:03 AM
frasercrmck added inline comments.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1986

Thanks for the assurance, that's much nicer!

This revision is now accepted and ready to land.Aug 6 2021, 11:46 AM
This revision was landed with ongoing or failed builds.Aug 9 2021, 2:41 AM
This revision was automatically updated to reflect the committed changes.
frasercrmck marked an inline comment as done.