bedc5e50af0067b5ffc385f38c5dbdf149e881ac
[oota-llvm.git] / lib / Target / X86 / X86InstrSSE.td
1 //====- X86InstrSSE.td - Describe the X86 Instruction Set -------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Evan Cheng and is distributed under the University
6 // of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
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.
13 //
14 //===----------------------------------------------------------------------===//
15
16
17 //===----------------------------------------------------------------------===//
18 // SSE specific DAG Nodes.
19 //===----------------------------------------------------------------------===//
20
21 def SDTX86FPShiftOp : SDTypeProfile<1, 2, [ SDTCisSameAs<0, 1>,
22                                             SDTCisFP<0>, SDTCisInt<2> ]>;
23
24 def X86loadp   : SDNode<"X86ISD::LOAD_PACK", SDTLoad, [SDNPHasChain]>;
25 def X86loadu   : SDNode<"X86ISD::LOAD_UA",   SDTLoad, [SDNPHasChain]>;
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                         [SDNPHasChain, SDNPOutFlag]>;
39 def X86ucomi   : SDNode<"X86ISD::UCOMI",     SDTX86CmpTest,
40                         [SDNPHasChain, SDNPOutFlag]>;
41 def X86s2vec   : SDNode<"X86ISD::S2VEC",  SDTypeProfile<1, 1, []>, []>;
42 def X86pextrw  : SDNode<"X86ISD::PEXTRW", SDTypeProfile<1, 2, []>, []>;
43 def X86pinsrw  : SDNode<"X86ISD::PINSRW", SDTypeProfile<1, 3, []>, []>;
44
45 //===----------------------------------------------------------------------===//
46 // SSE 'Special' Instructions
47 //===----------------------------------------------------------------------===//
48
49 def IMPLICIT_DEF_VR128 : I<0, Pseudo, (outs VR128:$dst), (ins),
50                            "#IMPLICIT_DEF $dst",
51                            [(set VR128:$dst, (v4f32 (undef)))]>,
52                          Requires<[HasSSE1]>;
53 def IMPLICIT_DEF_FR32  : I<0, Pseudo, (outs FR32:$dst), (ins),
54                            "#IMPLICIT_DEF $dst",
55                            [(set FR32:$dst, (undef))]>, Requires<[HasSSE2]>;
56 def IMPLICIT_DEF_FR64  : I<0, Pseudo, (outs FR64:$dst), (ins),
57                            "#IMPLICIT_DEF $dst",
58                            [(set FR64:$dst, (undef))]>, Requires<[HasSSE2]>;
59
60 //===----------------------------------------------------------------------===//
61 // SSE Complex Patterns
62 //===----------------------------------------------------------------------===//
63
64 // These are 'extloads' from a scalar to the low element of a vector, zeroing
65 // the top elements.  These are used for the SSE 'ss' and 'sd' instruction
66 // forms.
67 def sse_load_f32 : ComplexPattern<v4f32, 4, "SelectScalarSSELoad", [],
68                                   [SDNPHasChain]>;
69 def sse_load_f64 : ComplexPattern<v2f64, 4, "SelectScalarSSELoad", [],
70                                   [SDNPHasChain]>;
71
72 def ssmem : Operand<v4f32> {
73   let PrintMethod = "printf32mem";
74   let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
75 }
76 def sdmem : Operand<v2f64> {
77   let PrintMethod = "printf64mem";
78   let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
79 }
80
81 //===----------------------------------------------------------------------===//
82 // SSE pattern fragments
83 //===----------------------------------------------------------------------===//
84
85 def X86loadpf32  : PatFrag<(ops node:$ptr), (f32   (X86loadp node:$ptr))>;
86 def X86loadpf64  : PatFrag<(ops node:$ptr), (f64   (X86loadp node:$ptr))>;
87
88 def loadv4f32    : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
89 def loadv2f64    : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
90 def loadv4i32    : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
91 def loadv2i64    : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
92
93 // Like 'store', but always requires natural alignment.
94 def alignedstore : PatFrag<(ops node:$val, node:$ptr),
95                            (st node:$val, node:$ptr), [{
96   if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
97     return !ST->isTruncatingStore() &&
98            ST->getAddressingMode() == ISD::UNINDEXED &&
99            ST->getAlignment() * 8 >= MVT::getSizeInBits(ST->getStoredVT());
100   return false;
101 }]>;
102
103 // Like 'load', but always requires natural alignment.
104 def alignedload : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
105   if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
106     return LD->getExtensionType() == ISD::NON_EXTLOAD &&
107            LD->getAddressingMode() == ISD::UNINDEXED &&
108            LD->getAlignment() * 8 >= MVT::getSizeInBits(LD->getLoadedVT());
109   return false;
110 }]>;
111
112 def alignedloadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (alignedload node:$ptr))>;
113 def alignedloadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (alignedload node:$ptr))>;
114 def alignedloadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (alignedload node:$ptr))>;
115 def alignedloadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (alignedload node:$ptr))>;
116
117 // Like 'load', but uses special alignment checks suitable for use in
118 // memory operands in most SSE instructions, which are required to
119 // be naturally aligned on some targets but not on others.
120 // FIXME: Actually implement support for targets that don't require the
121 //        alignment. This probably wants a subtarget predicate.
122 def memop : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
123   if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
124     return LD->getExtensionType() == ISD::NON_EXTLOAD &&
125            LD->getAddressingMode() == ISD::UNINDEXED &&
126            LD->getAlignment() * 8 >= MVT::getSizeInBits(LD->getLoadedVT());
127   return false;
128 }]>;
129
130 def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
131 def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
132 def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
133 def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
134
135 def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
136 def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
137 def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
138 def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
139 def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
140 def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
141
142 def fp32imm0 : PatLeaf<(f32 fpimm), [{
143   return N->isExactlyValue(+0.0);
144 }]>;
145
146 def PSxLDQ_imm  : SDNodeXForm<imm, [{
147   // Transformation function: imm >> 3
148   return getI32Imm(N->getValue() >> 3);
149 }]>;
150
151 // SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
152 // SHUFP* etc. imm.
153 def SHUFFLE_get_shuf_imm : SDNodeXForm<build_vector, [{
154   return getI8Imm(X86::getShuffleSHUFImmediate(N));
155 }]>;
156
157 // SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to 
158 // PSHUFHW imm.
159 def SHUFFLE_get_pshufhw_imm : SDNodeXForm<build_vector, [{
160   return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
161 }]>;
162
163 // SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to 
164 // PSHUFLW imm.
165 def SHUFFLE_get_pshuflw_imm : SDNodeXForm<build_vector, [{
166   return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
167 }]>;
168
169 def SSE_splat_mask : PatLeaf<(build_vector), [{
170   return X86::isSplatMask(N);
171 }], SHUFFLE_get_shuf_imm>;
172
173 def SSE_splat_lo_mask : PatLeaf<(build_vector), [{
174   return X86::isSplatLoMask(N);
175 }]>;
176
177 def MOVHLPS_shuffle_mask : PatLeaf<(build_vector), [{
178   return X86::isMOVHLPSMask(N);
179 }]>;
180
181 def MOVHLPS_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
182   return X86::isMOVHLPS_v_undef_Mask(N);
183 }]>;
184
185 def MOVHP_shuffle_mask : PatLeaf<(build_vector), [{
186   return X86::isMOVHPMask(N);
187 }]>;
188
189 def MOVLP_shuffle_mask : PatLeaf<(build_vector), [{
190   return X86::isMOVLPMask(N);
191 }]>;
192
193 def MOVL_shuffle_mask : PatLeaf<(build_vector), [{
194   return X86::isMOVLMask(N);
195 }]>;
196
197 def MOVSHDUP_shuffle_mask : PatLeaf<(build_vector), [{
198   return X86::isMOVSHDUPMask(N);
199 }]>;
200
201 def MOVSLDUP_shuffle_mask : PatLeaf<(build_vector), [{
202   return X86::isMOVSLDUPMask(N);
203 }]>;
204
205 def UNPCKL_shuffle_mask : PatLeaf<(build_vector), [{
206   return X86::isUNPCKLMask(N);
207 }]>;
208
209 def UNPCKH_shuffle_mask : PatLeaf<(build_vector), [{
210   return X86::isUNPCKHMask(N);
211 }]>;
212
213 def UNPCKL_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
214   return X86::isUNPCKL_v_undef_Mask(N);
215 }]>;
216
217 def UNPCKH_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
218   return X86::isUNPCKH_v_undef_Mask(N);
219 }]>;
220
221 def PSHUFD_shuffle_mask : PatLeaf<(build_vector), [{
222   return X86::isPSHUFDMask(N);
223 }], SHUFFLE_get_shuf_imm>;
224
225 def PSHUFHW_shuffle_mask : PatLeaf<(build_vector), [{
226   return X86::isPSHUFHWMask(N);
227 }], SHUFFLE_get_pshufhw_imm>;
228
229 def PSHUFLW_shuffle_mask : PatLeaf<(build_vector), [{
230   return X86::isPSHUFLWMask(N);
231 }], SHUFFLE_get_pshuflw_imm>;
232
233 def SHUFP_unary_shuffle_mask : PatLeaf<(build_vector), [{
234   return X86::isPSHUFDMask(N);
235 }], SHUFFLE_get_shuf_imm>;
236
237 def SHUFP_shuffle_mask : PatLeaf<(build_vector), [{
238   return X86::isSHUFPMask(N);
239 }], SHUFFLE_get_shuf_imm>;
240
241 def PSHUFD_binary_shuffle_mask : PatLeaf<(build_vector), [{
242   return X86::isSHUFPMask(N);
243 }], SHUFFLE_get_shuf_imm>;
244
245 //===----------------------------------------------------------------------===//
246 // SSE scalar FP Instructions
247 //===----------------------------------------------------------------------===//
248
249 // CMOV* - Used to implement the SSE SELECT DAG operation.  Expanded by the
250 // scheduler into a branch sequence.
251 let usesCustomDAGSchedInserter = 1 in {  // Expanded by the scheduler.
252   def CMOV_FR32 : I<0, Pseudo,
253                     (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
254                     "#CMOV_FR32 PSEUDO!",
255                     [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond))]>;
256   def CMOV_FR64 : I<0, Pseudo,
257                     (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
258                     "#CMOV_FR64 PSEUDO!",
259                     [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond))]>;
260   def CMOV_V4F32 : I<0, Pseudo,
261                     (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
262                     "#CMOV_V4F32 PSEUDO!",
263                     [(set VR128:$dst,
264                       (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond)))]>;
265   def CMOV_V2F64 : I<0, Pseudo,
266                     (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
267                     "#CMOV_V2F64 PSEUDO!",
268                     [(set VR128:$dst,
269                       (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond)))]>;
270   def CMOV_V2I64 : I<0, Pseudo,
271                     (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
272                     "#CMOV_V2I64 PSEUDO!",
273                     [(set VR128:$dst,
274                       (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond)))]>;
275 }
276
277 //===----------------------------------------------------------------------===//
278 // SSE1 Instructions
279 //===----------------------------------------------------------------------===//
280
281 // SSE1 Instruction Templates:
282 // 
283 //   SSI   - SSE1 instructions with XS prefix.
284 //   PSI   - SSE1 instructions with TB prefix.
285 //   PSIi8 - SSE1 instructions with ImmT == Imm8 and TB prefix.
286
287 class SSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
288       : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
289 class PSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
290       : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
291 class PSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
292             list<dag> pattern>
293       : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
294
295 // Move Instructions
296 def MOVSSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
297                   "movss {$src, $dst|$dst, $src}", []>;
298 def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
299                   "movss {$src, $dst|$dst, $src}",
300                   [(set FR32:$dst, (loadf32 addr:$src))]>;
301 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
302                   "movss {$src, $dst|$dst, $src}",
303                   [(store FR32:$src, addr:$dst)]>;
304
305 // Conversion instructions
306 def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
307                       "cvttss2si {$src, $dst|$dst, $src}",
308                       [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
309 def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
310                       "cvttss2si {$src, $dst|$dst, $src}",
311                       [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
312 def CVTSI2SSrr  : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
313                       "cvtsi2ss {$src, $dst|$dst, $src}",
314                       [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
315 def CVTSI2SSrm  : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
316                       "cvtsi2ss {$src, $dst|$dst, $src}",
317                       [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
318
319 // Match intrinsics which expect XMM operand(s).
320 def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
321                          "cvtss2si {$src, $dst|$dst, $src}",
322                          [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
323 def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
324                          "cvtss2si {$src, $dst|$dst, $src}",
325                          [(set GR32:$dst, (int_x86_sse_cvtss2si
326                                            (load addr:$src)))]>;
327
328 // Aliases for intrinsics
329 def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
330                           "cvttss2si {$src, $dst|$dst, $src}",
331                           [(set GR32:$dst,
332                             (int_x86_sse_cvttss2si VR128:$src))]>;
333 def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
334                           "cvttss2si {$src, $dst|$dst, $src}",
335                           [(set GR32:$dst,
336                             (int_x86_sse_cvttss2si(load addr:$src)))]>;
337
338 let isTwoAddress = 1 in {
339   def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
340                            (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
341                            "cvtsi2ss {$src2, $dst|$dst, $src2}",
342                            [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
343                                               GR32:$src2))]>;
344   def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
345                            (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
346                            "cvtsi2ss {$src2, $dst|$dst, $src2}",
347                            [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
348                                               (loadi32 addr:$src2)))]>;
349 }
350
351 // Comparison instructions
352 let isTwoAddress = 1 in {
353   def CMPSSrr : SSI<0xC2, MRMSrcReg, 
354                     (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
355                     "cmp${cc}ss {$src, $dst|$dst, $src}",
356                     []>;
357   def CMPSSrm : SSI<0xC2, MRMSrcMem, 
358                     (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
359                     "cmp${cc}ss {$src, $dst|$dst, $src}", []>;
360 }
361
362 def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
363                    "ucomiss {$src2, $src1|$src1, $src2}",
364                    [(X86cmp FR32:$src1, FR32:$src2)]>;
365 def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
366                    "ucomiss {$src2, $src1|$src1, $src2}",
367                    [(X86cmp FR32:$src1, (loadf32 addr:$src2))]>;
368
369 // Aliases to match intrinsics which expect XMM operand(s).
370 let isTwoAddress = 1 in {
371   def Int_CMPSSrr : SSI<0xC2, MRMSrcReg, 
372                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
373                         "cmp${cc}ss {$src, $dst|$dst, $src}",
374                         [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
375                                            VR128:$src, imm:$cc))]>;
376   def Int_CMPSSrm : SSI<0xC2, MRMSrcMem, 
377                         (outs VR128:$dst), (ins VR128:$src1, f32mem:$src, SSECC:$cc),
378                         "cmp${cc}ss {$src, $dst|$dst, $src}",
379                         [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
380                                            (load addr:$src), imm:$cc))]>;
381 }
382
383 def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
384                        "ucomiss {$src2, $src1|$src1, $src2}",
385                        [(X86ucomi (v4f32 VR128:$src1), VR128:$src2)]>;
386 def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
387                        "ucomiss {$src2, $src1|$src1, $src2}",
388                        [(X86ucomi (v4f32 VR128:$src1), (load addr:$src2))]>;
389
390 def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
391                       "comiss {$src2, $src1|$src1, $src2}",
392                       [(X86comi (v4f32 VR128:$src1), VR128:$src2)]>;
393 def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
394                       "comiss {$src2, $src1|$src1, $src2}",
395                       [(X86comi (v4f32 VR128:$src1), (load addr:$src2))]>;
396
397 // Aliases of packed SSE1 instructions for scalar use. These all have names that
398 // start with 'Fs'.
399
400 // Alias instructions that map fld0 to pxor for sse.
401 def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins),
402                  "pxor $dst, $dst", [(set FR32:$dst, fp32imm0)]>,
403                Requires<[HasSSE1]>, TB, OpSize;
404
405 // Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
406 // disregarded.
407 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
408                      "movaps {$src, $dst|$dst, $src}", []>;
409
410 // Alias instruction to load FR32 from f128mem using movaps. Upper bits are
411 // disregarded.
412 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
413                      "movaps {$src, $dst|$dst, $src}",
414                      [(set FR32:$dst, (X86loadpf32 addr:$src))]>;
415
416 // Alias bitwise logical operations using SSE logical ops on packed FP values.
417 let isTwoAddress = 1 in {
418 let isCommutable = 1 in {
419   def FsANDPSrr : PSI<0x54, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
420                       "andps {$src2, $dst|$dst, $src2}",
421                       [(set FR32:$dst, (X86fand FR32:$src1, FR32:$src2))]>;
422   def FsORPSrr  : PSI<0x56, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
423                       "orps {$src2, $dst|$dst, $src2}",
424                       [(set FR32:$dst, (X86for FR32:$src1, FR32:$src2))]>;
425   def FsXORPSrr : PSI<0x57, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
426                       "xorps {$src2, $dst|$dst, $src2}",
427                       [(set FR32:$dst, (X86fxor FR32:$src1, FR32:$src2))]>;
428 }
429
430 def FsANDPSrm : PSI<0x54, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
431                     "andps {$src2, $dst|$dst, $src2}",
432                     [(set FR32:$dst, (X86fand FR32:$src1,
433                                       (X86loadpf32 addr:$src2)))]>;
434 def FsORPSrm  : PSI<0x56, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
435                     "orps {$src2, $dst|$dst, $src2}",
436                     [(set FR32:$dst, (X86for FR32:$src1,
437                                       (X86loadpf32 addr:$src2)))]>;
438 def FsXORPSrm : PSI<0x57, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
439                     "xorps {$src2, $dst|$dst, $src2}",
440                     [(set FR32:$dst, (X86fxor FR32:$src1,
441                                       (X86loadpf32 addr:$src2)))]>;
442
443 def FsANDNPSrr : PSI<0x55, MRMSrcReg,
444                      (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
445                      "andnps {$src2, $dst|$dst, $src2}", []>;
446 def FsANDNPSrm : PSI<0x55, MRMSrcMem,
447                      (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
448                      "andnps {$src2, $dst|$dst, $src2}", []>;
449 }
450
451 /// basic_sse1_fp_binop_rm - SSE1 binops come in both scalar and vector forms.
452 ///
453 /// In addition, we also have a special variant of the scalar form here to
454 /// represent the associated intrinsic operation.  This form is unlike the
455 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
456 /// and leaves the top elements undefined.
457 ///
458 /// These three forms can each be reg+reg or reg+mem, so there are a total of
459 /// six "instructions".
460 ///
461 let isTwoAddress = 1 in {
462 multiclass basic_sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
463                                   SDNode OpNode, Intrinsic F32Int,
464                                   bit Commutable = 0> {
465   // Scalar operation, reg+reg.
466   def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
467                  !strconcat(OpcodeStr, "ss {$src2, $dst|$dst, $src2}"),
468                  [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
469     let isCommutable = Commutable;
470   }
471
472   // Scalar operation, reg+mem.
473   def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
474                  !strconcat(OpcodeStr, "ss {$src2, $dst|$dst, $src2}"),
475                  [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
476                  
477   // Vector operation, reg+reg.
478   def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
479                !strconcat(OpcodeStr, "ps {$src2, $dst|$dst, $src2}"),
480                [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
481     let isCommutable = Commutable;
482   }
483
484   // Vector operation, reg+mem.
485   def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
486                  !strconcat(OpcodeStr, "ps {$src2, $dst|$dst, $src2}"),
487                  [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
488
489   // Intrinsic operation, reg+reg.
490   def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
491                      !strconcat(OpcodeStr, "ss {$src2, $dst|$dst, $src2}"),
492                      [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
493     let isCommutable = Commutable;
494   }
495
496   // Intrinsic operation, reg+mem.
497   def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
498                      !strconcat(OpcodeStr, "ss {$src2, $dst|$dst, $src2}"),
499                      [(set VR128:$dst, (F32Int VR128:$src1,
500                                                sse_load_f32:$src2))]>;
501 }
502 }
503
504 // Arithmetic instructions
505 defm ADD : basic_sse1_fp_binop_rm<0x58, "add", fadd, int_x86_sse_add_ss, 1>;
506 defm MUL : basic_sse1_fp_binop_rm<0x59, "mul", fmul, int_x86_sse_mul_ss, 1>;
507 defm SUB : basic_sse1_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse_sub_ss>;
508 defm DIV : basic_sse1_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse_div_ss>;
509
510 /// sse1_fp_binop_rm - Other SSE1 binops
511 ///
512 /// This multiclass is like basic_sse1_fp_binop_rm, with the addition of
513 /// instructions for a full-vector intrinsic form.  Operations that map
514 /// onto C operators don't use this form since they just use the plain
515 /// vector form instead of having a separate vector intrinsic form.
516 ///
517 /// This provides a total of eight "instructions".
518 ///
519 let isTwoAddress = 1 in {
520 multiclass sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
521                             SDNode OpNode,
522                             Intrinsic F32Int,
523                             Intrinsic V4F32Int,
524                             bit Commutable = 0> {
525
526   // Scalar operation, reg+reg.
527   def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
528                  !strconcat(OpcodeStr, "ss {$src2, $dst|$dst, $src2}"),
529                  [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
530     let isCommutable = Commutable;
531   }
532
533   // Scalar operation, reg+mem.
534   def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
535                  !strconcat(OpcodeStr, "ss {$src2, $dst|$dst, $src2}"),
536                  [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
537                  
538   // Vector operation, reg+reg.
539   def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
540                !strconcat(OpcodeStr, "ps {$src2, $dst|$dst, $src2}"),
541                [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
542     let isCommutable = Commutable;
543   }
544
545   // Vector operation, reg+mem.
546   def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
547                  !strconcat(OpcodeStr, "ps {$src2, $dst|$dst, $src2}"),
548                  [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
549
550   // Intrinsic operation, reg+reg.
551   def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
552                      !strconcat(OpcodeStr, "ss {$src2, $dst|$dst, $src2}"),
553                      [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
554     let isCommutable = Commutable;
555   }
556
557   // Intrinsic operation, reg+mem.
558   def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
559                      !strconcat(OpcodeStr, "ss {$src2, $dst|$dst, $src2}"),
560                      [(set VR128:$dst, (F32Int VR128:$src1,
561                                                sse_load_f32:$src2))]>;
562
563   // Vector intrinsic operation, reg+reg.
564   def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
565                      !strconcat(OpcodeStr, "ps {$src2, $dst|$dst, $src2}"),
566                      [(set VR128:$dst, (V4F32Int VR128:$src1, VR128:$src2))]> {
567     let isCommutable = Commutable;
568   }
569
570   // Vector intrinsic operation, reg+mem.
571   def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
572                      !strconcat(OpcodeStr, "ps {$src2, $dst|$dst, $src2}"),
573                      [(set VR128:$dst, (V4F32Int VR128:$src1, (load addr:$src2)))]>;
574 }
575 }
576
577 defm MAX : sse1_fp_binop_rm<0x5F, "max", X86fmax,
578                             int_x86_sse_max_ss, int_x86_sse_max_ps>;
579 defm MIN : sse1_fp_binop_rm<0x5D, "min", X86fmin,
580                             int_x86_sse_min_ss, int_x86_sse_min_ps>;
581
582 //===----------------------------------------------------------------------===//
583 // SSE packed FP Instructions
584
585 // Move Instructions
586 def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
587                    "movaps {$src, $dst|$dst, $src}", []>;
588 def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
589                    "movaps {$src, $dst|$dst, $src}",
590                    [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
591
592 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
593                    "movaps {$src, $dst|$dst, $src}",
594                    [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
595
596 def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
597                    "movups {$src, $dst|$dst, $src}", []>;
598 def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
599                    "movups {$src, $dst|$dst, $src}",
600                    [(set VR128:$dst, (loadv4f32 addr:$src))]>;
601 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
602                    "movups {$src, $dst|$dst, $src}",
603                    [(store (v4f32 VR128:$src), addr:$dst)]>;
604
605 // Intrinsic forms of MOVUPS load and store
606 def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
607                        "movups {$src, $dst|$dst, $src}",
608                        [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
609 def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
610                        "movups {$src, $dst|$dst, $src}",
611                        [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
612
613 let isTwoAddress = 1 in {
614   let AddedComplexity = 20 in {
615     def MOVLPSrm : PSI<0x12, MRMSrcMem,
616                        (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
617                        "movlps {$src2, $dst|$dst, $src2}",
618                        [(set VR128:$dst, 
619                          (v4f32 (vector_shuffle VR128:$src1,
620                          (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
621                                  MOVLP_shuffle_mask)))]>;
622     def MOVHPSrm : PSI<0x16, MRMSrcMem,
623                        (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
624                        "movhps {$src2, $dst|$dst, $src2}",
625                        [(set VR128:$dst, 
626                          (v4f32 (vector_shuffle VR128:$src1,
627                          (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
628                                  MOVHP_shuffle_mask)))]>;
629   } // AddedComplexity
630 } // isTwoAddress
631
632 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
633                    "movlps {$src, $dst|$dst, $src}",
634                    [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
635                                  (iPTR 0))), addr:$dst)]>;
636
637 // v2f64 extract element 1 is always custom lowered to unpack high to low
638 // and extract element 0 so the non-store version isn't too horrible.
639 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
640                    "movhps {$src, $dst|$dst, $src}",
641                    [(store (f64 (vector_extract
642                                  (v2f64 (vector_shuffle
643                                          (bc_v2f64 (v4f32 VR128:$src)), (undef),
644                                          UNPCKH_shuffle_mask)), (iPTR 0))),
645                      addr:$dst)]>;
646
647 let isTwoAddress = 1 in {
648 let AddedComplexity = 15 in {
649 def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
650                     "movlhps {$src2, $dst|$dst, $src2}",
651                     [(set VR128:$dst,
652                       (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
653                               MOVHP_shuffle_mask)))]>;
654
655 def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
656                     "movhlps {$src2, $dst|$dst, $src2}",
657                     [(set VR128:$dst,
658                       (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
659                               MOVHLPS_shuffle_mask)))]>;
660 } // AddedComplexity
661 } // isTwoAddress
662
663
664
665 // Arithmetic
666
667 /// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
668 ///
669 /// In addition, we also have a special variant of the scalar form here to
670 /// represent the associated intrinsic operation.  This form is unlike the
671 /// plain scalar form, in that it takes an entire vector (instead of a
672 /// scalar) and leaves the top elements undefined.
673 ///
674 /// And, we have a special variant form for a full-vector intrinsic form.
675 ///
676 /// These four forms can each have a reg or a mem operand, so there are a
677 /// total of eight "instructions".
678 ///
679 multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
680                            SDNode OpNode,
681                            Intrinsic F32Int,
682                            Intrinsic V4F32Int,
683                            bit Commutable = 0> {
684   // Scalar operation, reg.
685   def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
686                 !strconcat(OpcodeStr, "ss {$src, $dst|$dst, $src}"),
687                 [(set FR32:$dst, (OpNode FR32:$src))]> {
688     let isCommutable = Commutable;
689   }
690
691   // Scalar operation, mem.
692   def SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
693                 !strconcat(OpcodeStr, "ss {$src, $dst|$dst, $src}"),
694                 [(set FR32:$dst, (OpNode (load addr:$src)))]>;
695                  
696   // Vector operation, reg.
697   def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
698               !strconcat(OpcodeStr, "ps {$src, $dst|$dst, $src}"),
699               [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
700     let isCommutable = Commutable;
701   }
702
703   // Vector operation, mem.
704   def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
705                 !strconcat(OpcodeStr, "ps {$src, $dst|$dst, $src}"),
706                 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
707
708   // Intrinsic operation, reg.
709   def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
710                     !strconcat(OpcodeStr, "ss {$src, $dst|$dst, $src}"),
711                     [(set VR128:$dst, (F32Int VR128:$src))]> {
712     let isCommutable = Commutable;
713   }
714
715   // Intrinsic operation, mem.
716   def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
717                     !strconcat(OpcodeStr, "ss {$src, $dst|$dst, $src}"),
718                     [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
719
720   // Vector intrinsic operation, reg
721   def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
722                     !strconcat(OpcodeStr, "ps {$src, $dst|$dst, $src}"),
723                     [(set VR128:$dst, (V4F32Int VR128:$src))]> {
724     let isCommutable = Commutable;
725   }
726
727   // Vector intrinsic operation, mem
728   def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
729                     !strconcat(OpcodeStr, "ps {$src, $dst|$dst, $src}"),
730                     [(set VR128:$dst, (V4F32Int (load addr:$src)))]>;
731 }
732
733 // Square root.
734 defm SQRT  : sse1_fp_unop_rm<0x51, "sqrt",  fsqrt,
735                              int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
736
737 // Reciprocal approximations. Note that these typically require refinement
738 // in order to obtain suitable precision.
739 defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
740                              int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
741 defm RCP   : sse1_fp_unop_rm<0x53, "rcp",   X86frcp,
742                              int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
743
744 // Logical
745 let isTwoAddress = 1 in {
746   let isCommutable = 1 in {
747     def ANDPSrr : PSI<0x54, MRMSrcReg,
748                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
749                       "andps {$src2, $dst|$dst, $src2}",
750                       [(set VR128:$dst, (v2i64
751                                          (and VR128:$src1, VR128:$src2)))]>;
752     def ORPSrr  : PSI<0x56, MRMSrcReg,
753                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
754                       "orps {$src2, $dst|$dst, $src2}",
755                       [(set VR128:$dst, (v2i64
756                                          (or VR128:$src1, VR128:$src2)))]>;
757     def XORPSrr : PSI<0x57, MRMSrcReg,
758                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
759                       "xorps {$src2, $dst|$dst, $src2}",
760                       [(set VR128:$dst, (v2i64
761                                          (xor VR128:$src1, VR128:$src2)))]>;
762   }
763
764   def ANDPSrm : PSI<0x54, MRMSrcMem,
765                     (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
766                     "andps {$src2, $dst|$dst, $src2}",
767                     [(set VR128:$dst, (and (bc_v2i64 (v4f32 VR128:$src1)),
768                                        (memopv2i64 addr:$src2)))]>;
769   def ORPSrm  : PSI<0x56, MRMSrcMem,
770                     (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
771                     "orps {$src2, $dst|$dst, $src2}",
772                     [(set VR128:$dst, (or (bc_v2i64 (v4f32 VR128:$src1)),
773                                        (memopv2i64 addr:$src2)))]>;
774   def XORPSrm : PSI<0x57, MRMSrcMem,
775                     (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
776                     "xorps {$src2, $dst|$dst, $src2}",
777                     [(set VR128:$dst, (xor (bc_v2i64 (v4f32 VR128:$src1)),
778                                        (memopv2i64 addr:$src2)))]>;
779   def ANDNPSrr : PSI<0x55, MRMSrcReg,
780                      (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
781                      "andnps {$src2, $dst|$dst, $src2}",
782                      [(set VR128:$dst,
783                        (v2i64 (and (xor VR128:$src1,
784                                     (bc_v2i64 (v4i32 immAllOnesV))),
785                                VR128:$src2)))]>;
786   def ANDNPSrm : PSI<0x55, MRMSrcMem,
787                      (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
788                      "andnps {$src2, $dst|$dst, $src2}",
789                      [(set VR128:$dst,
790                        (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
791                                     (bc_v2i64 (v4i32 immAllOnesV))),
792                                (memopv2i64 addr:$src2))))]>;
793 }
794
795 let isTwoAddress = 1 in {
796   def CMPPSrri : PSIi8<0xC2, MRMSrcReg, 
797                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
798                       "cmp${cc}ps {$src, $dst|$dst, $src}",
799                       [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
800                                          VR128:$src, imm:$cc))]>;
801   def CMPPSrmi : PSIi8<0xC2, MRMSrcMem, 
802                       (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
803                       "cmp${cc}ps {$src, $dst|$dst, $src}",
804                       [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
805                                          (load addr:$src), imm:$cc))]>;
806 }
807
808 // Shuffle and unpack instructions
809 let isTwoAddress = 1 in {
810   let isConvertibleToThreeAddress = 1 in // Convert to pshufd
811     def SHUFPSrri : PSIi8<0xC6, MRMSrcReg, 
812                           (outs VR128:$dst), (ins VR128:$src1,
813                            VR128:$src2, i32i8imm:$src3),
814                           "shufps {$src3, $src2, $dst|$dst, $src2, $src3}",
815                           [(set VR128:$dst,
816                             (v4f32 (vector_shuffle
817                                     VR128:$src1, VR128:$src2,
818                                     SHUFP_shuffle_mask:$src3)))]>;
819   def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem, 
820                         (outs VR128:$dst), (ins VR128:$src1,
821                          f128mem:$src2, i32i8imm:$src3),
822                         "shufps {$src3, $src2, $dst|$dst, $src2, $src3}",
823                         [(set VR128:$dst,
824                           (v4f32 (vector_shuffle
825                                   VR128:$src1, (load addr:$src2),
826                                   SHUFP_shuffle_mask:$src3)))]>;
827
828   let AddedComplexity = 10 in {
829     def UNPCKHPSrr : PSI<0x15, MRMSrcReg, 
830                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
831                          "unpckhps {$src2, $dst|$dst, $src2}",
832                          [(set VR128:$dst,
833                            (v4f32 (vector_shuffle
834                                    VR128:$src1, VR128:$src2,
835                                    UNPCKH_shuffle_mask)))]>;
836     def UNPCKHPSrm : PSI<0x15, MRMSrcMem, 
837                          (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
838                          "unpckhps {$src2, $dst|$dst, $src2}",
839                          [(set VR128:$dst,
840                            (v4f32 (vector_shuffle
841                                    VR128:$src1, (load addr:$src2),
842                                    UNPCKH_shuffle_mask)))]>;
843
844     def UNPCKLPSrr : PSI<0x14, MRMSrcReg, 
845                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
846                          "unpcklps {$src2, $dst|$dst, $src2}",
847                          [(set VR128:$dst,
848                            (v4f32 (vector_shuffle
849                                    VR128:$src1, VR128:$src2,
850                                    UNPCKL_shuffle_mask)))]>;
851     def UNPCKLPSrm : PSI<0x14, MRMSrcMem, 
852                          (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
853                          "unpcklps {$src2, $dst|$dst, $src2}",
854                          [(set VR128:$dst,
855                            (v4f32 (vector_shuffle
856                                    VR128:$src1, (load addr:$src2),
857                                    UNPCKL_shuffle_mask)))]>;
858   } // AddedComplexity
859 } // isTwoAddress
860
861 // Mask creation
862 def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
863                      "movmskps {$src, $dst|$dst, $src}",
864                      [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
865 def MOVMSKPDrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
866                      "movmskpd {$src, $dst|$dst, $src}",
867                      [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
868
869 // Prefetching loads.
870 // TODO: no intrinsics for these?
871 def PREFETCHT0   : PSI<0x18, MRM1m, (outs), (ins i8mem:$src), "prefetcht0 $src", []>;
872 def PREFETCHT1   : PSI<0x18, MRM2m, (outs), (ins i8mem:$src), "prefetcht1 $src", []>;
873 def PREFETCHT2   : PSI<0x18, MRM3m, (outs), (ins i8mem:$src), "prefetcht2 $src", []>;
874 def PREFETCHNTA  : PSI<0x18, MRM0m, (outs), (ins i8mem:$src), "prefetchnta $src", []>;
875
876 // Non-temporal stores
877 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
878                     "movntps {$src, $dst|$dst, $src}",
879                     [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
880
881 // Load, store, and memory fence
882 def SFENCE : PSI<0xAE, MRM7m, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>;
883
884 // MXCSR register
885 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
886                   "ldmxcsr $src", [(int_x86_sse_ldmxcsr addr:$src)]>;
887 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
888                   "stmxcsr $dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
889
890 // Alias instructions that map zero vector to pxor / xorp* for sse.
891 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
892 let isReMaterializable = 1 in
893 def V_SET0 : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins),
894                  "xorps $dst, $dst",
895                  [(set VR128:$dst, (v4f32 immAllZerosV))]>;
896
897 // FR32 to 128-bit vector conversion.
898 def MOVSS2PSrr : SSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR32:$src),
899                       "movss {$src, $dst|$dst, $src}",
900                       [(set VR128:$dst,
901                         (v4f32 (scalar_to_vector FR32:$src)))]>;
902 def MOVSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
903                      "movss {$src, $dst|$dst, $src}",
904                      [(set VR128:$dst,
905                        (v4f32 (scalar_to_vector (loadf32 addr:$src))))]>;
906
907 // FIXME: may not be able to eliminate this movss with coalescing the src and
908 // dest register classes are different. We really want to write this pattern
909 // like this:
910 // def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
911 //           (f32 FR32:$src)>;
912 def MOVPS2SSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins VR128:$src),
913                      "movss {$src, $dst|$dst, $src}",
914                      [(set FR32:$dst, (vector_extract (v4f32 VR128:$src),
915                                        (iPTR 0)))]>;
916 def MOVPS2SSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
917                      "movss {$src, $dst|$dst, $src}",
918                      [(store (f32 (vector_extract (v4f32 VR128:$src),
919                                    (iPTR 0))), addr:$dst)]>;
920
921
922 // Move to lower bits of a VR128, leaving upper bits alone.
923 // Three operand (but two address) aliases.
924 let isTwoAddress = 1 in {
925   def MOVLSS2PSrr : SSI<0x10, MRMSrcReg,
926                         (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
927                         "movss {$src2, $dst|$dst, $src2}", []>;
928
929   let AddedComplexity = 15 in
930     def MOVLPSrr : SSI<0x10, MRMSrcReg,
931                        (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
932                        "movss {$src2, $dst|$dst, $src2}",
933                        [(set VR128:$dst,
934                          (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
935                                  MOVL_shuffle_mask)))]>;
936 }
937
938 // Move to lower bits of a VR128 and zeroing upper bits.
939 // Loading from memory automatically zeroing upper bits.
940 let AddedComplexity = 20 in
941 def MOVZSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
942                       "movss {$src, $dst|$dst, $src}",
943                       [(set VR128:$dst, (v4f32 (vector_shuffle immAllZerosV,
944                                  (v4f32 (scalar_to_vector (loadf32 addr:$src))),
945                                                 MOVL_shuffle_mask)))]>;
946
947
948 //===----------------------------------------------------------------------===//
949 // SSE2 Instructions
950 //===----------------------------------------------------------------------===//
951
952 // SSE2 Instruction Templates:
953 // 
954 //   SDI   - SSE2 instructions with XD prefix.
955 //   PDI   - SSE2 instructions with TB and OpSize prefixes.
956 //   PDIi8 - SSE2 instructions with ImmT == Imm8 and TB and OpSize prefixes.
957
958 class SDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
959       : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
960 class PDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
961       : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
962 class PDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
963             list<dag> pattern>
964       : Ii8<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
965
966 // Move Instructions
967 def MOVSDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
968                   "movsd {$src, $dst|$dst, $src}", []>;
969 def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
970                   "movsd {$src, $dst|$dst, $src}",
971                   [(set FR64:$dst, (loadf64 addr:$src))]>;
972 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
973                   "movsd {$src, $dst|$dst, $src}",
974                   [(store FR64:$src, addr:$dst)]>;
975
976 // Conversion instructions
977 def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
978                       "cvttsd2si {$src, $dst|$dst, $src}",
979                       [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
980 def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
981                       "cvttsd2si {$src, $dst|$dst, $src}",
982                       [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
983 def CVTSD2SSrr  : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
984                       "cvtsd2ss {$src, $dst|$dst, $src}",
985                       [(set FR32:$dst, (fround FR64:$src))]>;
986 def CVTSD2SSrm  : SDI<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src), 
987                       "cvtsd2ss {$src, $dst|$dst, $src}",
988                       [(set FR32:$dst, (fround (loadf64 addr:$src)))]>;
989 def CVTSI2SDrr  : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
990                       "cvtsi2sd {$src, $dst|$dst, $src}",
991                       [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
992 def CVTSI2SDrm  : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
993                       "cvtsi2sd {$src, $dst|$dst, $src}",
994                       [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
995
996 // SSE2 instructions with XS prefix
997 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
998                    "cvtss2sd {$src, $dst|$dst, $src}",
999                    [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1000                  Requires<[HasSSE2]>;
1001 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
1002                    "cvtss2sd {$src, $dst|$dst, $src}",
1003                    [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1004                  Requires<[HasSSE2]>;
1005
1006 // Match intrinsics which expect XMM operand(s).
1007 def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1008                          "cvtsd2si {$src, $dst|$dst, $src}",
1009                          [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
1010 def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
1011                          "cvtsd2si {$src, $dst|$dst, $src}",
1012                          [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1013                                            (load addr:$src)))]>;
1014
1015 // Aliases for intrinsics
1016 def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1017                           "cvttsd2si {$src, $dst|$dst, $src}",
1018                           [(set GR32:$dst,
1019                             (int_x86_sse2_cvttsd2si VR128:$src))]>;
1020 def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
1021                           "cvttsd2si {$src, $dst|$dst, $src}",
1022                           [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1023                                             (load addr:$src)))]>;
1024
1025 // Comparison instructions
1026 let isTwoAddress = 1 in {
1027   def CMPSDrr : SDI<0xC2, MRMSrcReg, 
1028                     (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
1029                     "cmp${cc}sd {$src, $dst|$dst, $src}", []>;
1030   def CMPSDrm : SDI<0xC2, MRMSrcMem, 
1031                     (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
1032                     "cmp${cc}sd {$src, $dst|$dst, $src}", []>;
1033 }
1034
1035 def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
1036                    "ucomisd {$src2, $src1|$src1, $src2}",
1037                    [(X86cmp FR64:$src1, FR64:$src2)]>;
1038 def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
1039                    "ucomisd {$src2, $src1|$src1, $src2}",
1040                    [(X86cmp FR64:$src1, (loadf64 addr:$src2))]>;
1041
1042 // Aliases to match intrinsics which expect XMM operand(s).
1043 let isTwoAddress = 1 in {
1044   def Int_CMPSDrr : SDI<0xC2, MRMSrcReg, 
1045                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1046                         "cmp${cc}sd {$src, $dst|$dst, $src}",
1047                         [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1048                                            VR128:$src, imm:$cc))]>;
1049   def Int_CMPSDrm : SDI<0xC2, MRMSrcMem, 
1050                         (outs VR128:$dst), (ins VR128:$src1, f64mem:$src, SSECC:$cc),
1051                         "cmp${cc}sd {$src, $dst|$dst, $src}",
1052                         [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1053                                            (load addr:$src), imm:$cc))]>;
1054 }
1055
1056 def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1057                        "ucomisd {$src2, $src1|$src1, $src2}",
1058                        [(X86ucomi (v2f64 VR128:$src1), (v2f64 VR128:$src2))]>;
1059 def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1060                        "ucomisd {$src2, $src1|$src1, $src2}",
1061                        [(X86ucomi (v2f64 VR128:$src1), (load addr:$src2))]>;
1062
1063 def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1064                       "comisd {$src2, $src1|$src1, $src2}",
1065                       [(X86comi (v2f64 VR128:$src1), (v2f64 VR128:$src2))]>;
1066 def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1067                       "comisd {$src2, $src1|$src1, $src2}",
1068                       [(X86comi (v2f64 VR128:$src1), (load addr:$src2))]>;
1069
1070 // Aliases of packed SSE2 instructions for scalar use. These all have names that
1071 // start with 'Fs'.
1072
1073 // Alias instructions that map fld0 to pxor for sse.
1074 def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins),
1075                  "pxor $dst, $dst", [(set FR64:$dst, fpimm0)]>,
1076                Requires<[HasSSE2]>, TB, OpSize;
1077
1078 // Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
1079 // disregarded.
1080 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1081                      "movapd {$src, $dst|$dst, $src}", []>;
1082
1083 // Alias instruction to load FR64 from f128mem using movapd. Upper bits are
1084 // disregarded.
1085 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1086                      "movapd {$src, $dst|$dst, $src}",
1087                      [(set FR64:$dst, (X86loadpf64 addr:$src))]>;
1088
1089 // Alias bitwise logical operations using SSE logical ops on packed FP values.
1090 let isTwoAddress = 1 in {
1091 let isCommutable = 1 in {
1092   def FsANDPDrr : PDI<0x54, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1093                       "andpd {$src2, $dst|$dst, $src2}",
1094                       [(set FR64:$dst, (X86fand FR64:$src1, FR64:$src2))]>;
1095   def FsORPDrr  : PDI<0x56, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1096                       "orpd {$src2, $dst|$dst, $src2}",
1097                       [(set FR64:$dst, (X86for FR64:$src1, FR64:$src2))]>;
1098   def FsXORPDrr : PDI<0x57, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1099                       "xorpd {$src2, $dst|$dst, $src2}",
1100                       [(set FR64:$dst, (X86fxor FR64:$src1, FR64:$src2))]>;
1101 }
1102
1103 def FsANDPDrm : PDI<0x54, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
1104                     "andpd {$src2, $dst|$dst, $src2}",
1105                     [(set FR64:$dst, (X86fand FR64:$src1,
1106                                       (X86loadpf64 addr:$src2)))]>;
1107 def FsORPDrm  : PDI<0x56, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
1108                     "orpd {$src2, $dst|$dst, $src2}",
1109                     [(set FR64:$dst, (X86for FR64:$src1,
1110                                       (X86loadpf64 addr:$src2)))]>;
1111 def FsXORPDrm : PDI<0x57, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
1112                     "xorpd {$src2, $dst|$dst, $src2}",
1113                     [(set FR64:$dst, (X86fxor FR64:$src1,
1114                                       (X86loadpf64 addr:$src2)))]>;
1115
1116 def FsANDNPDrr : PDI<0x55, MRMSrcReg,
1117                      (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1118                      "andnpd {$src2, $dst|$dst, $src2}", []>;
1119 def FsANDNPDrm : PDI<0x55, MRMSrcMem,
1120                      (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
1121                      "andnpd {$src2, $dst|$dst, $src2}", []>;
1122 }
1123
1124 /// basic_sse2_fp_binop_rm - SSE2 binops come in both scalar and vector forms.
1125 ///
1126 /// In addition, we also have a special variant of the scalar form here to
1127 /// represent the associated intrinsic operation.  This form is unlike the
1128 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
1129 /// and leaves the top elements undefined.
1130 ///
1131 /// These three forms can each be reg+reg or reg+mem, so there are a total of
1132 /// six "instructions".
1133 ///
1134 let isTwoAddress = 1 in {
1135 multiclass basic_sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1136                                   SDNode OpNode, Intrinsic F64Int,
1137                                   bit Commutable = 0> {
1138   // Scalar operation, reg+reg.
1139   def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1140                  !strconcat(OpcodeStr, "sd {$src2, $dst|$dst, $src2}"),
1141                  [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1142     let isCommutable = Commutable;
1143   }
1144
1145   // Scalar operation, reg+mem.
1146   def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
1147                  !strconcat(OpcodeStr, "sd {$src2, $dst|$dst, $src2}"),
1148                  [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1149                  
1150   // Vector operation, reg+reg.
1151   def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1152                !strconcat(OpcodeStr, "pd {$src2, $dst|$dst, $src2}"),
1153                [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1154     let isCommutable = Commutable;
1155   }
1156
1157   // Vector operation, reg+mem.
1158   def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1159                  !strconcat(OpcodeStr, "pd {$src2, $dst|$dst, $src2}"),
1160                  [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
1161
1162   // Intrinsic operation, reg+reg.
1163   def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1164                      !strconcat(OpcodeStr, "sd {$src2, $dst|$dst, $src2}"),
1165                      [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1166     let isCommutable = Commutable;
1167   }
1168
1169   // Intrinsic operation, reg+mem.
1170   def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
1171                      !strconcat(OpcodeStr, "sd {$src2, $dst|$dst, $src2}"),
1172                      [(set VR128:$dst, (F64Int VR128:$src1,
1173                                                sse_load_f64:$src2))]>;
1174 }
1175 }
1176
1177 // Arithmetic instructions
1178 defm ADD : basic_sse2_fp_binop_rm<0x58, "add", fadd, int_x86_sse2_add_sd, 1>;
1179 defm MUL : basic_sse2_fp_binop_rm<0x59, "mul", fmul, int_x86_sse2_mul_sd, 1>;
1180 defm SUB : basic_sse2_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse2_sub_sd>;
1181 defm DIV : basic_sse2_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse2_div_sd>;
1182
1183 /// sse2_fp_binop_rm - Other SSE2 binops
1184 ///
1185 /// This multiclass is like basic_sse2_fp_binop_rm, with the addition of
1186 /// instructions for a full-vector intrinsic form.  Operations that map
1187 /// onto C operators don't use this form since they just use the plain
1188 /// vector form instead of having a separate vector intrinsic form.
1189 ///
1190 /// This provides a total of eight "instructions".
1191 ///
1192 let isTwoAddress = 1 in {
1193 multiclass sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1194                             SDNode OpNode,
1195                             Intrinsic F64Int,
1196                             Intrinsic V2F64Int,
1197                             bit Commutable = 0> {
1198
1199   // Scalar operation, reg+reg.
1200   def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1201                  !strconcat(OpcodeStr, "sd {$src2, $dst|$dst, $src2}"),
1202                  [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1203     let isCommutable = Commutable;
1204   }
1205
1206   // Scalar operation, reg+mem.
1207   def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
1208                  !strconcat(OpcodeStr, "sd {$src2, $dst|$dst, $src2}"),
1209                  [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1210                  
1211   // Vector operation, reg+reg.
1212   def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1213                !strconcat(OpcodeStr, "pd {$src2, $dst|$dst, $src2}"),
1214                [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1215     let isCommutable = Commutable;
1216   }
1217
1218   // Vector operation, reg+mem.
1219   def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1220                  !strconcat(OpcodeStr, "pd {$src2, $dst|$dst, $src2}"),
1221                  [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
1222
1223   // Intrinsic operation, reg+reg.
1224   def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1225                      !strconcat(OpcodeStr, "sd {$src2, $dst|$dst, $src2}"),
1226                      [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1227     let isCommutable = Commutable;
1228   }
1229
1230   // Intrinsic operation, reg+mem.
1231   def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
1232                      !strconcat(OpcodeStr, "sd {$src2, $dst|$dst, $src2}"),
1233                      [(set VR128:$dst, (F64Int VR128:$src1,
1234                                                sse_load_f64:$src2))]>;
1235
1236   // Vector intrinsic operation, reg+reg.
1237   def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1238                      !strconcat(OpcodeStr, "pd {$src2, $dst|$dst, $src2}"),
1239                      [(set VR128:$dst, (V2F64Int VR128:$src1, VR128:$src2))]> {
1240     let isCommutable = Commutable;
1241   }
1242
1243   // Vector intrinsic operation, reg+mem.
1244   def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1245                      !strconcat(OpcodeStr, "pd {$src2, $dst|$dst, $src2}"),
1246                      [(set VR128:$dst, (V2F64Int VR128:$src1, (load addr:$src2)))]>;
1247 }
1248 }
1249
1250 defm MAX : sse2_fp_binop_rm<0x5F, "max", X86fmax,
1251                             int_x86_sse2_max_sd, int_x86_sse2_max_pd>;
1252 defm MIN : sse2_fp_binop_rm<0x5D, "min", X86fmin,
1253                             int_x86_sse2_min_sd, int_x86_sse2_min_pd>;
1254
1255 //===----------------------------------------------------------------------===//
1256 // SSE packed FP Instructions
1257
1258 // Move Instructions
1259 def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1260                    "movapd {$src, $dst|$dst, $src}", []>;
1261 def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1262                    "movapd {$src, $dst|$dst, $src}",
1263                    [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
1264
1265 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1266                    "movapd {$src, $dst|$dst, $src}",
1267                    [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
1268
1269 def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1270                    "movupd {$src, $dst|$dst, $src}", []>;
1271 def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1272                    "movupd {$src, $dst|$dst, $src}",
1273                    [(set VR128:$dst, (loadv2f64 addr:$src))]>;
1274 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1275                    "movupd {$src, $dst|$dst, $src}",
1276                    [(store (v2f64 VR128:$src), addr:$dst)]>;
1277
1278 // Intrinsic forms of MOVUPD load and store
1279 def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1280                        "movupd {$src, $dst|$dst, $src}",
1281                        [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
1282 def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1283                        "movupd {$src, $dst|$dst, $src}",
1284                        [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
1285
1286 let isTwoAddress = 1 in {
1287   let AddedComplexity = 20 in {
1288     def MOVLPDrm : PDI<0x12, MRMSrcMem,
1289                        (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1290                        "movlpd {$src2, $dst|$dst, $src2}",
1291                        [(set VR128:$dst, 
1292                          (v2f64 (vector_shuffle VR128:$src1,
1293                                  (scalar_to_vector (loadf64 addr:$src2)),
1294                                  MOVLP_shuffle_mask)))]>;
1295     def MOVHPDrm : PDI<0x16, MRMSrcMem,
1296                        (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1297                        "movhpd {$src2, $dst|$dst, $src2}",
1298                        [(set VR128:$dst, 
1299                          (v2f64 (vector_shuffle VR128:$src1,
1300                                  (scalar_to_vector (loadf64 addr:$src2)),
1301                                  MOVHP_shuffle_mask)))]>;
1302   } // AddedComplexity
1303 } // isTwoAddress
1304
1305 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1306                    "movlpd {$src, $dst|$dst, $src}",
1307                    [(store (f64 (vector_extract (v2f64 VR128:$src),
1308                                  (iPTR 0))), addr:$dst)]>;
1309
1310 // v2f64 extract element 1 is always custom lowered to unpack high to low
1311 // and extract element 0 so the non-store version isn't too horrible.
1312 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1313                    "movhpd {$src, $dst|$dst, $src}",
1314                    [(store (f64 (vector_extract
1315                                  (v2f64 (vector_shuffle VR128:$src, (undef),
1316                                          UNPCKH_shuffle_mask)), (iPTR 0))),
1317                      addr:$dst)]>;
1318
1319 // SSE2 instructions without OpSize prefix
1320 def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1321                        "cvtdq2ps {$src, $dst|$dst, $src}",
1322                        [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1323                      TB, Requires<[HasSSE2]>;
1324 def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1325                        "cvtdq2ps {$src, $dst|$dst, $src}",
1326                        [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1327                                          (bitconvert (memopv2i64 addr:$src))))]>,
1328                      TB, Requires<[HasSSE2]>;
1329
1330 // SSE2 instructions with XS prefix
1331 def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1332                        "cvtdq2pd {$src, $dst|$dst, $src}",
1333                        [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1334                      XS, Requires<[HasSSE2]>;
1335 def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1336                        "cvtdq2pd {$src, $dst|$dst, $src}",
1337                        [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1338                                           (bitconvert (memopv2i64 addr:$src))))]>,
1339                      XS, Requires<[HasSSE2]>;
1340
1341 def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1342                          "cvtps2dq {$src, $dst|$dst, $src}",
1343                          [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
1344 def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1345                          "cvtps2dq {$src, $dst|$dst, $src}",
1346                          [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1347                                             (load addr:$src)))]>;
1348 // SSE2 packed instructions with XS prefix
1349 def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1350                         "cvttps2dq {$src, $dst|$dst, $src}",
1351                         [(set VR128:$dst, (int_x86_sse2_cvttps2dq VR128:$src))]>,
1352                       XS, Requires<[HasSSE2]>;
1353 def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1354                         "cvttps2dq {$src, $dst|$dst, $src}",
1355                         [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1356                                            (load addr:$src)))]>,
1357                       XS, Requires<[HasSSE2]>;
1358
1359 // SSE2 packed instructions with XD prefix
1360 def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1361                        "cvtpd2dq {$src, $dst|$dst, $src}",
1362                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1363                      XD, Requires<[HasSSE2]>;
1364 def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1365                        "cvtpd2dq {$src, $dst|$dst, $src}",
1366                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1367                                           (load addr:$src)))]>,
1368                      XD, Requires<[HasSSE2]>;
1369
1370 def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1371                           "cvttpd2dq {$src, $dst|$dst, $src}",
1372                        [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
1373 def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1374                           "cvttpd2dq {$src, $dst|$dst, $src}",
1375                           [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1376                                              (load addr:$src)))]>;
1377
1378 // SSE2 instructions without OpSize prefix
1379 def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1380                        "cvtps2pd {$src, $dst|$dst, $src}",
1381                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1382                      TB, Requires<[HasSSE2]>;
1383 def Int_CVTPS2PDrm : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f64mem:$src),
1384                        "cvtps2pd {$src, $dst|$dst, $src}",
1385                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1386                                           (load addr:$src)))]>,
1387                      TB, Requires<[HasSSE2]>;
1388
1389 def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1390                          "cvtpd2ps {$src, $dst|$dst, $src}",
1391                         [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
1392 def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f128mem:$src),
1393                          "cvtpd2ps {$src, $dst|$dst, $src}",
1394                          [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1395                                             (load addr:$src)))]>;
1396
1397 // Match intrinsics which expect XMM operand(s).
1398 // Aliases for intrinsics
1399 let isTwoAddress = 1 in {
1400 def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
1401                         (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
1402                         "cvtsi2sd {$src2, $dst|$dst, $src2}",
1403                         [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1404                                            GR32:$src2))]>;
1405 def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
1406                         (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
1407                         "cvtsi2sd {$src2, $dst|$dst, $src2}",
1408                         [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1409                                            (loadi32 addr:$src2)))]>;
1410 def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
1411                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1412                    "cvtsd2ss {$src2, $dst|$dst, $src2}",
1413                    [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1414                                       VR128:$src2))]>;
1415 def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
1416                         (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2), 
1417                    "cvtsd2ss {$src2, $dst|$dst, $src2}",
1418                    [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1419                                       (load addr:$src2)))]>;
1420 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
1421                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1422                     "cvtss2sd {$src2, $dst|$dst, $src2}",
1423                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1424                                        VR128:$src2))]>, XS,
1425                     Requires<[HasSSE2]>;
1426 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
1427                       (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
1428                     "cvtss2sd {$src2, $dst|$dst, $src2}",
1429                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1430                                        (load addr:$src2)))]>, XS,
1431                     Requires<[HasSSE2]>;
1432 }
1433
1434 // Arithmetic
1435
1436 /// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1437 ///
1438 /// In addition, we also have a special variant of the scalar form here to
1439 /// represent the associated intrinsic operation.  This form is unlike the
1440 /// plain scalar form, in that it takes an entire vector (instead of a
1441 /// scalar) and leaves the top elements undefined.
1442 ///
1443 /// And, we have a special variant form for a full-vector intrinsic form.
1444 ///
1445 /// These four forms can each have a reg or a mem operand, so there are a
1446 /// total of eight "instructions".
1447 ///
1448 multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1449                            SDNode OpNode,
1450                            Intrinsic F64Int,
1451                            Intrinsic V2F64Int,
1452                            bit Commutable = 0> {
1453   // Scalar operation, reg.
1454   def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1455                 !strconcat(OpcodeStr, "sd {$src, $dst|$dst, $src}"),
1456                 [(set FR64:$dst, (OpNode FR64:$src))]> {
1457     let isCommutable = Commutable;
1458   }
1459
1460   // Scalar operation, mem.
1461   def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1462                 !strconcat(OpcodeStr, "sd {$src, $dst|$dst, $src}"),
1463                 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1464                  
1465   // Vector operation, reg.
1466   def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1467               !strconcat(OpcodeStr, "pd {$src, $dst|$dst, $src}"),
1468               [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1469     let isCommutable = Commutable;
1470   }
1471
1472   // Vector operation, mem.
1473   def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1474                 !strconcat(OpcodeStr, "pd {$src, $dst|$dst, $src}"),
1475                 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
1476
1477   // Intrinsic operation, reg.
1478   def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1479                     !strconcat(OpcodeStr, "sd {$src, $dst|$dst, $src}"),
1480                     [(set VR128:$dst, (F64Int VR128:$src))]> {
1481     let isCommutable = Commutable;
1482   }
1483
1484   // Intrinsic operation, mem.
1485   def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1486                     !strconcat(OpcodeStr, "sd {$src, $dst|$dst, $src}"),
1487                     [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1488
1489   // Vector intrinsic operation, reg
1490   def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1491                     !strconcat(OpcodeStr, "pd {$src, $dst|$dst, $src}"),
1492                     [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1493     let isCommutable = Commutable;
1494   }
1495
1496   // Vector intrinsic operation, mem
1497   def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1498                     !strconcat(OpcodeStr, "pd {$src, $dst|$dst, $src}"),
1499                     [(set VR128:$dst, (V2F64Int (load addr:$src)))]>;
1500 }
1501
1502 // Square root.
1503 defm SQRT  : sse2_fp_unop_rm<0x51, "sqrt",  fsqrt,
1504                              int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1505
1506 // There is no f64 version of the reciprocal approximation instructions.
1507
1508 // Logical
1509 let isTwoAddress = 1 in {
1510   let isCommutable = 1 in {
1511     def ANDPDrr : PDI<0x54, MRMSrcReg,
1512                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1513                       "andpd {$src2, $dst|$dst, $src2}",
1514                       [(set VR128:$dst,
1515                         (and (bc_v2i64 (v2f64 VR128:$src1)),
1516                          (bc_v2i64 (v2f64 VR128:$src2))))]>;
1517     def ORPDrr  : PDI<0x56, MRMSrcReg,
1518                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1519                       "orpd {$src2, $dst|$dst, $src2}",
1520                       [(set VR128:$dst,
1521                         (or (bc_v2i64 (v2f64 VR128:$src1)),
1522                          (bc_v2i64 (v2f64 VR128:$src2))))]>;
1523     def XORPDrr : PDI<0x57, MRMSrcReg,
1524                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1525                       "xorpd {$src2, $dst|$dst, $src2}",
1526                       [(set VR128:$dst,
1527                         (xor (bc_v2i64 (v2f64 VR128:$src1)),
1528                          (bc_v2i64 (v2f64 VR128:$src2))))]>;
1529   }
1530
1531   def ANDPDrm : PDI<0x54, MRMSrcMem,
1532                     (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1533                     "andpd {$src2, $dst|$dst, $src2}",
1534                     [(set VR128:$dst,
1535                       (and (bc_v2i64 (v2f64 VR128:$src1)),
1536                        (memopv2i64 addr:$src2)))]>;
1537   def ORPDrm  : PDI<0x56, MRMSrcMem,
1538                     (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1539                     "orpd {$src2, $dst|$dst, $src2}",
1540                     [(set VR128:$dst,
1541                       (or (bc_v2i64 (v2f64 VR128:$src1)),
1542                        (memopv2i64 addr:$src2)))]>;
1543   def XORPDrm : PDI<0x57, MRMSrcMem,
1544                     (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1545                     "xorpd {$src2, $dst|$dst, $src2}",
1546                     [(set VR128:$dst,
1547                       (xor (bc_v2i64 (v2f64 VR128:$src1)),
1548                        (memopv2i64 addr:$src2)))]>;
1549   def ANDNPDrr : PDI<0x55, MRMSrcReg,
1550                      (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1551                      "andnpd {$src2, $dst|$dst, $src2}",
1552                      [(set VR128:$dst,
1553                        (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1554                         (bc_v2i64 (v2f64 VR128:$src2))))]>;
1555   def ANDNPDrm : PDI<0x55, MRMSrcMem,
1556                      (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
1557                      "andnpd {$src2, $dst|$dst, $src2}",
1558                      [(set VR128:$dst,
1559                        (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1560                         (memopv2i64 addr:$src2)))]>;
1561 }
1562
1563 let isTwoAddress = 1 in {
1564   def CMPPDrri : PDIi8<0xC2, MRMSrcReg, 
1565                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1566                       "cmp${cc}pd {$src, $dst|$dst, $src}",
1567                       [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1568                                          VR128:$src, imm:$cc))]>;
1569   def CMPPDrmi : PDIi8<0xC2, MRMSrcMem, 
1570                       (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1571                       "cmp${cc}pd {$src, $dst|$dst, $src}",
1572                       [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1573                                          (load addr:$src), imm:$cc))]>;
1574 }
1575
1576 // Shuffle and unpack instructions
1577 let isTwoAddress = 1 in {
1578   def SHUFPDrri : PDIi8<0xC6, MRMSrcReg, 
1579                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1580                         "shufpd {$src3, $src2, $dst|$dst, $src2, $src3}",
1581                         [(set VR128:$dst, (v2f64 (vector_shuffle
1582                                                   VR128:$src1, VR128:$src2,
1583                                                   SHUFP_shuffle_mask:$src3)))]>;
1584   def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem, 
1585                         (outs VR128:$dst), (ins VR128:$src1,
1586                          f128mem:$src2, i8imm:$src3),
1587                         "shufpd {$src3, $src2, $dst|$dst, $src2, $src3}",
1588                         [(set VR128:$dst,
1589                           (v2f64 (vector_shuffle
1590                                   VR128:$src1, (load addr:$src2),
1591                                   SHUFP_shuffle_mask:$src3)))]>;
1592
1593   let AddedComplexity = 10 in {
1594     def UNPCKHPDrr : PDI<0x15, MRMSrcReg, 
1595                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1596                          "unpckhpd {$src2, $dst|$dst, $src2}",
1597                          [(set VR128:$dst,
1598                            (v2f64 (vector_shuffle
1599                                    VR128:$src1, VR128:$src2,
1600                                    UNPCKH_shuffle_mask)))]>;
1601     def UNPCKHPDrm : PDI<0x15, MRMSrcMem, 
1602                          (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1603                          "unpckhpd {$src2, $dst|$dst, $src2}",
1604                          [(set VR128:$dst,
1605                            (v2f64 (vector_shuffle
1606                                    VR128:$src1, (load addr:$src2),
1607                                    UNPCKH_shuffle_mask)))]>;
1608
1609     def UNPCKLPDrr : PDI<0x14, MRMSrcReg, 
1610                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1611                          "unpcklpd {$src2, $dst|$dst, $src2}",
1612                          [(set VR128:$dst,
1613                            (v2f64 (vector_shuffle
1614                                    VR128:$src1, VR128:$src2,
1615                                    UNPCKL_shuffle_mask)))]>;
1616     def UNPCKLPDrm : PDI<0x14, MRMSrcMem, 
1617                          (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1618                          "unpcklpd {$src2, $dst|$dst, $src2}",
1619                          [(set VR128:$dst,
1620                            (v2f64 (vector_shuffle
1621                                    VR128:$src1, (load addr:$src2),
1622                                    UNPCKL_shuffle_mask)))]>;
1623   } // AddedComplexity
1624 } // isTwoAddress
1625
1626
1627 //===----------------------------------------------------------------------===//
1628 // SSE integer instructions
1629
1630 // Move Instructions
1631 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1632                    "movdqa {$src, $dst|$dst, $src}", []>;
1633 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1634                    "movdqa {$src, $dst|$dst, $src}",
1635                    [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
1636 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1637                    "movdqa {$src, $dst|$dst, $src}",
1638                    [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
1639 def MOVDQUrm :   I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1640                    "movdqu {$src, $dst|$dst, $src}",
1641                    [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
1642                  XS, Requires<[HasSSE2]>;
1643 def MOVDQUmr :   I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1644                    "movdqu {$src, $dst|$dst, $src}",
1645                    [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
1646                  XS, Requires<[HasSSE2]>;
1647
1648 // Intrinsic forms of MOVDQU load and store
1649 def MOVDQUrm_Int :   I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1650                        "movdqu {$src, $dst|$dst, $src}",
1651                        [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1652                  XS, Requires<[HasSSE2]>;
1653 def MOVDQUmr_Int :   I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1654                        "movdqu {$src, $dst|$dst, $src}",
1655                        [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1656                      XS, Requires<[HasSSE2]>;
1657
1658 let isTwoAddress = 1 in {
1659
1660 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1661                             bit Commutable = 0> {
1662   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1663                !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
1664                [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1665     let isCommutable = Commutable;
1666   }
1667   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1668                !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
1669                [(set VR128:$dst, (IntId VR128:$src1,
1670                                         (bitconvert (memopv2i64 addr:$src2))))]>;
1671 }
1672
1673 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1674                              string OpcodeStr, Intrinsic IntId> {
1675   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1676                !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
1677                [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
1678   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1679                !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
1680                [(set VR128:$dst, (IntId VR128:$src1,
1681                                         (bitconvert (memopv2i64 addr:$src2))))]>;
1682   def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
1683                !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
1684                [(set VR128:$dst, (IntId VR128:$src1,
1685                                         (scalar_to_vector (i32 imm:$src2))))]>;
1686 }
1687
1688
1689 /// PDI_binop_rm - Simple SSE2 binary operator.
1690 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1691                         ValueType OpVT, bit Commutable = 0> {
1692   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1693                !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
1694                [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1695     let isCommutable = Commutable;
1696   }
1697   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1698                !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
1699                [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
1700                                        (bitconvert (memopv2i64 addr:$src2)))))]>;
1701 }
1702
1703 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1704 ///
1705 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1706 /// to collapse (bitconvert VT to VT) into its operand.
1707 ///
1708 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1709                               bit Commutable = 0> {
1710   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1711                !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
1712                [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1713     let isCommutable = Commutable;
1714   }
1715   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1716                !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
1717                [(set VR128:$dst, (OpNode VR128:$src1,(memopv2i64 addr:$src2)))]>;
1718 }
1719
1720 } // isTwoAddress
1721
1722 // 128-bit Integer Arithmetic
1723
1724 defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1725 defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1726 defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1727 defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1728
1729 defm PADDSB  : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1730 defm PADDSW  : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1731 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1732 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1733
1734 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1735 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1736 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1737 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1738
1739 defm PSUBSB  : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1740 defm PSUBSW  : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1741 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1742 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1743
1744 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1745
1746 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1747 defm PMULHW  : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1748 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1749
1750 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1751
1752 defm PAVGB  : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1753 defm PAVGW  : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1754
1755
1756 defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1757 defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1758 defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1759 defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
1760 defm PSADBW : PDI_binop_rm_int<0xE0, "psadbw", int_x86_sse2_psad_bw, 1>;
1761
1762
1763 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw", int_x86_sse2_psll_w>;
1764 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld", int_x86_sse2_psll_d>;
1765 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq", int_x86_sse2_psll_q>;
1766
1767 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw", int_x86_sse2_psrl_w>;
1768 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld", int_x86_sse2_psrl_d>;
1769 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq", int_x86_sse2_psrl_q>;
1770
1771 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw", int_x86_sse2_psra_w>;
1772 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad", int_x86_sse2_psra_d>;
1773 // PSRAQ doesn't exist in SSE[1-3].
1774
1775 // 128-bit logical shifts.
1776 let isTwoAddress = 1 in {
1777   def PSLLDQri : PDIi8<0x73, MRM7r,
1778                        (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
1779                        "pslldq {$src2, $dst|$dst, $src2}", []>;
1780   def PSRLDQri : PDIi8<0x73, MRM3r,
1781                        (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
1782                        "psrldq {$src2, $dst|$dst, $src2}", []>;
1783   // PSRADQri doesn't exist in SSE[1-3].
1784 }
1785
1786 let Predicates = [HasSSE2] in {
1787   def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
1788             (v2i64 (PSLLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1789   def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
1790             (v2i64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1791   def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
1792             (v2f64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1793 }
1794
1795 // Logical
1796 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
1797 defm POR  : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
1798 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
1799
1800 let isTwoAddress = 1 in {
1801   def PANDNrr : PDI<0xDF, MRMSrcReg,
1802                     (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1803                     "pandn {$src2, $dst|$dst, $src2}",
1804                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
1805                                               VR128:$src2)))]>;
1806
1807   def PANDNrm : PDI<0xDF, MRMSrcMem,
1808                     (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1809                     "pandn {$src2, $dst|$dst, $src2}",
1810                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
1811                                               (load addr:$src2))))]>;
1812 }
1813
1814 // SSE2 Integer comparison
1815 defm PCMPEQB  : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
1816 defm PCMPEQW  : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
1817 defm PCMPEQD  : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
1818 defm PCMPGTB  : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
1819 defm PCMPGTW  : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
1820 defm PCMPGTD  : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
1821
1822 // Pack instructions
1823 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
1824 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
1825 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
1826
1827 // Shuffle and unpack instructions
1828 def PSHUFDri : PDIi8<0x70, MRMSrcReg,
1829                      (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
1830                      "pshufd {$src2, $src1, $dst|$dst, $src1, $src2}",
1831                      [(set VR128:$dst, (v4i32 (vector_shuffle
1832                                                VR128:$src1, (undef),
1833                                                PSHUFD_shuffle_mask:$src2)))]>;
1834 def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
1835                      (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
1836                      "pshufd {$src2, $src1, $dst|$dst, $src1, $src2}",
1837                      [(set VR128:$dst, (v4i32 (vector_shuffle
1838                                                (bc_v4i32(memopv2i64 addr:$src1)),
1839                                                (undef),
1840                                                PSHUFD_shuffle_mask:$src2)))]>;
1841
1842 // SSE2 with ImmT == Imm8 and XS prefix.
1843 def PSHUFHWri : Ii8<0x70, MRMSrcReg,
1844                     (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
1845                     "pshufhw {$src2, $src1, $dst|$dst, $src1, $src2}",
1846                     [(set VR128:$dst, (v8i16 (vector_shuffle
1847                                               VR128:$src1, (undef),
1848                                               PSHUFHW_shuffle_mask:$src2)))]>,
1849                 XS, Requires<[HasSSE2]>;
1850 def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
1851                     (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
1852                     "pshufhw {$src2, $src1, $dst|$dst, $src1, $src2}",
1853                     [(set VR128:$dst, (v8i16 (vector_shuffle
1854                                               (bc_v8i16 (memopv2i64 addr:$src1)),
1855                                               (undef),
1856                                               PSHUFHW_shuffle_mask:$src2)))]>,
1857                 XS, Requires<[HasSSE2]>;
1858
1859 // SSE2 with ImmT == Imm8 and XD prefix.
1860 def PSHUFLWri : Ii8<0x70, MRMSrcReg,
1861                     (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
1862                     "pshuflw {$src2, $src1, $dst|$dst, $src1, $src2}",
1863                     [(set VR128:$dst, (v8i16 (vector_shuffle
1864                                               VR128:$src1, (undef),
1865                                               PSHUFLW_shuffle_mask:$src2)))]>,
1866                 XD, Requires<[HasSSE2]>;
1867 def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
1868                     (outs VR128:$dst), (ins i128mem:$src1, i32i8imm:$src2),
1869                     "pshuflw {$src2, $src1, $dst|$dst, $src1, $src2}",
1870                     [(set VR128:$dst, (v8i16 (vector_shuffle
1871                                               (bc_v8i16 (memopv2i64 addr:$src1)),
1872                                               (undef),
1873                                               PSHUFLW_shuffle_mask:$src2)))]>,
1874                 XD, Requires<[HasSSE2]>;
1875
1876
1877 let isTwoAddress = 1 in {
1878   def PUNPCKLBWrr : PDI<0x60, MRMSrcReg, 
1879                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1880                         "punpcklbw {$src2, $dst|$dst, $src2}",
1881                         [(set VR128:$dst,
1882                           (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
1883                                   UNPCKL_shuffle_mask)))]>;
1884   def PUNPCKLBWrm : PDI<0x60, MRMSrcMem, 
1885                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1886                         "punpcklbw {$src2, $dst|$dst, $src2}",
1887                         [(set VR128:$dst,
1888                           (v16i8 (vector_shuffle VR128:$src1,
1889                                   (bc_v16i8 (memopv2i64 addr:$src2)),
1890                                   UNPCKL_shuffle_mask)))]>;
1891   def PUNPCKLWDrr : PDI<0x61, MRMSrcReg, 
1892                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1893                         "punpcklwd {$src2, $dst|$dst, $src2}",
1894                         [(set VR128:$dst,
1895                           (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
1896                                   UNPCKL_shuffle_mask)))]>;
1897   def PUNPCKLWDrm : PDI<0x61, MRMSrcMem, 
1898                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1899                         "punpcklwd {$src2, $dst|$dst, $src2}",
1900                         [(set VR128:$dst,
1901                           (v8i16 (vector_shuffle VR128:$src1,
1902                                   (bc_v8i16 (memopv2i64 addr:$src2)),
1903                                   UNPCKL_shuffle_mask)))]>;
1904   def PUNPCKLDQrr : PDI<0x62, MRMSrcReg, 
1905                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1906                         "punpckldq {$src2, $dst|$dst, $src2}",
1907                         [(set VR128:$dst,
1908                           (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
1909                                   UNPCKL_shuffle_mask)))]>;
1910   def PUNPCKLDQrm : PDI<0x62, MRMSrcMem, 
1911                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1912                         "punpckldq {$src2, $dst|$dst, $src2}",
1913                         [(set VR128:$dst,
1914                           (v4i32 (vector_shuffle VR128:$src1,
1915                                   (bc_v4i32 (memopv2i64 addr:$src2)),
1916                                   UNPCKL_shuffle_mask)))]>;
1917   def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg, 
1918                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1919                          "punpcklqdq {$src2, $dst|$dst, $src2}",
1920                         [(set VR128:$dst,
1921                           (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
1922                                   UNPCKL_shuffle_mask)))]>;
1923   def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem, 
1924                          (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1925                          "punpcklqdq {$src2, $dst|$dst, $src2}",
1926                         [(set VR128:$dst,
1927                           (v2i64 (vector_shuffle VR128:$src1,
1928                                   (memopv2i64 addr:$src2),
1929                                   UNPCKL_shuffle_mask)))]>;
1930   
1931   def PUNPCKHBWrr : PDI<0x68, MRMSrcReg, 
1932                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1933                         "punpckhbw {$src2, $dst|$dst, $src2}",
1934                         [(set VR128:$dst,
1935                           (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
1936                                   UNPCKH_shuffle_mask)))]>;
1937   def PUNPCKHBWrm : PDI<0x68, MRMSrcMem, 
1938                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1939                         "punpckhbw {$src2, $dst|$dst, $src2}",
1940                         [(set VR128:$dst,
1941                           (v16i8 (vector_shuffle VR128:$src1,
1942                                   (bc_v16i8 (memopv2i64 addr:$src2)),
1943                                   UNPCKH_shuffle_mask)))]>;
1944   def PUNPCKHWDrr : PDI<0x69, MRMSrcReg, 
1945                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1946                         "punpckhwd {$src2, $dst|$dst, $src2}",
1947                         [(set VR128:$dst,
1948                           (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
1949                                   UNPCKH_shuffle_mask)))]>;
1950   def PUNPCKHWDrm : PDI<0x69, MRMSrcMem, 
1951                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1952                         "punpckhwd {$src2, $dst|$dst, $src2}",
1953                         [(set VR128:$dst,
1954                           (v8i16 (vector_shuffle VR128:$src1,
1955                                   (bc_v8i16 (memopv2i64 addr:$src2)),
1956                                   UNPCKH_shuffle_mask)))]>;
1957   def PUNPCKHDQrr : PDI<0x6A, MRMSrcReg, 
1958                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1959                         "punpckhdq {$src2, $dst|$dst, $src2}",
1960                         [(set VR128:$dst,
1961                           (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
1962                                   UNPCKH_shuffle_mask)))]>;
1963   def PUNPCKHDQrm : PDI<0x6A, MRMSrcMem, 
1964                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1965                         "punpckhdq {$src2, $dst|$dst, $src2}",
1966                         [(set VR128:$dst,
1967                           (v4i32 (vector_shuffle VR128:$src1,
1968                                   (bc_v4i32 (memopv2i64 addr:$src2)),
1969                                   UNPCKH_shuffle_mask)))]>;
1970   def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg, 
1971                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1972                          "punpckhqdq {$src2, $dst|$dst, $src2}",
1973                         [(set VR128:$dst,
1974                           (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
1975                                   UNPCKH_shuffle_mask)))]>;
1976   def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem, 
1977                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
1978                         "punpckhqdq {$src2, $dst|$dst, $src2}",
1979                         [(set VR128:$dst,
1980                           (v2i64 (vector_shuffle VR128:$src1,
1981                                   (memopv2i64 addr:$src2),
1982                                   UNPCKH_shuffle_mask)))]>;
1983 }
1984
1985 // Extract / Insert
1986 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
1987                     (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
1988                     "pextrw {$src2, $src1, $dst|$dst, $src1, $src2}",
1989                     [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
1990                                      (iPTR imm:$src2)))]>;
1991 let isTwoAddress = 1 in {
1992   def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
1993                        (outs VR128:$dst), (ins VR128:$src1,
1994                         GR32:$src2, i32i8imm:$src3),
1995                        "pinsrw {$src3, $src2, $dst|$dst, $src2, $src3}",
1996                        [(set VR128:$dst,
1997                          (v8i16 (X86pinsrw (v8i16 VR128:$src1),
1998                                  GR32:$src2, (iPTR imm:$src3))))]>;
1999   def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
2000                        (outs VR128:$dst), (ins VR128:$src1,
2001                         i16mem:$src2, i32i8imm:$src3),
2002                        "pinsrw {$src3, $src2, $dst|$dst, $src2, $src3}",
2003                        [(set VR128:$dst,
2004                          (v8i16 (X86pinsrw (v8i16 VR128:$src1),
2005                                  (i32 (anyext (loadi16 addr:$src2))),
2006                                  (iPTR imm:$src3))))]>;
2007 }
2008
2009 // Mask creation
2010 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2011                      "pmovmskb {$src, $dst|$dst, $src}",
2012                      [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2013
2014 // Conditional store
2015 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2016                      "maskmovdqu {$mask, $src|$src, $mask}",
2017                      [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>,
2018                  Imp<[EDI],[]>;
2019
2020 // Non-temporal stores
2021 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2022                     "movntpd {$src, $dst|$dst, $src}",
2023                     [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
2024 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2025                     "movntdq {$src, $dst|$dst, $src}",
2026                     [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2027 def MOVNTImr  :   I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2028                     "movnti {$src, $dst|$dst, $src}",
2029                     [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>, 
2030                   TB, Requires<[HasSSE2]>;
2031
2032 // Flush cache
2033 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
2034                "clflush $src", [(int_x86_sse2_clflush addr:$src)]>,
2035               TB, Requires<[HasSSE2]>;
2036
2037 // Load, store, and memory fence
2038 def LFENCE : I<0xAE, MRM5m, (outs), (ins),
2039                "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
2040 def MFENCE : I<0xAE, MRM6m, (outs), (ins),
2041                "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2042
2043
2044 // Alias instructions that map zero vector to pxor / xorp* for sse.
2045 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
2046 let isReMaterializable = 1 in
2047   def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins),
2048                          "pcmpeqd $dst, $dst",
2049                          [(set VR128:$dst, (v2f64 immAllOnesV))]>;
2050
2051 // FR64 to 128-bit vector conversion.
2052 def MOVSD2PDrr : SDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR64:$src),
2053                       "movsd {$src, $dst|$dst, $src}",
2054                       [(set VR128:$dst,
2055                         (v2f64 (scalar_to_vector FR64:$src)))]>;
2056 def MOVSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2057                      "movsd {$src, $dst|$dst, $src}",
2058                      [(set VR128:$dst, 
2059                        (v2f64 (scalar_to_vector (loadf64 addr:$src))))]>;
2060
2061 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2062                       "movd {$src, $dst|$dst, $src}",
2063                       [(set VR128:$dst,
2064                         (v4i32 (scalar_to_vector GR32:$src)))]>;
2065 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2066                       "movd {$src, $dst|$dst, $src}",
2067                       [(set VR128:$dst,
2068                         (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2069
2070 def MOVDI2SSrr  : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2071                       "movd {$src, $dst|$dst, $src}",
2072                       [(set FR32:$dst, (bitconvert GR32:$src))]>;
2073
2074 def MOVDI2SSrm  : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2075                       "movd {$src, $dst|$dst, $src}",
2076                       [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2077
2078 // SSE2 instructions with XS prefix
2079 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2080                     "movq {$src, $dst|$dst, $src}",
2081                     [(set VR128:$dst,
2082                       (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2083                   Requires<[HasSSE2]>;
2084 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2085                       "movq {$src, $dst|$dst, $src}",
2086                       [(store (i64 (vector_extract (v2i64 VR128:$src),
2087                                     (iPTR 0))), addr:$dst)]>;
2088
2089 // FIXME: may not be able to eliminate this movss with coalescing the src and
2090 // dest register classes are different. We really want to write this pattern
2091 // like this:
2092 // def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2093 //           (f32 FR32:$src)>;
2094 def MOVPD2SDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins VR128:$src),
2095                      "movsd {$src, $dst|$dst, $src}",
2096                      [(set FR64:$dst, (vector_extract (v2f64 VR128:$src),
2097                                        (iPTR 0)))]>;
2098 def MOVPD2SDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
2099                      "movsd {$src, $dst|$dst, $src}",
2100                      [(store (f64 (vector_extract (v2f64 VR128:$src),
2101                                    (iPTR 0))), addr:$dst)]>;
2102 def MOVPDI2DIrr  : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2103                        "movd {$src, $dst|$dst, $src}",
2104                        [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2105                                         (iPTR 0)))]>;
2106 def MOVPDI2DImr  : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
2107                        "movd {$src, $dst|$dst, $src}",
2108                        [(store (i32 (vector_extract (v4i32 VR128:$src),
2109                                      (iPTR 0))), addr:$dst)]>;
2110
2111 def MOVSS2DIrr  : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2112                       "movd {$src, $dst|$dst, $src}",
2113                       [(set GR32:$dst, (bitconvert FR32:$src))]>;
2114 def MOVSS2DImr  : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2115                       "movd {$src, $dst|$dst, $src}",
2116                       [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2117
2118
2119 // Move to lower bits of a VR128, leaving upper bits alone.
2120 // Three operand (but two address) aliases.
2121 let isTwoAddress = 1 in {
2122   def MOVLSD2PDrr : SDI<0x10, MRMSrcReg,
2123                         (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
2124                         "movsd {$src2, $dst|$dst, $src2}", []>;
2125
2126   let AddedComplexity = 15 in
2127     def MOVLPDrr : SDI<0x10, MRMSrcReg,
2128                        (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2129                        "movsd {$src2, $dst|$dst, $src2}",
2130                        [(set VR128:$dst,
2131                          (v2f64 (vector_shuffle VR128:$src1, VR128:$src2,
2132                                  MOVL_shuffle_mask)))]>;
2133 }
2134
2135 // Store / copy lower 64-bits of a XMM register.
2136 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2137                      "movq {$src, $dst|$dst, $src}",
2138                      [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2139
2140 // Move to lower bits of a VR128 and zeroing upper bits.
2141 // Loading from memory automatically zeroing upper bits.
2142 let AddedComplexity = 20 in
2143   def MOVZSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2144                         "movsd {$src, $dst|$dst, $src}",
2145                         [(set VR128:$dst,
2146                           (v2f64 (vector_shuffle immAllZerosV,
2147                                   (v2f64 (scalar_to_vector
2148                                           (loadf64 addr:$src))),
2149                                   MOVL_shuffle_mask)))]>;
2150
2151 let AddedComplexity = 15 in
2152 // movd / movq to XMM register zero-extends
2153 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2154                        "movd {$src, $dst|$dst, $src}",
2155                        [(set VR128:$dst,
2156                          (v4i32 (vector_shuffle immAllZerosV,
2157                                  (v4i32 (scalar_to_vector GR32:$src)),
2158                                  MOVL_shuffle_mask)))]>;
2159 let AddedComplexity = 20 in
2160 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2161                        "movd {$src, $dst|$dst, $src}",
2162                        [(set VR128:$dst,
2163                          (v4i32 (vector_shuffle immAllZerosV,
2164                                  (v4i32 (scalar_to_vector (loadi32 addr:$src))),
2165                                  MOVL_shuffle_mask)))]>;
2166
2167 // Moving from XMM to XMM but still clear upper 64 bits.
2168 let AddedComplexity = 15 in
2169 def MOVZQI2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2170                      "movq {$src, $dst|$dst, $src}",
2171                      [(set VR128:$dst, (int_x86_sse2_movl_dq VR128:$src))]>,
2172                    XS, Requires<[HasSSE2]>;
2173 let AddedComplexity = 20 in
2174 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2175                      "movq {$src, $dst|$dst, $src}",
2176                      [(set VR128:$dst, (int_x86_sse2_movl_dq
2177                                         (bitconvert (memopv2i64 addr:$src))))]>,
2178                    XS, Requires<[HasSSE2]>;
2179
2180
2181 //===----------------------------------------------------------------------===//
2182 // SSE3 Instructions
2183 //===----------------------------------------------------------------------===//
2184
2185 // SSE3 Instruction Templates:
2186 // 
2187 //   S3I   - SSE3 instructions with TB and OpSize prefixes.
2188 //   S3SI  - SSE3 instructions with XS prefix.
2189 //   S3DI  - SSE3 instructions with XD prefix.
2190
2191 class S3SI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
2192       : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE3]>;
2193 class S3DI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
2194       : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE3]>;
2195 class S3I<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
2196       : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE3]>;
2197
2198 // Move Instructions
2199 def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2200                       "movshdup {$src, $dst|$dst, $src}",
2201                       [(set VR128:$dst, (v4f32 (vector_shuffle
2202                                                 VR128:$src, (undef),
2203                                                 MOVSHDUP_shuffle_mask)))]>;
2204 def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2205                       "movshdup {$src, $dst|$dst, $src}",
2206                       [(set VR128:$dst, (v4f32 (vector_shuffle
2207                                                 (memopv4f32 addr:$src), (undef),
2208                                                 MOVSHDUP_shuffle_mask)))]>;
2209
2210 def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2211                       "movsldup {$src, $dst|$dst, $src}",
2212                       [(set VR128:$dst, (v4f32 (vector_shuffle
2213                                                 VR128:$src, (undef),
2214                                                 MOVSLDUP_shuffle_mask)))]>;
2215 def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2216                       "movsldup {$src, $dst|$dst, $src}",
2217                       [(set VR128:$dst, (v4f32 (vector_shuffle
2218                                                 (memopv4f32 addr:$src), (undef),
2219                                                 MOVSLDUP_shuffle_mask)))]>;
2220
2221 def MOVDDUPrr  : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2222                       "movddup {$src, $dst|$dst, $src}",
2223                       [(set VR128:$dst, (v2f64 (vector_shuffle
2224                                                 VR128:$src, (undef),
2225                                                 SSE_splat_lo_mask)))]>;
2226 def MOVDDUPrm  : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2227                       "movddup {$src, $dst|$dst, $src}",
2228                       [(set VR128:$dst,
2229                         (v2f64 (vector_shuffle
2230                                 (scalar_to_vector (loadf64 addr:$src)),
2231                                 (undef),
2232                                 SSE_splat_lo_mask)))]>;
2233
2234 // Arithmetic
2235 let isTwoAddress = 1 in {
2236   def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
2237                         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2238                         "addsubps {$src2, $dst|$dst, $src2}",
2239                         [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2240                                            VR128:$src2))]>;
2241   def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
2242                         (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2243                         "addsubps {$src2, $dst|$dst, $src2}",
2244                         [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2245                                            (load addr:$src2)))]>;
2246   def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
2247                        (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2248                        "addsubpd {$src2, $dst|$dst, $src2}",
2249                        [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2250                                           VR128:$src2))]>;
2251   def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
2252                        (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2253                        "addsubpd {$src2, $dst|$dst, $src2}",
2254                        [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2255                                           (load addr:$src2)))]>;
2256 }
2257
2258 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2259                    "lddqu {$src, $dst|$dst, $src}",
2260                    [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2261
2262 // Horizontal ops
2263 class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2264   : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2265          !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
2266          [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2267 class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2268   : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2269          !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
2270          [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (load addr:$src2))))]>;
2271 class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2272   : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2273         !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
2274         [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2275 class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2276   : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2277         !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
2278         [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (load addr:$src2))))]>;
2279
2280 let isTwoAddress = 1 in {
2281   def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2282   def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2283   def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2284   def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2285   def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2286   def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2287   def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2288   def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2289 }
2290
2291 // Thread synchronization
2292 def MONITOR : I<0xC8, RawFrm, (outs), (ins), "monitor",
2293                 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
2294 def MWAIT   : I<0xC9, RawFrm, (outs), (ins), "mwait",
2295                 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2296
2297 // vector_shuffle v1, <undef> <1, 1, 3, 3>
2298 let AddedComplexity = 15 in
2299 def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2300                   MOVSHDUP_shuffle_mask)),
2301           (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2302 let AddedComplexity = 20 in
2303 def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
2304                   MOVSHDUP_shuffle_mask)),
2305           (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2306
2307 // vector_shuffle v1, <undef> <0, 0, 2, 2>
2308 let AddedComplexity = 15 in
2309   def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2310                     MOVSLDUP_shuffle_mask)),
2311             (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2312 let AddedComplexity = 20 in
2313   def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
2314                     MOVSLDUP_shuffle_mask)),
2315             (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2316
2317 //===----------------------------------------------------------------------===//
2318 // SSSE3 Instructions
2319 //===----------------------------------------------------------------------===//
2320
2321 // SSE3 Instruction Templates:
2322 // 
2323 //   SS38I - SSSE3 instructions with T8 and OpSize prefixes.
2324 //   SS3AI - SSSE3 instructions with TA and OpSize prefixes.
2325
2326 class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
2327             list<dag> pattern>
2328       : I<o, F, outs, ins, asm, pattern>, T8, OpSize, Requires<[HasSSSE3]>;
2329 class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
2330             list<dag> pattern>
2331       : I<o, F, outs, ins, asm, pattern>, TA, OpSize, Requires<[HasSSSE3]>;
2332
2333 /// SS3I_binop_rm_int - Simple SSSE3 binary operatr whose type is v2i64.
2334 let isTwoAddress = 1 in {
2335   multiclass SS3I_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
2336                                bit Commutable = 0> {
2337     def rr : SS38I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2338                    !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
2339                    [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
2340       let isCommutable = Commutable;
2341     }
2342     def rm : SS38I<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2343                    !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
2344                    [(set VR128:$dst,
2345                      (IntId VR128:$src1,
2346                       (bitconvert (memopv2i64 addr:$src2))))]>;
2347   }
2348 }
2349
2350 defm PMULHRSW128 : SS3I_binop_rm_int<0x0B, "pmulhrsw",
2351                                      int_x86_ssse3_pmulhrsw_128, 1>;
2352
2353 //===----------------------------------------------------------------------===//
2354 // Non-Instruction Patterns
2355 //===----------------------------------------------------------------------===//
2356
2357 // 128-bit vector undef's.
2358 def : Pat<(v2f64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2359 def : Pat<(v16i8 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2360 def : Pat<(v8i16 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2361 def : Pat<(v4i32 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2362 def : Pat<(v2i64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2363
2364 // 128-bit vector all zero's.
2365 def : Pat<(v16i8 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2366 def : Pat<(v8i16 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2367 def : Pat<(v4i32 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2368 def : Pat<(v2i64 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2369 def : Pat<(v2f64 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2370
2371 // 128-bit vector all one's.
2372 def : Pat<(v16i8 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2373 def : Pat<(v8i16 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2374 def : Pat<(v4i32 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2375 def : Pat<(v2i64 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2376 def : Pat<(v4f32 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE1]>;
2377
2378
2379 // Scalar to v8i16 / v16i8. The source may be a GR32, but only the lower 8 or
2380 // 16-bits matter.
2381 def : Pat<(v8i16 (X86s2vec GR32:$src)), (MOVDI2PDIrr GR32:$src)>,
2382       Requires<[HasSSE2]>;
2383 def : Pat<(v16i8 (X86s2vec GR32:$src)), (MOVDI2PDIrr GR32:$src)>,
2384       Requires<[HasSSE2]>;
2385
2386 // bit_convert
2387 let Predicates = [HasSSE2] in {
2388   def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2389   def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2390   def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2391   def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2392   def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2393   def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2394   def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2395   def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2396   def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2397   def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2398   def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2399   def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2400   def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2401   def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2402   def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2403   def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2404   def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2405   def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2406   def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2407   def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2408   def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2409   def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2410   def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2411   def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2412   def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2413   def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2414   def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2415   def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2416   def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2417   def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2418 }
2419
2420 // Move scalar to XMM zero-extended
2421 // movd to XMM register zero-extends
2422 let AddedComplexity = 15 in {
2423 def : Pat<(v8i16 (vector_shuffle immAllZerosV,
2424                   (v8i16 (X86s2vec GR32:$src)), MOVL_shuffle_mask)),
2425           (MOVZDI2PDIrr GR32:$src)>, Requires<[HasSSE2]>;
2426 def : Pat<(v16i8 (vector_shuffle immAllZerosV,
2427                   (v16i8 (X86s2vec GR32:$src)), MOVL_shuffle_mask)),
2428           (MOVZDI2PDIrr GR32:$src)>, Requires<[HasSSE2]>;
2429 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
2430 def : Pat<(v2f64 (vector_shuffle immAllZerosV,
2431                   (v2f64 (scalar_to_vector FR64:$src)), MOVL_shuffle_mask)),
2432           (MOVLSD2PDrr (V_SET0), FR64:$src)>, Requires<[HasSSE2]>;
2433 def : Pat<(v4f32 (vector_shuffle immAllZerosV,
2434                   (v4f32 (scalar_to_vector FR32:$src)), MOVL_shuffle_mask)),
2435           (MOVLSS2PSrr (V_SET0), FR32:$src)>, Requires<[HasSSE2]>;
2436 }
2437
2438 // Splat v2f64 / v2i64
2439 let AddedComplexity = 10 in {
2440 def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2441           (UNPCKLPDrr VR128:$src, VR128:$src)>,   Requires<[HasSSE2]>;
2442 def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2443           (UNPCKHPDrr VR128:$src, VR128:$src)>,   Requires<[HasSSE2]>;
2444 def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2445           (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2446 def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2447           (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2448 }
2449
2450 // Splat v4f32
2451 def : Pat<(vector_shuffle (v4f32 VR128:$src), (undef), SSE_splat_mask:$sm),
2452           (SHUFPSrri VR128:$src, VR128:$src, SSE_splat_mask:$sm)>,
2453       Requires<[HasSSE1]>;
2454
2455 // Special unary SHUFPSrri case.
2456 // FIXME: when we want non two-address code, then we should use PSHUFD?
2457 def : Pat<(vector_shuffle (v4f32 VR128:$src1), (undef),
2458            SHUFP_unary_shuffle_mask:$sm),
2459           (SHUFPSrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2460       Requires<[HasSSE1]>;
2461 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
2462 def : Pat<(vector_shuffle (memopv4f32 addr:$src1), (undef),
2463            SHUFP_unary_shuffle_mask:$sm),
2464           (PSHUFDmi addr:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2465       Requires<[HasSSE2]>;
2466 // Special binary v4i32 shuffle cases with SHUFPS.
2467 def : Pat<(vector_shuffle (v4i32 VR128:$src1), (v4i32 VR128:$src2),
2468            PSHUFD_binary_shuffle_mask:$sm),
2469           (SHUFPSrri VR128:$src1, VR128:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2470            Requires<[HasSSE2]>;
2471 def : Pat<(vector_shuffle (v4i32 VR128:$src1),
2472            (bc_v4i32 (memopv2i64 addr:$src2)), PSHUFD_binary_shuffle_mask:$sm),
2473           (SHUFPSrmi VR128:$src1, addr:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2474            Requires<[HasSSE2]>;
2475
2476 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
2477 let AddedComplexity = 10 in {
2478 def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2479                   UNPCKL_v_undef_shuffle_mask)),
2480           (UNPCKLPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2481 def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2482                   UNPCKL_v_undef_shuffle_mask)),
2483           (PUNPCKLBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2484 def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2485                   UNPCKL_v_undef_shuffle_mask)),
2486           (PUNPCKLWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2487 def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2488                   UNPCKL_v_undef_shuffle_mask)),
2489           (PUNPCKLDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2490 }
2491
2492 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
2493 let AddedComplexity = 10 in {
2494 def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2495                   UNPCKH_v_undef_shuffle_mask)),
2496           (UNPCKHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2497 def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2498                   UNPCKH_v_undef_shuffle_mask)),
2499           (PUNPCKHBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2500 def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2501                   UNPCKH_v_undef_shuffle_mask)),
2502           (PUNPCKHWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2503 def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2504                   UNPCKH_v_undef_shuffle_mask)),
2505           (PUNPCKHDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2506 }
2507
2508 let AddedComplexity = 15 in {
2509 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
2510 def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2511                   MOVHP_shuffle_mask)),
2512           (MOVLHPSrr VR128:$src1, VR128:$src2)>;
2513
2514 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
2515 def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2516                   MOVHLPS_shuffle_mask)),
2517           (MOVHLPSrr VR128:$src1, VR128:$src2)>;
2518
2519 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
2520 def : Pat<(v4f32 (vector_shuffle VR128:$src1, (undef),
2521                   MOVHLPS_v_undef_shuffle_mask)),
2522           (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2523 def : Pat<(v4i32 (vector_shuffle VR128:$src1, (undef),
2524                   MOVHLPS_v_undef_shuffle_mask)),
2525           (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2526 }
2527
2528 let AddedComplexity = 20 in {
2529 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
2530 // vector_shuffle v1, (load v2) <0, 1, 4, 5> using MOVHPS
2531 def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
2532                   MOVLP_shuffle_mask)),
2533           (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
2534 def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
2535                   MOVLP_shuffle_mask)),
2536           (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2537 def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
2538                   MOVHP_shuffle_mask)),
2539           (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
2540 def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
2541                   MOVHP_shuffle_mask)),
2542           (MOVHPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2543
2544 def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
2545                   MOVLP_shuffle_mask)),
2546           (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2547 def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
2548                   MOVLP_shuffle_mask)),
2549           (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2550 def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
2551                   MOVHP_shuffle_mask)),
2552           (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
2553 def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
2554                   MOVLP_shuffle_mask)),
2555           (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2556 }
2557
2558 let AddedComplexity = 15 in {
2559 // Setting the lowest element in the vector.
2560 def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2561                   MOVL_shuffle_mask)),
2562           (MOVLPSrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2563 def : Pat<(v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2564                   MOVL_shuffle_mask)),
2565           (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2566
2567 // vector_shuffle v1, v2 <4, 5, 2, 3> using MOVLPDrr (movsd)
2568 def : Pat<(v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
2569                   MOVLP_shuffle_mask)),
2570           (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2571 def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2572                   MOVLP_shuffle_mask)),
2573           (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2574 }
2575
2576 // Set lowest element and zero upper elements.
2577 let AddedComplexity = 20 in
2578 def : Pat<(bc_v2i64 (vector_shuffle immAllZerosV,
2579                      (v2f64 (scalar_to_vector (loadf64 addr:$src))),
2580                      MOVL_shuffle_mask)),
2581           (MOVZQI2PQIrm addr:$src)>, Requires<[HasSSE2]>;
2582
2583 // FIXME: Temporary workaround since 2-wide shuffle is broken.
2584 def : Pat<(int_x86_sse2_movs_d  VR128:$src1, VR128:$src2),
2585           (v2f64 (MOVLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2586 def : Pat<(int_x86_sse2_loadh_pd VR128:$src1, addr:$src2),
2587           (v2f64 (MOVHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2588 def : Pat<(int_x86_sse2_loadl_pd VR128:$src1, addr:$src2),
2589           (v2f64 (MOVLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2590 def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, VR128:$src2, imm:$src3),
2591           (v2f64 (SHUFPDrri VR128:$src1, VR128:$src2, imm:$src3))>,
2592       Requires<[HasSSE2]>;
2593 def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, (load addr:$src2), imm:$src3),
2594           (v2f64 (SHUFPDrmi VR128:$src1, addr:$src2, imm:$src3))>,
2595       Requires<[HasSSE2]>;
2596 def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, VR128:$src2),
2597           (v2f64 (UNPCKHPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2598 def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, (load addr:$src2)),
2599           (v2f64 (UNPCKHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2600 def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, VR128:$src2),
2601           (v2f64 (UNPCKLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2602 def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, (load addr:$src2)),
2603           (v2f64 (UNPCKLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2604 def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, VR128:$src2),
2605           (v2i64 (PUNPCKHQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2606 def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, (load addr:$src2)),
2607           (v2i64 (PUNPCKHQDQrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2608 def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, VR128:$src2),
2609           (v2i64 (PUNPCKLQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2610 def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, (load addr:$src2)),
2611           (PUNPCKLQDQrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2612
2613 // Some special case pandn patterns.
2614 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
2615                   VR128:$src2)),
2616           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2617 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
2618                   VR128:$src2)),
2619           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2620 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
2621                   VR128:$src2)),
2622           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2623
2624 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
2625                   (load addr:$src2))),
2626           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2627 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
2628                   (load addr:$src2))),
2629           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2630 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
2631                   (load addr:$src2))),
2632           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2633
2634 // Unaligned load
2635 def : Pat<(v4f32 (X86loadu addr:$src)), (MOVUPSrm addr:$src)>,
2636       Requires<[HasSSE1]>;
2637
2638 // Use movaps / movups for SSE integer load / store (one byte shorter).
2639 def : Pat<(alignedloadv2i64 addr:$src),
2640           (MOVAPSrm addr:$src)>, Requires<[HasSSE2]>;
2641 def : Pat<(loadv2i64 addr:$src),
2642           (MOVUPSrm addr:$src)>, Requires<[HasSSE2]>;
2643
2644 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
2645           (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2646 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
2647           (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2648 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
2649           (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2650 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
2651           (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2652 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
2653           (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2654 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
2655           (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2656 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
2657           (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2658 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
2659           (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;