1 //======- X86InstrFragmentsSIMD.td - x86 ISA -------------*- tablegen -*-=====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides pattern fragments useful for SIMD instructions.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // MMX Pattern Fragments
16 //===----------------------------------------------------------------------===//
18 def load_mmx : PatFrag<(ops node:$ptr), (x86mmx (load node:$ptr))>;
19 def bc_mmx : PatFrag<(ops node:$in), (x86mmx (bitconvert node:$in))>;
21 //===----------------------------------------------------------------------===//
22 // SSE specific DAG Nodes.
23 //===----------------------------------------------------------------------===//
25 def SDTX86FPShiftOp : SDTypeProfile<1, 2, [ SDTCisSameAs<0, 1>,
26 SDTCisFP<0>, SDTCisInt<2> ]>;
27 def SDTX86VFCMP : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<1, 2>,
28 SDTCisFP<1>, SDTCisVT<3, i8>]>;
30 def X86fmin : SDNode<"X86ISD::FMIN", SDTFPBinOp>;
31 def X86fmax : SDNode<"X86ISD::FMAX", SDTFPBinOp>;
32 def X86fand : SDNode<"X86ISD::FAND", SDTFPBinOp,
33 [SDNPCommutative, SDNPAssociative]>;
34 def X86for : SDNode<"X86ISD::FOR", SDTFPBinOp,
35 [SDNPCommutative, SDNPAssociative]>;
36 def X86fxor : SDNode<"X86ISD::FXOR", SDTFPBinOp,
37 [SDNPCommutative, SDNPAssociative]>;
38 def X86frsqrt : SDNode<"X86ISD::FRSQRT", SDTFPUnaryOp>;
39 def X86frcp : SDNode<"X86ISD::FRCP", SDTFPUnaryOp>;
40 def X86fsrl : SDNode<"X86ISD::FSRL", SDTX86FPShiftOp>;
41 def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest>;
42 def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest>;
43 def X86pshufb : SDNode<"X86ISD::PSHUFB",
44 SDTypeProfile<1, 2, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
46 def X86pextrb : SDNode<"X86ISD::PEXTRB",
47 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
48 def X86pextrw : SDNode<"X86ISD::PEXTRW",
49 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
50 def X86pinsrb : SDNode<"X86ISD::PINSRB",
51 SDTypeProfile<1, 3, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
52 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
53 def X86pinsrw : SDNode<"X86ISD::PINSRW",
54 SDTypeProfile<1, 3, [SDTCisVT<0, v8i16>, SDTCisSameAs<0,1>,
55 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
56 def X86insrtps : SDNode<"X86ISD::INSERTPS",
57 SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisSameAs<0,1>,
58 SDTCisVT<2, v4f32>, SDTCisPtrTy<3>]>>;
59 def X86vzmovl : SDNode<"X86ISD::VZEXT_MOVL",
60 SDTypeProfile<1, 1, [SDTCisSameAs<0,1>]>>;
61 def X86vzload : SDNode<"X86ISD::VZEXT_LOAD", SDTLoad,
62 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
63 def X86vshl : SDNode<"X86ISD::VSHL", SDTIntShiftOp>;
64 def X86vshr : SDNode<"X86ISD::VSRL", SDTIntShiftOp>;
65 def X86cmpps : SDNode<"X86ISD::CMPPS", SDTX86VFCMP>;
66 def X86cmppd : SDNode<"X86ISD::CMPPD", SDTX86VFCMP>;
67 def X86pcmpeqb : SDNode<"X86ISD::PCMPEQB", SDTIntBinOp, [SDNPCommutative]>;
68 def X86pcmpeqw : SDNode<"X86ISD::PCMPEQW", SDTIntBinOp, [SDNPCommutative]>;
69 def X86pcmpeqd : SDNode<"X86ISD::PCMPEQD", SDTIntBinOp, [SDNPCommutative]>;
70 def X86pcmpeqq : SDNode<"X86ISD::PCMPEQQ", SDTIntBinOp, [SDNPCommutative]>;
71 def X86pcmpgtb : SDNode<"X86ISD::PCMPGTB", SDTIntBinOp>;
72 def X86pcmpgtw : SDNode<"X86ISD::PCMPGTW", SDTIntBinOp>;
73 def X86pcmpgtd : SDNode<"X86ISD::PCMPGTD", SDTIntBinOp>;
74 def X86pcmpgtq : SDNode<"X86ISD::PCMPGTQ", SDTIntBinOp>;
76 def SDTX86CmpPTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>,
79 def X86ptest : SDNode<"X86ISD::PTEST", SDTX86CmpPTest>;
80 def X86testp : SDNode<"X86ISD::TESTP", SDTX86CmpPTest>;
82 // Specific shuffle nodes - At some point ISD::VECTOR_SHUFFLE will always get
83 // translated into one of the target nodes below during lowering.
84 // Note: this is a work in progress...
85 def SDTShuff1Op : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisSameAs<0,1>]>;
86 def SDTShuff2Op : SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisSameAs<0,1>,
89 def SDTShuff2OpI : SDTypeProfile<1, 2, [SDTCisVec<0>,
90 SDTCisSameAs<0,1>, SDTCisInt<2>]>;
91 def SDTShuff3OpI : SDTypeProfile<1, 3, [SDTCisVec<0>, SDTCisSameAs<0,1>,
92 SDTCisSameAs<0,2>, SDTCisInt<3>]>;
94 def X86PAlign : SDNode<"X86ISD::PALIGN", SDTShuff3OpI>;
96 def X86PShufd : SDNode<"X86ISD::PSHUFD", SDTShuff2OpI>;
97 def X86PShufhw : SDNode<"X86ISD::PSHUFHW", SDTShuff2OpI>;
98 def X86PShuflw : SDNode<"X86ISD::PSHUFLW", SDTShuff2OpI>;
100 def X86Shufpd : SDNode<"X86ISD::SHUFPD", SDTShuff3OpI>;
101 def X86Shufps : SDNode<"X86ISD::SHUFPS", SDTShuff3OpI>;
103 def X86Movddup : SDNode<"X86ISD::MOVDDUP", SDTShuff1Op>;
104 def X86Movshdup : SDNode<"X86ISD::MOVSHDUP", SDTShuff1Op>;
105 def X86Movsldup : SDNode<"X86ISD::MOVSLDUP", SDTShuff1Op>;
107 def X86Movsd : SDNode<"X86ISD::MOVSD", SDTShuff2Op>;
108 def X86Movss : SDNode<"X86ISD::MOVSS", SDTShuff2Op>;
110 def X86Movlhps : SDNode<"X86ISD::MOVLHPS", SDTShuff2Op>;
111 def X86Movlhpd : SDNode<"X86ISD::MOVLHPD", SDTShuff2Op>;
112 def X86Movhlps : SDNode<"X86ISD::MOVHLPS", SDTShuff2Op>;
113 def X86Movhlpd : SDNode<"X86ISD::MOVHLPD", SDTShuff2Op>;
115 def X86Movlps : SDNode<"X86ISD::MOVLPS", SDTShuff2Op>;
116 def X86Movlpd : SDNode<"X86ISD::MOVLPD", SDTShuff2Op>;
118 def X86Unpcklps : SDNode<"X86ISD::UNPCKLPS", SDTShuff2Op>;
119 def X86Unpcklpd : SDNode<"X86ISD::UNPCKLPD", SDTShuff2Op>;
120 def X86Unpckhps : SDNode<"X86ISD::UNPCKHPS", SDTShuff2Op>;
121 def X86Unpckhpd : SDNode<"X86ISD::UNPCKHPD", SDTShuff2Op>;
123 def X86Punpcklbw : SDNode<"X86ISD::PUNPCKLBW", SDTShuff2Op>;
124 def X86Punpcklwd : SDNode<"X86ISD::PUNPCKLWD", SDTShuff2Op>;
125 def X86Punpckldq : SDNode<"X86ISD::PUNPCKLDQ", SDTShuff2Op>;
126 def X86Punpcklqdq : SDNode<"X86ISD::PUNPCKLQDQ", SDTShuff2Op>;
128 def X86Punpckhbw : SDNode<"X86ISD::PUNPCKHBW", SDTShuff2Op>;
129 def X86Punpckhwd : SDNode<"X86ISD::PUNPCKHWD", SDTShuff2Op>;
130 def X86Punpckhdq : SDNode<"X86ISD::PUNPCKHDQ", SDTShuff2Op>;
131 def X86Punpckhqdq : SDNode<"X86ISD::PUNPCKHQDQ", SDTShuff2Op>;
133 //===----------------------------------------------------------------------===//
134 // SSE Complex Patterns
135 //===----------------------------------------------------------------------===//
137 // These are 'extloads' from a scalar to the low element of a vector, zeroing
138 // the top elements. These are used for the SSE 'ss' and 'sd' instruction
140 def sse_load_f32 : ComplexPattern<v4f32, 5, "SelectScalarSSELoad", [],
141 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand,
143 def sse_load_f64 : ComplexPattern<v2f64, 5, "SelectScalarSSELoad", [],
144 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand,
147 def ssmem : Operand<v4f32> {
148 let PrintMethod = "printf32mem";
149 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
150 let ParserMatchClass = X86MemAsmOperand;
152 def sdmem : Operand<v2f64> {
153 let PrintMethod = "printf64mem";
154 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
155 let ParserMatchClass = X86MemAsmOperand;
158 //===----------------------------------------------------------------------===//
159 // SSE pattern fragments
160 //===----------------------------------------------------------------------===//
162 // 128-bit load pattern fragments
163 def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
164 def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
165 def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
166 def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
168 // 256-bit load pattern fragments
169 def loadv8f32 : PatFrag<(ops node:$ptr), (v8f32 (load node:$ptr))>;
170 def loadv4f64 : PatFrag<(ops node:$ptr), (v4f64 (load node:$ptr))>;
171 def loadv8i32 : PatFrag<(ops node:$ptr), (v8i32 (load node:$ptr))>;
172 def loadv4i64 : PatFrag<(ops node:$ptr), (v4i64 (load node:$ptr))>;
174 // Like 'store', but always requires vector alignment.
175 def alignedstore : PatFrag<(ops node:$val, node:$ptr),
176 (store node:$val, node:$ptr), [{
177 return cast<StoreSDNode>(N)->getAlignment() >= 16;
180 // Like 'load', but always requires vector alignment.
181 def alignedload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
182 return cast<LoadSDNode>(N)->getAlignment() >= 16;
185 def alignedloadfsf32 : PatFrag<(ops node:$ptr),
186 (f32 (alignedload node:$ptr))>;
187 def alignedloadfsf64 : PatFrag<(ops node:$ptr),
188 (f64 (alignedload node:$ptr))>;
190 // 128-bit aligned load pattern fragments
191 def alignedloadv4f32 : PatFrag<(ops node:$ptr),
192 (v4f32 (alignedload node:$ptr))>;
193 def alignedloadv2f64 : PatFrag<(ops node:$ptr),
194 (v2f64 (alignedload node:$ptr))>;
195 def alignedloadv4i32 : PatFrag<(ops node:$ptr),
196 (v4i32 (alignedload node:$ptr))>;
197 def alignedloadv2i64 : PatFrag<(ops node:$ptr),
198 (v2i64 (alignedload node:$ptr))>;
200 // 256-bit aligned load pattern fragments
201 def alignedloadv8f32 : PatFrag<(ops node:$ptr),
202 (v8f32 (alignedload node:$ptr))>;
203 def alignedloadv4f64 : PatFrag<(ops node:$ptr),
204 (v4f64 (alignedload node:$ptr))>;
205 def alignedloadv8i32 : PatFrag<(ops node:$ptr),
206 (v8i32 (alignedload node:$ptr))>;
207 def alignedloadv4i64 : PatFrag<(ops node:$ptr),
208 (v4i64 (alignedload node:$ptr))>;
210 // Like 'load', but uses special alignment checks suitable for use in
211 // memory operands in most SSE instructions, which are required to
212 // be naturally aligned on some targets but not on others. If the subtarget
213 // allows unaligned accesses, match any load, though this may require
214 // setting a feature bit in the processor (on startup, for example).
215 // Opteron 10h and later implement such a feature.
216 def memop : PatFrag<(ops node:$ptr), (load node:$ptr), [{
217 return Subtarget->hasVectorUAMem()
218 || cast<LoadSDNode>(N)->getAlignment() >= 16;
221 def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
222 def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
224 // 128-bit memop pattern fragments
225 def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
226 def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
227 def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
228 def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
229 def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop node:$ptr))>;
230 def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
232 // 256-bit memop pattern fragments
233 def memopv32i8 : PatFrag<(ops node:$ptr), (v32i8 (memop node:$ptr))>;
234 def memopv8f32 : PatFrag<(ops node:$ptr), (v8f32 (memop node:$ptr))>;
235 def memopv4f64 : PatFrag<(ops node:$ptr), (v4f64 (memop node:$ptr))>;
236 def memopv4i64 : PatFrag<(ops node:$ptr), (v4i64 (memop node:$ptr))>;
237 def memopv8i32 : PatFrag<(ops node:$ptr), (v8i32 (memop node:$ptr))>;
239 // SSSE3 uses MMX registers for some instructions. They aren't aligned on a
241 // FIXME: 8 byte alignment for mmx reads is not required
242 def memop64 : PatFrag<(ops node:$ptr), (load node:$ptr), [{
243 return cast<LoadSDNode>(N)->getAlignment() >= 8;
246 def memopmmx : PatFrag<(ops node:$ptr), (x86mmx (memop64 node:$ptr))>;
249 // Like 'store', but requires the non-temporal bit to be set
250 def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
251 (st node:$val, node:$ptr), [{
252 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
253 return ST->isNonTemporal();
257 def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
258 (st node:$val, node:$ptr), [{
259 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
260 return ST->isNonTemporal() && !ST->isTruncatingStore() &&
261 ST->getAddressingMode() == ISD::UNINDEXED &&
262 ST->getAlignment() >= 16;
266 def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
267 (st node:$val, node:$ptr), [{
268 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
269 return ST->isNonTemporal() &&
270 ST->getAlignment() < 16;
274 // 128-bit bitconvert pattern fragments
275 def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
276 def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
277 def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
278 def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
279 def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
280 def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
282 // 256-bit bitconvert pattern fragments
283 def bc_v8i32 : PatFrag<(ops node:$in), (v8i32 (bitconvert node:$in))>;
285 def vzmovl_v2i64 : PatFrag<(ops node:$src),
286 (bitconvert (v2i64 (X86vzmovl
287 (v2i64 (scalar_to_vector (loadi64 node:$src))))))>;
288 def vzmovl_v4i32 : PatFrag<(ops node:$src),
289 (bitconvert (v4i32 (X86vzmovl
290 (v4i32 (scalar_to_vector (loadi32 node:$src))))))>;
292 def vzload_v2i64 : PatFrag<(ops node:$src),
293 (bitconvert (v2i64 (X86vzload node:$src)))>;
296 def fp32imm0 : PatLeaf<(f32 fpimm), [{
297 return N->isExactlyValue(+0.0);
300 // BYTE_imm - Transform bit immediates into byte immediates.
301 def BYTE_imm : SDNodeXForm<imm, [{
302 // Transformation function: imm >> 3
303 return getI32Imm(N->getZExtValue() >> 3);
306 // SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
308 def SHUFFLE_get_shuf_imm : SDNodeXForm<vector_shuffle, [{
309 return getI8Imm(X86::getShuffleSHUFImmediate(N));
312 // SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
314 def SHUFFLE_get_pshufhw_imm : SDNodeXForm<vector_shuffle, [{
315 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
318 // SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
320 def SHUFFLE_get_pshuflw_imm : SDNodeXForm<vector_shuffle, [{
321 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
324 // SHUFFLE_get_palign_imm xform function: convert vector_shuffle mask to
326 def SHUFFLE_get_palign_imm : SDNodeXForm<vector_shuffle, [{
327 return getI8Imm(X86::getShufflePALIGNRImmediate(N));
330 def splat_lo : PatFrag<(ops node:$lhs, node:$rhs),
331 (vector_shuffle node:$lhs, node:$rhs), [{
332 ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N);
333 return SVOp->isSplat() && SVOp->getSplatIndex() == 0;
336 def movddup : PatFrag<(ops node:$lhs, node:$rhs),
337 (vector_shuffle node:$lhs, node:$rhs), [{
338 return X86::isMOVDDUPMask(cast<ShuffleVectorSDNode>(N));
341 def movhlps : PatFrag<(ops node:$lhs, node:$rhs),
342 (vector_shuffle node:$lhs, node:$rhs), [{
343 return X86::isMOVHLPSMask(cast<ShuffleVectorSDNode>(N));
346 def movhlps_undef : PatFrag<(ops node:$lhs, node:$rhs),
347 (vector_shuffle node:$lhs, node:$rhs), [{
348 return X86::isMOVHLPS_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
351 def movlhps : PatFrag<(ops node:$lhs, node:$rhs),
352 (vector_shuffle node:$lhs, node:$rhs), [{
353 return X86::isMOVLHPSMask(cast<ShuffleVectorSDNode>(N));
356 def movlp : PatFrag<(ops node:$lhs, node:$rhs),
357 (vector_shuffle node:$lhs, node:$rhs), [{
358 return X86::isMOVLPMask(cast<ShuffleVectorSDNode>(N));
361 def movl : PatFrag<(ops node:$lhs, node:$rhs),
362 (vector_shuffle node:$lhs, node:$rhs), [{
363 return X86::isMOVLMask(cast<ShuffleVectorSDNode>(N));
366 def movshdup : PatFrag<(ops node:$lhs, node:$rhs),
367 (vector_shuffle node:$lhs, node:$rhs), [{
368 return X86::isMOVSHDUPMask(cast<ShuffleVectorSDNode>(N));
371 def movsldup : PatFrag<(ops node:$lhs, node:$rhs),
372 (vector_shuffle node:$lhs, node:$rhs), [{
373 return X86::isMOVSLDUPMask(cast<ShuffleVectorSDNode>(N));
376 def unpckl : PatFrag<(ops node:$lhs, node:$rhs),
377 (vector_shuffle node:$lhs, node:$rhs), [{
378 return X86::isUNPCKLMask(cast<ShuffleVectorSDNode>(N));
381 def unpckh : PatFrag<(ops node:$lhs, node:$rhs),
382 (vector_shuffle node:$lhs, node:$rhs), [{
383 return X86::isUNPCKHMask(cast<ShuffleVectorSDNode>(N));
386 def unpckl_undef : PatFrag<(ops node:$lhs, node:$rhs),
387 (vector_shuffle node:$lhs, node:$rhs), [{
388 return X86::isUNPCKL_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
391 def unpckh_undef : PatFrag<(ops node:$lhs, node:$rhs),
392 (vector_shuffle node:$lhs, node:$rhs), [{
393 return X86::isUNPCKH_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
396 def pshufd : PatFrag<(ops node:$lhs, node:$rhs),
397 (vector_shuffle node:$lhs, node:$rhs), [{
398 return X86::isPSHUFDMask(cast<ShuffleVectorSDNode>(N));
399 }], SHUFFLE_get_shuf_imm>;
401 def shufp : PatFrag<(ops node:$lhs, node:$rhs),
402 (vector_shuffle node:$lhs, node:$rhs), [{
403 return X86::isSHUFPMask(cast<ShuffleVectorSDNode>(N));
404 }], SHUFFLE_get_shuf_imm>;
406 def pshufhw : PatFrag<(ops node:$lhs, node:$rhs),
407 (vector_shuffle node:$lhs, node:$rhs), [{
408 return X86::isPSHUFHWMask(cast<ShuffleVectorSDNode>(N));
409 }], SHUFFLE_get_pshufhw_imm>;
411 def pshuflw : PatFrag<(ops node:$lhs, node:$rhs),
412 (vector_shuffle node:$lhs, node:$rhs), [{
413 return X86::isPSHUFLWMask(cast<ShuffleVectorSDNode>(N));
414 }], SHUFFLE_get_pshuflw_imm>;
416 def palign : PatFrag<(ops node:$lhs, node:$rhs),
417 (vector_shuffle node:$lhs, node:$rhs), [{
418 return X86::isPALIGNRMask(cast<ShuffleVectorSDNode>(N));
419 }], SHUFFLE_get_palign_imm>;