This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Implement splitting of G_SHUFFLE_VECTOR.
ClosedPublic

Authored by aemerson on May 20 2021, 12:39 AM.

Details

Summary

This is a port from the DAG legalization. We're still missing some of the canonicalizations of shuffles but it's a start.

Diff Detail

Event Timeline

aemerson created this revision.May 20 2021, 12:39 AM
aemerson requested review of this revision.May 20 2021, 12:39 AM
aemerson updated this revision to Diff 346644.May 20 2021, 12:40 AM
arsenm added inline comments.May 20 2021, 5:37 AM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4231

I don't like simply discarding NarrowTy. It would be better to compute the type you do handle, and fail if it doesn't match the requested type

4234–4236

It should be relatively easy to use extractGCDType + buildLCMMergePieces to form a widened vector for the non-power-of-2 case

aemerson added inline comments.May 20 2021, 10:04 AM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4231

But if you do that, fewerElements isn't going to know which narrow type it supports. Legalizing <16 x s64> is going to use a narrow ty of <2 x s64> with the rules as they're written now.

aemerson added inline comments.May 20 2021, 3:35 PM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4234–4236

I think for shuffle splitting, we should do what the DAG does here and insist on a power-of-2 size with moreElementsToNextPow2.

arsenm added inline comments.May 20 2021, 3:41 PM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4231

I don't follow, the parameter tells you which type to use

aemerson added inline comments.May 20 2021, 4:01 PM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4231

For AArch64, if you have an oversize shuffle like <8 x s64>, fewerElementsVector is called with NarrowTy set to <2 x s64> since that's the type that we support. We can't just error out if in that case since this can be legalized, it just needs to the fewerElementsVector action to be done multiple times until we reach <2 x s64>.

arsenm added inline comments.May 20 2021, 6:53 PM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4231

The API suggests this should make the full transform all the way to <2 x s64> pieces in one shot

aemerson added inline comments.May 20 2021, 7:26 PM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4234–4236

IIRC the original intention of the legalizer rewrite was that the legalisation could be done in steps if needed, with the type as a direction to move towards.

It also seems cleaner to me to use the existing mechanism to handle further illegal operations than to duplicate that logic twice.

arsenm accepted this revision.May 24 2021, 5:18 PM
arsenm added inline comments.
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4234–4236

Legalization can be done in multiple steps, but I think the fewerElements would be considered one step (e.g. as a further step the scalars could be legalized)

This revision is now accepted and ready to land.May 24 2021, 5:18 PM
This revision was landed with ongoing or failed builds.May 27 2021, 12:29 AM
This revision was automatically updated to reflect the committed changes.