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