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