This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Teach lowerVECTOR_SHUFFLE to recognize some shuffles as vnsrl.
ClosedPublic

Authored by craig.topper on Sep 12 2022, 3:57 PM.

Details

Summary

Unary shuffles such as <0,2,4,6,8,10,12,14> or <1,3,5,7,9,11,13,15>
where half the elements are returned, can be lowered using vnsrl.

SelectionDAGBuilder lowers such shuffles as a build_vector of
extract_elements since the mask has less elements than the source.
To fix this, I've enable the extractSubvectorIsCheapHook to allow
DAGCombine to rebuild the shuffle using 2 extract_subvectors preceding
the shufffle.

I've gone very conservative on extractSubvectorIsCheapHook to minimize
test impact and match what we have test coverage for. This can be
improved in the future.

Diff Detail

Event Timeline

craig.topper created this revision.Sep 12 2022, 3:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 12 2022, 3:57 PM
craig.topper requested review of this revision.Sep 12 2022, 3:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 12 2022, 3:57 PM
reames accepted this revision.Sep 13 2022, 10:45 AM

LGTM

A couple thoughts for possible generalization.

I think we can extract any Nth element where N is a power of two, and N * sizeof(Element) is less than equal ELEN. So, every 8th element in an i8 vector for instance.

We should be able to handle a sequence with a non-zero/non-one base. This requires an extra slidedown to align the sequence.

As noted, we can handle undefs.

This revision is now accepted and ready to land.Sep 13 2022, 10:45 AM