Skip to content

[X86] Add growShuffleMask helper to grow the shuffle mask for a larger value type. NFC. #134243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3941,6 +3941,24 @@ static bool canScaleShuffleElements(ArrayRef<int> Mask, unsigned NumDstElts) {
return scaleShuffleElements(Mask, NumDstElts, ScaledMask);
}

// Helper to grow the shuffle mask for a larger value type.
// NOTE: This is different to scaleShuffleElements which is a same size type.
static void growShuffleMask(ArrayRef<int> SrcMask,
SmallVectorImpl<int> &DstMask,
unsigned SrcSizeInBits, unsigned DstSizeInBits) {
assert(DstMask.empty() && "Expected an empty shuffle mas");
assert((DstSizeInBits % SrcSizeInBits) == 0 && "Illegal shuffle scale");
unsigned Scale = DstSizeInBits / SrcSizeInBits;
unsigned NumSrcElts = SrcMask.size();
DstMask.assign(SrcMask.begin(), SrcMask.end());
for (int &M : DstMask) {
if (M < 0)
continue;
M = (M % NumSrcElts) + ((M / NumSrcElts) * Scale * NumSrcElts);
}
DstMask.append((Scale - 1) * NumSrcElts, SM_SentinelUndef);
}

/// Returns true if Elt is a constant zero or a floating point constant +0.0.
bool X86::isZeroNode(SDValue Elt) {
return isNullConstant(Elt) || isNullFPConstant(Elt);
Expand Down Expand Up @@ -40456,19 +40474,13 @@ static SDValue combineX86ShuffleChainWithExtract(
}

// Bail if we fail to find a source larger than the existing root.
unsigned Scale = WideSizeInBits / RootSizeInBits;
if (WideSizeInBits <= RootSizeInBits ||
(WideSizeInBits % RootSizeInBits) != 0)
return SDValue();

// Create new mask for larger type.
SmallVector<int, 64> WideMask(BaseMask);
for (int &M : WideMask) {
if (M < 0)
continue;
M = (M % NumMaskElts) + ((M / NumMaskElts) * Scale * NumMaskElts);
}
WideMask.append((Scale - 1) * NumMaskElts, SM_SentinelUndef);
SmallVector<int, 64> WideMask;
growShuffleMask(BaseMask, WideMask, RootSizeInBits, WideSizeInBits);

// Attempt to peek through inputs and adjust mask when we extract from an
// upper subvector.
Expand Down