llvm.org GIT mirror llvm / e8f279c
Reapply considered harmfull part of rr112934 and r112942. "Use target specific nodes instead of relying in unpckl and unpckh pattern fragments during isel time. Also place a depth limit in getShuffleScalarElt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113020 91177308-0d34-0410-b5e6-96231b3b80d8 Bruno Cardoso Lopes 10 years ago
1 changed file(s) with 109 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
1515 #include "X86.h"
1616 #include "X86InstrBuilder.h"
1717 #include "X86ISelLowering.h"
18 #include "X86ShuffleDecode.h"
1819 #include "X86TargetMachine.h"
1920 #include "X86TargetObjectFile.h"
2021 #include "llvm/CallingConv.h"
36863687
36873688 /// getShuffleScalarElt - Returns the scalar element that will make up the ith
36883689 /// element of the result of the vector shuffle.
3689 SDValue getShuffleScalarElt(SDNode *N, int Index, SelectionDAG &DAG) {
3690 SDValue getShuffleScalarElt(SDNode *N, int Index, SelectionDAG &DAG,
3691 unsigned Depth) {
3692 if (Depth == 6)
3693 return SDValue(); // Limit search depth.
3694
36903695 SDValue V = SDValue(N, 0);
36913696 EVT VT = V.getValueType();
36923697 unsigned Opcode = V.getOpcode();
37003705
37013706 int NumElems = VT.getVectorNumElements();
37023707 SDValue NewV = (Index < NumElems) ? SV->getOperand(0) : SV->getOperand(1);
3703 return getShuffleScalarElt(NewV.getNode(), Index % NumElems, DAG);
3708 return getShuffleScalarElt(NewV.getNode(), Index % NumElems, DAG, Depth+1);
37043709 }
37053710
37063711 // Recurse into target specific vector shuffles to find scalars.
37073712 if (isTargetShuffle(Opcode)) {
3713 int NumElems = VT.getVectorNumElements();
3714 SmallVector ShuffleMask;
3715 SDValue ImmN;
3716
37083717 switch(Opcode) {
3718 case X86ISD::SHUFPS:
3719 case X86ISD::SHUFPD:
3720 ImmN = N->getOperand(N->getNumOperands()-1);
3721 DecodeSHUFPSMask(NumElems,
3722 cast(ImmN)->getZExtValue(),
3723 ShuffleMask);
3724 break;
3725 case X86ISD::PUNPCKHBW:
3726 case X86ISD::PUNPCKHWD:
3727 case X86ISD::PUNPCKHDQ:
3728 case X86ISD::PUNPCKHQDQ:
3729 DecodePUNPCKHMask(NumElems, ShuffleMask);
3730 break;
3731 case X86ISD::UNPCKHPS:
3732 case X86ISD::UNPCKHPD:
3733 DecodeUNPCKHPMask(NumElems, ShuffleMask);
3734 break;
3735 case X86ISD::PUNPCKLBW:
3736 case X86ISD::PUNPCKLWD:
3737 case X86ISD::PUNPCKLDQ:
3738 case X86ISD::PUNPCKLQDQ:
3739 DecodePUNPCKLMask(NumElems, ShuffleMask);
3740 break;
3741 case X86ISD::UNPCKLPS:
3742 case X86ISD::UNPCKLPD:
3743 DecodeUNPCKLPMask(NumElems, ShuffleMask);
3744 break;
3745 case X86ISD::MOVHLPS:
3746 DecodeMOVHLPSMask(NumElems, ShuffleMask);
3747 break;
3748 case X86ISD::MOVLHPS:
3749 DecodeMOVLHPSMask(NumElems, ShuffleMask);
3750 break;
3751 case X86ISD::PSHUFD:
3752 ImmN = N->getOperand(N->getNumOperands()-1);
3753 DecodePSHUFMask(NumElems,
3754 cast(ImmN)->getZExtValue(),
3755 ShuffleMask);
3756 break;
3757 case X86ISD::PSHUFHW:
3758 ImmN = N->getOperand(N->getNumOperands()-1);
3759 DecodePSHUFHWMask(cast(ImmN)->getZExtValue(),
3760 ShuffleMask);
3761 break;
3762 case X86ISD::PSHUFLW:
3763 ImmN = N->getOperand(N->getNumOperands()-1);
3764 DecodePSHUFLWMask(cast(ImmN)->getZExtValue(),
3765 ShuffleMask);
3766 break;
37093767 case X86ISD::MOVSS:
37103768 case X86ISD::MOVSD: {
37113769 // The index 0 always comes from the first element of the second source,
37123770 // this is why MOVSS and MOVSD are used in the first place. The other
37133771 // elements come from the other positions of the first source vector.
37143772 unsigned OpNum = (Index == 0) ? 1 : 0;
3715 return getShuffleScalarElt(V.getOperand(OpNum).getNode(), Index, DAG);
3773 return getShuffleScalarElt(V.getOperand(OpNum).getNode(), Index, DAG,
3774 Depth+1);
37163775 }
37173776 default:
37183777 assert("not implemented for target shuffle node");
37193778 return SDValue();
37203779 }
3780
3781 Index = ShuffleMask[Index];
3782 if (Index < 0)
3783 return DAG.getUNDEF(VT.getVectorElementType());
3784
3785 SDValue NewV = (Index < NumElems) ? N->getOperand(0) : N->getOperand(1);
3786 return getShuffleScalarElt(NewV.getNode(), Index % NumElems, DAG,
3787 Depth+1);
37213788 }
37223789
37233790 // Actual nodes that may contain scalar elements
37503817
37513818 while (i < NumElems) {
37523819 unsigned Index = ZerosFromLeft ? i : NumElems-i-1;
3753 SDValue Elt = getShuffleScalarElt(N, Index, DAG);
3820 SDValue Elt = getShuffleScalarElt(N, Index, DAG, 0);
37543821 if (!(Elt.getNode() &&
37553822 (Elt.getOpcode() == ISD::UNDEF || X86::isZeroNode(Elt))))
37563823 break;
53635430 return getMOVL(DAG, dl, VT, V2, V1);
53645431 }
53655432
5366 if (X86::isUNPCKLMask(SVOp) ||
5367 X86::isUNPCKHMask(SVOp))
5368 return Op;
5433 if (X86::isUNPCKLMask(SVOp))
5434 return (isMMX) ?
5435 Op : getTargetShuffleNode(getUNPCKLOpcode(VT), dl, VT, V1, V2, DAG);
5436
5437 if (X86::isUNPCKHMask(SVOp))
5438 return (isMMX) ?
5439 Op : getTargetShuffleNode(getUNPCKHOpcode(VT), dl, VT, V1, V2, DAG);
53695440
53705441 if (V2IsSplat) {
53715442 // Normalize mask so all entries that point to V2 points to its first
53875458 // FIXME: this seems wrong.
53885459 SDValue NewOp = CommuteVectorShuffle(SVOp, DAG);
53895460 ShuffleVectorSDNode *NewSVOp = cast(NewOp);
5390 if (X86::isUNPCKLMask(NewSVOp) ||
5391 X86::isUNPCKHMask(NewSVOp))
5392 return NewOp;
5461
5462 if (X86::isUNPCKLMask(NewSVOp))
5463 return (isMMX) ?
5464 NewOp : getTargetShuffleNode(getUNPCKLOpcode(VT), dl, VT, V2, V1, DAG);
5465
5466 if (X86::isUNPCKHMask(NewSVOp))
5467 return (isMMX) ?
5468 NewOp : getTargetShuffleNode(getUNPCKHOpcode(VT), dl, VT, V2, V1, DAG);
53935469 }
53945470
53955471 // FIXME: for mmx, bitcast v2i32 to v4i16 for shuffle.
97309806
97319807 SmallVector Elts;
97329808 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i)
9733 Elts.push_back(getShuffleScalarElt(N, i, DAG));
9809 Elts.push_back(getShuffleScalarElt(N, i, DAG, 0));
97349810
97359811 return EltsFromConsecutiveLoads(VT, Elts, dl, DAG);
97369812 }
1065810734 SelectionDAG &DAG = DCI.DAG;
1065910735 switch (N->getOpcode()) {
1066010736 default: break;
10661 case ISD::VECTOR_SHUFFLE: return PerformShuffleCombine(N, DAG, *this);
1066210737 case ISD::EXTRACT_VECTOR_ELT:
1066310738 return PerformEXTRACT_VECTOR_ELTCombine(N, DAG, *this);
1066410739 case ISD::SELECT: return PerformSELECTCombine(N, DAG, Subtarget);
1067510750 case X86ISD::BT: return PerformBTCombine(N, DAG, DCI);
1067610751 case X86ISD::VZEXT_MOVL: return PerformVZEXT_MOVLCombine(N, DAG);
1067710752 case ISD::ZERO_EXTEND: return PerformZExtCombine(N, DAG);
10753 case X86ISD::SHUFPS: // Handle all target specific shuffles
10754 case X86ISD::SHUFPD:
10755 case X86ISD::PUNPCKHBW:
10756 case X86ISD::PUNPCKHWD:
10757 case X86ISD::PUNPCKHDQ:
10758 case X86ISD::PUNPCKHQDQ:
10759 case X86ISD::UNPCKHPS:
10760 case X86ISD::UNPCKHPD:
10761 case X86ISD::PUNPCKLBW:
10762 case X86ISD::PUNPCKLWD:
10763 case X86ISD::PUNPCKLDQ:
10764 case X86ISD::PUNPCKLQDQ:
10765 case X86ISD::UNPCKLPS:
10766 case X86ISD::UNPCKLPD:
10767 case X86ISD::MOVHLPS:
10768 case X86ISD::MOVLHPS:
10769 case X86ISD::PSHUFD:
10770 case X86ISD::PSHUFHW:
10771 case X86ISD::PSHUFLW:
10772 case X86ISD::MOVSS:
10773 case X86ISD::MOVSD:
10774 case ISD::VECTOR_SHUFFLE: return PerformShuffleCombine(N, DAG, *this);
1067810775 }
1067910776
1068010777 return SDValue();