mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-27 13:30:05 +00:00
Don't try to match 'unpackl/h v, v' for 32xi8 and 16xi16 when only AVX1 is supported. Fix 'unpackh v, v' for 256-bit types to understand 128-bit lanes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146726 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
de0cfe81b4
commit
94438ba538
@ -3472,7 +3472,7 @@ bool X86::isMOVLHPSMask(ShuffleVectorSDNode *N) {
|
||||
/// specifies a shuffle of elements that is suitable for input to UNPCKL.
|
||||
static bool isUNPCKLMask(const SmallVectorImpl<int> &Mask, EVT VT,
|
||||
bool HasAVX2, bool V2IsSplat = false) {
|
||||
int NumElts = VT.getVectorNumElements();
|
||||
unsigned NumElts = VT.getVectorNumElements();
|
||||
|
||||
assert((VT.is128BitVector() || VT.is256BitVector()) &&
|
||||
"Unsupported vector type for unpckh");
|
||||
@ -3486,11 +3486,9 @@ static bool isUNPCKLMask(const SmallVectorImpl<int> &Mask, EVT VT,
|
||||
unsigned NumLanes = VT.getSizeInBits()/128;
|
||||
unsigned NumLaneElts = NumElts/NumLanes;
|
||||
|
||||
unsigned Start = 0;
|
||||
unsigned End = NumLaneElts;
|
||||
for (unsigned s = 0; s < NumLanes; ++s) {
|
||||
for (unsigned i = Start, j = s * NumLaneElts;
|
||||
i != End;
|
||||
for (unsigned l = 0; l != NumLanes; ++l) {
|
||||
for (unsigned i = l*NumLaneElts, j = l*NumLaneElts;
|
||||
i != (l+1)*NumLaneElts;
|
||||
i += 2, ++j) {
|
||||
int BitI = Mask[i];
|
||||
int BitI1 = Mask[i+1];
|
||||
@ -3504,9 +3502,6 @@ static bool isUNPCKLMask(const SmallVectorImpl<int> &Mask, EVT VT,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Process the next 128 bits.
|
||||
Start += NumLaneElts;
|
||||
End += NumLaneElts;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -3522,7 +3517,7 @@ bool X86::isUNPCKLMask(ShuffleVectorSDNode *N, bool HasAVX2, bool V2IsSplat) {
|
||||
/// specifies a shuffle of elements that is suitable for input to UNPCKH.
|
||||
static bool isUNPCKHMask(const SmallVectorImpl<int> &Mask, EVT VT,
|
||||
bool HasAVX2, bool V2IsSplat = false) {
|
||||
int NumElts = VT.getVectorNumElements();
|
||||
unsigned NumElts = VT.getVectorNumElements();
|
||||
|
||||
assert((VT.is128BitVector() || VT.is256BitVector()) &&
|
||||
"Unsupported vector type for unpckh");
|
||||
@ -3536,11 +3531,9 @@ static bool isUNPCKHMask(const SmallVectorImpl<int> &Mask, EVT VT,
|
||||
unsigned NumLanes = VT.getSizeInBits()/128;
|
||||
unsigned NumLaneElts = NumElts/NumLanes;
|
||||
|
||||
unsigned Start = 0;
|
||||
unsigned End = NumLaneElts;
|
||||
for (unsigned l = 0; l != NumLanes; ++l) {
|
||||
for (unsigned i = Start, j = (l*NumLaneElts)+NumLaneElts/2;
|
||||
i != End; i += 2, ++j) {
|
||||
for (unsigned i = l*NumLaneElts, j = (l*NumLaneElts)+NumLaneElts/2;
|
||||
i != (l+1)*NumLaneElts; i += 2, ++j) {
|
||||
int BitI = Mask[i];
|
||||
int BitI1 = Mask[i+1];
|
||||
if (!isUndefOrEqual(BitI, j))
|
||||
@ -3553,9 +3546,6 @@ static bool isUNPCKHMask(const SmallVectorImpl<int> &Mask, EVT VT,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Process the next 128 bits.
|
||||
Start += NumLaneElts;
|
||||
End += NumLaneElts;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -3569,26 +3559,32 @@ bool X86::isUNPCKHMask(ShuffleVectorSDNode *N, bool HasAVX2, bool V2IsSplat) {
|
||||
/// isUNPCKL_v_undef_Mask - Special case of isUNPCKLMask for canonical form
|
||||
/// of vector_shuffle v, v, <0, 4, 1, 5>, i.e. vector_shuffle v, undef,
|
||||
/// <0, 0, 1, 1>
|
||||
static bool isUNPCKL_v_undef_Mask(const SmallVectorImpl<int> &Mask, EVT VT) {
|
||||
int NumElems = VT.getVectorNumElements();
|
||||
if (NumElems != 2 && NumElems != 4 && NumElems != 8 && NumElems != 16)
|
||||
static bool isUNPCKL_v_undef_Mask(const SmallVectorImpl<int> &Mask, EVT VT,
|
||||
bool HasAVX2) {
|
||||
unsigned NumElts = VT.getVectorNumElements();
|
||||
|
||||
assert((VT.is128BitVector() || VT.is256BitVector()) &&
|
||||
"Unsupported vector type for unpckh");
|
||||
|
||||
if (VT.getSizeInBits() == 256 && NumElts != 4 && NumElts != 8 &&
|
||||
(!HasAVX2 || (NumElts != 16 && NumElts != 32)))
|
||||
return false;
|
||||
|
||||
// For 256-bit i64/f64, use MOVDDUPY instead, so reject the matching pattern
|
||||
// FIXME: Need a better way to get rid of this, there's no latency difference
|
||||
// between UNPCKLPD and MOVDDUP, the later should always be checked first and
|
||||
// the former later. We should also remove the "_undef" special mask.
|
||||
if (NumElems == 4 && VT.getSizeInBits() == 256)
|
||||
if (NumElts == 4 && VT.getSizeInBits() == 256)
|
||||
return false;
|
||||
|
||||
// Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate
|
||||
// independently on 128-bit lanes.
|
||||
unsigned NumLanes = VT.getSizeInBits() / 128;
|
||||
unsigned NumLaneElts = NumElems / NumLanes;
|
||||
unsigned NumLanes = VT.getSizeInBits()/128;
|
||||
unsigned NumLaneElts = NumElts/NumLanes;
|
||||
|
||||
for (unsigned s = 0; s < NumLanes; ++s) {
|
||||
for (unsigned i = s * NumLaneElts, j = s * NumLaneElts;
|
||||
i != NumLaneElts * (s + 1);
|
||||
for (unsigned l = 0; l != NumLanes; ++l) {
|
||||
for (unsigned i = l*NumLaneElts, j = l*NumLaneElts;
|
||||
i != (l+1)*NumLaneElts;
|
||||
i += 2, ++j) {
|
||||
int BitI = Mask[i];
|
||||
int BitI1 = Mask[i+1];
|
||||
@ -3603,35 +3599,49 @@ static bool isUNPCKL_v_undef_Mask(const SmallVectorImpl<int> &Mask, EVT VT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool X86::isUNPCKL_v_undef_Mask(ShuffleVectorSDNode *N) {
|
||||
bool X86::isUNPCKL_v_undef_Mask(ShuffleVectorSDNode *N, bool HasAVX2) {
|
||||
SmallVector<int, 8> M;
|
||||
N->getMask(M);
|
||||
return ::isUNPCKL_v_undef_Mask(M, N->getValueType(0));
|
||||
return ::isUNPCKL_v_undef_Mask(M, N->getValueType(0), HasAVX2);
|
||||
}
|
||||
|
||||
/// isUNPCKH_v_undef_Mask - Special case of isUNPCKHMask for canonical form
|
||||
/// of vector_shuffle v, v, <2, 6, 3, 7>, i.e. vector_shuffle v, undef,
|
||||
/// <2, 2, 3, 3>
|
||||
static bool isUNPCKH_v_undef_Mask(const SmallVectorImpl<int> &Mask, EVT VT) {
|
||||
int NumElems = VT.getVectorNumElements();
|
||||
if (NumElems != 2 && NumElems != 4 && NumElems != 8 && NumElems != 16)
|
||||
static bool isUNPCKH_v_undef_Mask(const SmallVectorImpl<int> &Mask, EVT VT,
|
||||
bool HasAVX2) {
|
||||
unsigned NumElts = VT.getVectorNumElements();
|
||||
|
||||
assert((VT.is128BitVector() || VT.is256BitVector()) &&
|
||||
"Unsupported vector type for unpckh");
|
||||
|
||||
if (VT.getSizeInBits() == 256 && NumElts != 4 && NumElts != 8 &&
|
||||
(!HasAVX2 || (NumElts != 16 && NumElts != 32)))
|
||||
return false;
|
||||
|
||||
for (int i = 0, j = NumElems / 2; i != NumElems; i += 2, ++j) {
|
||||
int BitI = Mask[i];
|
||||
int BitI1 = Mask[i+1];
|
||||
if (!isUndefOrEqual(BitI, j))
|
||||
return false;
|
||||
if (!isUndefOrEqual(BitI1, j))
|
||||
return false;
|
||||
// Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate
|
||||
// independently on 128-bit lanes.
|
||||
unsigned NumLanes = VT.getSizeInBits()/128;
|
||||
unsigned NumLaneElts = NumElts/NumLanes;
|
||||
|
||||
for (unsigned l = 0; l != NumLanes; ++l) {
|
||||
for (unsigned i = l*NumLaneElts, j = (l*NumLaneElts)+NumLaneElts/2;
|
||||
i != (l+1)*NumLaneElts; i += 2, ++j) {
|
||||
int BitI = Mask[i];
|
||||
int BitI1 = Mask[i+1];
|
||||
if (!isUndefOrEqual(BitI, j))
|
||||
return false;
|
||||
if (!isUndefOrEqual(BitI1, j))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool X86::isUNPCKH_v_undef_Mask(ShuffleVectorSDNode *N) {
|
||||
bool X86::isUNPCKH_v_undef_Mask(ShuffleVectorSDNode *N, bool HasAVX2) {
|
||||
SmallVector<int, 8> M;
|
||||
N->getMask(M);
|
||||
return ::isUNPCKH_v_undef_Mask(M, N->getValueType(0));
|
||||
return ::isUNPCKH_v_undef_Mask(M, N->getValueType(0), HasAVX2);
|
||||
}
|
||||
|
||||
/// isMOVLMask - Return true if the specified VECTOR_SHUFFLE operand
|
||||
@ -6481,9 +6491,9 @@ X86TargetLowering::LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const {
|
||||
|
||||
// NOTE: isPSHUFDMask can also match both masks below (unpckl_undef and
|
||||
// unpckh_undef). Only use pshufd if speed is more important than size.
|
||||
if (OptForSize && X86::isUNPCKL_v_undef_Mask(SVOp))
|
||||
if (OptForSize && X86::isUNPCKL_v_undef_Mask(SVOp, HasAVX2))
|
||||
return getTargetShuffleNode(X86ISD::UNPCKL, dl, VT, V1, V1, DAG);
|
||||
if (OptForSize && X86::isUNPCKH_v_undef_Mask(SVOp))
|
||||
if (OptForSize && X86::isUNPCKH_v_undef_Mask(SVOp, HasAVX2))
|
||||
return getTargetShuffleNode(X86ISD::UNPCKH, dl, VT, V1, V1, DAG);
|
||||
|
||||
if (X86::isMOVDDUPMask(SVOp) && Subtarget->hasSSE3orAVX() &&
|
||||
@ -6663,9 +6673,9 @@ X86TargetLowering::LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const {
|
||||
return getTargetShuffleNode(getSHUFPOpcode(VT), dl, VT, V1, V2,
|
||||
X86::getShuffleSHUFImmediate(SVOp), DAG);
|
||||
|
||||
if (isUNPCKL_v_undef_Mask(M, VT))
|
||||
if (isUNPCKL_v_undef_Mask(M, VT, HasAVX2))
|
||||
return getTargetShuffleNode(X86ISD::UNPCKL, dl, VT, V1, V1, DAG);
|
||||
if (isUNPCKH_v_undef_Mask(M, VT))
|
||||
if (isUNPCKH_v_undef_Mask(M, VT, HasAVX2))
|
||||
return getTargetShuffleNode(X86ISD::UNPCKH, dl, VT, V1, V1, DAG);
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
@ -11100,8 +11110,8 @@ X86TargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M,
|
||||
isPALIGNRMask(M, VT, Subtarget->hasSSSE3orAVX()) ||
|
||||
isUNPCKLMask(M, VT, Subtarget->hasAVX2()) ||
|
||||
isUNPCKHMask(M, VT, Subtarget->hasAVX2()) ||
|
||||
isUNPCKL_v_undef_Mask(M, VT) ||
|
||||
isUNPCKH_v_undef_Mask(M, VT));
|
||||
isUNPCKL_v_undef_Mask(M, VT, Subtarget->hasAVX2()) ||
|
||||
isUNPCKH_v_undef_Mask(M, VT, Subtarget->hasAVX2()));
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -408,12 +408,12 @@ namespace llvm {
|
||||
/// isUNPCKL_v_undef_Mask - Special case of isUNPCKLMask for canonical form
|
||||
/// of vector_shuffle v, v, <0, 4, 1, 5>, i.e. vector_shuffle v, undef,
|
||||
/// <0, 0, 1, 1>
|
||||
bool isUNPCKL_v_undef_Mask(ShuffleVectorSDNode *N);
|
||||
bool isUNPCKL_v_undef_Mask(ShuffleVectorSDNode *N, bool HasAVX2);
|
||||
|
||||
/// isUNPCKH_v_undef_Mask - Special case of isUNPCKHMask for canonical form
|
||||
/// of vector_shuffle v, v, <2, 6, 3, 7>, i.e. vector_shuffle v, undef,
|
||||
/// <2, 2, 3, 3>
|
||||
bool isUNPCKH_v_undef_Mask(ShuffleVectorSDNode *N);
|
||||
bool isUNPCKH_v_undef_Mask(ShuffleVectorSDNode *N, bool HasAVX2);
|
||||
|
||||
/// isMOVLMask - Return true if the specified VECTOR_SHUFFLE operand
|
||||
/// specifies a shuffle of elements that is suitable for input to MOVSS,
|
||||
|
@ -123,3 +123,39 @@ entry:
|
||||
%shuffle.i = shufflevector <4 x i64> %a, <4 x i64> %b, <4 x i32> <i32 0, i32 4, i32 2, i32 6>
|
||||
ret <4 x i64> %shuffle.i
|
||||
}
|
||||
|
||||
; CHECK: vpunpckhwd
|
||||
; CHECK: vpunpckhwd
|
||||
; CHECK: vinsertf128
|
||||
define <16 x i16> @unpackhwd_undef(<16 x i16> %src1) nounwind uwtable readnone ssp {
|
||||
entry:
|
||||
%shuffle.i = shufflevector <16 x i16> %src1, <16 x i16> %src1, <16 x i32> <i32 4, i32 20, i32 5, i32 21, i32 6, i32 22, i32 7, i32 23, i32 12, i32 28, i32 13, i32 29, i32 14, i32 30, i32 15, i32 31>
|
||||
ret <16 x i16> %shuffle.i
|
||||
}
|
||||
|
||||
; CHECK: vpunpcklwd
|
||||
; CHECK: vpunpcklwd
|
||||
; CHECK: vinsertf128
|
||||
define <16 x i16> @unpacklwd_undef(<16 x i16> %src1) nounwind uwtable readnone ssp {
|
||||
entry:
|
||||
%shuffle.i = shufflevector <16 x i16> %src1, <16 x i16> %src1, <16 x i32> <i32 0, i32 16, i32 1, i32 17, i32 2, i32 18, i32 3, i32 19, i32 8, i32 24, i32 9, i32 25, i32 10, i32 26, i32 11, i32 27>
|
||||
ret <16 x i16> %shuffle.i
|
||||
}
|
||||
|
||||
; CHECK: vpunpckhbw
|
||||
; CHECK: vpunpckhbw
|
||||
; CHECK: vinsertf128
|
||||
define <32 x i8> @unpackhbw_undef(<32 x i8> %src1, <32 x i8> %src2) nounwind uwtable readnone ssp {
|
||||
entry:
|
||||
%shuffle.i = shufflevector <32 x i8> %src1, <32 x i8> %src1, <32 x i32> <i32 8, i32 40, i32 9, i32 41, i32 10, i32 42, i32 11, i32 43, i32 12, i32 44, i32 13, i32 45, i32 14, i32 46, i32 15, i32 47, i32 24, i32 56, i32 25, i32 57, i32 26, i32 58, i32 27, i32 59, i32 28, i32 60, i32 29, i32 61, i32 30, i32 62, i32 31, i32 63>
|
||||
ret <32 x i8> %shuffle.i
|
||||
}
|
||||
|
||||
; CHECK: vpunpcklbw
|
||||
; CHECK: vpunpcklbw
|
||||
; CHECK: vinsertf128
|
||||
define <32 x i8> @unpacklbw_undef(<32 x i8> %src1) nounwind uwtable readnone ssp {
|
||||
entry:
|
||||
%shuffle.i = shufflevector <32 x i8> %src1, <32 x i8> %src1, <32 x i32> <i32 0, i32 32, i32 1, i32 33, i32 2, i32 34, i32 3, i32 35, i32 4, i32 36, i32 5, i32 37, i32 6, i32 38, i32 7, i32 39, i32 16, i32 48, i32 17, i32 49, i32 18, i32 50, i32 19, i32 51, i32 20, i32 52, i32 21, i32 53, i32 22, i32 54, i32 23, i32 55>
|
||||
ret <32 x i8> %shuffle.i
|
||||
}
|
||||
|
@ -55,3 +55,32 @@ entry:
|
||||
%shuffle.i = shufflevector <32 x i8> %src1, <32 x i8> %src2, <32 x i32> <i32 0, i32 32, i32 1, i32 33, i32 2, i32 34, i32 3, i32 35, i32 4, i32 36, i32 5, i32 37, i32 6, i32 38, i32 7, i32 39, i32 16, i32 48, i32 17, i32 49, i32 18, i32 50, i32 19, i32 51, i32 20, i32 52, i32 21, i32 53, i32 22, i32 54, i32 23, i32 55>
|
||||
ret <32 x i8> %shuffle.i
|
||||
}
|
||||
|
||||
; CHECK: vpunpckhdq
|
||||
define <8 x i32> @unpackhidq1_undef(<8 x i32> %src1) nounwind uwtable readnone ssp {
|
||||
entry:
|
||||
%shuffle.i = shufflevector <8 x i32> %src1, <8 x i32> %src1, <8 x i32> <i32 2, i32 10, i32 3, i32 11, i32 6, i32 14, i32 7, i32 15>
|
||||
ret <8 x i32> %shuffle.i
|
||||
}
|
||||
|
||||
; CHECK: vpunpckhqdq
|
||||
define <4 x i64> @unpackhiqdq1_undef(<4 x i64> %src1) nounwind uwtable readnone ssp {
|
||||
entry:
|
||||
%shuffle.i = shufflevector <4 x i64> %src1, <4 x i64> %src1, <4 x i32> <i32 1, i32 5, i32 3, i32 7>
|
||||
ret <4 x i64> %shuffle.i
|
||||
}
|
||||
|
||||
; CHECK: vpunpckhwd
|
||||
define <16 x i16> @unpackhwd_undef(<16 x i16> %src1) nounwind uwtable readnone ssp {
|
||||
entry:
|
||||
%shuffle.i = shufflevector <16 x i16> %src1, <16 x i16> %src1, <16 x i32> <i32 4, i32 20, i32 5, i32 21, i32 6, i32 22, i32 7, i32 23, i32 12, i32 28, i32 13, i32 29, i32 14, i32 30, i32 15, i32 31>
|
||||
ret <16 x i16> %shuffle.i
|
||||
}
|
||||
|
||||
; CHECK: vpunpcklwd
|
||||
define <16 x i16> @unpacklwd_undef(<16 x i16> %src1) nounwind uwtable readnone ssp {
|
||||
entry:
|
||||
%shuffle.i = shufflevector <16 x i16> %src1, <16 x i16> %src1, <16 x i32> <i32 0, i32 16, i32 1, i32 17, i32 2, i32 18, i32 3, i32 19, i32 8, i32 24, i32 9, i32 25, i32 10, i32 26, i32 11, i32 27>
|
||||
ret <16 x i16> %shuffle.i
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user