Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit f317897

Browse files
committed
[X86][SSE] Split off matchVectorShuffleWithPACK. NFCI.
Split matchVectorShuffleWithPACK from lowerVectorShuffleWithPACK so that we can reuse it for target shuffle combines git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316844 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a101cd0 commit f317897

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

lib/Target/X86/X86ISelLowering.cpp

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8756,45 +8756,70 @@ static SDValue lowerVectorShuffleWithUNPCK(const SDLoc &DL, MVT VT,
87568756

87578757
// X86 has dedicated pack instructions that can handle specific truncation
87588758
// operations: PACKSS and PACKUS.
8759-
static SDValue lowerVectorShuffleWithPACK(const SDLoc &DL, MVT VT,
8760-
ArrayRef<int> Mask, SDValue V1,
8761-
SDValue V2, SelectionDAG &DAG,
8762-
const X86Subtarget &Subtarget) {
8759+
static bool matchVectorShuffleWithPACK(MVT VT, MVT &SrcVT, SDValue &V1,
8760+
SDValue &V2, unsigned &PackOpcode,
8761+
ArrayRef<int> TargetMask,
8762+
SelectionDAG &DAG,
8763+
const X86Subtarget &Subtarget) {
87638764
unsigned NumElts = VT.getVectorNumElements();
87648765
unsigned BitSize = VT.getScalarSizeInBits();
87658766
MVT PackSVT = MVT::getIntegerVT(BitSize * 2);
87668767
MVT PackVT = MVT::getVectorVT(PackSVT, NumElts / 2);
87678768

8768-
auto LowerWithPACK = [&](SDValue N1, SDValue N2) {
8769+
auto MatchPACK = [&](SDValue N1, SDValue N2) {
87698770
SDValue VV1 = DAG.getBitcast(PackVT, N1);
87708771
SDValue VV2 = DAG.getBitcast(PackVT, N2);
87718772
if ((N1.isUndef() || DAG.ComputeNumSignBits(VV1) > BitSize) &&
8772-
(N2.isUndef() || DAG.ComputeNumSignBits(VV2) > BitSize))
8773-
return DAG.getNode(X86ISD::PACKSS, DL, VT, VV1, VV2);
8773+
(N2.isUndef() || DAG.ComputeNumSignBits(VV2) > BitSize)) {
8774+
V1 = VV1;
8775+
V2 = VV2;
8776+
SrcVT = PackVT;
8777+
PackOpcode = X86ISD::PACKSS;
8778+
return true;
8779+
}
87748780

87758781
if (Subtarget.hasSSE41() || PackSVT == MVT::i16) {
87768782
APInt ZeroMask = APInt::getHighBitsSet(BitSize * 2, BitSize);
87778783
if ((N1.isUndef() || DAG.MaskedValueIsZero(VV1, ZeroMask)) &&
8778-
(N2.isUndef() || DAG.MaskedValueIsZero(VV2, ZeroMask)))
8779-
return DAG.getNode(X86ISD::PACKUS, DL, VT, VV1, VV2);
8784+
(N2.isUndef() || DAG.MaskedValueIsZero(VV2, ZeroMask))) {
8785+
V1 = VV1;
8786+
V2 = VV2;
8787+
SrcVT = PackVT;
8788+
PackOpcode = X86ISD::PACKUS;
8789+
return true;
8790+
}
87808791
}
87818792

8782-
return SDValue();
8793+
return false;
87838794
};
87848795

87858796
// Try binary shuffle.
87868797
SmallVector<int, 32> BinaryMask;
87878798
createPackShuffleMask(VT, BinaryMask, false);
8788-
if (isShuffleEquivalent(V1, V2, Mask, BinaryMask))
8789-
if (SDValue Pack = LowerWithPACK(V1, V2))
8790-
return Pack;
8799+
if (isTargetShuffleEquivalent(TargetMask, BinaryMask))
8800+
if (MatchPACK(V1, V2))
8801+
return true;
87918802

87928803
// Try unary shuffle.
87938804
SmallVector<int, 32> UnaryMask;
87948805
createPackShuffleMask(VT, UnaryMask, true);
8795-
if (isShuffleEquivalent(V1, V2, Mask, UnaryMask))
8796-
if (SDValue Pack = LowerWithPACK(V1, V1))
8797-
return Pack;
8806+
if (isTargetShuffleEquivalent(TargetMask, UnaryMask))
8807+
if (MatchPACK(V1, V1))
8808+
return true;
8809+
8810+
return false;
8811+
}
8812+
8813+
static SDValue lowerVectorShuffleWithPACK(const SDLoc &DL, MVT VT,
8814+
ArrayRef<int> Mask, SDValue V1,
8815+
SDValue V2, SelectionDAG &DAG,
8816+
const X86Subtarget &Subtarget) {
8817+
MVT PackVT;
8818+
unsigned PackOpcode;
8819+
if (matchVectorShuffleWithPACK(VT, PackVT, V1, V2, PackOpcode, Mask, DAG,
8820+
Subtarget))
8821+
return DAG.getNode(PackOpcode, DL, VT, DAG.getBitcast(PackVT, V1),
8822+
DAG.getBitcast(PackVT, V2));
87988823

87998824
return SDValue();
88008825
}

0 commit comments

Comments
 (0)