This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Legalize G_SHUFFLE_VECTOR with different lengths
ClosedPublic

Authored by dzhidzhoev on Aug 18 2022, 5:32 PM.

Details

Summary

Legalize G_SHUFFLE_VECTOR having destination vector length greater than
source vector length by reshaping source vectors.

Partial implementation of SelectionDAGBuilder::visitShuffleVector.

Diff Detail

Event Timeline

dzhidzhoev created this revision.Aug 18 2022, 5:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2022, 5:32 PM
dzhidzhoev requested review of this revision.Aug 18 2022, 5:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2022, 5:32 PM

Rebase & ping

paquette added inline comments.Aug 25 2022, 4:02 PM
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
968

might want a TODO here so we can see it ought to be supported?

975

can we have a comment here which, at a high level, describes the general legalization algorithm/approach?

988

static_cast for greppability?

aemerson added a subscriber: foad.Aug 26 2022, 3:23 AM

I’m on vacation so haven’t done a review, but this seems to be something that needs to be done generically for all targets. I was considering doing this as some sort of canonicalization phase during translation but wasn’t decided.

@arsenm @foad any opinions on where we should do this?

foad added a comment.Aug 30 2022, 4:51 AM

this seems to be something that needs to be done generically for all targets

It seems like something that could be available in LegalizerHelper for targets that want to use it. I don't see why it is necessarily required for all targets.

this seems to be something that needs to be done generically for all targets

It seems like something that could be available in LegalizerHelper for targets that want to use it. I don't see why it is necessarily required for all targets.

In that case I wonder if this could be done as a Lower action as an intermediate step before the legalizer tries to scalarize the shuffle.

this seems to be something that needs to be done generically for all targets

It seems like something that could be available in LegalizerHelper for targets that want to use it. I don't see why it is necessarily required for all targets.

In that case I wonder if this could be done as a Lower action as an intermediate step before the legalizer tries to scalarize the shuffle.

But on second thought, doing so would probably make the target's legalizer rules more complex since we'd have to check for non-canonical forms with the legalizer predicates.

This is a similarly complicated case to unaligned load/store access. My plan for that is to move all the logic into a generic lower function in LegalizerHelper, possibly with different implementation helper functions. However, the generic lower pass would be reliant on calling into some kind of TargetLowering hook to make decisions based on legal masks

arsenm requested changes to this revision.Nov 16 2022, 3:05 PM
arsenm added inline comments.
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
953

Nothing here really looks target specific, can this move to an implementation in LegalizerHelper? This looks like fewerElements to me

This revision now requires changes to proceed.Nov 16 2022, 3:05 PM

Moved the implementation to LegalizerHelper.

arsenm accepted this revision.Dec 13 2022, 2:19 PM
arsenm added inline comments.
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4995

Maybe use small size 16?

5000

If we don't have a MIRBuilder helper to create an extract with a constant index already, there should be one

llvm/test/CodeGen/AArch64/GlobalISel/legalize-shuffle-vector.mir
435

Some odd number of element cases would be nice

This revision is now accepted and ready to land.Dec 13 2022, 2:19 PM

Addressed @arsenm comments.

arsenm accepted this revision.Dec 14 2022, 10:40 AM
This revision was landed with ongoing or failed builds.Dec 15 2022, 4:03 AM
This revision was automatically updated to reflect the committed changes.
kda added a subscriber: kda.Dec 15 2022, 10:16 AM

This has broken UBSAN buildbot:
https://lab.llvm.org/buildbot/#/builders/85/builds/13003

I reverted it locally and it passed...
I will revert in 1 hour.