1 //====- X86InstrSSE.td - Describe the X86 Instruction Set --*- 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 describes the X86 SSE instruction set, defining the instructions,
11 // and properties of the instructions which are needed for code generation,
12 // machine code emission, and analysis.
14 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
18 // SSE specific DAG Nodes.
19 //===----------------------------------------------------------------------===//
21 def SDTX86FPShiftOp : SDTypeProfile<1, 2, [ SDTCisSameAs<0, 1>,
22 SDTCisFP<0>, SDTCisInt<2> ]>;
23 def SDTX86VFCMP : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<1, 2>,
24 SDTCisFP<1>, SDTCisVT<3, i8>]>;
26 def X86fmin : SDNode<"X86ISD::FMIN", SDTFPBinOp>;
27 def X86fmax : SDNode<"X86ISD::FMAX", SDTFPBinOp>;
28 def X86fand : SDNode<"X86ISD::FAND", SDTFPBinOp,
29 [SDNPCommutative, SDNPAssociative]>;
30 def X86for : SDNode<"X86ISD::FOR", SDTFPBinOp,
31 [SDNPCommutative, SDNPAssociative]>;
32 def X86fxor : SDNode<"X86ISD::FXOR", SDTFPBinOp,
33 [SDNPCommutative, SDNPAssociative]>;
34 def X86frsqrt : SDNode<"X86ISD::FRSQRT", SDTFPUnaryOp>;
35 def X86frcp : SDNode<"X86ISD::FRCP", SDTFPUnaryOp>;
36 def X86fsrl : SDNode<"X86ISD::FSRL", SDTX86FPShiftOp>;
37 def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest>;
38 def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest>;
39 def X86pshufb : SDNode<"X86ISD::PSHUFB",
40 SDTypeProfile<1, 2, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
42 def X86pextrb : SDNode<"X86ISD::PEXTRB",
43 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
44 def X86pextrw : SDNode<"X86ISD::PEXTRW",
45 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
46 def X86pinsrb : SDNode<"X86ISD::PINSRB",
47 SDTypeProfile<1, 3, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
48 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
49 def X86pinsrw : SDNode<"X86ISD::PINSRW",
50 SDTypeProfile<1, 3, [SDTCisVT<0, v8i16>, SDTCisSameAs<0,1>,
51 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
52 def X86insrtps : SDNode<"X86ISD::INSERTPS",
53 SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisSameAs<0,1>,
54 SDTCisVT<2, v4f32>, SDTCisPtrTy<3>]>>;
55 def X86vzmovl : SDNode<"X86ISD::VZEXT_MOVL",
56 SDTypeProfile<1, 1, [SDTCisSameAs<0,1>]>>;
57 def X86vzload : SDNode<"X86ISD::VZEXT_LOAD", SDTLoad,
58 [SDNPHasChain, SDNPMayLoad]>;
59 def X86vshl : SDNode<"X86ISD::VSHL", SDTIntShiftOp>;
60 def X86vshr : SDNode<"X86ISD::VSRL", SDTIntShiftOp>;
61 def X86cmpps : SDNode<"X86ISD::CMPPS", SDTX86VFCMP>;
62 def X86cmppd : SDNode<"X86ISD::CMPPD", SDTX86VFCMP>;
63 def X86pcmpeqb : SDNode<"X86ISD::PCMPEQB", SDTIntBinOp, [SDNPCommutative]>;
64 def X86pcmpeqw : SDNode<"X86ISD::PCMPEQW", SDTIntBinOp, [SDNPCommutative]>;
65 def X86pcmpeqd : SDNode<"X86ISD::PCMPEQD", SDTIntBinOp, [SDNPCommutative]>;
66 def X86pcmpeqq : SDNode<"X86ISD::PCMPEQQ", SDTIntBinOp, [SDNPCommutative]>;
67 def X86pcmpgtb : SDNode<"X86ISD::PCMPGTB", SDTIntBinOp>;
68 def X86pcmpgtw : SDNode<"X86ISD::PCMPGTW", SDTIntBinOp>;
69 def X86pcmpgtd : SDNode<"X86ISD::PCMPGTD", SDTIntBinOp>;
70 def X86pcmpgtq : SDNode<"X86ISD::PCMPGTQ", SDTIntBinOp>;
72 def SDTX86CmpPTest : SDTypeProfile<0, 2, [SDTCisVT<0, v4f32>,
74 def X86ptest : SDNode<"X86ISD::PTEST", SDTX86CmpPTest>;
76 //===----------------------------------------------------------------------===//
77 // SSE Complex Patterns
78 //===----------------------------------------------------------------------===//
80 // These are 'extloads' from a scalar to the low element of a vector, zeroing
81 // the top elements. These are used for the SSE 'ss' and 'sd' instruction
83 def sse_load_f32 : ComplexPattern<v4f32, 5, "SelectScalarSSELoad", [],
84 [SDNPHasChain, SDNPMayLoad]>;
85 def sse_load_f64 : ComplexPattern<v2f64, 5, "SelectScalarSSELoad", [],
86 [SDNPHasChain, SDNPMayLoad]>;
88 def ssmem : Operand<v4f32> {
89 let PrintMethod = "printf32mem";
90 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
91 let ParserMatchClass = X86MemAsmOperand;
93 def sdmem : Operand<v2f64> {
94 let PrintMethod = "printf64mem";
95 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
96 let ParserMatchClass = X86MemAsmOperand;
99 //===----------------------------------------------------------------------===//
100 // SSE pattern fragments
101 //===----------------------------------------------------------------------===//
103 def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
104 def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
105 def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
106 def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
108 // Like 'store', but always requires vector alignment.
109 def alignedstore : PatFrag<(ops node:$val, node:$ptr),
110 (store node:$val, node:$ptr), [{
111 return cast<StoreSDNode>(N)->getAlignment() >= 16;
114 // Like 'load', but always requires vector alignment.
115 def alignedload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
116 return cast<LoadSDNode>(N)->getAlignment() >= 16;
119 def alignedloadfsf32 : PatFrag<(ops node:$ptr), (f32 (alignedload node:$ptr))>;
120 def alignedloadfsf64 : PatFrag<(ops node:$ptr), (f64 (alignedload node:$ptr))>;
121 def alignedloadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (alignedload node:$ptr))>;
122 def alignedloadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (alignedload node:$ptr))>;
123 def alignedloadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (alignedload node:$ptr))>;
124 def alignedloadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (alignedload node:$ptr))>;
126 // Like 'load', but uses special alignment checks suitable for use in
127 // memory operands in most SSE instructions, which are required to
128 // be naturally aligned on some targets but not on others.
129 // FIXME: Actually implement support for targets that don't require the
130 // alignment. This probably wants a subtarget predicate.
131 def memop : PatFrag<(ops node:$ptr), (load node:$ptr), [{
132 return cast<LoadSDNode>(N)->getAlignment() >= 16;
135 def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
136 def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
137 def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
138 def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
139 def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
140 def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
141 def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
143 // SSSE3 uses MMX registers for some instructions. They aren't aligned on a
145 // FIXME: 8 byte alignment for mmx reads is not required
146 def memop64 : PatFrag<(ops node:$ptr), (load node:$ptr), [{
147 return cast<LoadSDNode>(N)->getAlignment() >= 8;
150 def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
151 def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
152 def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
153 def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
155 def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
156 def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
157 def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
158 def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
159 def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
160 def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
162 def vzmovl_v2i64 : PatFrag<(ops node:$src),
163 (bitconvert (v2i64 (X86vzmovl
164 (v2i64 (scalar_to_vector (loadi64 node:$src))))))>;
165 def vzmovl_v4i32 : PatFrag<(ops node:$src),
166 (bitconvert (v4i32 (X86vzmovl
167 (v4i32 (scalar_to_vector (loadi32 node:$src))))))>;
169 def vzload_v2i64 : PatFrag<(ops node:$src),
170 (bitconvert (v2i64 (X86vzload node:$src)))>;
173 def fp32imm0 : PatLeaf<(f32 fpimm), [{
174 return N->isExactlyValue(+0.0);
177 // BYTE_imm - Transform bit immediates into byte immediates.
178 def BYTE_imm : SDNodeXForm<imm, [{
179 // Transformation function: imm >> 3
180 return getI32Imm(N->getZExtValue() >> 3);
183 // SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
185 def SHUFFLE_get_shuf_imm : SDNodeXForm<vector_shuffle, [{
186 return getI8Imm(X86::getShuffleSHUFImmediate(N));
189 // SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
191 def SHUFFLE_get_pshufhw_imm : SDNodeXForm<vector_shuffle, [{
192 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
195 // SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
197 def SHUFFLE_get_pshuflw_imm : SDNodeXForm<vector_shuffle, [{
198 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
201 // SHUFFLE_get_palign_imm xform function: convert vector_shuffle mask to
203 def SHUFFLE_get_palign_imm : SDNodeXForm<vector_shuffle, [{
204 return getI8Imm(X86::getShufflePALIGNRImmediate(N));
207 def splat_lo : PatFrag<(ops node:$lhs, node:$rhs),
208 (vector_shuffle node:$lhs, node:$rhs), [{
209 ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N);
210 return SVOp->isSplat() && SVOp->getSplatIndex() == 0;
213 def movddup : PatFrag<(ops node:$lhs, node:$rhs),
214 (vector_shuffle node:$lhs, node:$rhs), [{
215 return X86::isMOVDDUPMask(cast<ShuffleVectorSDNode>(N));
218 def movhlps : PatFrag<(ops node:$lhs, node:$rhs),
219 (vector_shuffle node:$lhs, node:$rhs), [{
220 return X86::isMOVHLPSMask(cast<ShuffleVectorSDNode>(N));
223 def movhlps_undef : PatFrag<(ops node:$lhs, node:$rhs),
224 (vector_shuffle node:$lhs, node:$rhs), [{
225 return X86::isMOVHLPS_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
228 def movlhps : PatFrag<(ops node:$lhs, node:$rhs),
229 (vector_shuffle node:$lhs, node:$rhs), [{
230 return X86::isMOVLHPSMask(cast<ShuffleVectorSDNode>(N));
233 def movlp : PatFrag<(ops node:$lhs, node:$rhs),
234 (vector_shuffle node:$lhs, node:$rhs), [{
235 return X86::isMOVLPMask(cast<ShuffleVectorSDNode>(N));
238 def movl : PatFrag<(ops node:$lhs, node:$rhs),
239 (vector_shuffle node:$lhs, node:$rhs), [{
240 return X86::isMOVLMask(cast<ShuffleVectorSDNode>(N));
243 def movshdup : PatFrag<(ops node:$lhs, node:$rhs),
244 (vector_shuffle node:$lhs, node:$rhs), [{
245 return X86::isMOVSHDUPMask(cast<ShuffleVectorSDNode>(N));
248 def movsldup : PatFrag<(ops node:$lhs, node:$rhs),
249 (vector_shuffle node:$lhs, node:$rhs), [{
250 return X86::isMOVSLDUPMask(cast<ShuffleVectorSDNode>(N));
253 def unpckl : PatFrag<(ops node:$lhs, node:$rhs),
254 (vector_shuffle node:$lhs, node:$rhs), [{
255 return X86::isUNPCKLMask(cast<ShuffleVectorSDNode>(N));
258 def unpckh : PatFrag<(ops node:$lhs, node:$rhs),
259 (vector_shuffle node:$lhs, node:$rhs), [{
260 return X86::isUNPCKHMask(cast<ShuffleVectorSDNode>(N));
263 def unpckl_undef : PatFrag<(ops node:$lhs, node:$rhs),
264 (vector_shuffle node:$lhs, node:$rhs), [{
265 return X86::isUNPCKL_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
268 def unpckh_undef : PatFrag<(ops node:$lhs, node:$rhs),
269 (vector_shuffle node:$lhs, node:$rhs), [{
270 return X86::isUNPCKH_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
273 def pshufd : PatFrag<(ops node:$lhs, node:$rhs),
274 (vector_shuffle node:$lhs, node:$rhs), [{
275 return X86::isPSHUFDMask(cast<ShuffleVectorSDNode>(N));
276 }], SHUFFLE_get_shuf_imm>;
278 def shufp : PatFrag<(ops node:$lhs, node:$rhs),
279 (vector_shuffle node:$lhs, node:$rhs), [{
280 return X86::isSHUFPMask(cast<ShuffleVectorSDNode>(N));
281 }], SHUFFLE_get_shuf_imm>;
283 def pshufhw : PatFrag<(ops node:$lhs, node:$rhs),
284 (vector_shuffle node:$lhs, node:$rhs), [{
285 return X86::isPSHUFHWMask(cast<ShuffleVectorSDNode>(N));
286 }], SHUFFLE_get_pshufhw_imm>;
288 def pshuflw : PatFrag<(ops node:$lhs, node:$rhs),
289 (vector_shuffle node:$lhs, node:$rhs), [{
290 return X86::isPSHUFLWMask(cast<ShuffleVectorSDNode>(N));
291 }], SHUFFLE_get_pshuflw_imm>;
293 def palign : PatFrag<(ops node:$lhs, node:$rhs),
294 (vector_shuffle node:$lhs, node:$rhs), [{
295 return X86::isPALIGNRMask(cast<ShuffleVectorSDNode>(N));
296 }], SHUFFLE_get_palign_imm>;
298 //===----------------------------------------------------------------------===//
299 // SSE scalar FP Instructions
300 //===----------------------------------------------------------------------===//
302 // CMOV* - Used to implement the SSE SELECT DAG operation. Expanded after
303 // instruction selection into a branch sequence.
304 let Uses = [EFLAGS], usesCustomInserter = 1 in {
305 def CMOV_FR32 : I<0, Pseudo,
306 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
307 "#CMOV_FR32 PSEUDO!",
308 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
310 def CMOV_FR64 : I<0, Pseudo,
311 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
312 "#CMOV_FR64 PSEUDO!",
313 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
315 def CMOV_V4F32 : I<0, Pseudo,
316 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
317 "#CMOV_V4F32 PSEUDO!",
319 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
321 def CMOV_V2F64 : I<0, Pseudo,
322 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
323 "#CMOV_V2F64 PSEUDO!",
325 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
327 def CMOV_V2I64 : I<0, Pseudo,
328 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
329 "#CMOV_V2I64 PSEUDO!",
331 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
335 //===----------------------------------------------------------------------===//
337 //===----------------------------------------------------------------------===//
340 let neverHasSideEffects = 1 in
341 def MOVSSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
342 "movss\t{$src, $dst|$dst, $src}", []>;
343 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
344 def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
345 "movss\t{$src, $dst|$dst, $src}",
346 [(set FR32:$dst, (loadf32 addr:$src))]>;
347 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
348 "movss\t{$src, $dst|$dst, $src}",
349 [(store FR32:$src, addr:$dst)]>;
351 // Conversion instructions
352 def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
353 "cvttss2si\t{$src, $dst|$dst, $src}",
354 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
355 def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
356 "cvttss2si\t{$src, $dst|$dst, $src}",
357 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
358 def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
359 "cvtsi2ss\t{$src, $dst|$dst, $src}",
360 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
361 def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
362 "cvtsi2ss\t{$src, $dst|$dst, $src}",
363 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
365 // Match intrinsics which expect XMM operand(s).
366 def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
367 "cvtss2si\t{$src, $dst|$dst, $src}",
368 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
369 def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
370 "cvtss2si\t{$src, $dst|$dst, $src}",
371 [(set GR32:$dst, (int_x86_sse_cvtss2si
372 (load addr:$src)))]>;
374 // Match intrinisics which expect MM and XMM operand(s).
375 def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
376 "cvtps2pi\t{$src, $dst|$dst, $src}",
377 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
378 def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
379 "cvtps2pi\t{$src, $dst|$dst, $src}",
380 [(set VR64:$dst, (int_x86_sse_cvtps2pi
381 (load addr:$src)))]>;
382 def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
383 "cvttps2pi\t{$src, $dst|$dst, $src}",
384 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
385 def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
386 "cvttps2pi\t{$src, $dst|$dst, $src}",
387 [(set VR64:$dst, (int_x86_sse_cvttps2pi
388 (load addr:$src)))]>;
389 let Constraints = "$src1 = $dst" in {
390 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
391 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
392 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
393 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
395 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
396 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
397 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
398 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
399 (load addr:$src2)))]>;
402 // Aliases for intrinsics
403 def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
404 "cvttss2si\t{$src, $dst|$dst, $src}",
406 (int_x86_sse_cvttss2si VR128:$src))]>;
407 def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
408 "cvttss2si\t{$src, $dst|$dst, $src}",
410 (int_x86_sse_cvttss2si(load addr:$src)))]>;
412 let Constraints = "$src1 = $dst" in {
413 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
414 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
415 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
416 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
418 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
419 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
420 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
421 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
422 (loadi32 addr:$src2)))]>;
425 // Comparison instructions
426 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
427 def CMPSSrr : SSIi8<0xC2, MRMSrcReg,
428 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
429 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
431 def CMPSSrm : SSIi8<0xC2, MRMSrcMem,
432 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
433 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
436 let Defs = [EFLAGS] in {
437 def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
438 "ucomiss\t{$src2, $src1|$src1, $src2}",
439 [(X86cmp FR32:$src1, FR32:$src2), (implicit EFLAGS)]>;
440 def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
441 "ucomiss\t{$src2, $src1|$src1, $src2}",
442 [(X86cmp FR32:$src1, (loadf32 addr:$src2)),
446 // Aliases to match intrinsics which expect XMM operand(s).
447 let Constraints = "$src1 = $dst" in {
448 def Int_CMPSSrr : SSIi8<0xC2, MRMSrcReg,
449 (outs VR128:$dst), (ins VR128:$src1, VR128:$src,
451 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
452 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
453 VR128:$src, imm:$cc))]>;
454 def Int_CMPSSrm : SSIi8<0xC2, MRMSrcMem,
455 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src,
457 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
458 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
459 (load addr:$src), imm:$cc))]>;
462 let Defs = [EFLAGS] in {
463 def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
464 "ucomiss\t{$src2, $src1|$src1, $src2}",
465 [(X86ucomi (v4f32 VR128:$src1), VR128:$src2),
467 def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
468 "ucomiss\t{$src2, $src1|$src1, $src2}",
469 [(X86ucomi (v4f32 VR128:$src1), (load addr:$src2)),
472 def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
473 "comiss\t{$src2, $src1|$src1, $src2}",
474 [(X86comi (v4f32 VR128:$src1), VR128:$src2),
476 def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
477 "comiss\t{$src2, $src1|$src1, $src2}",
478 [(X86comi (v4f32 VR128:$src1), (load addr:$src2)),
482 // Aliases of packed SSE1 instructions for scalar use. These all have names
483 // that start with 'Fs'.
485 // Alias instructions that map fld0 to pxor for sse.
486 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
488 def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins),
489 "pxor\t$dst, $dst", [(set FR32:$dst, fp32imm0)]>,
490 Requires<[HasSSE1]>, TB, OpSize;
492 // Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
494 let neverHasSideEffects = 1 in
495 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
496 "movaps\t{$src, $dst|$dst, $src}", []>;
498 // Alias instruction to load FR32 from f128mem using movaps. Upper bits are
500 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
501 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
502 "movaps\t{$src, $dst|$dst, $src}",
503 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
505 // Alias bitwise logical operations using SSE logical ops on packed FP values.
506 let Constraints = "$src1 = $dst" in {
507 let isCommutable = 1 in {
508 def FsANDPSrr : PSI<0x54, MRMSrcReg, (outs FR32:$dst),
509 (ins FR32:$src1, FR32:$src2),
510 "andps\t{$src2, $dst|$dst, $src2}",
511 [(set FR32:$dst, (X86fand FR32:$src1, FR32:$src2))]>;
512 def FsORPSrr : PSI<0x56, MRMSrcReg, (outs FR32:$dst),
513 (ins FR32:$src1, FR32:$src2),
514 "orps\t{$src2, $dst|$dst, $src2}",
515 [(set FR32:$dst, (X86for FR32:$src1, FR32:$src2))]>;
516 def FsXORPSrr : PSI<0x57, MRMSrcReg, (outs FR32:$dst),
517 (ins FR32:$src1, FR32:$src2),
518 "xorps\t{$src2, $dst|$dst, $src2}",
519 [(set FR32:$dst, (X86fxor FR32:$src1, FR32:$src2))]>;
522 def FsANDPSrm : PSI<0x54, MRMSrcMem, (outs FR32:$dst),
523 (ins FR32:$src1, f128mem:$src2),
524 "andps\t{$src2, $dst|$dst, $src2}",
525 [(set FR32:$dst, (X86fand FR32:$src1,
526 (memopfsf32 addr:$src2)))]>;
527 def FsORPSrm : PSI<0x56, MRMSrcMem, (outs FR32:$dst),
528 (ins FR32:$src1, f128mem:$src2),
529 "orps\t{$src2, $dst|$dst, $src2}",
530 [(set FR32:$dst, (X86for FR32:$src1,
531 (memopfsf32 addr:$src2)))]>;
532 def FsXORPSrm : PSI<0x57, MRMSrcMem, (outs FR32:$dst),
533 (ins FR32:$src1, f128mem:$src2),
534 "xorps\t{$src2, $dst|$dst, $src2}",
535 [(set FR32:$dst, (X86fxor FR32:$src1,
536 (memopfsf32 addr:$src2)))]>;
538 let neverHasSideEffects = 1 in {
539 def FsANDNPSrr : PSI<0x55, MRMSrcReg,
540 (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
541 "andnps\t{$src2, $dst|$dst, $src2}", []>;
543 def FsANDNPSrm : PSI<0x55, MRMSrcMem,
544 (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
545 "andnps\t{$src2, $dst|$dst, $src2}", []>;
549 /// basic_sse1_fp_binop_rm - SSE1 binops come in both scalar and vector forms.
551 /// In addition, we also have a special variant of the scalar form here to
552 /// represent the associated intrinsic operation. This form is unlike the
553 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
554 /// and leaves the top elements unmodified (therefore these cannot be commuted).
556 /// These three forms can each be reg+reg or reg+mem, so there are a total of
557 /// six "instructions".
559 let Constraints = "$src1 = $dst" in {
560 multiclass basic_sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
561 SDNode OpNode, Intrinsic F32Int,
562 bit Commutable = 0> {
563 // Scalar operation, reg+reg.
564 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
565 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
566 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
567 let isCommutable = Commutable;
570 // Scalar operation, reg+mem.
571 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst),
572 (ins FR32:$src1, f32mem:$src2),
573 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
574 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
576 // Vector operation, reg+reg.
577 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
578 (ins VR128:$src1, VR128:$src2),
579 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
580 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
581 let isCommutable = Commutable;
584 // Vector operation, reg+mem.
585 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
586 (ins VR128:$src1, f128mem:$src2),
587 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
588 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
590 // Intrinsic operation, reg+reg.
591 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
592 (ins VR128:$src1, VR128:$src2),
593 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
594 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]>;
596 // Intrinsic operation, reg+mem.
597 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
598 (ins VR128:$src1, ssmem:$src2),
599 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
600 [(set VR128:$dst, (F32Int VR128:$src1,
601 sse_load_f32:$src2))]>;
605 // Arithmetic instructions
606 defm ADD : basic_sse1_fp_binop_rm<0x58, "add", fadd, int_x86_sse_add_ss, 1>;
607 defm MUL : basic_sse1_fp_binop_rm<0x59, "mul", fmul, int_x86_sse_mul_ss, 1>;
608 defm SUB : basic_sse1_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse_sub_ss>;
609 defm DIV : basic_sse1_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse_div_ss>;
611 /// sse1_fp_binop_rm - Other SSE1 binops
613 /// This multiclass is like basic_sse1_fp_binop_rm, with the addition of
614 /// instructions for a full-vector intrinsic form. Operations that map
615 /// onto C operators don't use this form since they just use the plain
616 /// vector form instead of having a separate vector intrinsic form.
618 /// This provides a total of eight "instructions".
620 let Constraints = "$src1 = $dst" in {
621 multiclass sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
625 bit Commutable = 0> {
627 // Scalar operation, reg+reg.
628 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
629 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
630 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
631 let isCommutable = Commutable;
634 // Scalar operation, reg+mem.
635 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst),
636 (ins FR32:$src1, f32mem:$src2),
637 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
638 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
640 // Vector operation, reg+reg.
641 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
642 (ins VR128:$src1, VR128:$src2),
643 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
644 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
645 let isCommutable = Commutable;
648 // Vector operation, reg+mem.
649 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
650 (ins VR128:$src1, f128mem:$src2),
651 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
652 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
654 // Intrinsic operation, reg+reg.
655 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
656 (ins VR128:$src1, VR128:$src2),
657 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
658 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
659 let isCommutable = Commutable;
662 // Intrinsic operation, reg+mem.
663 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
664 (ins VR128:$src1, ssmem:$src2),
665 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
666 [(set VR128:$dst, (F32Int VR128:$src1,
667 sse_load_f32:$src2))]>;
669 // Vector intrinsic operation, reg+reg.
670 def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst),
671 (ins VR128:$src1, VR128:$src2),
672 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
673 [(set VR128:$dst, (V4F32Int VR128:$src1, VR128:$src2))]> {
674 let isCommutable = Commutable;
677 // Vector intrinsic operation, reg+mem.
678 def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst),
679 (ins VR128:$src1, f128mem:$src2),
680 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
681 [(set VR128:$dst, (V4F32Int VR128:$src1, (memopv4f32 addr:$src2)))]>;
685 defm MAX : sse1_fp_binop_rm<0x5F, "max", X86fmax,
686 int_x86_sse_max_ss, int_x86_sse_max_ps>;
687 defm MIN : sse1_fp_binop_rm<0x5D, "min", X86fmin,
688 int_x86_sse_min_ss, int_x86_sse_min_ps>;
690 //===----------------------------------------------------------------------===//
691 // SSE packed FP Instructions
694 let neverHasSideEffects = 1 in
695 def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
696 "movaps\t{$src, $dst|$dst, $src}", []>;
697 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
698 def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
699 "movaps\t{$src, $dst|$dst, $src}",
700 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
702 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
703 "movaps\t{$src, $dst|$dst, $src}",
704 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
706 let neverHasSideEffects = 1 in
707 def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
708 "movups\t{$src, $dst|$dst, $src}", []>;
709 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
710 def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
711 "movups\t{$src, $dst|$dst, $src}",
712 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
713 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
714 "movups\t{$src, $dst|$dst, $src}",
715 [(store (v4f32 VR128:$src), addr:$dst)]>;
717 // Intrinsic forms of MOVUPS load and store
718 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
719 def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
720 "movups\t{$src, $dst|$dst, $src}",
721 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
722 def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
723 "movups\t{$src, $dst|$dst, $src}",
724 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
726 let Constraints = "$src1 = $dst" in {
727 let AddedComplexity = 20 in {
728 def MOVLPSrm : PSI<0x12, MRMSrcMem,
729 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
730 "movlps\t{$src2, $dst|$dst, $src2}",
733 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
734 def MOVHPSrm : PSI<0x16, MRMSrcMem,
735 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
736 "movhps\t{$src2, $dst|$dst, $src2}",
738 (movlhps VR128:$src1,
739 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
741 } // Constraints = "$src1 = $dst"
744 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
745 "movlps\t{$src, $dst|$dst, $src}",
746 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
747 (iPTR 0))), addr:$dst)]>;
749 // v2f64 extract element 1 is always custom lowered to unpack high to low
750 // and extract element 0 so the non-store version isn't too horrible.
751 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
752 "movhps\t{$src, $dst|$dst, $src}",
753 [(store (f64 (vector_extract
754 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
755 (undef)), (iPTR 0))), addr:$dst)]>;
757 let Constraints = "$src1 = $dst" in {
758 let AddedComplexity = 20 in {
759 def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
760 (ins VR128:$src1, VR128:$src2),
761 "movlhps\t{$src2, $dst|$dst, $src2}",
763 (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
765 def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
766 (ins VR128:$src1, VR128:$src2),
767 "movhlps\t{$src2, $dst|$dst, $src2}",
769 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
771 } // Constraints = "$src1 = $dst"
773 let AddedComplexity = 20 in {
774 def : Pat<(v4f32 (movddup VR128:$src, (undef))),
775 (MOVLHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
776 def : Pat<(v2i64 (movddup VR128:$src, (undef))),
777 (MOVLHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
784 /// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
786 /// In addition, we also have a special variant of the scalar form here to
787 /// represent the associated intrinsic operation. This form is unlike the
788 /// plain scalar form, in that it takes an entire vector (instead of a
789 /// scalar) and leaves the top elements undefined.
791 /// And, we have a special variant form for a full-vector intrinsic form.
793 /// These four forms can each have a reg or a mem operand, so there are a
794 /// total of eight "instructions".
796 multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
800 bit Commutable = 0> {
801 // Scalar operation, reg.
802 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
803 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
804 [(set FR32:$dst, (OpNode FR32:$src))]> {
805 let isCommutable = Commutable;
808 // Scalar operation, mem.
809 def SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
810 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
811 [(set FR32:$dst, (OpNode (load addr:$src)))]>;
813 // Vector operation, reg.
814 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
815 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
816 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
817 let isCommutable = Commutable;
820 // Vector operation, mem.
821 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
822 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
823 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
825 // Intrinsic operation, reg.
826 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
827 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
828 [(set VR128:$dst, (F32Int VR128:$src))]> {
829 let isCommutable = Commutable;
832 // Intrinsic operation, mem.
833 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
834 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
835 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
837 // Vector intrinsic operation, reg
838 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
839 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
840 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
841 let isCommutable = Commutable;
844 // Vector intrinsic operation, mem
845 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
846 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
847 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
851 defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
852 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
854 // Reciprocal approximations. Note that these typically require refinement
855 // in order to obtain suitable precision.
856 defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
857 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
858 defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
859 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
862 let Constraints = "$src1 = $dst" in {
863 let isCommutable = 1 in {
864 def ANDPSrr : PSI<0x54, MRMSrcReg,
865 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
866 "andps\t{$src2, $dst|$dst, $src2}",
867 [(set VR128:$dst, (v2i64
868 (and VR128:$src1, VR128:$src2)))]>;
869 def ORPSrr : PSI<0x56, MRMSrcReg,
870 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
871 "orps\t{$src2, $dst|$dst, $src2}",
872 [(set VR128:$dst, (v2i64
873 (or VR128:$src1, VR128:$src2)))]>;
874 def XORPSrr : PSI<0x57, MRMSrcReg,
875 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
876 "xorps\t{$src2, $dst|$dst, $src2}",
877 [(set VR128:$dst, (v2i64
878 (xor VR128:$src1, VR128:$src2)))]>;
881 def ANDPSrm : PSI<0x54, MRMSrcMem,
882 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
883 "andps\t{$src2, $dst|$dst, $src2}",
884 [(set VR128:$dst, (and (bc_v2i64 (v4f32 VR128:$src1)),
885 (memopv2i64 addr:$src2)))]>;
886 def ORPSrm : PSI<0x56, MRMSrcMem,
887 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
888 "orps\t{$src2, $dst|$dst, $src2}",
889 [(set VR128:$dst, (or (bc_v2i64 (v4f32 VR128:$src1)),
890 (memopv2i64 addr:$src2)))]>;
891 def XORPSrm : PSI<0x57, MRMSrcMem,
892 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
893 "xorps\t{$src2, $dst|$dst, $src2}",
894 [(set VR128:$dst, (xor (bc_v2i64 (v4f32 VR128:$src1)),
895 (memopv2i64 addr:$src2)))]>;
896 def ANDNPSrr : PSI<0x55, MRMSrcReg,
897 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
898 "andnps\t{$src2, $dst|$dst, $src2}",
900 (v2i64 (and (xor VR128:$src1,
901 (bc_v2i64 (v4i32 immAllOnesV))),
903 def ANDNPSrm : PSI<0x55, MRMSrcMem,
904 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
905 "andnps\t{$src2, $dst|$dst, $src2}",
907 (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
908 (bc_v2i64 (v4i32 immAllOnesV))),
909 (memopv2i64 addr:$src2))))]>;
912 let Constraints = "$src1 = $dst" in {
913 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
914 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
915 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
916 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
917 VR128:$src, imm:$cc))]>;
918 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
919 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
920 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
921 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
922 (memop addr:$src), imm:$cc))]>;
924 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
925 (CMPPSrri VR128:$src1, VR128:$src2, imm:$cc)>;
926 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
927 (CMPPSrmi VR128:$src1, addr:$src2, imm:$cc)>;
929 // Shuffle and unpack instructions
930 let Constraints = "$src1 = $dst" in {
931 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
932 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
933 (outs VR128:$dst), (ins VR128:$src1,
934 VR128:$src2, i8imm:$src3),
935 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
937 (v4f32 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
938 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
939 (outs VR128:$dst), (ins VR128:$src1,
940 f128mem:$src2, i8imm:$src3),
941 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
944 VR128:$src1, (memopv4f32 addr:$src2))))]>;
946 let AddedComplexity = 10 in {
947 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
948 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
949 "unpckhps\t{$src2, $dst|$dst, $src2}",
951 (v4f32 (unpckh VR128:$src1, VR128:$src2)))]>;
952 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
953 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
954 "unpckhps\t{$src2, $dst|$dst, $src2}",
956 (v4f32 (unpckh VR128:$src1,
957 (memopv4f32 addr:$src2))))]>;
959 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
960 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
961 "unpcklps\t{$src2, $dst|$dst, $src2}",
963 (v4f32 (unpckl VR128:$src1, VR128:$src2)))]>;
964 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
965 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
966 "unpcklps\t{$src2, $dst|$dst, $src2}",
968 (unpckl VR128:$src1, (memopv4f32 addr:$src2)))]>;
970 } // Constraints = "$src1 = $dst"
973 def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
974 "movmskps\t{$src, $dst|$dst, $src}",
975 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
976 def MOVMSKPDrr : PDI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
977 "movmskpd\t{$src, $dst|$dst, $src}",
978 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
980 // Prefetch intrinsic.
981 def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
982 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
983 def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
984 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
985 def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
986 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
987 def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
988 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
990 // Non-temporal stores
991 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
992 "movntps\t{$src, $dst|$dst, $src}",
993 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
995 // Load, store, and memory fence
996 def SFENCE : PSI<0xAE, MRM7r, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>;
999 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
1000 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
1001 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
1002 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
1004 // Alias instructions that map zero vector to pxor / xorp* for sse.
1005 // We set canFoldAsLoad because this can be converted to a constant-pool
1006 // load of an all-zeros value if folding it would be beneficial.
1007 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
1008 isCodeGenOnly = 1 in
1009 def V_SET0 : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins),
1010 "xorps\t$dst, $dst",
1011 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
1013 let Predicates = [HasSSE1] in {
1014 def : Pat<(v2i64 immAllZerosV), (V_SET0)>;
1015 def : Pat<(v8i16 immAllZerosV), (V_SET0)>;
1016 def : Pat<(v16i8 immAllZerosV), (V_SET0)>;
1017 def : Pat<(v2f64 immAllZerosV), (V_SET0)>;
1018 def : Pat<(v4f32 immAllZerosV), (V_SET0)>;
1021 // FR32 to 128-bit vector conversion.
1022 let isAsCheapAsAMove = 1 in
1023 def MOVSS2PSrr : SSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR32:$src),
1024 "movss\t{$src, $dst|$dst, $src}",
1026 (v4f32 (scalar_to_vector FR32:$src)))]>;
1027 def MOVSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
1028 "movss\t{$src, $dst|$dst, $src}",
1030 (v4f32 (scalar_to_vector (loadf32 addr:$src))))]>;
1032 // FIXME: may not be able to eliminate this movss with coalescing the src and
1033 // dest register classes are different. We really want to write this pattern
1035 // def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
1036 // (f32 FR32:$src)>;
1037 let isAsCheapAsAMove = 1 in
1038 def MOVPS2SSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins VR128:$src),
1039 "movss\t{$src, $dst|$dst, $src}",
1040 [(set FR32:$dst, (vector_extract (v4f32 VR128:$src),
1042 def MOVPS2SSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
1043 "movss\t{$src, $dst|$dst, $src}",
1044 [(store (f32 (vector_extract (v4f32 VR128:$src),
1045 (iPTR 0))), addr:$dst)]>;
1048 // Move to lower bits of a VR128, leaving upper bits alone.
1049 // Three operand (but two address) aliases.
1050 let Constraints = "$src1 = $dst" in {
1051 let neverHasSideEffects = 1 in
1052 def MOVLSS2PSrr : SSI<0x10, MRMSrcReg,
1053 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
1054 "movss\t{$src2, $dst|$dst, $src2}", []>;
1056 let AddedComplexity = 15 in
1057 def MOVLPSrr : SSI<0x10, MRMSrcReg,
1058 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1059 "movss\t{$src2, $dst|$dst, $src2}",
1061 (v4f32 (movl VR128:$src1, VR128:$src2)))]>;
1064 // Move to lower bits of a VR128 and zeroing upper bits.
1065 // Loading from memory automatically zeroing upper bits.
1066 let AddedComplexity = 20 in
1067 def MOVZSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
1068 "movss\t{$src, $dst|$dst, $src}",
1069 [(set VR128:$dst, (v4f32 (X86vzmovl (v4f32 (scalar_to_vector
1070 (loadf32 addr:$src))))))]>;
1072 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
1073 (MOVZSS2PSrm addr:$src)>;
1075 //===---------------------------------------------------------------------===//
1076 // SSE2 Instructions
1077 //===---------------------------------------------------------------------===//
1079 // Move Instructions
1080 let neverHasSideEffects = 1 in
1081 def MOVSDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1082 "movsd\t{$src, $dst|$dst, $src}", []>;
1083 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
1084 def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1085 "movsd\t{$src, $dst|$dst, $src}",
1086 [(set FR64:$dst, (loadf64 addr:$src))]>;
1087 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
1088 "movsd\t{$src, $dst|$dst, $src}",
1089 [(store FR64:$src, addr:$dst)]>;
1091 // Conversion instructions
1092 def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
1093 "cvttsd2si\t{$src, $dst|$dst, $src}",
1094 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
1095 def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
1096 "cvttsd2si\t{$src, $dst|$dst, $src}",
1097 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1098 def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
1099 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1100 [(set FR32:$dst, (fround FR64:$src))]>;
1101 def CVTSD2SSrm : SDI<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
1102 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1103 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>;
1104 def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
1105 "cvtsi2sd\t{$src, $dst|$dst, $src}",
1106 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
1107 def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
1108 "cvtsi2sd\t{$src, $dst|$dst, $src}",
1109 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1111 def CVTPD2DQrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1112 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1113 def CVTPD2DQrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1114 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1115 def CVTDQ2PDrm : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1116 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1117 def CVTDQ2PDrr : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1118 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1119 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1120 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1121 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1122 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1123 def CVTDQ2PSrr : PSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1124 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1125 def CVTDQ2PSrm : PSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1126 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1127 def COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1128 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1129 def COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1130 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1132 // SSE2 instructions with XS prefix
1133 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
1134 "cvtss2sd\t{$src, $dst|$dst, $src}",
1135 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1136 Requires<[HasSSE2]>;
1137 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
1138 "cvtss2sd\t{$src, $dst|$dst, $src}",
1139 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1140 Requires<[HasSSE2]>;
1142 // Match intrinsics which expect XMM operand(s).
1143 def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1144 "cvtsd2si\t{$src, $dst|$dst, $src}",
1145 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
1146 def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
1147 "cvtsd2si\t{$src, $dst|$dst, $src}",
1148 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1149 (load addr:$src)))]>;
1151 // Match intrinisics which expect MM and XMM operand(s).
1152 def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1153 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1154 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1155 def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1156 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1157 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
1158 (memop addr:$src)))]>;
1159 def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1160 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1161 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1162 def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1163 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1164 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
1165 (memop addr:$src)))]>;
1166 def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1167 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1168 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1169 def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1170 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1171 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
1172 (load addr:$src)))]>;
1174 // Aliases for intrinsics
1175 def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1176 "cvttsd2si\t{$src, $dst|$dst, $src}",
1178 (int_x86_sse2_cvttsd2si VR128:$src))]>;
1179 def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
1180 "cvttsd2si\t{$src, $dst|$dst, $src}",
1181 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1182 (load addr:$src)))]>;
1184 // Comparison instructions
1185 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
1186 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
1187 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
1188 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
1190 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
1191 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
1192 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
1195 let Defs = [EFLAGS] in {
1196 def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
1197 "ucomisd\t{$src2, $src1|$src1, $src2}",
1198 [(X86cmp FR64:$src1, FR64:$src2), (implicit EFLAGS)]>;
1199 def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
1200 "ucomisd\t{$src2, $src1|$src1, $src2}",
1201 [(X86cmp FR64:$src1, (loadf64 addr:$src2)),
1202 (implicit EFLAGS)]>;
1203 } // Defs = [EFLAGS]
1205 // Aliases to match intrinsics which expect XMM operand(s).
1206 let Constraints = "$src1 = $dst" in {
1207 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
1208 (outs VR128:$dst), (ins VR128:$src1, VR128:$src,
1210 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
1211 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1212 VR128:$src, imm:$cc))]>;
1213 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
1214 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src,
1216 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
1217 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1218 (load addr:$src), imm:$cc))]>;
1221 let Defs = [EFLAGS] in {
1222 def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1223 "ucomisd\t{$src2, $src1|$src1, $src2}",
1224 [(X86ucomi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1225 (implicit EFLAGS)]>;
1226 def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
1227 "ucomisd\t{$src2, $src1|$src1, $src2}",
1228 [(X86ucomi (v2f64 VR128:$src1), (load addr:$src2)),
1229 (implicit EFLAGS)]>;
1231 def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1232 "comisd\t{$src2, $src1|$src1, $src2}",
1233 [(X86comi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1234 (implicit EFLAGS)]>;
1235 def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1236 "comisd\t{$src2, $src1|$src1, $src2}",
1237 [(X86comi (v2f64 VR128:$src1), (load addr:$src2)),
1238 (implicit EFLAGS)]>;
1239 } // Defs = [EFLAGS]
1241 // Aliases of packed SSE2 instructions for scalar use. These all have names
1242 // that start with 'Fs'.
1244 // Alias instructions that map fld0 to pxor for sse.
1245 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
1246 canFoldAsLoad = 1 in
1247 def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins),
1248 "pxor\t$dst, $dst", [(set FR64:$dst, fpimm0)]>,
1249 Requires<[HasSSE2]>, TB, OpSize;
1251 // Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
1253 let neverHasSideEffects = 1 in
1254 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1255 "movapd\t{$src, $dst|$dst, $src}", []>;
1257 // Alias instruction to load FR64 from f128mem using movapd. Upper bits are
1259 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
1260 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1261 "movapd\t{$src, $dst|$dst, $src}",
1262 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
1264 // Alias bitwise logical operations using SSE logical ops on packed FP values.
1265 let Constraints = "$src1 = $dst" in {
1266 let isCommutable = 1 in {
1267 def FsANDPDrr : PDI<0x54, MRMSrcReg, (outs FR64:$dst),
1268 (ins FR64:$src1, FR64:$src2),
1269 "andpd\t{$src2, $dst|$dst, $src2}",
1270 [(set FR64:$dst, (X86fand FR64:$src1, FR64:$src2))]>;
1271 def FsORPDrr : PDI<0x56, MRMSrcReg, (outs FR64:$dst),
1272 (ins FR64:$src1, FR64:$src2),
1273 "orpd\t{$src2, $dst|$dst, $src2}",
1274 [(set FR64:$dst, (X86for FR64:$src1, FR64:$src2))]>;
1275 def FsXORPDrr : PDI<0x57, MRMSrcReg, (outs FR64:$dst),
1276 (ins FR64:$src1, FR64:$src2),
1277 "xorpd\t{$src2, $dst|$dst, $src2}",
1278 [(set FR64:$dst, (X86fxor FR64:$src1, FR64:$src2))]>;
1281 def FsANDPDrm : PDI<0x54, MRMSrcMem, (outs FR64:$dst),
1282 (ins FR64:$src1, f128mem:$src2),
1283 "andpd\t{$src2, $dst|$dst, $src2}",
1284 [(set FR64:$dst, (X86fand FR64:$src1,
1285 (memopfsf64 addr:$src2)))]>;
1286 def FsORPDrm : PDI<0x56, MRMSrcMem, (outs FR64:$dst),
1287 (ins FR64:$src1, f128mem:$src2),
1288 "orpd\t{$src2, $dst|$dst, $src2}",
1289 [(set FR64:$dst, (X86for FR64:$src1,
1290 (memopfsf64 addr:$src2)))]>;
1291 def FsXORPDrm : PDI<0x57, MRMSrcMem, (outs FR64:$dst),
1292 (ins FR64:$src1, f128mem:$src2),
1293 "xorpd\t{$src2, $dst|$dst, $src2}",
1294 [(set FR64:$dst, (X86fxor FR64:$src1,
1295 (memopfsf64 addr:$src2)))]>;
1297 let neverHasSideEffects = 1 in {
1298 def FsANDNPDrr : PDI<0x55, MRMSrcReg,
1299 (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1300 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
1302 def FsANDNPDrm : PDI<0x55, MRMSrcMem,
1303 (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
1304 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
1308 /// basic_sse2_fp_binop_rm - SSE2 binops come in both scalar and vector forms.
1310 /// In addition, we also have a special variant of the scalar form here to
1311 /// represent the associated intrinsic operation. This form is unlike the
1312 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
1313 /// and leaves the top elements unmodified (therefore these cannot be commuted).
1315 /// These three forms can each be reg+reg or reg+mem, so there are a total of
1316 /// six "instructions".
1318 let Constraints = "$src1 = $dst" in {
1319 multiclass basic_sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1320 SDNode OpNode, Intrinsic F64Int,
1321 bit Commutable = 0> {
1322 // Scalar operation, reg+reg.
1323 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1324 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1325 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1326 let isCommutable = Commutable;
1329 // Scalar operation, reg+mem.
1330 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst),
1331 (ins FR64:$src1, f64mem:$src2),
1332 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1333 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1335 // Vector operation, reg+reg.
1336 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1337 (ins VR128:$src1, VR128:$src2),
1338 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1339 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1340 let isCommutable = Commutable;
1343 // Vector operation, reg+mem.
1344 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1345 (ins VR128:$src1, f128mem:$src2),
1346 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1347 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
1349 // Intrinsic operation, reg+reg.
1350 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst),
1351 (ins VR128:$src1, VR128:$src2),
1352 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1353 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]>;
1355 // Intrinsic operation, reg+mem.
1356 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
1357 (ins VR128:$src1, sdmem:$src2),
1358 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1359 [(set VR128:$dst, (F64Int VR128:$src1,
1360 sse_load_f64:$src2))]>;
1364 // Arithmetic instructions
1365 defm ADD : basic_sse2_fp_binop_rm<0x58, "add", fadd, int_x86_sse2_add_sd, 1>;
1366 defm MUL : basic_sse2_fp_binop_rm<0x59, "mul", fmul, int_x86_sse2_mul_sd, 1>;
1367 defm SUB : basic_sse2_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse2_sub_sd>;
1368 defm DIV : basic_sse2_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse2_div_sd>;
1370 /// sse2_fp_binop_rm - Other SSE2 binops
1372 /// This multiclass is like basic_sse2_fp_binop_rm, with the addition of
1373 /// instructions for a full-vector intrinsic form. Operations that map
1374 /// onto C operators don't use this form since they just use the plain
1375 /// vector form instead of having a separate vector intrinsic form.
1377 /// This provides a total of eight "instructions".
1379 let Constraints = "$src1 = $dst" in {
1380 multiclass sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1384 bit Commutable = 0> {
1386 // Scalar operation, reg+reg.
1387 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1388 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1389 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1390 let isCommutable = Commutable;
1393 // Scalar operation, reg+mem.
1394 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst),
1395 (ins FR64:$src1, f64mem:$src2),
1396 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1397 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1399 // Vector operation, reg+reg.
1400 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1401 (ins VR128:$src1, VR128:$src2),
1402 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1403 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1404 let isCommutable = Commutable;
1407 // Vector operation, reg+mem.
1408 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1409 (ins VR128:$src1, f128mem:$src2),
1410 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1411 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
1413 // Intrinsic operation, reg+reg.
1414 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst),
1415 (ins VR128:$src1, VR128:$src2),
1416 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1417 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1418 let isCommutable = Commutable;
1421 // Intrinsic operation, reg+mem.
1422 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
1423 (ins VR128:$src1, sdmem:$src2),
1424 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1425 [(set VR128:$dst, (F64Int VR128:$src1,
1426 sse_load_f64:$src2))]>;
1428 // Vector intrinsic operation, reg+reg.
1429 def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1430 (ins VR128:$src1, VR128:$src2),
1431 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1432 [(set VR128:$dst, (V2F64Int VR128:$src1, VR128:$src2))]> {
1433 let isCommutable = Commutable;
1436 // Vector intrinsic operation, reg+mem.
1437 def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1438 (ins VR128:$src1, f128mem:$src2),
1439 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1440 [(set VR128:$dst, (V2F64Int VR128:$src1,
1441 (memopv2f64 addr:$src2)))]>;
1445 defm MAX : sse2_fp_binop_rm<0x5F, "max", X86fmax,
1446 int_x86_sse2_max_sd, int_x86_sse2_max_pd>;
1447 defm MIN : sse2_fp_binop_rm<0x5D, "min", X86fmin,
1448 int_x86_sse2_min_sd, int_x86_sse2_min_pd>;
1450 //===---------------------------------------------------------------------===//
1451 // SSE packed FP Instructions
1453 // Move Instructions
1454 let neverHasSideEffects = 1 in
1455 def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1456 "movapd\t{$src, $dst|$dst, $src}", []>;
1457 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
1458 def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1459 "movapd\t{$src, $dst|$dst, $src}",
1460 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
1462 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1463 "movapd\t{$src, $dst|$dst, $src}",
1464 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
1466 let neverHasSideEffects = 1 in
1467 def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1468 "movupd\t{$src, $dst|$dst, $src}", []>;
1469 let canFoldAsLoad = 1 in
1470 def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1471 "movupd\t{$src, $dst|$dst, $src}",
1472 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
1473 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1474 "movupd\t{$src, $dst|$dst, $src}",
1475 [(store (v2f64 VR128:$src), addr:$dst)]>;
1477 // Intrinsic forms of MOVUPD load and store
1478 def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1479 "movupd\t{$src, $dst|$dst, $src}",
1480 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
1481 def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1482 "movupd\t{$src, $dst|$dst, $src}",
1483 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
1485 let Constraints = "$src1 = $dst" in {
1486 let AddedComplexity = 20 in {
1487 def MOVLPDrm : PDI<0x12, MRMSrcMem,
1488 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1489 "movlpd\t{$src2, $dst|$dst, $src2}",
1491 (v2f64 (movlp VR128:$src1,
1492 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1493 def MOVHPDrm : PDI<0x16, MRMSrcMem,
1494 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1495 "movhpd\t{$src2, $dst|$dst, $src2}",
1497 (v2f64 (movlhps VR128:$src1,
1498 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1499 } // AddedComplexity
1500 } // Constraints = "$src1 = $dst"
1502 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1503 "movlpd\t{$src, $dst|$dst, $src}",
1504 [(store (f64 (vector_extract (v2f64 VR128:$src),
1505 (iPTR 0))), addr:$dst)]>;
1507 // v2f64 extract element 1 is always custom lowered to unpack high to low
1508 // and extract element 0 so the non-store version isn't too horrible.
1509 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1510 "movhpd\t{$src, $dst|$dst, $src}",
1511 [(store (f64 (vector_extract
1512 (v2f64 (unpckh VR128:$src, (undef))),
1513 (iPTR 0))), addr:$dst)]>;
1515 // SSE2 instructions without OpSize prefix
1516 def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1517 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1518 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1519 TB, Requires<[HasSSE2]>;
1520 def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1521 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1522 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1523 (bitconvert (memopv2i64 addr:$src))))]>,
1524 TB, Requires<[HasSSE2]>;
1526 // SSE2 instructions with XS prefix
1527 def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1528 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1529 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1530 XS, Requires<[HasSSE2]>;
1531 def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1532 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1533 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1534 (bitconvert (memopv2i64 addr:$src))))]>,
1535 XS, Requires<[HasSSE2]>;
1537 def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1538 "cvtps2dq\t{$src, $dst|$dst, $src}",
1539 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
1540 def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1541 "cvtps2dq\t{$src, $dst|$dst, $src}",
1542 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1543 (memop addr:$src)))]>;
1544 // SSE2 packed instructions with XS prefix
1545 def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1546 "cvttps2dq\t{$src, $dst|$dst, $src}",
1547 [(set VR128:$dst, (int_x86_sse2_cvttps2dq VR128:$src))]>,
1548 XS, Requires<[HasSSE2]>;
1549 def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1550 "cvttps2dq\t{$src, $dst|$dst, $src}",
1551 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1552 (memop addr:$src)))]>,
1553 XS, Requires<[HasSSE2]>;
1555 // SSE2 packed instructions with XD prefix
1556 def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1557 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1558 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1559 XD, Requires<[HasSSE2]>;
1560 def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1561 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1562 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1563 (memop addr:$src)))]>,
1564 XD, Requires<[HasSSE2]>;
1566 def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1567 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1568 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
1569 def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
1570 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1571 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1572 (memop addr:$src)))]>;
1574 // SSE2 instructions without OpSize prefix
1575 def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1576 "cvtps2pd\t{$src, $dst|$dst, $src}",
1577 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1578 TB, Requires<[HasSSE2]>;
1579 def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1580 "cvtps2pd\t{$src, $dst|$dst, $src}",
1581 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1582 (load addr:$src)))]>,
1583 TB, Requires<[HasSSE2]>;
1585 def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1586 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1587 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
1588 def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1589 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1590 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1591 (memop addr:$src)))]>;
1593 // Match intrinsics which expect XMM operand(s).
1594 // Aliases for intrinsics
1595 let Constraints = "$src1 = $dst" in {
1596 def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
1597 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
1598 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1599 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1601 def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
1602 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
1603 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1604 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1605 (loadi32 addr:$src2)))]>;
1606 def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
1607 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1608 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1609 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1611 def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
1612 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1613 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1614 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1615 (load addr:$src2)))]>;
1616 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
1617 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1618 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1619 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1620 VR128:$src2))]>, XS,
1621 Requires<[HasSSE2]>;
1622 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
1623 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
1624 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1625 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1626 (load addr:$src2)))]>, XS,
1627 Requires<[HasSSE2]>;
1632 /// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1634 /// In addition, we also have a special variant of the scalar form here to
1635 /// represent the associated intrinsic operation. This form is unlike the
1636 /// plain scalar form, in that it takes an entire vector (instead of a
1637 /// scalar) and leaves the top elements undefined.
1639 /// And, we have a special variant form for a full-vector intrinsic form.
1641 /// These four forms can each have a reg or a mem operand, so there are a
1642 /// total of eight "instructions".
1644 multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1648 bit Commutable = 0> {
1649 // Scalar operation, reg.
1650 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1651 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1652 [(set FR64:$dst, (OpNode FR64:$src))]> {
1653 let isCommutable = Commutable;
1656 // Scalar operation, mem.
1657 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1658 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1659 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1661 // Vector operation, reg.
1662 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1663 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1664 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1665 let isCommutable = Commutable;
1668 // Vector operation, mem.
1669 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1670 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1671 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
1673 // Intrinsic operation, reg.
1674 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1675 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1676 [(set VR128:$dst, (F64Int VR128:$src))]> {
1677 let isCommutable = Commutable;
1680 // Intrinsic operation, mem.
1681 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1682 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1683 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1685 // Vector intrinsic operation, reg
1686 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1687 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1688 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1689 let isCommutable = Commutable;
1692 // Vector intrinsic operation, mem
1693 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1694 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1695 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
1699 defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1700 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1702 // There is no f64 version of the reciprocal approximation instructions.
1705 let Constraints = "$src1 = $dst" in {
1706 let isCommutable = 1 in {
1707 def ANDPDrr : PDI<0x54, MRMSrcReg,
1708 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1709 "andpd\t{$src2, $dst|$dst, $src2}",
1711 (and (bc_v2i64 (v2f64 VR128:$src1)),
1712 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1713 def ORPDrr : PDI<0x56, MRMSrcReg,
1714 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1715 "orpd\t{$src2, $dst|$dst, $src2}",
1717 (or (bc_v2i64 (v2f64 VR128:$src1)),
1718 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1719 def XORPDrr : PDI<0x57, MRMSrcReg,
1720 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1721 "xorpd\t{$src2, $dst|$dst, $src2}",
1723 (xor (bc_v2i64 (v2f64 VR128:$src1)),
1724 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1727 def ANDPDrm : PDI<0x54, MRMSrcMem,
1728 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1729 "andpd\t{$src2, $dst|$dst, $src2}",
1731 (and (bc_v2i64 (v2f64 VR128:$src1)),
1732 (memopv2i64 addr:$src2)))]>;
1733 def ORPDrm : PDI<0x56, MRMSrcMem,
1734 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1735 "orpd\t{$src2, $dst|$dst, $src2}",
1737 (or (bc_v2i64 (v2f64 VR128:$src1)),
1738 (memopv2i64 addr:$src2)))]>;
1739 def XORPDrm : PDI<0x57, MRMSrcMem,
1740 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1741 "xorpd\t{$src2, $dst|$dst, $src2}",
1743 (xor (bc_v2i64 (v2f64 VR128:$src1)),
1744 (memopv2i64 addr:$src2)))]>;
1745 def ANDNPDrr : PDI<0x55, MRMSrcReg,
1746 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1747 "andnpd\t{$src2, $dst|$dst, $src2}",
1749 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1750 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1751 def ANDNPDrm : PDI<0x55, MRMSrcMem,
1752 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
1753 "andnpd\t{$src2, $dst|$dst, $src2}",
1755 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1756 (memopv2i64 addr:$src2)))]>;
1759 let Constraints = "$src1 = $dst" in {
1760 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
1761 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1762 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1763 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1764 VR128:$src, imm:$cc))]>;
1765 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
1766 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1767 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1768 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1769 (memop addr:$src), imm:$cc))]>;
1771 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
1772 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
1773 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
1774 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
1776 // Shuffle and unpack instructions
1777 let Constraints = "$src1 = $dst" in {
1778 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
1779 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1780 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1782 (v2f64 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
1783 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
1784 (outs VR128:$dst), (ins VR128:$src1,
1785 f128mem:$src2, i8imm:$src3),
1786 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1789 VR128:$src1, (memopv2f64 addr:$src2))))]>;
1791 let AddedComplexity = 10 in {
1792 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
1793 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1794 "unpckhpd\t{$src2, $dst|$dst, $src2}",
1796 (v2f64 (unpckh VR128:$src1, VR128:$src2)))]>;
1797 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
1798 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1799 "unpckhpd\t{$src2, $dst|$dst, $src2}",
1801 (v2f64 (unpckh VR128:$src1,
1802 (memopv2f64 addr:$src2))))]>;
1804 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
1805 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1806 "unpcklpd\t{$src2, $dst|$dst, $src2}",
1808 (v2f64 (unpckl VR128:$src1, VR128:$src2)))]>;
1809 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
1810 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1811 "unpcklpd\t{$src2, $dst|$dst, $src2}",
1813 (unpckl VR128:$src1, (memopv2f64 addr:$src2)))]>;
1814 } // AddedComplexity
1815 } // Constraints = "$src1 = $dst"
1818 //===---------------------------------------------------------------------===//
1819 // SSE integer instructions
1821 // Move Instructions
1822 let neverHasSideEffects = 1 in
1823 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1824 "movdqa\t{$src, $dst|$dst, $src}", []>;
1825 let canFoldAsLoad = 1, mayLoad = 1 in
1826 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1827 "movdqa\t{$src, $dst|$dst, $src}",
1828 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
1830 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1831 "movdqa\t{$src, $dst|$dst, $src}",
1832 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
1833 let canFoldAsLoad = 1, mayLoad = 1 in
1834 def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1835 "movdqu\t{$src, $dst|$dst, $src}",
1836 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
1837 XS, Requires<[HasSSE2]>;
1839 def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1840 "movdqu\t{$src, $dst|$dst, $src}",
1841 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
1842 XS, Requires<[HasSSE2]>;
1844 // Intrinsic forms of MOVDQU load and store
1845 let canFoldAsLoad = 1 in
1846 def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1847 "movdqu\t{$src, $dst|$dst, $src}",
1848 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1849 XS, Requires<[HasSSE2]>;
1850 def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1851 "movdqu\t{$src, $dst|$dst, $src}",
1852 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1853 XS, Requires<[HasSSE2]>;
1855 let Constraints = "$src1 = $dst" in {
1857 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1858 bit Commutable = 0> {
1859 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1860 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1861 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1862 let isCommutable = Commutable;
1864 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1865 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1866 [(set VR128:$dst, (IntId VR128:$src1,
1867 (bitconvert (memopv2i64 addr:$src2))))]>;
1870 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1872 Intrinsic IntId, Intrinsic IntId2> {
1873 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1,
1875 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1876 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
1877 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1,
1879 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1880 [(set VR128:$dst, (IntId VR128:$src1,
1881 (bitconvert (memopv2i64 addr:$src2))))]>;
1882 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst), (ins VR128:$src1,
1884 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1885 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1888 /// PDI_binop_rm - Simple SSE2 binary operator.
1889 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1890 ValueType OpVT, bit Commutable = 0> {
1891 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1,
1893 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1894 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1895 let isCommutable = Commutable;
1897 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1,
1899 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1900 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
1901 (bitconvert (memopv2i64 addr:$src2)))))]>;
1904 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1906 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1907 /// to collapse (bitconvert VT to VT) into its operand.
1909 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1910 bit Commutable = 0> {
1911 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1912 (ins VR128:$src1, VR128:$src2),
1913 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1914 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1915 let isCommutable = Commutable;
1917 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1918 (ins VR128:$src1, i128mem:$src2),
1919 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1920 [(set VR128:$dst, (OpNode VR128:$src1,
1921 (memopv2i64 addr:$src2)))]>;
1924 } // Constraints = "$src1 = $dst"
1926 // 128-bit Integer Arithmetic
1928 defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1929 defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1930 defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1931 defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1933 defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1934 defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1935 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1936 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1938 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1939 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1940 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1941 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1943 defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1944 defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1945 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1946 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1948 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1950 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1951 defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1952 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1954 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1956 defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1957 defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1960 defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1961 defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1962 defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1963 defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
1964 defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
1967 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
1968 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
1969 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
1970 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
1971 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
1972 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
1974 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
1975 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
1976 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
1977 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
1978 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
1979 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
1981 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
1982 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
1983 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
1984 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
1986 // 128-bit logical shifts.
1987 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
1988 def PSLLDQri : PDIi8<0x73, MRM7r,
1989 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
1990 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
1991 def PSRLDQri : PDIi8<0x73, MRM3r,
1992 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
1993 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
1994 // PSRADQri doesn't exist in SSE[1-3].
1997 let Predicates = [HasSSE2] in {
1998 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
1999 (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2000 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2001 (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2002 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2003 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2004 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2005 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
2006 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2007 (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2009 // Shift up / down and insert zero's.
2010 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
2011 (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2012 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
2013 (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2017 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2018 defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
2019 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2021 let Constraints = "$src1 = $dst" in {
2022 def PANDNrr : PDI<0xDF, MRMSrcReg,
2023 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2024 "pandn\t{$src2, $dst|$dst, $src2}",
2025 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2028 def PANDNrm : PDI<0xDF, MRMSrcMem,
2029 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2030 "pandn\t{$src2, $dst|$dst, $src2}",
2031 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2032 (memopv2i64 addr:$src2))))]>;
2035 // SSE2 Integer comparison
2036 defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2037 defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2038 defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2039 defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2040 defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2041 defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2043 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
2044 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
2045 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
2046 (PCMPEQBrm VR128:$src1, addr:$src2)>;
2047 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
2048 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
2049 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
2050 (PCMPEQWrm VR128:$src1, addr:$src2)>;
2051 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
2052 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
2053 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
2054 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2056 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
2057 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
2058 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
2059 (PCMPGTBrm VR128:$src1, addr:$src2)>;
2060 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
2061 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
2062 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
2063 (PCMPGTWrm VR128:$src1, addr:$src2)>;
2064 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
2065 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
2066 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
2067 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2070 // Pack instructions
2071 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2072 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2073 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2075 // Shuffle and unpack instructions
2076 let AddedComplexity = 5 in {
2077 def PSHUFDri : PDIi8<0x70, MRMSrcReg,
2078 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2079 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2080 [(set VR128:$dst, (v4i32 (pshufd:$src2
2081 VR128:$src1, (undef))))]>;
2082 def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
2083 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2084 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2085 [(set VR128:$dst, (v4i32 (pshufd:$src2
2086 (bc_v4i32 (memopv2i64 addr:$src1)),
2090 // SSE2 with ImmT == Imm8 and XS prefix.
2091 def PSHUFHWri : Ii8<0x70, MRMSrcReg,
2092 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2093 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2094 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2096 XS, Requires<[HasSSE2]>;
2097 def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
2098 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2099 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2100 [(set VR128:$dst, (v8i16 (pshufhw:$src2
2101 (bc_v8i16 (memopv2i64 addr:$src1)),
2103 XS, Requires<[HasSSE2]>;
2105 // SSE2 with ImmT == Imm8 and XD prefix.
2106 def PSHUFLWri : Ii8<0x70, MRMSrcReg,
2107 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2108 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2109 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2111 XD, Requires<[HasSSE2]>;
2112 def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
2113 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2114 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2115 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2116 (bc_v8i16 (memopv2i64 addr:$src1)),
2118 XD, Requires<[HasSSE2]>;
2121 let Constraints = "$src1 = $dst" in {
2122 def PUNPCKLBWrr : PDI<0x60, MRMSrcReg,
2123 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2124 "punpcklbw\t{$src2, $dst|$dst, $src2}",
2126 (v16i8 (unpckl VR128:$src1, VR128:$src2)))]>;
2127 def PUNPCKLBWrm : PDI<0x60, MRMSrcMem,
2128 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2129 "punpcklbw\t{$src2, $dst|$dst, $src2}",
2131 (unpckl VR128:$src1,
2132 (bc_v16i8 (memopv2i64 addr:$src2))))]>;
2133 def PUNPCKLWDrr : PDI<0x61, MRMSrcReg,
2134 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2135 "punpcklwd\t{$src2, $dst|$dst, $src2}",
2137 (v8i16 (unpckl VR128:$src1, VR128:$src2)))]>;
2138 def PUNPCKLWDrm : PDI<0x61, MRMSrcMem,
2139 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2140 "punpcklwd\t{$src2, $dst|$dst, $src2}",
2142 (unpckl VR128:$src1,
2143 (bc_v8i16 (memopv2i64 addr:$src2))))]>;
2144 def PUNPCKLDQrr : PDI<0x62, MRMSrcReg,
2145 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2146 "punpckldq\t{$src2, $dst|$dst, $src2}",
2148 (v4i32 (unpckl VR128:$src1, VR128:$src2)))]>;
2149 def PUNPCKLDQrm : PDI<0x62, MRMSrcMem,
2150 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2151 "punpckldq\t{$src2, $dst|$dst, $src2}",
2153 (unpckl VR128:$src1,
2154 (bc_v4i32 (memopv2i64 addr:$src2))))]>;
2155 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2156 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2157 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2159 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
2160 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2161 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2162 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2164 (v2i64 (unpckl VR128:$src1,
2165 (memopv2i64 addr:$src2))))]>;
2167 def PUNPCKHBWrr : PDI<0x68, MRMSrcReg,
2168 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2169 "punpckhbw\t{$src2, $dst|$dst, $src2}",
2171 (v16i8 (unpckh VR128:$src1, VR128:$src2)))]>;
2172 def PUNPCKHBWrm : PDI<0x68, MRMSrcMem,
2173 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2174 "punpckhbw\t{$src2, $dst|$dst, $src2}",
2176 (unpckh VR128:$src1,
2177 (bc_v16i8 (memopv2i64 addr:$src2))))]>;
2178 def PUNPCKHWDrr : PDI<0x69, MRMSrcReg,
2179 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2180 "punpckhwd\t{$src2, $dst|$dst, $src2}",
2182 (v8i16 (unpckh VR128:$src1, VR128:$src2)))]>;
2183 def PUNPCKHWDrm : PDI<0x69, MRMSrcMem,
2184 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2185 "punpckhwd\t{$src2, $dst|$dst, $src2}",
2187 (unpckh VR128:$src1,
2188 (bc_v8i16 (memopv2i64 addr:$src2))))]>;
2189 def PUNPCKHDQrr : PDI<0x6A, MRMSrcReg,
2190 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2191 "punpckhdq\t{$src2, $dst|$dst, $src2}",
2193 (v4i32 (unpckh VR128:$src1, VR128:$src2)))]>;
2194 def PUNPCKHDQrm : PDI<0x6A, MRMSrcMem,
2195 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2196 "punpckhdq\t{$src2, $dst|$dst, $src2}",
2198 (unpckh VR128:$src1,
2199 (bc_v4i32 (memopv2i64 addr:$src2))))]>;
2200 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2201 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2202 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2204 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
2205 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2206 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2207 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2209 (v2i64 (unpckh VR128:$src1,
2210 (memopv2i64 addr:$src2))))]>;
2214 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
2215 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2216 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2217 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2219 let Constraints = "$src1 = $dst" in {
2220 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
2221 (outs VR128:$dst), (ins VR128:$src1,
2222 GR32:$src2, i32i8imm:$src3),
2223 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2225 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
2226 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
2227 (outs VR128:$dst), (ins VR128:$src1,
2228 i16mem:$src2, i32i8imm:$src3),
2229 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2231 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2236 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2237 "pmovmskb\t{$src, $dst|$dst, $src}",
2238 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2240 // Conditional store
2242 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2243 "maskmovdqu\t{$mask, $src|$src, $mask}",
2244 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
2247 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2248 "maskmovdqu\t{$mask, $src|$src, $mask}",
2249 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2251 // Non-temporal stores
2252 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2253 "movntpd\t{$src, $dst|$dst, $src}",
2254 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
2255 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2256 "movntdq\t{$src, $dst|$dst, $src}",
2257 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2258 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2259 "movnti\t{$src, $dst|$dst, $src}",
2260 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2261 TB, Requires<[HasSSE2]>;
2264 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
2265 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
2266 TB, Requires<[HasSSE2]>;
2268 // Load, store, and memory fence
2269 def LFENCE : I<0xAE, MRM5r, (outs), (ins),
2270 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
2271 def MFENCE : I<0xAE, MRM6r, (outs), (ins),
2272 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2274 //TODO: custom lower this so as to never even generate the noop
2275 def : Pat<(membarrier (i8 imm:$ll), (i8 imm:$ls), (i8 imm:$sl), (i8 imm:$ss),
2277 def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2278 def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
2279 def : Pat<(membarrier (i8 imm:$ll), (i8 imm:$ls), (i8 imm:$sl), (i8 imm:$ss),
2282 // Alias instructions that map zero vector to pxor / xorp* for sse.
2283 // We set canFoldAsLoad because this can be converted to a constant-pool
2284 // load of an all-ones value if folding it would be beneficial.
2285 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
2286 isCodeGenOnly = 1 in
2287 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins),
2288 "pcmpeqd\t$dst, $dst",
2289 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
2291 // FR64 to 128-bit vector conversion.
2292 let isAsCheapAsAMove = 1 in
2293 def MOVSD2PDrr : SDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR64:$src),
2294 "movsd\t{$src, $dst|$dst, $src}",
2296 (v2f64 (scalar_to_vector FR64:$src)))]>;
2297 def MOVSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2298 "movsd\t{$src, $dst|$dst, $src}",
2300 (v2f64 (scalar_to_vector (loadf64 addr:$src))))]>;
2302 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2303 "movd\t{$src, $dst|$dst, $src}",
2305 (v4i32 (scalar_to_vector GR32:$src)))]>;
2306 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2307 "movd\t{$src, $dst|$dst, $src}",
2309 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2311 def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2312 "movd\t{$src, $dst|$dst, $src}",
2313 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2315 def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2316 "movd\t{$src, $dst|$dst, $src}",
2317 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2319 // SSE2 instructions with XS prefix
2320 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2321 "movq\t{$src, $dst|$dst, $src}",
2323 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2324 Requires<[HasSSE2]>;
2325 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2326 "movq\t{$src, $dst|$dst, $src}",
2327 [(store (i64 (vector_extract (v2i64 VR128:$src),
2328 (iPTR 0))), addr:$dst)]>;
2330 // FIXME: may not be able to eliminate this movss with coalescing the src and
2331 // dest register classes are different. We really want to write this pattern
2333 // def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2334 // (f32 FR32:$src)>;
2335 let isAsCheapAsAMove = 1 in
2336 def MOVPD2SDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins VR128:$src),
2337 "movsd\t{$src, $dst|$dst, $src}",
2338 [(set FR64:$dst, (vector_extract (v2f64 VR128:$src),
2340 def MOVPD2SDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
2341 "movsd\t{$src, $dst|$dst, $src}",
2342 [(store (f64 (vector_extract (v2f64 VR128:$src),
2343 (iPTR 0))), addr:$dst)]>;
2344 def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2345 "movd\t{$src, $dst|$dst, $src}",
2346 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2348 def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
2349 "movd\t{$src, $dst|$dst, $src}",
2350 [(store (i32 (vector_extract (v4i32 VR128:$src),
2351 (iPTR 0))), addr:$dst)]>;
2353 def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2354 "movd\t{$src, $dst|$dst, $src}",
2355 [(set GR32:$dst, (bitconvert FR32:$src))]>;
2356 def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2357 "movd\t{$src, $dst|$dst, $src}",
2358 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2361 // Move to lower bits of a VR128, leaving upper bits alone.
2362 // Three operand (but two address) aliases.
2363 let Constraints = "$src1 = $dst" in {
2364 let neverHasSideEffects = 1 in
2365 def MOVLSD2PDrr : SDI<0x10, MRMSrcReg,
2366 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
2367 "movsd\t{$src2, $dst|$dst, $src2}", []>;
2369 let AddedComplexity = 15 in
2370 def MOVLPDrr : SDI<0x10, MRMSrcReg,
2371 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2372 "movsd\t{$src2, $dst|$dst, $src2}",
2374 (v2f64 (movl VR128:$src1, VR128:$src2)))]>;
2377 // Store / copy lower 64-bits of a XMM register.
2378 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2379 "movq\t{$src, $dst|$dst, $src}",
2380 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2382 // Move to lower bits of a VR128 and zeroing upper bits.
2383 // Loading from memory automatically zeroing upper bits.
2384 let AddedComplexity = 20 in {
2385 def MOVZSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2386 "movsd\t{$src, $dst|$dst, $src}",
2388 (v2f64 (X86vzmovl (v2f64 (scalar_to_vector
2389 (loadf64 addr:$src))))))]>;
2391 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
2392 (MOVZSD2PDrm addr:$src)>;
2393 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
2394 (MOVZSD2PDrm addr:$src)>;
2395 def : Pat<(v2f64 (X86vzload addr:$src)), (MOVZSD2PDrm addr:$src)>;
2398 // movd / movq to XMM register zero-extends
2399 let AddedComplexity = 15 in {
2400 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2401 "movd\t{$src, $dst|$dst, $src}",
2402 [(set VR128:$dst, (v4i32 (X86vzmovl
2403 (v4i32 (scalar_to_vector GR32:$src)))))]>;
2404 // This is X86-64 only.
2405 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2406 "mov{d|q}\t{$src, $dst|$dst, $src}",
2407 [(set VR128:$dst, (v2i64 (X86vzmovl
2408 (v2i64 (scalar_to_vector GR64:$src)))))]>;
2411 let AddedComplexity = 20 in {
2412 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2413 "movd\t{$src, $dst|$dst, $src}",
2415 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2416 (loadi32 addr:$src))))))]>;
2418 def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2419 (MOVZDI2PDIrm addr:$src)>;
2420 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2421 (MOVZDI2PDIrm addr:$src)>;
2422 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2423 (MOVZDI2PDIrm addr:$src)>;
2425 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2426 "movq\t{$src, $dst|$dst, $src}",
2428 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2429 (loadi64 addr:$src))))))]>, XS,
2430 Requires<[HasSSE2]>;
2432 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2433 (MOVZQI2PQIrm addr:$src)>;
2434 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2435 (MOVZQI2PQIrm addr:$src)>;
2436 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
2439 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2440 // IA32 document. movq xmm1, xmm2 does clear the high bits.
2441 let AddedComplexity = 15 in
2442 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2443 "movq\t{$src, $dst|$dst, $src}",
2444 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2445 XS, Requires<[HasSSE2]>;
2447 let AddedComplexity = 20 in {
2448 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2449 "movq\t{$src, $dst|$dst, $src}",
2450 [(set VR128:$dst, (v2i64 (X86vzmovl
2451 (loadv2i64 addr:$src))))]>,
2452 XS, Requires<[HasSSE2]>;
2454 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2455 (MOVZPQILo2PQIrm addr:$src)>;
2458 //===---------------------------------------------------------------------===//
2459 // SSE3 Instructions
2460 //===---------------------------------------------------------------------===//
2462 // Move Instructions
2463 def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2464 "movshdup\t{$src, $dst|$dst, $src}",
2465 [(set VR128:$dst, (v4f32 (movshdup
2466 VR128:$src, (undef))))]>;
2467 def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2468 "movshdup\t{$src, $dst|$dst, $src}",
2469 [(set VR128:$dst, (movshdup
2470 (memopv4f32 addr:$src), (undef)))]>;
2472 def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2473 "movsldup\t{$src, $dst|$dst, $src}",
2474 [(set VR128:$dst, (v4f32 (movsldup
2475 VR128:$src, (undef))))]>;
2476 def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2477 "movsldup\t{$src, $dst|$dst, $src}",
2478 [(set VR128:$dst, (movsldup
2479 (memopv4f32 addr:$src), (undef)))]>;
2481 def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2482 "movddup\t{$src, $dst|$dst, $src}",
2483 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
2484 def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2485 "movddup\t{$src, $dst|$dst, $src}",
2487 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2490 def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2492 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2494 let AddedComplexity = 5 in {
2495 def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
2496 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2497 def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2498 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2499 def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2500 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2501 def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2502 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2506 let Constraints = "$src1 = $dst" in {
2507 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
2508 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2509 "addsubps\t{$src2, $dst|$dst, $src2}",
2510 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2512 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
2513 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2514 "addsubps\t{$src2, $dst|$dst, $src2}",
2515 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2516 (memop addr:$src2)))]>;
2517 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
2518 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2519 "addsubpd\t{$src2, $dst|$dst, $src2}",
2520 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2522 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
2523 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2524 "addsubpd\t{$src2, $dst|$dst, $src2}",
2525 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2526 (memop addr:$src2)))]>;
2529 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2530 "lddqu\t{$src, $dst|$dst, $src}",
2531 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2534 class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2535 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2536 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2537 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2538 class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2539 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2540 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2541 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
2542 class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2543 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2544 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2545 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2546 class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2547 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2548 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2549 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
2551 let Constraints = "$src1 = $dst" in {
2552 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2553 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2554 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2555 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2556 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2557 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2558 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2559 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2562 // Thread synchronization
2563 def MONITOR : I<0x01, MRM1r, (outs), (ins), "monitor",
2564 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
2565 def MWAIT : I<0x01, MRM1r, (outs), (ins), "mwait",
2566 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2568 // vector_shuffle v1, <undef> <1, 1, 3, 3>
2569 let AddedComplexity = 15 in
2570 def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
2571 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2572 let AddedComplexity = 20 in
2573 def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2574 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2576 // vector_shuffle v1, <undef> <0, 0, 2, 2>
2577 let AddedComplexity = 15 in
2578 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
2579 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2580 let AddedComplexity = 20 in
2581 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2582 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2584 //===---------------------------------------------------------------------===//
2585 // SSSE3 Instructions
2586 //===---------------------------------------------------------------------===//
2588 /// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
2589 multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2590 Intrinsic IntId64, Intrinsic IntId128> {
2591 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2592 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2593 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2595 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2596 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2598 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2600 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2602 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2603 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2606 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2608 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2611 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
2614 /// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
2615 multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2616 Intrinsic IntId64, Intrinsic IntId128> {
2617 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2619 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2620 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2622 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2624 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2627 (bitconvert (memopv4i16 addr:$src))))]>;
2629 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2631 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2632 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2635 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2637 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2640 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
2643 /// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
2644 multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2645 Intrinsic IntId64, Intrinsic IntId128> {
2646 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2648 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2649 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2651 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2653 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2656 (bitconvert (memopv2i32 addr:$src))))]>;
2658 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2660 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2661 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2664 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2666 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2669 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
2672 defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2673 int_x86_ssse3_pabs_b,
2674 int_x86_ssse3_pabs_b_128>;
2675 defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2676 int_x86_ssse3_pabs_w,
2677 int_x86_ssse3_pabs_w_128>;
2678 defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2679 int_x86_ssse3_pabs_d,
2680 int_x86_ssse3_pabs_d_128>;
2682 /// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
2683 let Constraints = "$src1 = $dst" in {
2684 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2685 Intrinsic IntId64, Intrinsic IntId128,
2686 bit Commutable = 0> {
2687 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2688 (ins VR64:$src1, VR64:$src2),
2689 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2690 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2691 let isCommutable = Commutable;
2693 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2694 (ins VR64:$src1, i64mem:$src2),
2695 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2697 (IntId64 VR64:$src1,
2698 (bitconvert (memopv8i8 addr:$src2))))]>;
2700 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2701 (ins VR128:$src1, VR128:$src2),
2702 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2703 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2705 let isCommutable = Commutable;
2707 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2708 (ins VR128:$src1, i128mem:$src2),
2709 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2711 (IntId128 VR128:$src1,
2712 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2716 /// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
2717 let Constraints = "$src1 = $dst" in {
2718 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2719 Intrinsic IntId64, Intrinsic IntId128,
2720 bit Commutable = 0> {
2721 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2722 (ins VR64:$src1, VR64:$src2),
2723 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2724 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2725 let isCommutable = Commutable;
2727 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2728 (ins VR64:$src1, i64mem:$src2),
2729 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2731 (IntId64 VR64:$src1,
2732 (bitconvert (memopv4i16 addr:$src2))))]>;
2734 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2735 (ins VR128:$src1, VR128:$src2),
2736 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2737 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2739 let isCommutable = Commutable;
2741 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2742 (ins VR128:$src1, i128mem:$src2),
2743 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2745 (IntId128 VR128:$src1,
2746 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2750 /// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
2751 let Constraints = "$src1 = $dst" in {
2752 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2753 Intrinsic IntId64, Intrinsic IntId128,
2754 bit Commutable = 0> {
2755 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2756 (ins VR64:$src1, VR64:$src2),
2757 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2758 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2759 let isCommutable = Commutable;
2761 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2762 (ins VR64:$src1, i64mem:$src2),
2763 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2765 (IntId64 VR64:$src1,
2766 (bitconvert (memopv2i32 addr:$src2))))]>;
2768 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2769 (ins VR128:$src1, VR128:$src2),
2770 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2771 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2773 let isCommutable = Commutable;
2775 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2776 (ins VR128:$src1, i128mem:$src2),
2777 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2779 (IntId128 VR128:$src1,
2780 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2784 defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2785 int_x86_ssse3_phadd_w,
2786 int_x86_ssse3_phadd_w_128>;
2787 defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2788 int_x86_ssse3_phadd_d,
2789 int_x86_ssse3_phadd_d_128>;
2790 defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2791 int_x86_ssse3_phadd_sw,
2792 int_x86_ssse3_phadd_sw_128>;
2793 defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2794 int_x86_ssse3_phsub_w,
2795 int_x86_ssse3_phsub_w_128>;
2796 defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2797 int_x86_ssse3_phsub_d,
2798 int_x86_ssse3_phsub_d_128>;
2799 defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2800 int_x86_ssse3_phsub_sw,
2801 int_x86_ssse3_phsub_sw_128>;
2802 defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2803 int_x86_ssse3_pmadd_ub_sw,
2804 int_x86_ssse3_pmadd_ub_sw_128>;
2805 defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2806 int_x86_ssse3_pmul_hr_sw,
2807 int_x86_ssse3_pmul_hr_sw_128, 1>;
2808 defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2809 int_x86_ssse3_pshuf_b,
2810 int_x86_ssse3_pshuf_b_128>;
2811 defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2812 int_x86_ssse3_psign_b,
2813 int_x86_ssse3_psign_b_128>;
2814 defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2815 int_x86_ssse3_psign_w,
2816 int_x86_ssse3_psign_w_128>;
2817 defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
2818 int_x86_ssse3_psign_d,
2819 int_x86_ssse3_psign_d_128>;
2821 let Constraints = "$src1 = $dst" in {
2822 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2823 (ins VR64:$src1, VR64:$src2, i8imm:$src3),
2824 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2826 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
2827 (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
2828 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2831 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2832 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
2833 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2835 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
2836 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
2837 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2841 // palignr patterns.
2842 def : Pat<(int_x86_ssse3_palign_r VR64:$src1, VR64:$src2, (i8 imm:$src3)),
2843 (PALIGNR64rr VR64:$src1, VR64:$src2, (BYTE_imm imm:$src3))>,
2844 Requires<[HasSSSE3]>;
2845 def : Pat<(int_x86_ssse3_palign_r VR64:$src1,
2846 (memop64 addr:$src2),
2848 (PALIGNR64rm VR64:$src1, addr:$src2, (BYTE_imm imm:$src3))>,
2849 Requires<[HasSSSE3]>;
2851 def : Pat<(int_x86_ssse3_palign_r_128 VR128:$src1, VR128:$src2, (i8 imm:$src3)),
2852 (PALIGNR128rr VR128:$src1, VR128:$src2, (BYTE_imm imm:$src3))>,
2853 Requires<[HasSSSE3]>;
2854 def : Pat<(int_x86_ssse3_palign_r_128 VR128:$src1,
2855 (memopv2i64 addr:$src2),
2857 (PALIGNR128rm VR128:$src1, addr:$src2, (BYTE_imm imm:$src3))>,
2858 Requires<[HasSSSE3]>;
2860 let AddedComplexity = 5 in {
2861 def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
2862 (PALIGNR128rr VR128:$src2, VR128:$src1,
2863 (SHUFFLE_get_palign_imm VR128:$src3))>,
2864 Requires<[HasSSSE3]>;
2865 def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
2866 (PALIGNR128rr VR128:$src2, VR128:$src1,
2867 (SHUFFLE_get_palign_imm VR128:$src3))>,
2868 Requires<[HasSSSE3]>;
2869 def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
2870 (PALIGNR128rr VR128:$src2, VR128:$src1,
2871 (SHUFFLE_get_palign_imm VR128:$src3))>,
2872 Requires<[HasSSSE3]>;
2873 def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
2874 (PALIGNR128rr VR128:$src2, VR128:$src1,
2875 (SHUFFLE_get_palign_imm VR128:$src3))>,
2876 Requires<[HasSSSE3]>;
2879 def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2880 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2881 def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2882 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2884 //===---------------------------------------------------------------------===//
2885 // Non-Instruction Patterns
2886 //===---------------------------------------------------------------------===//
2888 // extload f32 -> f64. This matches load+fextend because we have a hack in
2889 // the isel (PreprocessForFPConvert) that can introduce loads after dag
2891 // Since these loads aren't folded into the fextend, we have to match it
2893 let Predicates = [HasSSE2] in
2894 def : Pat<(fextend (loadf32 addr:$src)),
2895 (CVTSS2SDrm addr:$src)>;
2898 let Predicates = [HasSSE2] in {
2899 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2900 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2901 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2902 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2903 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2904 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2905 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2906 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2907 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2908 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2909 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2910 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2911 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2912 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2913 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2914 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2915 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2916 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2917 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2918 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2919 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2920 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2921 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2922 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2923 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2924 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2925 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2926 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2927 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2928 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2931 // Move scalar to XMM zero-extended
2932 // movd to XMM register zero-extends
2933 let AddedComplexity = 15 in {
2934 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
2935 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
2936 (MOVLSD2PDrr (V_SET0), FR64:$src)>, Requires<[HasSSE2]>;
2937 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
2938 (MOVLSS2PSrr (V_SET0), FR32:$src)>, Requires<[HasSSE1]>;
2939 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
2940 (MOVLPSrr (V_SET0), VR128:$src)>, Requires<[HasSSE1]>;
2941 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
2942 (MOVLPSrr (V_SET0), VR128:$src)>, Requires<[HasSSE1]>;
2945 // Splat v2f64 / v2i64
2946 let AddedComplexity = 10 in {
2947 def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
2948 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2949 def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
2950 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2951 def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
2952 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2953 def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
2954 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2957 // Special unary SHUFPSrri case.
2958 def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2959 (SHUFPSrri VR128:$src1, VR128:$src1,
2960 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2961 Requires<[HasSSE1]>;
2962 let AddedComplexity = 5 in
2963 def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2964 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2965 Requires<[HasSSE2]>;
2966 // Special unary SHUFPDrri case.
2967 def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
2968 (SHUFPDrri VR128:$src1, VR128:$src1,
2969 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2970 Requires<[HasSSE2]>;
2971 // Special unary SHUFPDrri case.
2972 def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
2973 (SHUFPDrri VR128:$src1, VR128:$src1,
2974 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2975 Requires<[HasSSE2]>;
2976 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
2977 def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2978 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2979 Requires<[HasSSE2]>;
2981 // Special binary v4i32 shuffle cases with SHUFPS.
2982 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
2983 (SHUFPSrri VR128:$src1, VR128:$src2,
2984 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2985 Requires<[HasSSE2]>;
2986 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
2987 (SHUFPSrmi VR128:$src1, addr:$src2,
2988 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2989 Requires<[HasSSE2]>;
2990 // Special binary v2i64 shuffle cases using SHUFPDrri.
2991 def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
2992 (SHUFPDrri VR128:$src1, VR128:$src2,
2993 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2994 Requires<[HasSSE2]>;
2996 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
2997 let AddedComplexity = 15 in {
2998 def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
2999 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3000 Requires<[OptForSpeed, HasSSE2]>;
3001 def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
3002 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3003 Requires<[OptForSpeed, HasSSE2]>;
3005 let AddedComplexity = 10 in {
3006 def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
3007 (UNPCKLPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
3008 def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
3009 (PUNPCKLBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3010 def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
3011 (PUNPCKLWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3012 def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
3013 (PUNPCKLDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3016 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
3017 let AddedComplexity = 15 in {
3018 def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
3019 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3020 Requires<[OptForSpeed, HasSSE2]>;
3021 def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
3022 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3023 Requires<[OptForSpeed, HasSSE2]>;
3025 let AddedComplexity = 10 in {
3026 def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
3027 (UNPCKHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
3028 def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
3029 (PUNPCKHBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3030 def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
3031 (PUNPCKHWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3032 def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
3033 (PUNPCKHDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3036 let AddedComplexity = 20 in {
3037 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
3038 def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
3039 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
3041 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
3042 def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
3043 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
3045 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
3046 def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
3047 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3048 def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
3049 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3052 let AddedComplexity = 20 in {
3053 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
3054 def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
3055 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
3056 def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
3057 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3058 def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
3059 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3060 def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
3061 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3064 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3065 def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3066 (MOVLPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
3067 def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3068 (MOVLPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3069 def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3071 (MOVLPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
3072 def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3073 (MOVLPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3075 let AddedComplexity = 15 in {
3076 // Setting the lowest element in the vector.
3077 def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
3078 (MOVLPSrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3079 def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
3080 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3082 // vector_shuffle v1, v2 <4, 5, 2, 3> using MOVLPDrr (movsd)
3083 def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
3084 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3085 def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
3086 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3089 // vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3090 // fall back to this for SSE1)
3091 def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
3092 (SHUFPSrri VR128:$src2, VR128:$src1,
3093 (SHUFFLE_get_shuf_imm VR128:$src3))>, Requires<[HasSSE1]>;
3095 // Set lowest element and zero upper elements.
3096 let AddedComplexity = 15 in
3097 def : Pat<(v2f64 (movl immAllZerosV_bc, VR128:$src)),
3098 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3099 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
3100 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3102 // Some special case pandn patterns.
3103 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3105 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3106 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3108 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3109 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3111 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3113 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3114 (memop addr:$src2))),
3115 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3116 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3117 (memop addr:$src2))),
3118 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3119 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3120 (memop addr:$src2))),
3121 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3123 // vector -> vector casts
3124 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3125 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3126 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3127 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3128 def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3129 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3130 def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3131 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
3133 // Use movaps / movups for SSE integer load / store (one byte shorter).
3134 def : Pat<(alignedloadv4i32 addr:$src),
3135 (MOVAPSrm addr:$src)>, Requires<[HasSSE1]>;
3136 def : Pat<(loadv4i32 addr:$src),
3137 (MOVUPSrm addr:$src)>, Requires<[HasSSE1]>;
3138 def : Pat<(alignedloadv2i64 addr:$src),
3139 (MOVAPSrm addr:$src)>, Requires<[HasSSE2]>;
3140 def : Pat<(loadv2i64 addr:$src),
3141 (MOVUPSrm addr:$src)>, Requires<[HasSSE2]>;
3143 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3144 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3145 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3146 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3147 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3148 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3149 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3150 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3151 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3152 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3153 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3154 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3155 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3156 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3157 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3158 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3160 //===----------------------------------------------------------------------===//
3161 // SSE4.1 Instructions
3162 //===----------------------------------------------------------------------===//
3164 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
3167 Intrinsic V2F64Int> {
3168 // Intrinsic operation, reg.
3169 // Vector intrinsic operation, reg
3170 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
3171 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3172 !strconcat(OpcodeStr,
3173 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3174 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3177 // Vector intrinsic operation, mem
3178 def PSm_Int : SS4AIi8<opcps, MRMSrcMem,
3179 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3180 !strconcat(OpcodeStr,
3181 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3183 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
3186 // Vector intrinsic operation, reg
3187 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
3188 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3189 !strconcat(OpcodeStr,
3190 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3191 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3194 // Vector intrinsic operation, mem
3195 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
3196 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3197 !strconcat(OpcodeStr,
3198 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3200 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
3204 let Constraints = "$src1 = $dst" in {
3205 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3209 // Intrinsic operation, reg.
3210 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
3212 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3213 !strconcat(OpcodeStr,
3214 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3216 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3219 // Intrinsic operation, mem.
3220 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3222 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
3223 !strconcat(OpcodeStr,
3224 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3226 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3229 // Intrinsic operation, reg.
3230 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
3232 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3233 !strconcat(OpcodeStr,
3234 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3236 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3239 // Intrinsic operation, mem.
3240 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
3242 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3243 !strconcat(OpcodeStr,
3244 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3246 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3251 // FP round - roundss, roundps, roundsd, roundpd
3252 defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3253 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3254 defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3255 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
3257 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3258 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3259 Intrinsic IntId128> {
3260 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3262 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3263 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3264 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3266 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3269 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3272 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3273 int_x86_sse41_phminposuw>;
3275 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3276 let Constraints = "$src1 = $dst" in {
3277 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3278 Intrinsic IntId128, bit Commutable = 0> {
3279 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3280 (ins VR128:$src1, VR128:$src2),
3281 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3282 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3284 let isCommutable = Commutable;
3286 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3287 (ins VR128:$src1, i128mem:$src2),
3288 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3290 (IntId128 VR128:$src1,
3291 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3295 defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3296 int_x86_sse41_pcmpeqq, 1>;
3297 defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3298 int_x86_sse41_packusdw, 0>;
3299 defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3300 int_x86_sse41_pminsb, 1>;
3301 defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3302 int_x86_sse41_pminsd, 1>;
3303 defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3304 int_x86_sse41_pminud, 1>;
3305 defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3306 int_x86_sse41_pminuw, 1>;
3307 defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3308 int_x86_sse41_pmaxsb, 1>;
3309 defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3310 int_x86_sse41_pmaxsd, 1>;
3311 defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3312 int_x86_sse41_pmaxud, 1>;
3313 defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3314 int_x86_sse41_pmaxuw, 1>;
3316 defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3318 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3319 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3320 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3321 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3323 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3324 let Constraints = "$src1 = $dst" in {
3325 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3326 SDNode OpNode, Intrinsic IntId128,
3327 bit Commutable = 0> {
3328 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3329 (ins VR128:$src1, VR128:$src2),
3330 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3331 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3332 VR128:$src2))]>, OpSize {
3333 let isCommutable = Commutable;
3335 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3336 (ins VR128:$src1, VR128:$src2),
3337 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3338 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3340 let isCommutable = Commutable;
3342 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3343 (ins VR128:$src1, i128mem:$src2),
3344 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3346 (OpNode VR128:$src1, (memop addr:$src2)))]>, OpSize;
3347 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3348 (ins VR128:$src1, i128mem:$src2),
3349 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3351 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
3355 defm PMULLD : SS41I_binop_patint<0x40, "pmulld", v4i32, mul,
3356 int_x86_sse41_pmulld, 1>;
3358 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
3359 let Constraints = "$src1 = $dst" in {
3360 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3361 Intrinsic IntId128, bit Commutable = 0> {
3362 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3363 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3364 !strconcat(OpcodeStr,
3365 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3367 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3369 let isCommutable = Commutable;
3371 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3372 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3373 !strconcat(OpcodeStr,
3374 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3376 (IntId128 VR128:$src1,
3377 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3382 defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3383 int_x86_sse41_blendps, 0>;
3384 defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3385 int_x86_sse41_blendpd, 0>;
3386 defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3387 int_x86_sse41_pblendw, 0>;
3388 defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3389 int_x86_sse41_dpps, 1>;
3390 defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3391 int_x86_sse41_dppd, 1>;
3392 defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
3393 int_x86_sse41_mpsadbw, 1>;
3396 /// SS41I_ternary_int - SSE 4.1 ternary operator
3397 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
3398 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3399 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3400 (ins VR128:$src1, VR128:$src2),
3401 !strconcat(OpcodeStr,
3402 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3403 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3406 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3407 (ins VR128:$src1, i128mem:$src2),
3408 !strconcat(OpcodeStr,
3409 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3412 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3416 defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3417 defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3418 defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3421 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3422 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3423 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3424 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3426 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3427 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3429 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3433 defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3434 defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3435 defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3436 defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3437 defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3438 defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3440 // Common patterns involving scalar load.
3441 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3442 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3443 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3444 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3446 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3447 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3448 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3449 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3451 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3452 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3453 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3454 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3456 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3457 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3458 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3459 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3461 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3462 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3463 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3464 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3466 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3467 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3468 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3469 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3472 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3473 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3474 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3475 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3477 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3478 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3480 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3484 defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3485 defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3486 defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3487 defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3489 // Common patterns involving scalar load
3490 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
3491 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
3492 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
3493 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
3495 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
3496 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
3497 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
3498 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
3501 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3502 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3503 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3504 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3506 // Expecting a i16 load any extended to i32 value.
3507 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3508 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3509 [(set VR128:$dst, (IntId (bitconvert
3510 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3514 defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3515 defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
3517 // Common patterns involving scalar load
3518 def : Pat<(int_x86_sse41_pmovsxbq
3519 (bitconvert (v4i32 (X86vzmovl
3520 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3521 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
3523 def : Pat<(int_x86_sse41_pmovzxbq
3524 (bitconvert (v4i32 (X86vzmovl
3525 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3526 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
3529 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3530 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
3531 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3532 (ins VR128:$src1, i32i8imm:$src2),
3533 !strconcat(OpcodeStr,
3534 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3535 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3537 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3538 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
3539 !strconcat(OpcodeStr,
3540 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3543 // There's an AssertZext in the way of writing the store pattern
3544 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3547 defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
3550 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3551 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
3552 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3553 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
3554 !strconcat(OpcodeStr,
3555 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3558 // There's an AssertZext in the way of writing the store pattern
3559 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3562 defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3565 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3566 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
3567 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3568 (ins VR128:$src1, i32i8imm:$src2),
3569 !strconcat(OpcodeStr,
3570 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3572 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
3573 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3574 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
3575 !strconcat(OpcodeStr,
3576 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3577 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3578 addr:$dst)]>, OpSize;
3581 defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
3584 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3586 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
3587 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3588 (ins VR128:$src1, i32i8imm:$src2),
3589 !strconcat(OpcodeStr,
3590 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3592 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
3594 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3595 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
3596 !strconcat(OpcodeStr,
3597 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3598 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
3599 addr:$dst)]>, OpSize;
3602 defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
3604 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3605 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3608 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3609 Requires<[HasSSE41]>;
3611 let Constraints = "$src1 = $dst" in {
3612 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
3613 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3614 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3615 !strconcat(OpcodeStr,
3616 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3618 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
3619 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3620 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3621 !strconcat(OpcodeStr,
3622 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3624 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3625 imm:$src3))]>, OpSize;
3629 defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3631 let Constraints = "$src1 = $dst" in {
3632 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
3633 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3634 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3635 !strconcat(OpcodeStr,
3636 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3638 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3640 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3641 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3642 !strconcat(OpcodeStr,
3643 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3645 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3646 imm:$src3)))]>, OpSize;
3650 defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3652 // insertps has a few different modes, there's the first two here below which
3653 // are optimized inserts that won't zero arbitrary elements in the destination
3654 // vector. The next one matches the intrinsic and could zero arbitrary elements
3655 // in the target vector.
3656 let Constraints = "$src1 = $dst" in {
3657 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
3658 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3659 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3660 !strconcat(OpcodeStr,
3661 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3663 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
3665 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3666 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3667 !strconcat(OpcodeStr,
3668 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3670 (X86insrtps VR128:$src1,
3671 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
3672 imm:$src3))]>, OpSize;
3676 defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
3678 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3679 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3681 // ptest instruction we'll lower to this in X86ISelLowering primarily from
3682 // the intel intrinsic that corresponds to this.
3683 let Defs = [EFLAGS] in {
3684 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
3685 "ptest \t{$src2, $src1|$src1, $src2}",
3686 [(X86ptest VR128:$src1, VR128:$src2),
3687 (implicit EFLAGS)]>, OpSize;
3688 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
3689 "ptest \t{$src2, $src1|$src1, $src2}",
3690 [(X86ptest VR128:$src1, (load addr:$src2)),
3691 (implicit EFLAGS)]>, OpSize;
3694 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3695 "movntdqa\t{$src, $dst|$dst, $src}",
3696 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>;
3699 //===----------------------------------------------------------------------===//
3700 // SSE4.2 Instructions
3701 //===----------------------------------------------------------------------===//
3703 /// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3704 let Constraints = "$src1 = $dst" in {
3705 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3706 Intrinsic IntId128, bit Commutable = 0> {
3707 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3708 (ins VR128:$src1, VR128:$src2),
3709 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3710 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3712 let isCommutable = Commutable;
3714 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3715 (ins VR128:$src1, i128mem:$src2),
3716 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3718 (IntId128 VR128:$src1,
3719 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3723 defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
3725 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3726 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3727 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3728 (PCMPGTQrm VR128:$src1, addr:$src2)>;
3730 // crc intrinsic instruction
3731 // This set of instructions are only rm, the only difference is the size
3733 let Constraints = "$src1 = $dst" in {
3734 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
3735 (ins GR32:$src1, i8mem:$src2),
3736 "crc32 \t{$src2, $src1|$src1, $src2}",
3738 (int_x86_sse42_crc32_8 GR32:$src1,
3739 (load addr:$src2)))]>, OpSize;
3740 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
3741 (ins GR32:$src1, GR8:$src2),
3742 "crc32 \t{$src2, $src1|$src1, $src2}",
3744 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>,
3746 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3747 (ins GR32:$src1, i16mem:$src2),
3748 "crc32 \t{$src2, $src1|$src1, $src2}",
3750 (int_x86_sse42_crc32_16 GR32:$src1,
3751 (load addr:$src2)))]>,
3753 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3754 (ins GR32:$src1, GR16:$src2),
3755 "crc32 \t{$src2, $src1|$src1, $src2}",
3757 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
3759 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3760 (ins GR32:$src1, i32mem:$src2),
3761 "crc32 \t{$src2, $src1|$src1, $src2}",
3763 (int_x86_sse42_crc32_32 GR32:$src1,
3764 (load addr:$src2)))]>, OpSize;
3765 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3766 (ins GR32:$src1, GR32:$src2),
3767 "crc32 \t{$src2, $src1|$src1, $src2}",
3769 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>,
3771 def CRC64m64 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3772 (ins GR64:$src1, i64mem:$src2),
3773 "crc32 \t{$src2, $src1|$src1, $src2}",
3775 (int_x86_sse42_crc32_64 GR64:$src1,
3776 (load addr:$src2)))]>,
3778 def CRC64r64 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3779 (ins GR64:$src1, GR64:$src2),
3780 "crc32 \t{$src2, $src1|$src1, $src2}",
3782 (int_x86_sse42_crc32_64 GR64:$src1, GR64:$src2))]>,
3786 // String/text processing instructions.
3787 let Defs = [EFLAGS], usesCustomInserter = 1 in {
3788 def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3789 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3790 "#PCMPISTRM128rr PSEUDO!",
3792 (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
3793 imm:$src3))]>, OpSize;
3794 def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3795 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3796 "#PCMPISTRM128rm PSEUDO!",
3798 (int_x86_sse42_pcmpistrm128 VR128:$src1,
3800 imm:$src3))]>, OpSize;
3803 let Defs = [XMM0, EFLAGS] in {
3804 def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
3805 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3806 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3808 def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
3809 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3810 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3814 let Defs = [EFLAGS], Uses = [EAX, EDX],
3815 usesCustomInserter = 1 in {
3816 def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3817 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3818 "#PCMPESTRM128rr PSEUDO!",
3820 (int_x86_sse42_pcmpestrm128 VR128:$src1, EAX,
3822 EDX, imm:$src5))]>, OpSize;
3823 def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3824 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3825 "#PCMPESTRM128rm PSEUDO!",
3827 (int_x86_sse42_pcmpestrm128 VR128:$src1, EAX,
3829 EDX, imm:$src5))]>, OpSize;
3832 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
3833 def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
3834 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3835 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3837 def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
3838 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3839 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3843 let Defs = [ECX, EFLAGS] in {
3844 multiclass SS42AI_pcmpistri<Intrinsic IntId128> {
3845 def rr : SS42AI<0x63, MRMSrcReg, (outs),
3846 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3847 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3849 (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
3850 (implicit EFLAGS)]>,
3852 def rm : SS42AI<0x63, MRMSrcMem, (outs),
3853 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3854 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3856 (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
3857 (implicit EFLAGS)]>,
3862 defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
3863 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
3864 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
3865 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
3866 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
3867 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
3869 let Defs = [ECX, EFLAGS] in {
3870 let Uses = [EAX, EDX] in {
3871 multiclass SS42AI_pcmpestri<Intrinsic IntId128> {
3872 def rr : SS42AI<0x61, MRMSrcReg, (outs),
3873 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3874 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3876 (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
3877 (implicit EFLAGS)]>,
3879 def rm : SS42AI<0x61, MRMSrcMem, (outs),
3880 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3881 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3883 (IntId128 VR128:$src1, EAX, (load addr:$src3),
3885 (implicit EFLAGS)]>,
3891 defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
3892 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
3893 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
3894 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
3895 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
3896 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;