Skip to content

Commit 7c281a9

Browse files
[AIE2] Implement legalization for G_SHUFFLE_VECTOR
This implements the simple legalization that lowers G_SHUFFLE_VECTOR into extracts of the elements based on the mask and then combining them using a G_BUILD_VECTOR. Our architecture has a VSHUFFLE instruction which could be used to implement some patterns more efficiently.
1 parent f2d030e commit 7c281a9

File tree

2 files changed

+663
-0
lines changed

2 files changed

+663
-0
lines changed

llvm/lib/Target/AIE/AIELegalizerInfo.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,29 @@ AIELegalizerInfo::AIELegalizerInfo(const AIEBaseSubtarget &ST) {
490490
.clampMaxNumElements(0, S16, 32)
491491
.clampMaxNumElements(0, S32, 16)
492492
.custom();
493+
494+
getActionDefinitionsBuilder(G_SHUFFLE_VECTOR)
495+
.unsupportedIf(IsNotValidDestinationVector)
496+
// ShuffleVector allows having scalar inputs
497+
.lowerIf([=](const LegalityQuery &Query) {
498+
const LLT DstTy = Query.Types[0];
499+
const LLT SrcTy = Query.Types[1];
500+
501+
return DstTy.isVector() && SrcTy.isScalar() &&
502+
(2 * SrcTy.getSizeInBits()) == DstTy.getSizeInBits();
503+
})
504+
.clampMinNumElements(0, S8, 32)
505+
.clampMinNumElements(0, S16, 16)
506+
.clampMinNumElements(0, S32, 8)
507+
// The most typical form of a shuffle is having it act as merge of two
508+
// vectors
509+
.lowerIf(isValidVectorMergeUnmergeOp(0, 1))
510+
// Checks if the shuffle is "canonical", this enables additional actions
511+
// in the LLVM backend
512+
.lowerIf([=](const LegalityQuery &Query) {
513+
return Query.Types[0] == Query.Types[1];
514+
})
515+
.lower();
493516
}
494517

495518
getActionDefinitionsBuilder(G_JUMP_TABLE).custom();

0 commit comments

Comments
 (0)