llvm.org GIT mirror llvm / d156dc1
Add shuffle decoding support for 256-bit pshufd. Merge vpermilp* and pshufd decoding. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149859 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 8 years ago
4 changed file(s) with 72 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
7575 case X86::PSHUFDmi:
7676 case X86::VPSHUFDmi:
7777 DestName = getRegName(MI->getOperand(0).getReg());
78 DecodePSHUFMask(4, MI->getOperand(MI->getNumOperands()-1).getImm(),
79 ShuffleMask);
80 break;
78 DecodePSHUFMask(MVT::v4i32, MI->getOperand(MI->getNumOperands()-1).getImm(),
79 ShuffleMask);
80 break;
81 case X86::VPSHUFDYri:
82 Src1Name = getRegName(MI->getOperand(1).getReg());
83 // FALL THROUGH.
84 case X86::VPSHUFDYmi:
85 DestName = getRegName(MI->getOperand(0).getReg());
86 DecodePSHUFMask(MVT::v8i32, MI->getOperand(MI->getNumOperands()-1).getImm(),
87 ShuffleMask);
88 break;
89
8190
8291 case X86::PSHUFHWri:
8392 case X86::VPSHUFHWri:
436445 Src1Name = getRegName(MI->getOperand(1).getReg());
437446 // FALL THROUGH.
438447 case X86::VPERMILPSmi:
439 DecodeVPERMILPMask(MVT::v4f32, MI->getOperand(MI->getNumOperands()-1).getImm(),
440 ShuffleMask);
448 DecodePSHUFMask(MVT::v4f32, MI->getOperand(MI->getNumOperands()-1).getImm(),
449 ShuffleMask);
441450 DestName = getRegName(MI->getOperand(0).getReg());
442451 break;
443452 case X86::VPERMILPSYri:
444453 Src1Name = getRegName(MI->getOperand(1).getReg());
445454 // FALL THROUGH.
446455 case X86::VPERMILPSYmi:
447 DecodeVPERMILPMask(MVT::v8f32, MI->getOperand(MI->getNumOperands()-1).getImm(),
448 ShuffleMask);
456 DecodePSHUFMask(MVT::v8f32, MI->getOperand(MI->getNumOperands()-1).getImm(),
457 ShuffleMask);
449458 DestName = getRegName(MI->getOperand(0).getReg());
450459 break;
451460 case X86::VPERMILPDri:
452461 Src1Name = getRegName(MI->getOperand(1).getReg());
453462 // FALL THROUGH.
454463 case X86::VPERMILPDmi:
455 DecodeVPERMILPMask(MVT::v2f64, MI->getOperand(MI->getNumOperands()-1).getImm(),
456 ShuffleMask);
464 DecodePSHUFMask(MVT::v2f64, MI->getOperand(MI->getNumOperands()-1).getImm(),
465 ShuffleMask);
457466 DestName = getRegName(MI->getOperand(0).getReg());
458467 break;
459468 case X86::VPERMILPDYri:
460469 Src1Name = getRegName(MI->getOperand(1).getReg());
461470 // FALL THROUGH.
462471 case X86::VPERMILPDYmi:
463 DecodeVPERMILPMask(MVT::v4f64, MI->getOperand(MI->getNumOperands()-1).getImm(),
472 DecodePSHUFMask(MVT::v4f64, MI->getOperand(MI->getNumOperands()-1).getImm(),
464473 ShuffleMask);
465474 DestName = getRegName(MI->getOperand(0).getReg());
466475 break;
470479 // FALL THROUGH.
471480 case X86::VPERM2F128rm:
472481 case X86::VPERM2I128rm:
473 DecodeVPERM2F128Mask(MI->getOperand(MI->getNumOperands()-1).getImm(),
482 // For instruction comments purpose, assume the 256-bit vector is v4i64.
483 DecodeVPERM2X128Mask(MVT::v4i64,
484 MI->getOperand(MI->getNumOperands()-1).getImm(),
474485 ShuffleMask);
475486 Src1Name = getRegName(MI->getOperand(1).getReg());
476487 DestName = getRegName(MI->getOperand(0).getReg());
6262 ShuffleMask.push_back(NElts+i);
6363 }
6464
65 void DecodePSHUFMask(unsigned NElts, unsigned Imm,
65 /// DecodePSHUFMask - This decodes the shuffle masks for pshufd, and vpermilp*.
66 /// VT indicates the type of the vector allowing it to handle different
67 /// datatypes and vector widths.
68 void DecodePSHUFMask(EVT VT, unsigned Imm,
6669 SmallVectorImpl &ShuffleMask) {
67 for (unsigned i = 0; i != NElts; ++i) {
68 ShuffleMask.push_back(Imm % NElts);
69 Imm /= NElts;
70 unsigned NumElts = VT.getVectorNumElements();
71
72 unsigned NumLanes = VT.getSizeInBits() / 128;
73 unsigned NumLaneElts = NumElts / NumLanes;
74
75 int NewImm = Imm;
76 for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
77 for (unsigned i = 0; i != NumLaneElts; ++i) {
78 ShuffleMask.push_back(NewImm % NumLaneElts + l);
79 NewImm /= NumLaneElts;
80 }
81 if (NumLaneElts == 4) NewImm = Imm; // reload imm
7082 }
7183 }
7284
94106 ShuffleMask.push_back(7);
95107 }
96108
109 /// DecodeSHUFPMask - This decodes the shuffle masks for shufp*. VT indicates
110 /// the type of the vector allowing it to handle different datatypes and vector
111 /// widths.
97112 void DecodeSHUFPMask(EVT VT, unsigned Imm,
98113 SmallVectorImpl &ShuffleMask) {
99114 unsigned NumElts = VT.getVectorNumElements();
102117 unsigned NumLaneElts = NumElts / NumLanes;
103118
104119 int NewImm = Imm;
105 for (unsigned l = 0; l < NumLanes; ++l) {
106 unsigned LaneStart = l * NumLaneElts;
120 for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
107121 // Part that reads from dest.
108122 for (unsigned i = 0; i != NumLaneElts/2; ++i) {
109 ShuffleMask.push_back(NewImm % NumLaneElts + LaneStart);
123 ShuffleMask.push_back(NewImm % NumLaneElts + l);
110124 NewImm /= NumLaneElts;
111125 }
112126 // Part that reads from src.
113127 for (unsigned i = 0; i != NumLaneElts/2; ++i) {
114 ShuffleMask.push_back(NewImm % NumLaneElts + NumElts + LaneStart);
128 ShuffleMask.push_back(NewImm % NumLaneElts + NumElts + l);
115129 NewImm /= NumLaneElts;
116130 }
117131 if (NumLaneElts == 4) NewImm = Imm; // reload imm
118132 }
119133 }
120134
135 /// DecodeUNPCKHMask - This decodes the shuffle masks for unpckhps/unpckhpd
136 /// and punpckh*. VT indicates the type of the vector allowing it to handle
137 /// different datatypes and vector widths.
121138 void DecodeUNPCKHMask(EVT VT, SmallVectorImpl &ShuffleMask) {
122139 unsigned NumElts = VT.getVectorNumElements();
123140
127144 if (NumLanes == 0 ) NumLanes = 1; // Handle MMX
128145 unsigned NumLaneElts = NumElts / NumLanes;
129146
130 for (unsigned s = 0; s < NumLanes; ++s) {
131 unsigned Start = s * NumLaneElts + NumLaneElts/2;
132 unsigned End = s * NumLaneElts + NumLaneElts;
133 for (unsigned i = Start; i != End; ++i) {
147 for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
148 for (unsigned i = l + NumLaneElts/2, e = l + NumLaneElts; i != e; ++i) {
134149 ShuffleMask.push_back(i); // Reads from dest/src1
135150 ShuffleMask.push_back(i+NumElts); // Reads from src/src2
136151 }
138153 }
139154
140155 /// DecodeUNPCKLMask - This decodes the shuffle masks for unpcklps/unpcklpd
141 /// etc. VT indicates the type of the vector allowing it to handle different
142 /// datatypes and vector widths.
156 /// and punpckl*. VT indicates the type of the vector allowing it to handle
157 /// different datatypes and vector widths.
143158 void DecodeUNPCKLMask(EVT VT, SmallVectorImpl &ShuffleMask) {
144159 unsigned NumElts = VT.getVectorNumElements();
145160
149164 if (NumLanes == 0 ) NumLanes = 1; // Handle MMX
150165 unsigned NumLaneElts = NumElts / NumLanes;
151166
152 for (unsigned s = 0; s < NumLanes; ++s) {
153 unsigned Start = s * NumLaneElts;
154 unsigned End = s * NumLaneElts + NumLaneElts/2;
155 for (unsigned i = Start; i != End; ++i) {
167 for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
168 for (unsigned i = l, e = l + NumLaneElts/2; i != e; ++i) {
156169 ShuffleMask.push_back(i); // Reads from dest/src1
157170 ShuffleMask.push_back(i+NumElts); // Reads from src/src2
158171 }
159172 }
160173 }
161174
162 // DecodeVPERMILPMask - Decodes VPERMILPS/ VPERMILPD permutes for any 128-bit
163 // 32-bit or 64-bit elements. For 256-bit vectors, it's considered as two 128
164 // lanes. For VPERMILPS, referenced elements can't cross lanes and the mask of
165 // the first lane must be the same of the second.
166 void DecodeVPERMILPMask(EVT VT, unsigned Imm,
167 SmallVectorImpl &ShuffleMask) {
168 unsigned NumElts = VT.getVectorNumElements();
169
170 unsigned NumLanes = VT.getSizeInBits() / 128;
171 unsigned NumLaneElts = NumElts / NumLanes;
172
173 for (unsigned l = 0; l != NumLanes; ++l) {
174 unsigned LaneStart = l*NumLaneElts;
175 for (unsigned i = 0; i != NumLaneElts; ++i) {
176 unsigned Idx = NumLaneElts == 4 ? (Imm >> (i*2)) & 0x3
177 : (Imm >> (i+LaneStart)) & 0x1;
178 ShuffleMask.push_back(Idx+LaneStart);
179 }
180 }
181 }
182
183 void DecodeVPERM2F128Mask(EVT VT, unsigned Imm,
175 void DecodeVPERM2X128Mask(EVT VT, unsigned Imm,
184176 SmallVectorImpl &ShuffleMask) {
185177 unsigned HalfSize = VT.getVectorNumElements()/2;
186178 unsigned FstHalfBegin = (Imm & 0x3) * HalfSize;
192184 ShuffleMask.push_back(i);
193185 }
194186
195 void DecodeVPERM2F128Mask(unsigned Imm,
196 SmallVectorImpl &ShuffleMask) {
197 // VPERM2F128 is used by any 256-bit EVT, but X86InstComments only
198 // has information about the instruction and not the types. So for
199 // instruction comments purpose, assume the 256-bit vector is v4i64.
200 return DecodeVPERM2F128Mask(MVT::v4i64, Imm, ShuffleMask);
201 }
202
203187 } // llvm namespace
3636 void DecodeMOVLHPSMask(unsigned NElts,
3737 SmallVectorImpl &ShuffleMask);
3838
39 void DecodePSHUFMask(unsigned NElts, unsigned Imm,
39 void DecodePSHUFMask(EVT VT, unsigned Imm,
4040 SmallVectorImpl &ShuffleMask);
4141
4242 void DecodePSHUFHWMask(unsigned Imm,
4545 void DecodePSHUFLWMask(unsigned Imm,
4646 SmallVectorImpl &ShuffleMask);
4747
48 /// DecodeSHUFPMask - This decodes the shuffle masks for shufp*. VT indicates
49 /// the type of the vector allowing it to handle different datatypes and vector
50 /// widths.
4851 void DecodeSHUFPMask(EVT VT, unsigned Imm,
4952 SmallVectorImpl &ShuffleMask);
5053
5154 /// DecodeUNPCKHMask - This decodes the shuffle masks for unpckhps/unpckhpd
52 /// etc. VT indicates the type of the vector allowing it to handle different
53 /// datatypes and vector widths.
55 /// and punpckh*. VT indicates the type of the vector allowing it to handle
56 /// different datatypes and vector widths.
5457 void DecodeUNPCKHMask(EVT VT, SmallVectorImpl &ShuffleMask);
5558
5659 /// DecodeUNPCKLMask - This decodes the shuffle masks for unpcklps/unpcklpd
57 /// etc. VT indicates the type of the vector allowing it to handle different
58 /// datatypes and vector widths.
60 /// and punpckl*. VT indicates the type of the vector allowing it to handle
61 /// different datatypes and vector widths.
5962 void DecodeUNPCKLMask(EVT VT, SmallVectorImpl &ShuffleMask);
6063
6164
62 // DecodeVPERMILPMask - Decodes VPERMILPS/ VPERMILPD permutes for any 128-bit
63 // 32-bit or 64-bit elements. For 256-bit vectors, it's considered as two 128
64 // lanes. For VPERMILPS, referenced elements can't cross lanes and the mask of
65 // the first lane must be the same of the second.
66 void DecodeVPERMILPMask(EVT VT, unsigned Imm,
67 SmallVectorImpl &ShuffleMask);
68
69 void DecodeVPERM2F128Mask(unsigned Imm,
70 SmallVectorImpl &ShuffleMask);
71 void DecodeVPERM2F128Mask(EVT VT, unsigned Imm,
65 void DecodeVPERM2X128Mask(EVT VT, unsigned Imm,
7266 SmallVectorImpl &ShuffleMask);
7367
7468 } // llvm namespace
44294429 if (Index < 0)
44304430 return DAG.getUNDEF(VT.getVectorElementType());
44314431
4432 int NumElems = VT.getVectorNumElements();
4433 SDValue NewV = (Index < NumElems) ? SV->getOperand(0) : SV->getOperand(1);
4432 unsigned NumElems = VT.getVectorNumElements();
4433 SDValue NewV = (Index < (int)NumElems) ? SV->getOperand(0)
4434 : SV->getOperand(1);
44344435 return getShuffleScalarElt(NewV.getNode(), Index % NumElems, DAG, Depth+1);
44354436 }
44364437
44374438 // Recurse into target specific vector shuffles to find scalars.
44384439 if (isTargetShuffle(Opcode)) {
4439 int NumElems = VT.getVectorNumElements();
4440 unsigned NumElems = VT.getVectorNumElements();
44404441 SmallVector ShuffleMask;
44414442 SDValue ImmN;
44424443
44594460 DecodeMOVLHPSMask(NumElems, ShuffleMask);
44604461 break;
44614462 case X86ISD::PSHUFD:
4463 case X86ISD::VPERMILP:
44624464 ImmN = N->getOperand(N->getNumOperands()-1);
4463 DecodePSHUFMask(NumElems,
4464 cast(ImmN)->getZExtValue(),
4465 DecodePSHUFMask(VT, cast(ImmN)->getZExtValue(),
44654466 ShuffleMask);
44664467 break;
44674468 case X86ISD::PSHUFHW:
44834484 return getShuffleScalarElt(V.getOperand(OpNum).getNode(), Index, DAG,
44844485 Depth+1);
44854486 }
4486 case X86ISD::VPERMILP:
4487 ImmN = N->getOperand(N->getNumOperands()-1);
4488 DecodeVPERMILPMask(VT, cast(ImmN)->getZExtValue(),
4489 ShuffleMask);
4490 break;
44914487 case X86ISD::VPERM2X128:
44924488 ImmN = N->getOperand(N->getNumOperands()-1);
4493 DecodeVPERM2F128Mask(VT, cast(ImmN)->getZExtValue(),
4489 DecodeVPERM2X128Mask(VT, cast(ImmN)->getZExtValue(),
44944490 ShuffleMask);
44954491 break;
44964492 case X86ISD::MOVDDUP:
45084504 if (Index < 0)
45094505 return DAG.getUNDEF(VT.getVectorElementType());
45104506
4511 SDValue NewV = (Index < NumElems) ? N->getOperand(0) : N->getOperand(1);
4507 SDValue NewV = (Index < (int)NumElems) ? N->getOperand(0)
4508 : N->getOperand(1);
45124509 return getShuffleScalarElt(NewV.getNode(), Index % NumElems, DAG,
45134510 Depth+1);
45144511 }