57fa3036b74af8eda5c3e4596b36a5427966d953
[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 scalar FP Instructions
19 //===----------------------------------------------------------------------===//
20
21 // CMOV* - Used to implement the SSE SELECT DAG operation.  Expanded after
22 // instruction selection into a branch sequence.
23 let Uses = [EFLAGS], usesCustomInserter = 1 in {
24   def CMOV_FR32 : I<0, Pseudo,
25                     (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
26                     "#CMOV_FR32 PSEUDO!",
27                     [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
28                                                   EFLAGS))]>;
29   def CMOV_FR64 : I<0, Pseudo,
30                     (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
31                     "#CMOV_FR64 PSEUDO!",
32                     [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
33                                                   EFLAGS))]>;
34   def CMOV_V4F32 : I<0, Pseudo,
35                     (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
36                     "#CMOV_V4F32 PSEUDO!",
37                     [(set VR128:$dst,
38                       (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
39                                           EFLAGS)))]>;
40   def CMOV_V2F64 : I<0, Pseudo,
41                     (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
42                     "#CMOV_V2F64 PSEUDO!",
43                     [(set VR128:$dst,
44                       (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
45                                           EFLAGS)))]>;
46   def CMOV_V2I64 : I<0, Pseudo,
47                     (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
48                     "#CMOV_V2I64 PSEUDO!",
49                     [(set VR128:$dst,
50                       (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
51                                           EFLAGS)))]>;
52 }
53
54 //===----------------------------------------------------------------------===//
55 // SSE 1 & 2 Instructions Classes
56 //===----------------------------------------------------------------------===//
57
58 /// sse12_fp_scalar - SSE 1 & 2 scalar instructions class
59 multiclass sse12_fp_scalar<bits<8> opc, string OpcodeStr, SDNode OpNode,
60                            RegisterClass RC, X86MemOperand x86memop,
61                            bit Is2Addr = 1> {
62   let isCommutable = 1 in {
63     def rr : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
64        !if(Is2Addr,
65            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
66            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
67        [(set RC:$dst, (OpNode RC:$src1, RC:$src2))]>;
68   }
69   def rm : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
70        !if(Is2Addr,
71            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
72            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
73        [(set RC:$dst, (OpNode RC:$src1, (load addr:$src2)))]>;
74 }
75
76 /// sse12_fp_scalar_int - SSE 1 & 2 scalar instructions intrinsics class
77 multiclass sse12_fp_scalar_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
78                              string asm, string SSEVer, string FPSizeStr,
79                              Operand memopr, ComplexPattern mem_cpat,
80                              bit Is2Addr = 1> {
81   def rr_Int : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
82        !if(Is2Addr,
83            !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
84            !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
85        [(set RC:$dst, (!nameconcat<Intrinsic>("int_x86_sse",
86                        !strconcat(SSEVer, !strconcat("_",
87                        !strconcat(OpcodeStr, FPSizeStr))))
88              RC:$src1, RC:$src2))]>;
89   def rm_Int : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, memopr:$src2),
90        !if(Is2Addr,
91            !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
92            !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
93        [(set RC:$dst, (!nameconcat<Intrinsic>("int_x86_sse",
94                        !strconcat(SSEVer, !strconcat("_",
95                        !strconcat(OpcodeStr, FPSizeStr))))
96              RC:$src1, mem_cpat:$src2))]>;
97 }
98
99 /// sse12_fp_packed - SSE 1 & 2 packed instructions class
100 multiclass sse12_fp_packed<bits<8> opc, string OpcodeStr, SDNode OpNode,
101                            RegisterClass RC, ValueType vt,
102                            X86MemOperand x86memop, PatFrag mem_frag,
103                            Domain d, bit Is2Addr = 1> {
104   let isCommutable = 1 in
105     def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
106        !if(Is2Addr,
107            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
108            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
109        [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))], d>;
110   let mayLoad = 1 in
111     def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
112        !if(Is2Addr,
113            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
114            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
115        [(set RC:$dst, (OpNode RC:$src1, (mem_frag addr:$src2)))], d>;
116 }
117
118 /// sse12_fp_packed_logical_rm - SSE 1 & 2 packed instructions class
119 multiclass sse12_fp_packed_logical_rm<bits<8> opc, RegisterClass RC, Domain d,
120                                       string OpcodeStr, X86MemOperand x86memop,
121                                       list<dag> pat_rr, list<dag> pat_rm,
122                                       bit Is2Addr = 1> {
123   let isCommutable = 1 in
124     def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
125        !if(Is2Addr,
126            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
127            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
128        pat_rr, d>;
129   def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
130        !if(Is2Addr,
131            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
132            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
133        pat_rm, d>;
134 }
135
136 /// sse12_fp_packed_int - SSE 1 & 2 packed instructions intrinsics class
137 multiclass sse12_fp_packed_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
138                            string asm, string SSEVer, string FPSizeStr,
139                            X86MemOperand x86memop, PatFrag mem_frag,
140                            Domain d, bit Is2Addr = 1> {
141   def rr_Int : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
142        !if(Is2Addr,
143            !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
144            !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
145            [(set RC:$dst, (!nameconcat<Intrinsic>("int_x86_sse",
146                            !strconcat(SSEVer, !strconcat("_",
147                            !strconcat(OpcodeStr, FPSizeStr))))
148                  RC:$src1, RC:$src2))], d>;
149   def rm_Int : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1,x86memop:$src2),
150        !if(Is2Addr,
151            !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
152            !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
153        [(set RC:$dst, (!nameconcat<Intrinsic>("int_x86_sse",
154                        !strconcat(SSEVer, !strconcat("_",
155                        !strconcat(OpcodeStr, FPSizeStr))))
156              RC:$src1, (mem_frag addr:$src2)))], d>;
157 }
158
159 //===----------------------------------------------------------------------===//
160 // SSE 1 & 2 - Move Instructions
161 //===----------------------------------------------------------------------===//
162
163 class sse12_move_rr<RegisterClass RC, ValueType vt, string asm> :
164       SI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, RC:$src2), asm,
165       [(set (vt VR128:$dst), (movl VR128:$src1, (scalar_to_vector RC:$src2)))]>;
166
167 // Loading from memory automatically zeroing upper bits.
168 class sse12_move_rm<RegisterClass RC, X86MemOperand x86memop,
169                     PatFrag mem_pat, string OpcodeStr> :
170       SI<0x10, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
171          !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
172                         [(set RC:$dst, (mem_pat addr:$src))]>;
173
174 // Move Instructions. Register-to-register movss/movsd is not used for FR32/64
175 // register copies because it's a partial register update; FsMOVAPSrr/FsMOVAPDrr
176 // is used instead. Register-to-register movss/movsd is not modeled as an
177 // INSERT_SUBREG because INSERT_SUBREG requires that the insert be implementable
178 // in terms of a copy, and just mentioned, we don't use movss/movsd for copies.
179 let isAsmParserOnly = 1 in {
180   def VMOVSSrr : sse12_move_rr<FR32, v4f32,
181                   "movss\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XS, VEX_4V;
182   def VMOVSDrr : sse12_move_rr<FR64, v2f64,
183                   "movsd\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XD, VEX_4V;
184
185   let canFoldAsLoad = 1, isReMaterializable = 1 in {
186     def VMOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS, VEX;
187
188     let AddedComplexity = 20 in
189       def VMOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD, VEX;
190   }
191 }
192
193 let Constraints = "$src1 = $dst" in {
194   def MOVSSrr : sse12_move_rr<FR32, v4f32,
195                           "movss\t{$src2, $dst|$dst, $src2}">, XS;
196   def MOVSDrr : sse12_move_rr<FR64, v2f64,
197                           "movsd\t{$src2, $dst|$dst, $src2}">, XD;
198 }
199
200 let canFoldAsLoad = 1, isReMaterializable = 1 in {
201   def MOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS;
202
203   let AddedComplexity = 20 in
204     def MOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD;
205 }
206
207 let AddedComplexity = 15 in {
208 // Extract the low 32-bit value from one vector and insert it into another.
209 def : Pat<(v4f32 (movl VR128:$src1, VR128:$src2)),
210           (MOVSSrr (v4f32 VR128:$src1),
211                    (EXTRACT_SUBREG (v4f32 VR128:$src2), sub_ss))>;
212 // Extract the low 64-bit value from one vector and insert it into another.
213 def : Pat<(v2f64 (movl VR128:$src1, VR128:$src2)),
214           (MOVSDrr (v2f64 VR128:$src1),
215                    (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
216 }
217
218 // Implicitly promote a 32-bit scalar to a vector.
219 def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
220           (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss)>;
221 // Implicitly promote a 64-bit scalar to a vector.
222 def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
223           (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
224
225 let AddedComplexity = 20 in {
226 // MOVSSrm zeros the high parts of the register; represent this
227 // with SUBREG_TO_REG.
228 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
229           (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
230 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
231           (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
232 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
233           (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
234 // MOVSDrm zeros the high parts of the register; represent this
235 // with SUBREG_TO_REG.
236 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
237           (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
238 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
239           (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
240 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
241           (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
242 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
243           (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
244 def : Pat<(v2f64 (X86vzload addr:$src)),
245           (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
246 }
247
248 // Store scalar value to memory.
249 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
250                   "movss\t{$src, $dst|$dst, $src}",
251                   [(store FR32:$src, addr:$dst)]>;
252 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
253                   "movsd\t{$src, $dst|$dst, $src}",
254                   [(store FR64:$src, addr:$dst)]>;
255
256 let isAsmParserOnly = 1 in {
257 def VMOVSSmr : SI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
258                   "movss\t{$src, $dst|$dst, $src}",
259                   [(store FR32:$src, addr:$dst)]>, XS, VEX_4V;
260 def VMOVSDmr : SI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
261                   "movsd\t{$src, $dst|$dst, $src}",
262                   [(store FR64:$src, addr:$dst)]>, XD, VEX_4V;
263 }
264
265 // Extract and store.
266 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
267                  addr:$dst),
268           (MOVSSmr addr:$dst,
269                    (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
270 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
271                  addr:$dst),
272           (MOVSDmr addr:$dst,
273                    (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
274
275 // Move Aligned/Unaligned floating point values
276 multiclass sse12_mov_packed<bits<8> opc, RegisterClass RC,
277                             X86MemOperand x86memop, PatFrag ld_frag,
278                             string asm, Domain d,
279                             bit IsReMaterializable = 1> {
280 let neverHasSideEffects = 1 in
281   def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src),
282               !strconcat(asm, "\t{$src, $dst|$dst, $src}"), [], d>;
283 let canFoldAsLoad = 1, isReMaterializable = IsReMaterializable in
284   def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
285               !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
286                    [(set RC:$dst, (ld_frag addr:$src))], d>;
287 }
288
289 let isAsmParserOnly = 1 in {
290 defm VMOVAPS : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv4f32,
291                               "movaps", SSEPackedSingle>, VEX;
292 defm VMOVAPD : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv2f64,
293                               "movapd", SSEPackedDouble>, OpSize, VEX;
294 defm VMOVUPS : sse12_mov_packed<0x10, VR128, f128mem, loadv4f32,
295                               "movups", SSEPackedSingle>, VEX;
296 defm VMOVUPD : sse12_mov_packed<0x10, VR128, f128mem, loadv2f64,
297                               "movupd", SSEPackedDouble, 0>, OpSize, VEX;
298
299 defm VMOVAPSY : sse12_mov_packed<0x28, VR256, f256mem, alignedloadv8f32,
300                               "movaps", SSEPackedSingle>, VEX;
301 defm VMOVAPDY : sse12_mov_packed<0x28, VR256, f256mem, alignedloadv4f64,
302                               "movapd", SSEPackedDouble>, OpSize, VEX;
303 defm VMOVUPSY : sse12_mov_packed<0x10, VR256, f256mem, loadv8f32,
304                               "movups", SSEPackedSingle>, VEX;
305 defm VMOVUPDY : sse12_mov_packed<0x10, VR256, f256mem, loadv4f64,
306                               "movupd", SSEPackedDouble, 0>, OpSize, VEX;
307 }
308 defm MOVAPS : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv4f32,
309                               "movaps", SSEPackedSingle>, TB;
310 defm MOVAPD : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv2f64,
311                               "movapd", SSEPackedDouble>, TB, OpSize;
312 defm MOVUPS : sse12_mov_packed<0x10, VR128, f128mem, loadv4f32,
313                               "movups", SSEPackedSingle>, TB;
314 defm MOVUPD : sse12_mov_packed<0x10, VR128, f128mem, loadv2f64,
315                               "movupd", SSEPackedDouble, 0>, TB, OpSize;
316
317 let isAsmParserOnly = 1 in {
318 def VMOVAPSmr : VPSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
319                    "movaps\t{$src, $dst|$dst, $src}",
320                    [(alignedstore (v4f32 VR128:$src), addr:$dst)]>, VEX;
321 def VMOVAPDmr : VPDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
322                    "movapd\t{$src, $dst|$dst, $src}",
323                    [(alignedstore (v2f64 VR128:$src), addr:$dst)]>, VEX;
324 def VMOVUPSmr : VPSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
325                    "movups\t{$src, $dst|$dst, $src}",
326                    [(store (v4f32 VR128:$src), addr:$dst)]>, VEX;
327 def VMOVUPDmr : VPDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
328                    "movupd\t{$src, $dst|$dst, $src}",
329                    [(store (v2f64 VR128:$src), addr:$dst)]>, VEX;
330 def VMOVAPSYmr : VPSI<0x29, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
331                    "movaps\t{$src, $dst|$dst, $src}",
332                    [(alignedstore (v8f32 VR256:$src), addr:$dst)]>, VEX;
333 def VMOVAPDYmr : VPDI<0x29, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
334                    "movapd\t{$src, $dst|$dst, $src}",
335                    [(alignedstore (v4f64 VR256:$src), addr:$dst)]>, VEX;
336 def VMOVUPSYmr : VPSI<0x11, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
337                    "movups\t{$src, $dst|$dst, $src}",
338                    [(store (v8f32 VR256:$src), addr:$dst)]>, VEX;
339 def VMOVUPDYmr : VPDI<0x11, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
340                    "movupd\t{$src, $dst|$dst, $src}",
341                    [(store (v4f64 VR256:$src), addr:$dst)]>, VEX;
342 }
343 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
344                    "movaps\t{$src, $dst|$dst, $src}",
345                    [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
346 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
347                    "movapd\t{$src, $dst|$dst, $src}",
348                    [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
349 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
350                    "movups\t{$src, $dst|$dst, $src}",
351                    [(store (v4f32 VR128:$src), addr:$dst)]>;
352 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
353                    "movupd\t{$src, $dst|$dst, $src}",
354                    [(store (v2f64 VR128:$src), addr:$dst)]>;
355
356 // Intrinsic forms of MOVUPS/D load and store
357 let isAsmParserOnly = 1 in {
358   let canFoldAsLoad = 1, isReMaterializable = 1 in
359   def VMOVUPSrm_Int : VPSI<0x10, MRMSrcMem, (outs VR128:$dst),
360              (ins f128mem:$src),
361              "movups\t{$src, $dst|$dst, $src}",
362              [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>, VEX;
363   def VMOVUPDrm_Int : VPDI<0x10, MRMSrcMem, (outs VR128:$dst),
364              (ins f128mem:$src),
365              "movupd\t{$src, $dst|$dst, $src}",
366              [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>, VEX;
367   def VMOVUPSmr_Int : VPSI<0x11, MRMDestMem, (outs),
368              (ins f128mem:$dst, VR128:$src),
369              "movups\t{$src, $dst|$dst, $src}",
370              [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>, VEX;
371   def VMOVUPDmr_Int : VPDI<0x11, MRMDestMem, (outs),
372              (ins f128mem:$dst, VR128:$src),
373              "movupd\t{$src, $dst|$dst, $src}",
374              [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>, VEX;
375 }
376 let canFoldAsLoad = 1, isReMaterializable = 1 in
377 def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
378                        "movups\t{$src, $dst|$dst, $src}",
379                        [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
380 def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
381                        "movupd\t{$src, $dst|$dst, $src}",
382                        [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
383
384 def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
385                        "movups\t{$src, $dst|$dst, $src}",
386                        [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
387 def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
388                        "movupd\t{$src, $dst|$dst, $src}",
389                        [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
390
391 // Move Low/High packed floating point values
392 multiclass sse12_mov_hilo_packed<bits<8>opc, RegisterClass RC,
393                                  PatFrag mov_frag, string base_opc,
394                                  string asm_opr> {
395   def PSrm : PI<opc, MRMSrcMem,
396          (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
397          !strconcat(!strconcat(base_opc,"s"), asm_opr),
398      [(set RC:$dst,
399        (mov_frag RC:$src1,
400               (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))],
401               SSEPackedSingle>, TB;
402
403   def PDrm : PI<opc, MRMSrcMem,
404          (outs RC:$dst), (ins RC:$src1, f64mem:$src2),
405          !strconcat(!strconcat(base_opc,"d"), asm_opr),
406      [(set RC:$dst, (v2f64 (mov_frag RC:$src1,
407                               (scalar_to_vector (loadf64 addr:$src2)))))],
408               SSEPackedDouble>, TB, OpSize;
409 }
410
411 let isAsmParserOnly = 1, AddedComplexity = 20 in {
412   defm VMOVL : sse12_mov_hilo_packed<0x12, VR128, movlp, "movlp",
413                      "\t{$src2, $src1, $dst|$dst, $src1, $src2}">, VEX_4V;
414   defm VMOVH : sse12_mov_hilo_packed<0x16, VR128, movlhps, "movhp",
415                      "\t{$src2, $src1, $dst|$dst, $src1, $src2}">, VEX_4V;
416 }
417 let Constraints = "$src1 = $dst", AddedComplexity = 20 in {
418   defm MOVL : sse12_mov_hilo_packed<0x12, VR128, movlp, "movlp",
419                                    "\t{$src2, $dst|$dst, $src2}">;
420   defm MOVH : sse12_mov_hilo_packed<0x16, VR128, movlhps, "movhp",
421                                    "\t{$src2, $dst|$dst, $src2}">;
422 }
423
424 let isAsmParserOnly = 1 in {
425 def VMOVLPSmr : VPSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
426                    "movlps\t{$src, $dst|$dst, $src}",
427                    [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
428                                  (iPTR 0))), addr:$dst)]>, VEX;
429 def VMOVLPDmr : VPDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
430                    "movlpd\t{$src, $dst|$dst, $src}",
431                    [(store (f64 (vector_extract (v2f64 VR128:$src),
432                                  (iPTR 0))), addr:$dst)]>, VEX;
433 }
434 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
435                    "movlps\t{$src, $dst|$dst, $src}",
436                    [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
437                                  (iPTR 0))), addr:$dst)]>;
438 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
439                    "movlpd\t{$src, $dst|$dst, $src}",
440                    [(store (f64 (vector_extract (v2f64 VR128:$src),
441                                  (iPTR 0))), addr:$dst)]>;
442
443 // v2f64 extract element 1 is always custom lowered to unpack high to low
444 // and extract element 0 so the non-store version isn't too horrible.
445 let isAsmParserOnly = 1 in {
446 def VMOVHPSmr : VPSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
447                    "movhps\t{$src, $dst|$dst, $src}",
448                    [(store (f64 (vector_extract
449                                  (unpckh (bc_v2f64 (v4f32 VR128:$src)),
450                                          (undef)), (iPTR 0))), addr:$dst)]>,
451                    VEX;
452 def VMOVHPDmr : VPDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
453                    "movhpd\t{$src, $dst|$dst, $src}",
454                    [(store (f64 (vector_extract
455                                  (v2f64 (unpckh VR128:$src, (undef))),
456                                  (iPTR 0))), addr:$dst)]>,
457                    VEX;
458 }
459 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
460                    "movhps\t{$src, $dst|$dst, $src}",
461                    [(store (f64 (vector_extract
462                                  (unpckh (bc_v2f64 (v4f32 VR128:$src)),
463                                          (undef)), (iPTR 0))), addr:$dst)]>;
464 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
465                    "movhpd\t{$src, $dst|$dst, $src}",
466                    [(store (f64 (vector_extract
467                                  (v2f64 (unpckh VR128:$src, (undef))),
468                                  (iPTR 0))), addr:$dst)]>;
469
470 let isAsmParserOnly = 1, AddedComplexity = 20 in {
471   def VMOVLHPSrr : VPSI<0x16, MRMSrcReg, (outs VR128:$dst),
472                                        (ins VR128:$src1, VR128:$src2),
473                       "movlhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
474                       [(set VR128:$dst,
475                         (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>,
476                       VEX_4V;
477   def VMOVHLPSrr : VPSI<0x12, MRMSrcReg, (outs VR128:$dst),
478                                        (ins VR128:$src1, VR128:$src2),
479                       "movhlps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
480                       [(set VR128:$dst,
481                         (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>,
482                       VEX_4V;
483 }
484 let Constraints = "$src1 = $dst", AddedComplexity = 20 in {
485   def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
486                                        (ins VR128:$src1, VR128:$src2),
487                       "movlhps\t{$src2, $dst|$dst, $src2}",
488                       [(set VR128:$dst,
489                         (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
490   def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
491                                        (ins VR128:$src1, VR128:$src2),
492                       "movhlps\t{$src2, $dst|$dst, $src2}",
493                       [(set VR128:$dst,
494                         (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
495 }
496
497 def : Pat<(movlhps VR128:$src1, (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
498           (MOVHPSrm (v4i32 VR128:$src1), addr:$src2)>;
499 let AddedComplexity = 20 in {
500   def : Pat<(v4f32 (movddup VR128:$src, (undef))),
501             (MOVLHPSrr (v4f32 VR128:$src), (v4f32 VR128:$src))>;
502   def : Pat<(v2i64 (movddup VR128:$src, (undef))),
503             (MOVLHPSrr (v2i64 VR128:$src), (v2i64 VR128:$src))>;
504 }
505
506 //===----------------------------------------------------------------------===//
507 // SSE 1 & 2 - Conversion Instructions
508 //===----------------------------------------------------------------------===//
509
510 multiclass sse12_cvt_s<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
511                      SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
512                      string asm> {
513   def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
514                         [(set DstRC:$dst, (OpNode SrcRC:$src))]>;
515   def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
516                         [(set DstRC:$dst, (OpNode (ld_frag addr:$src)))]>;
517 }
518
519 multiclass sse12_cvt_p<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
520                          SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
521                          string asm, Domain d> {
522   def rr : PI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
523                         [(set DstRC:$dst, (OpNode SrcRC:$src))], d>;
524   def rm : PI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
525                         [(set DstRC:$dst, (OpNode (ld_frag addr:$src)))], d>;
526 }
527
528 multiclass sse12_vcvt_avx<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
529                      SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
530                      string asm> {
531   def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src),
532               asm, []>;
533   def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
534               (ins DstRC:$src1, x86memop:$src), asm, []>;
535 }
536
537 let isAsmParserOnly = 1 in {
538 defm VCVTTSS2SI : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
539                       "cvttss2si\t{$src, $dst|$dst, $src}">, XS, VEX;
540 defm VCVTTSD2SI : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
541                       "cvttsd2si\t{$src, $dst|$dst, $src}">, XD, VEX;
542 defm VCVTSI2SS  : sse12_vcvt_avx<0x2A, GR32, FR32, sint_to_fp, i32mem, loadi32,
543                       "cvtsi2ss\t{$src, $src1, $dst|$dst, $src1, $src}">, XS,
544                       VEX_4V;
545 defm VCVTSI2SD  : sse12_vcvt_avx<0x2A, GR32, FR64, sint_to_fp, i32mem, loadi32,
546                       "cvtsi2sd\t{$src, $src1, $dst|$dst, $src1, $src}">, XD,
547                       VEX_4V;
548 }
549
550 defm CVTTSS2SI : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
551                       "cvttss2si\t{$src, $dst|$dst, $src}">, XS;
552 defm CVTTSD2SI : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
553                       "cvttsd2si\t{$src, $dst|$dst, $src}">, XD;
554 defm CVTSI2SS  : sse12_cvt_s<0x2A, GR32, FR32, sint_to_fp, i32mem, loadi32,
555                       "cvtsi2ss\t{$src, $dst|$dst, $src}">, XS;
556 defm CVTSI2SD  : sse12_cvt_s<0x2A, GR32, FR64, sint_to_fp, i32mem, loadi32,
557                       "cvtsi2sd\t{$src, $dst|$dst, $src}">, XD;
558
559 // Conversion Instructions Intrinsics - Match intrinsics which expect MM
560 // and/or XMM operand(s).
561 multiclass sse12_cvt_pint<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
562                          Intrinsic Int, X86MemOperand x86memop, PatFrag ld_frag,
563                          string asm, Domain d> {
564   def rr : PI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
565                         [(set DstRC:$dst, (Int SrcRC:$src))], d>;
566   def rm : PI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
567                         [(set DstRC:$dst, (Int (ld_frag addr:$src)))], d>;
568 }
569
570 multiclass sse12_cvt_sint<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
571                          Intrinsic Int, X86MemOperand x86memop, PatFrag ld_frag,
572                          string asm> {
573   def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
574                         [(set DstRC:$dst, (Int SrcRC:$src))]>;
575   def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
576                         [(set DstRC:$dst, (Int (ld_frag addr:$src)))]>;
577 }
578
579 multiclass sse12_cvt_pint_3addr<bits<8> opc, RegisterClass SrcRC,
580                     RegisterClass DstRC, Intrinsic Int, X86MemOperand x86memop,
581                     PatFrag ld_frag, string asm, Domain d> {
582   def rr : PI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src2),
583               asm, [(set DstRC:$dst, (Int DstRC:$src1, SrcRC:$src2))], d>;
584   def rm : PI<opc, MRMSrcMem, (outs DstRC:$dst),
585                    (ins DstRC:$src1, x86memop:$src2), asm,
586               [(set DstRC:$dst, (Int DstRC:$src1, (ld_frag addr:$src2)))], d>;
587 }
588
589 multiclass sse12_cvt_sint_3addr<bits<8> opc, RegisterClass SrcRC,
590                     RegisterClass DstRC, Intrinsic Int, X86MemOperand x86memop,
591                     PatFrag ld_frag, string asm> {
592   def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src2),
593               asm, [(set DstRC:$dst, (Int DstRC:$src1, SrcRC:$src2))]>;
594   def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
595                    (ins DstRC:$src1, x86memop:$src2), asm,
596               [(set DstRC:$dst, (Int DstRC:$src1, (ld_frag addr:$src2)))]>;
597 }
598
599 let isAsmParserOnly = 1 in {
600   defm Int_VCVTSS2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse_cvtss2si,
601                         f32mem, load, "cvtss2si\t{$src, $dst|$dst, $src}">, XS,
602                         VEX;
603   defm Int_VCVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse2_cvtsd2si,
604                         f128mem, load, "cvtsd2si\t{$src, $dst|$dst, $src}">, XD,
605                         VEX;
606 }
607 defm Int_CVTSS2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse_cvtss2si,
608                       f32mem, load, "cvtss2si\t{$src, $dst|$dst, $src}">, XS;
609 defm Int_CVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse2_cvtsd2si,
610                       f128mem, load, "cvtsd2si\t{$src, $dst|$dst, $src}">, XD;
611
612
613 let Constraints = "$src1 = $dst" in {
614   defm Int_CVTSI2SS : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
615                         int_x86_sse_cvtsi2ss, i32mem, loadi32,
616                         "cvtsi2ss\t{$src2, $dst|$dst, $src2}">, XS;
617   defm Int_CVTSI2SD : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
618                         int_x86_sse2_cvtsi2sd, i32mem, loadi32,
619                         "cvtsi2ss\t{$src2, $dst|$dst, $src2}">, XD;
620 }
621
622 // Instructions below don't have an AVX form.
623 defm Int_CVTPS2PI : sse12_cvt_pint<0x2D, VR128, VR64, int_x86_sse_cvtps2pi,
624                       f64mem, load, "cvtps2pi\t{$src, $dst|$dst, $src}",
625                       SSEPackedSingle>, TB;
626 defm Int_CVTPD2PI : sse12_cvt_pint<0x2D, VR128, VR64, int_x86_sse_cvtpd2pi,
627                       f128mem, memop, "cvtpd2pi\t{$src, $dst|$dst, $src}",
628                       SSEPackedDouble>, TB, OpSize;
629 defm Int_CVTTPS2PI : sse12_cvt_pint<0x2C, VR128, VR64, int_x86_sse_cvttps2pi,
630                        f64mem, load, "cvttps2pi\t{$src, $dst|$dst, $src}",
631                        SSEPackedSingle>, TB;
632 defm Int_CVTTPD2PI : sse12_cvt_pint<0x2C, VR128, VR64, int_x86_sse_cvttpd2pi,
633                        f128mem, memop, "cvttpd2pi\t{$src, $dst|$dst, $src}",
634                        SSEPackedDouble>, TB, OpSize;
635 defm Int_CVTPI2PD : sse12_cvt_pint<0x2A, VR64, VR128, int_x86_sse_cvtpi2pd,
636                          i64mem, load, "cvtpi2pd\t{$src, $dst|$dst, $src}",
637                          SSEPackedDouble>, TB, OpSize;
638 let Constraints = "$src1 = $dst" in {
639   defm Int_CVTPI2PS : sse12_cvt_pint_3addr<0x2A, VR64, VR128,
640                          int_x86_sse_cvtpi2ps,
641                          i64mem, load, "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
642                          SSEPackedSingle>, TB;
643 }
644
645 /// SSE 1 Only
646
647 // Aliases for intrinsics
648 let isAsmParserOnly = 1, Pattern = []<dag> in {
649 defm Int_VCVTTSS2SI : sse12_cvt_sint_3addr<0x2C, VR128, GR32,
650                 int_x86_sse_cvttss2si, f32mem, load,
651                 "cvttss2si\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XS;
652 defm Int_VCVTTSD2SI : sse12_cvt_sint_3addr<0x2C, VR128, GR32,
653                 int_x86_sse2_cvttsd2si, f128mem, load,
654                 "cvttss2si\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XD;
655 }
656 defm Int_CVTTSS2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse_cvttss2si,
657                           f32mem, load, "cvttss2si\t{$src, $dst|$dst, $src}">,
658                           XS;
659 defm Int_CVTTSD2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse2_cvttsd2si,
660                           f128mem, load, "cvttss2si\t{$src, $dst|$dst, $src}">,
661                           XD;
662
663 let isAsmParserOnly = 1, Pattern = []<dag> in {
664 defm VCVTSS2SI : sse12_cvt_s<0x2D, FR32, GR32, undef, f32mem, load,
665                           "cvtss2si{l}\t{$src, $dst|$dst, $src}">, XS, VEX;
666 defm VCVTDQ2PS : sse12_cvt_p<0x5B, VR128, VR128, undef, f128mem, load,
667                             "cvtdq2ps\t{$src, $dst|$dst, $src}",
668                             SSEPackedSingle>, TB, VEX;
669 }
670 let Pattern = []<dag> in {
671 defm CVTSS2SI : sse12_cvt_s<0x2D, FR32, GR32, undef, f32mem, load /*dummy*/,
672                           "cvtss2si{l}\t{$src, $dst|$dst, $src}">, XS;
673 defm CVTDQ2PS : sse12_cvt_p<0x5B, VR128, VR128, undef, f128mem, load /*dummy*/,
674                             "cvtdq2ps\t{$src, $dst|$dst, $src}",
675                             SSEPackedSingle>, TB; /* PD SSE3 form is avaiable */
676 }
677
678 /// SSE 2 Only
679
680 // Convert scalar double to scalar single
681 let isAsmParserOnly = 1 in {
682 def VCVTSD2SSrr  : VSDI<0x5A, MRMSrcReg, (outs FR32:$dst),
683                        (ins FR64:$src1, FR64:$src2),
684                       "cvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
685                       VEX_4V;
686 def VCVTSD2SSrm  : I<0x5A, MRMSrcMem, (outs FR32:$dst),
687                        (ins FR64:$src1, f64mem:$src2),
688                       "vcvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
689                       []>, XD, Requires<[HasAVX, HasSSE2, OptForSize]>, VEX_4V;
690 }
691 def CVTSD2SSrr  : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
692                       "cvtsd2ss\t{$src, $dst|$dst, $src}",
693                       [(set FR32:$dst, (fround FR64:$src))]>;
694 def CVTSD2SSrm  : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
695                       "cvtsd2ss\t{$src, $dst|$dst, $src}",
696                       [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
697                   Requires<[HasSSE2, OptForSize]>;
698
699 let isAsmParserOnly = 1 in
700 defm Int_VCVTSD2SS: sse12_cvt_sint_3addr<0x5A, VR128, VR128,
701                     int_x86_sse2_cvtsd2ss, f64mem, load,
702                     "cvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}">,
703                     XS, VEX_4V;
704 let Constraints = "$src1 = $dst" in
705 defm Int_CVTSD2SS: sse12_cvt_sint_3addr<0x5A, VR128, VR128,
706              int_x86_sse2_cvtsd2ss, f64mem, load,
707              "cvtsd2ss\t{$src2, $dst|$dst, $src2}">, XS;
708
709 // Convert scalar single to scalar double
710 let isAsmParserOnly = 1 in { // SSE2 instructions with XS prefix
711 def VCVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst),
712                     (ins FR32:$src1, FR32:$src2),
713                     "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
714                     []>, XS, Requires<[HasAVX, HasSSE2]>, VEX_4V;
715 def VCVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst),
716                     (ins FR32:$src1, f32mem:$src2),
717                     "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
718                     []>, XS, VEX_4V, Requires<[HasAVX, HasSSE2, OptForSize]>;
719 }
720 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
721                    "cvtss2sd\t{$src, $dst|$dst, $src}",
722                    [(set FR64:$dst, (fextend FR32:$src))]>, XS,
723                  Requires<[HasSSE2]>;
724 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
725                    "cvtss2sd\t{$src, $dst|$dst, $src}",
726                    [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
727                  Requires<[HasSSE2, OptForSize]>;
728
729 let isAsmParserOnly = 1 in {
730 def Int_VCVTSS2SDrr: I<0x5A, MRMSrcReg,
731                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
732                     "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
733                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
734                                        VR128:$src2))]>, XS, VEX_4V,
735                     Requires<[HasAVX, HasSSE2]>;
736 def Int_VCVTSS2SDrm: I<0x5A, MRMSrcMem,
737                       (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
738                     "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
739                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
740                                        (load addr:$src2)))]>, XS, VEX_4V,
741                     Requires<[HasAVX, HasSSE2]>;
742 }
743 let Constraints = "$src1 = $dst" in { // SSE2 instructions with XS prefix
744 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
745                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
746                     "cvtss2sd\t{$src2, $dst|$dst, $src2}",
747                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
748                                        VR128:$src2))]>, XS,
749                     Requires<[HasSSE2]>;
750 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
751                       (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
752                     "cvtss2sd\t{$src2, $dst|$dst, $src2}",
753                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
754                                        (load addr:$src2)))]>, XS,
755                     Requires<[HasSSE2]>;
756 }
757
758 def : Pat<(extloadf32 addr:$src),
759           (CVTSS2SDrr (MOVSSrm addr:$src))>,
760       Requires<[HasSSE2, OptForSpeed]>;
761
762 // Convert doubleword to packed single/double fp
763 let isAsmParserOnly = 1 in { // SSE2 instructions without OpSize prefix
764 def Int_VCVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
765                        "vcvtdq2ps\t{$src, $dst|$dst, $src}",
766                        [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
767                      TB, VEX, Requires<[HasAVX, HasSSE2]>;
768 def Int_VCVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
769                       "vcvtdq2ps\t{$src, $dst|$dst, $src}",
770                       [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
771                                         (bitconvert (memopv2i64 addr:$src))))]>,
772                      TB, VEX, Requires<[HasAVX, HasSSE2]>;
773 }
774 def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
775                        "cvtdq2ps\t{$src, $dst|$dst, $src}",
776                        [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
777                      TB, Requires<[HasSSE2]>;
778 def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
779                       "cvtdq2ps\t{$src, $dst|$dst, $src}",
780                       [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
781                                         (bitconvert (memopv2i64 addr:$src))))]>,
782                      TB, Requires<[HasSSE2]>;
783
784 // FIXME: why the non-intrinsic version is described as SSE3?
785 let isAsmParserOnly = 1 in { // SSE2 instructions with XS prefix
786 def Int_VCVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
787                        "vcvtdq2pd\t{$src, $dst|$dst, $src}",
788                        [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
789                      XS, VEX, Requires<[HasAVX, HasSSE2]>;
790 def Int_VCVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
791                        "vcvtdq2pd\t{$src, $dst|$dst, $src}",
792                        [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
793                                         (bitconvert (memopv2i64 addr:$src))))]>,
794                      XS, VEX, Requires<[HasAVX, HasSSE2]>;
795 }
796 def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
797                        "cvtdq2pd\t{$src, $dst|$dst, $src}",
798                        [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
799                      XS, Requires<[HasSSE2]>;
800 def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
801                      "cvtdq2pd\t{$src, $dst|$dst, $src}",
802                      [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
803                                         (bitconvert (memopv2i64 addr:$src))))]>,
804                      XS, Requires<[HasSSE2]>;
805
806 // Convert packed single/double fp to doubleword
807 let isAsmParserOnly = 1 in {
808 def VCVTPS2DQrr : VPDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
809                      "cvtps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
810 def VCVTPS2DQrm : VPDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
811                      "cvtps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
812 }
813 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
814                      "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
815 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
816                      "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
817
818 let isAsmParserOnly = 1 in {
819 def Int_VCVTPS2DQrr : VPDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
820                         "cvtps2dq\t{$src, $dst|$dst, $src}",
821                         [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>,
822                         VEX;
823 def Int_VCVTPS2DQrm : VPDI<0x5B, MRMSrcMem, (outs VR128:$dst),
824                          (ins f128mem:$src),
825                          "cvtps2dq\t{$src, $dst|$dst, $src}",
826                          [(set VR128:$dst, (int_x86_sse2_cvtps2dq
827                                             (memop addr:$src)))]>, VEX;
828 }
829 def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
830                         "cvtps2dq\t{$src, $dst|$dst, $src}",
831                         [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
832 def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
833                          "cvtps2dq\t{$src, $dst|$dst, $src}",
834                          [(set VR128:$dst, (int_x86_sse2_cvtps2dq
835                                             (memop addr:$src)))]>;
836
837 let isAsmParserOnly = 1 in { // SSE2 packed instructions with XD prefix
838 def Int_VCVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
839                        "vcvtpd2dq\t{$src, $dst|$dst, $src}",
840                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
841                      XD, VEX, Requires<[HasAVX, HasSSE2]>;
842 def Int_VCVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
843                        "vcvtpd2dq\t{$src, $dst|$dst, $src}",
844                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
845                                           (memop addr:$src)))]>,
846                      XD, VEX, Requires<[HasAVX, HasSSE2]>;
847 }
848 def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
849                        "cvtpd2dq\t{$src, $dst|$dst, $src}",
850                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
851                      XD, Requires<[HasSSE2]>;
852 def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
853                        "cvtpd2dq\t{$src, $dst|$dst, $src}",
854                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
855                                           (memop addr:$src)))]>,
856                      XD, Requires<[HasSSE2]>;
857
858
859 // Convert with truncation packed single/double fp to doubleword
860 let isAsmParserOnly = 1 in { // SSE2 packed instructions with XS prefix
861 def VCVTTPS2DQrr : VSSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
862                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
863 def VCVTTPS2DQrm : VSSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
864                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
865 }
866 def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
867                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
868 def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
869                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
870
871
872 let isAsmParserOnly = 1 in {
873 def Int_VCVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
874                         "vcvttps2dq\t{$src, $dst|$dst, $src}",
875                         [(set VR128:$dst,
876                               (int_x86_sse2_cvttps2dq VR128:$src))]>,
877                       XS, VEX, Requires<[HasAVX, HasSSE2]>;
878 def Int_VCVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
879                         "vcvttps2dq\t{$src, $dst|$dst, $src}",
880                         [(set VR128:$dst, (int_x86_sse2_cvttps2dq
881                                            (memop addr:$src)))]>,
882                       XS, VEX, Requires<[HasAVX, HasSSE2]>;
883 }
884 def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
885                         "cvttps2dq\t{$src, $dst|$dst, $src}",
886                         [(set VR128:$dst,
887                               (int_x86_sse2_cvttps2dq VR128:$src))]>,
888                       XS, Requires<[HasSSE2]>;
889 def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
890                         "cvttps2dq\t{$src, $dst|$dst, $src}",
891                         [(set VR128:$dst, (int_x86_sse2_cvttps2dq
892                                            (memop addr:$src)))]>,
893                       XS, Requires<[HasSSE2]>;
894
895 let isAsmParserOnly = 1 in {
896 def Int_VCVTTPD2DQrr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst),
897                             (ins VR128:$src),
898                           "cvttpd2dq\t{$src, $dst|$dst, $src}",
899                        [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>,
900                        VEX;
901 def Int_VCVTTPD2DQrm : VPDI<0xE6, MRMSrcMem, (outs VR128:$dst),
902                           (ins f128mem:$src),
903                           "cvttpd2dq\t{$src, $dst|$dst, $src}",
904                           [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
905                                              (memop addr:$src)))]>, VEX;
906 }
907 def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
908                           "cvttpd2dq\t{$src, $dst|$dst, $src}",
909                        [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
910 def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
911                           "cvttpd2dq\t{$src, $dst|$dst, $src}",
912                           [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
913                                              (memop addr:$src)))]>;
914
915 // Convert packed single to packed double
916 let isAsmParserOnly = 1 in { // SSE2 instructions without OpSize prefix
917 def VCVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
918                        "vcvtps2pd\t{$src, $dst|$dst, $src}", []>, VEX,
919                        Requires<[HasAVX]>;
920 def VCVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
921                        "vcvtps2pd\t{$src, $dst|$dst, $src}", []>, VEX,
922                        Requires<[HasAVX]>;
923 }
924 def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
925                        "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
926 def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
927                        "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
928
929 let isAsmParserOnly = 1 in {
930 def Int_VCVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
931                        "cvtps2pd\t{$src, $dst|$dst, $src}",
932                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
933                      VEX, Requires<[HasAVX, HasSSE2]>;
934 def Int_VCVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
935                        "cvtps2pd\t{$src, $dst|$dst, $src}",
936                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd
937                                           (load addr:$src)))]>,
938                      VEX, Requires<[HasAVX, HasSSE2]>;
939 }
940 def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
941                        "cvtps2pd\t{$src, $dst|$dst, $src}",
942                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
943                      TB, Requires<[HasSSE2]>;
944 def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
945                        "cvtps2pd\t{$src, $dst|$dst, $src}",
946                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd
947                                           (load addr:$src)))]>,
948                      TB, Requires<[HasSSE2]>;
949
950 // Convert packed double to packed single
951 let isAsmParserOnly = 1 in {
952 def VCVTPD2PSrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
953                      "cvtpd2ps\t{$src, $dst|$dst, $src}", []>, VEX;
954 // FIXME: the memory form of this instruction should described using
955 // use extra asm syntax
956 }
957 def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
958                      "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
959 def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
960                      "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
961
962
963 let isAsmParserOnly = 1 in {
964 def Int_VCVTPD2PSrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
965                          "cvtpd2ps\t{$src, $dst|$dst, $src}",
966                         [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
967 def Int_VCVTPD2PSrm : VPDI<0x5A, MRMSrcMem, (outs VR128:$dst),
968                          (ins f128mem:$src),
969                          "cvtpd2ps\t{$src, $dst|$dst, $src}",
970                          [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
971                                             (memop addr:$src)))]>;
972 }
973 def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
974                          "cvtpd2ps\t{$src, $dst|$dst, $src}",
975                         [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
976 def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
977                          "cvtpd2ps\t{$src, $dst|$dst, $src}",
978                          [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
979                                             (memop addr:$src)))]>;
980
981 //===----------------------------------------------------------------------===//
982 // SSE 1 & 2 - Compare Instructions
983 //===----------------------------------------------------------------------===//
984
985 // sse12_cmp_scalar - sse 1 & 2 compare scalar instructions
986 multiclass sse12_cmp_scalar<RegisterClass RC, X86MemOperand x86memop,
987                             string asm, string asm_alt> {
988   def rr : SIi8<0xC2, MRMSrcReg,
989                     (outs RC:$dst), (ins RC:$src1, RC:$src, SSECC:$cc),
990                     asm, []>;
991   let mayLoad = 1 in
992   def rm : SIi8<0xC2, MRMSrcMem,
993                     (outs RC:$dst), (ins RC:$src1, x86memop:$src, SSECC:$cc),
994                     asm, []>;
995   // Accept explicit immediate argument form instead of comparison code.
996   let isAsmParserOnly = 1 in {
997     def rr_alt : SIi8<0xC2, MRMSrcReg,
998                   (outs RC:$dst), (ins RC:$src1, RC:$src, i8imm:$src2),
999                   asm_alt, []>;
1000     let mayLoad = 1 in
1001     def rm_alt : SIi8<0xC2, MRMSrcMem,
1002                   (outs RC:$dst), (ins RC:$src1, x86memop:$src, i8imm:$src2),
1003                   asm_alt, []>;
1004   }
1005 }
1006
1007 let neverHasSideEffects = 1, isAsmParserOnly = 1 in {
1008   defm VCMPSS  : sse12_cmp_scalar<FR32, f32mem,
1009                   "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}",
1010                   "cmpss\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}">,
1011                   XS, VEX_4V;
1012   defm VCMPSD  : sse12_cmp_scalar<FR64, f64mem,
1013                   "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}",
1014                   "cmpsd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}">,
1015                   XD, VEX_4V;
1016 }
1017
1018 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
1019   defm CMPSS  : sse12_cmp_scalar<FR32, f32mem,
1020                     "cmp${cc}ss\t{$src, $dst|$dst, $src}",
1021                     "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}">, XS;
1022   defm CMPSD  : sse12_cmp_scalar<FR64, f64mem,
1023                     "cmp${cc}sd\t{$src, $dst|$dst, $src}",
1024                     "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}">, XD;
1025 }
1026
1027 multiclass sse12_cmp_scalar_int<RegisterClass RC, X86MemOperand x86memop,
1028                          Intrinsic Int, string asm> {
1029   def rr : SIi8<0xC2, MRMSrcReg, (outs VR128:$dst),
1030                       (ins VR128:$src1, VR128:$src, SSECC:$cc), asm,
1031                         [(set VR128:$dst, (Int VR128:$src1,
1032                                                VR128:$src, imm:$cc))]>;
1033   def rm : SIi8<0xC2, MRMSrcMem, (outs VR128:$dst),
1034                       (ins VR128:$src1, f32mem:$src, SSECC:$cc), asm,
1035                         [(set VR128:$dst, (Int VR128:$src1,
1036                                                (load addr:$src), imm:$cc))]>;
1037 }
1038
1039 // Aliases to match intrinsics which expect XMM operand(s).
1040 let isAsmParserOnly = 1 in {
1041   defm Int_VCMPSS  : sse12_cmp_scalar_int<VR128, f32mem, int_x86_sse_cmp_ss,
1042                        "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}">,
1043                        XS, VEX_4V;
1044   defm Int_VCMPSD  : sse12_cmp_scalar_int<VR128, f64mem, int_x86_sse2_cmp_sd,
1045                        "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}">,
1046                        XD, VEX_4V;
1047 }
1048 let Constraints = "$src1 = $dst" in {
1049   defm Int_CMPSS  : sse12_cmp_scalar_int<VR128, f32mem, int_x86_sse_cmp_ss,
1050                        "cmp${cc}ss\t{$src, $dst|$dst, $src}">, XS;
1051   defm Int_CMPSD  : sse12_cmp_scalar_int<VR128, f64mem, int_x86_sse2_cmp_sd,
1052                        "cmp${cc}sd\t{$src, $dst|$dst, $src}">, XD;
1053 }
1054
1055
1056 // sse12_ord_cmp - Unordered/Ordered scalar fp compare and set EFLAGS
1057 multiclass sse12_ord_cmp<bits<8> opc, RegisterClass RC, SDNode OpNode,
1058                             ValueType vt, X86MemOperand x86memop,
1059                             PatFrag ld_frag, string OpcodeStr, Domain d> {
1060   def rr: PI<opc, MRMSrcReg, (outs), (ins RC:$src1, RC:$src2),
1061                      !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
1062                      [(set EFLAGS, (OpNode (vt RC:$src1), RC:$src2))], d>;
1063   def rm: PI<opc, MRMSrcMem, (outs), (ins RC:$src1, x86memop:$src2),
1064                      !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
1065                      [(set EFLAGS, (OpNode (vt RC:$src1),
1066                                            (ld_frag addr:$src2)))], d>;
1067 }
1068
1069 let Defs = [EFLAGS] in {
1070   let isAsmParserOnly = 1 in {
1071     defm VUCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
1072                                     "ucomiss", SSEPackedSingle>, VEX;
1073     defm VUCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
1074                                     "ucomisd", SSEPackedDouble>, OpSize, VEX;
1075     let Pattern = []<dag> in {
1076       defm VCOMISS  : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
1077                                       "comiss", SSEPackedSingle>, VEX;
1078       defm VCOMISD  : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
1079                                       "comisd", SSEPackedDouble>, OpSize, VEX;
1080     }
1081
1082     defm Int_VUCOMISS  : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
1083                               load, "ucomiss", SSEPackedSingle>, VEX;
1084     defm Int_VUCOMISD  : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
1085                               load, "ucomisd", SSEPackedDouble>, OpSize, VEX;
1086
1087     defm Int_VCOMISS  : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem,
1088                               load, "comiss", SSEPackedSingle>, VEX;
1089     defm Int_VCOMISD  : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem,
1090                               load, "comisd", SSEPackedDouble>, OpSize, VEX;
1091   }
1092   defm UCOMISS  : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
1093                                   "ucomiss", SSEPackedSingle>, TB;
1094   defm UCOMISD  : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
1095                                   "ucomisd", SSEPackedDouble>, TB, OpSize;
1096
1097   let Pattern = []<dag> in {
1098     defm COMISS  : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
1099                                     "comiss", SSEPackedSingle>, TB;
1100     defm COMISD  : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
1101                                     "comisd", SSEPackedDouble>, TB, OpSize;
1102   }
1103
1104   defm Int_UCOMISS  : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
1105                               load, "ucomiss", SSEPackedSingle>, TB;
1106   defm Int_UCOMISD  : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
1107                               load, "ucomisd", SSEPackedDouble>, TB, OpSize;
1108
1109   defm Int_COMISS  : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem, load,
1110                                   "comiss", SSEPackedSingle>, TB;
1111   defm Int_COMISD  : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem, load,
1112                                   "comisd", SSEPackedDouble>, TB, OpSize;
1113 } // Defs = [EFLAGS]
1114
1115 // sse12_cmp_packed - sse 1 & 2 compared packed instructions
1116 multiclass sse12_cmp_packed<RegisterClass RC, X86MemOperand x86memop,
1117                             Intrinsic Int, string asm, string asm_alt,
1118                             Domain d> {
1119   def rri : PIi8<0xC2, MRMSrcReg,
1120              (outs RC:$dst), (ins RC:$src1, RC:$src, SSECC:$cc), asm,
1121              [(set RC:$dst, (Int RC:$src1, RC:$src, imm:$cc))], d>;
1122   def rmi : PIi8<0xC2, MRMSrcMem,
1123              (outs RC:$dst), (ins RC:$src1, f128mem:$src, SSECC:$cc), asm,
1124              [(set RC:$dst, (Int RC:$src1, (memop addr:$src), imm:$cc))], d>;
1125   // Accept explicit immediate argument form instead of comparison code.
1126   let isAsmParserOnly = 1 in {
1127     def rri_alt : PIi8<0xC2, MRMSrcReg,
1128                (outs RC:$dst), (ins RC:$src1, RC:$src, i8imm:$src2),
1129                asm_alt, [], d>;
1130     def rmi_alt : PIi8<0xC2, MRMSrcMem,
1131                (outs RC:$dst), (ins RC:$src1, f128mem:$src, i8imm:$src2),
1132                asm_alt, [], d>;
1133   }
1134 }
1135
1136 let isAsmParserOnly = 1 in {
1137   defm VCMPPS : sse12_cmp_packed<VR128, f128mem, int_x86_sse_cmp_ps,
1138                  "cmp${cc}ps\t{$src, $src1, $dst|$dst, $src1, $src}",
1139                  "cmpps\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
1140                  SSEPackedSingle>, VEX_4V;
1141   defm VCMPPD : sse12_cmp_packed<VR128, f128mem, int_x86_sse2_cmp_pd,
1142                  "cmp${cc}pd\t{$src, $src1, $dst|$dst, $src1, $src}",
1143                  "cmppd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
1144                  SSEPackedDouble>, OpSize, VEX_4V;
1145 }
1146 let Constraints = "$src1 = $dst" in {
1147   defm CMPPS : sse12_cmp_packed<VR128, f128mem, int_x86_sse_cmp_ps,
1148                  "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1149                  "cmpps\t{$src2, $src, $dst|$dst, $src, $src2}",
1150                  SSEPackedSingle>, TB;
1151   defm CMPPD : sse12_cmp_packed<VR128, f128mem, int_x86_sse2_cmp_pd,
1152                  "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1153                  "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}",
1154                  SSEPackedDouble>, TB, OpSize;
1155 }
1156
1157 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
1158           (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
1159 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
1160           (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
1161 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
1162           (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
1163 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
1164           (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
1165
1166 //===----------------------------------------------------------------------===//
1167 // SSE 1 & 2 - Shuffle Instructions
1168 //===----------------------------------------------------------------------===//
1169
1170 /// sse12_shuffle - sse 1 & 2 shuffle instructions
1171 multiclass sse12_shuffle<RegisterClass RC, X86MemOperand x86memop,
1172                          ValueType vt, string asm, PatFrag mem_frag,
1173                          Domain d, bit IsConvertibleToThreeAddress = 0> {
1174   def rmi : PIi8<0xC6, MRMSrcMem, (outs VR128:$dst),
1175                    (ins VR128:$src1, f128mem:$src2, i8imm:$src3), asm,
1176                    [(set VR128:$dst, (vt (shufp:$src3
1177                             VR128:$src1, (mem_frag addr:$src2))))], d>;
1178   let isConvertibleToThreeAddress = IsConvertibleToThreeAddress in
1179     def rri : PIi8<0xC6, MRMSrcReg, (outs VR128:$dst),
1180                    (ins VR128:$src1, VR128:$src2, i8imm:$src3), asm,
1181                    [(set VR128:$dst,
1182                             (vt (shufp:$src3 VR128:$src1, VR128:$src2)))], d>;
1183 }
1184
1185 let isAsmParserOnly = 1 in {
1186   defm VSHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
1187             "shufps\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
1188             memopv4f32, SSEPackedSingle>, VEX_4V;
1189   defm VSHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
1190             "shufpd\t{$src3, $src2, $src1, $dst|$dst, $src2, $src2, $src3}",
1191             memopv2f64, SSEPackedDouble>, OpSize, VEX_4V;
1192 }
1193
1194 let Constraints = "$src1 = $dst" in {
1195   defm SHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
1196                     "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1197                     memopv4f32, SSEPackedSingle, 1 /* cvt to pshufd */>,
1198                     TB;
1199   defm SHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
1200                     "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1201                     memopv2f64, SSEPackedDouble>, TB, OpSize;
1202 }
1203
1204 //===----------------------------------------------------------------------===//
1205 // SSE 1 & 2 - Unpack Instructions
1206 //===----------------------------------------------------------------------===//
1207
1208 /// sse12_unpack_interleave - sse 1 & 2 unpack and interleave
1209 multiclass sse12_unpack_interleave<bits<8> opc, PatFrag OpNode, ValueType vt,
1210                                    PatFrag mem_frag, RegisterClass RC,
1211                                    X86MemOperand x86memop, string asm,
1212                                    Domain d> {
1213     def rr : PI<opc, MRMSrcReg,
1214                 (outs RC:$dst), (ins RC:$src1, RC:$src2),
1215                 asm, [(set RC:$dst,
1216                            (vt (OpNode RC:$src1, RC:$src2)))], d>;
1217     def rm : PI<opc, MRMSrcMem,
1218                 (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
1219                 asm, [(set RC:$dst,
1220                            (vt (OpNode RC:$src1,
1221                                        (mem_frag addr:$src2))))], d>;
1222 }
1223
1224 let AddedComplexity = 10 in {
1225   let isAsmParserOnly = 1 in {
1226     defm VUNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
1227           VR128, f128mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1228                          SSEPackedSingle>, VEX_4V;
1229     defm VUNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
1230           VR128, f128mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1231                          SSEPackedDouble>, OpSize, VEX_4V;
1232     defm VUNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
1233           VR128, f128mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1234                          SSEPackedSingle>, VEX_4V;
1235     defm VUNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
1236           VR128, f128mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1237                          SSEPackedDouble>, OpSize, VEX_4V;
1238
1239     defm VUNPCKHPSY: sse12_unpack_interleave<0x15, unpckh, v8f32, memopv8f32,
1240           VR256, f256mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1241                          SSEPackedSingle>, VEX_4V;
1242     defm VUNPCKHPDY: sse12_unpack_interleave<0x15, unpckh, v4f64, memopv4f64,
1243           VR256, f256mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1244                          SSEPackedDouble>, OpSize, VEX_4V;
1245     defm VUNPCKLPSY: sse12_unpack_interleave<0x14, unpckl, v8f32, memopv8f32,
1246           VR256, f256mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1247                          SSEPackedSingle>, VEX_4V;
1248     defm VUNPCKLPDY: sse12_unpack_interleave<0x14, unpckl, v4f64, memopv4f64,
1249           VR256, f256mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1250                          SSEPackedDouble>, OpSize, VEX_4V;
1251   }
1252
1253   let Constraints = "$src1 = $dst" in {
1254     defm UNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
1255           VR128, f128mem, "unpckhps\t{$src2, $dst|$dst, $src2}",
1256                          SSEPackedSingle>, TB;
1257     defm UNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
1258           VR128, f128mem, "unpckhpd\t{$src2, $dst|$dst, $src2}",
1259                          SSEPackedDouble>, TB, OpSize;
1260     defm UNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
1261           VR128, f128mem, "unpcklps\t{$src2, $dst|$dst, $src2}",
1262                          SSEPackedSingle>, TB;
1263     defm UNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
1264           VR128, f128mem, "unpcklpd\t{$src2, $dst|$dst, $src2}",
1265                          SSEPackedDouble>, TB, OpSize;
1266   } // Constraints = "$src1 = $dst"
1267 } // AddedComplexity
1268
1269 //===----------------------------------------------------------------------===//
1270 // SSE 1 & 2 - Extract Floating-Point Sign mask
1271 //===----------------------------------------------------------------------===//
1272
1273 /// sse12_extr_sign_mask - sse 1 & 2 unpack and interleave
1274 multiclass sse12_extr_sign_mask<RegisterClass RC, Intrinsic Int, string asm,
1275                                 Domain d> {
1276   def rr : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins RC:$src),
1277               !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
1278                      [(set GR32:$dst, (Int RC:$src))], d>;
1279 }
1280
1281 // Mask creation
1282 defm MOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps, "movmskps",
1283                                      SSEPackedSingle>, TB;
1284 defm MOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd, "movmskpd",
1285                                      SSEPackedDouble>, TB, OpSize;
1286
1287 let isAsmParserOnly = 1 in {
1288   defm VMOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps,
1289                                         "movmskps", SSEPackedSingle>, VEX;
1290   defm VMOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd,
1291                                         "movmskpd", SSEPackedDouble>, OpSize,
1292                                         VEX;
1293   // FIXME: merge with multiclass above when the intrinsics come.
1294   def VMOVMSKPSYrr : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR256:$src),
1295              "movmskps\t{$src, $dst|$dst, $src}", [], SSEPackedSingle>, VEX;
1296   def VMOVMSKPDYrr : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR256:$src),
1297              "movmskpd\t{$src, $dst|$dst, $src}", [], SSEPackedDouble>, OpSize,
1298                                                                         VEX;
1299 }
1300
1301 //===----------------------------------------------------------------------===//
1302 // SSE 1 & 2 - Misc aliasing of packed SSE 1 & 2 instructions
1303 //===----------------------------------------------------------------------===//
1304
1305 // Aliases of packed SSE1 & SSE2 instructions for scalar use. These all have
1306 // names that start with 'Fs'.
1307
1308 // Alias instructions that map fld0 to pxor for sse.
1309 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
1310     canFoldAsLoad = 1 in {
1311   // FIXME: Set encoding to pseudo!
1312 def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins), "",
1313                  [(set FR32:$dst, fp32imm0)]>,
1314                  Requires<[HasSSE1]>, TB, OpSize;
1315 def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
1316                  [(set FR64:$dst, fpimm0)]>,
1317                Requires<[HasSSE2]>, TB, OpSize;
1318 }
1319
1320 // Alias instruction to do FR32 or FR64 reg-to-reg copy using movaps. Upper
1321 // bits are disregarded.
1322 let neverHasSideEffects = 1 in {
1323 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1324                      "movaps\t{$src, $dst|$dst, $src}", []>;
1325 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1326                      "movapd\t{$src, $dst|$dst, $src}", []>;
1327 }
1328
1329 // Alias instruction to load FR32 or FR64 from f128mem using movaps. Upper
1330 // bits are disregarded.
1331 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1332 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
1333                      "movaps\t{$src, $dst|$dst, $src}",
1334                      [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
1335 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1336                      "movapd\t{$src, $dst|$dst, $src}",
1337                      [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
1338 }
1339
1340 //===----------------------------------------------------------------------===//
1341 // SSE 1 & 2 - Logical Instructions
1342 //===----------------------------------------------------------------------===//
1343
1344 /// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
1345 ///
1346 multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
1347                                        SDNode OpNode> {
1348   let isAsmParserOnly = 1 in {
1349     defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode,
1350                 FR32, f32, f128mem, memopfsf32, SSEPackedSingle, 0>, VEX_4V;
1351
1352     defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode,
1353           FR64, f64, f128mem, memopfsf64, SSEPackedDouble, 0>, OpSize, VEX_4V;
1354   }
1355
1356   let Constraints = "$src1 = $dst" in {
1357     defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, FR32,
1358                 f32, f128mem, memopfsf32, SSEPackedSingle>, TB;
1359
1360     defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, FR64,
1361                 f64, f128mem, memopfsf64, SSEPackedDouble>, TB, OpSize;
1362   }
1363 }
1364
1365 // Alias bitwise logical operations using SSE logical ops on packed FP values.
1366 let mayLoad = 0 in {
1367   defm FsAND  : sse12_fp_alias_pack_logical<0x54, "and", X86fand>;
1368   defm FsOR   : sse12_fp_alias_pack_logical<0x56, "or", X86for>;
1369   defm FsXOR  : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor>;
1370 }
1371
1372 let neverHasSideEffects = 1, Pattern = []<dag>, isCommutable = 0 in
1373   defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef>;
1374
1375 /// sse12_fp_packed_logical - SSE 1 & 2 packed FP logical ops
1376 ///
1377 multiclass sse12_fp_packed_logical<bits<8> opc, string OpcodeStr,
1378                                  SDNode OpNode, int HasPat = 0,
1379                                  list<list<dag>> Pattern = []> {
1380   let isAsmParserOnly = 1 in {
1381     defm V#NAME#PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1382          !strconcat(OpcodeStr, "ps"), f128mem,
1383          !if(HasPat, Pattern[0], // rr
1384                      [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1385                                                       VR128:$src2)))]),
1386          !if(HasPat, Pattern[2], // rm
1387                      [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1388                                                (memopv2i64 addr:$src2)))]), 0>,
1389                                                VEX_4V;
1390
1391     defm V#NAME#PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1392          !strconcat(OpcodeStr, "pd"), f128mem,
1393          !if(HasPat, Pattern[1], // rr
1394                      [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1395                                                (bc_v2i64 (v2f64
1396                                                VR128:$src2))))]),
1397          !if(HasPat, Pattern[3], // rm
1398                      [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1399                                                (memopv2i64 addr:$src2)))]), 0>,
1400                                                                OpSize, VEX_4V;
1401   }
1402   let Constraints = "$src1 = $dst" in {
1403     defm PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1404          !strconcat(OpcodeStr, "ps"), f128mem,
1405          !if(HasPat, Pattern[0], // rr
1406                      [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1407                                                       VR128:$src2)))]),
1408          !if(HasPat, Pattern[2], // rm
1409                      [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1410                                                (memopv2i64 addr:$src2)))])>, TB;
1411
1412     defm PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1413          !strconcat(OpcodeStr, "pd"), f128mem,
1414          !if(HasPat, Pattern[1], // rr
1415                      [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1416                                                (bc_v2i64 (v2f64
1417                                                VR128:$src2))))]),
1418          !if(HasPat, Pattern[3], // rm
1419                      [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1420                                                (memopv2i64 addr:$src2)))])>,
1421                                                                     TB, OpSize;
1422   }
1423 }
1424
1425 defm AND  : sse12_fp_packed_logical<0x54, "and", and>;
1426 defm OR   : sse12_fp_packed_logical<0x56, "or", or>;
1427 defm XOR  : sse12_fp_packed_logical<0x57, "xor", xor>;
1428 let isCommutable = 0 in
1429   defm ANDN : sse12_fp_packed_logical<0x55, "andn", undef /* dummy */, 1, [
1430     // single r+r
1431     [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
1432                                        (bc_v2i64 (v4i32 immAllOnesV))),
1433                                    VR128:$src2)))],
1434     // double r+r
1435     [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1436                                  (bc_v2i64 (v2f64 VR128:$src2))))],
1437     // single r+m
1438     [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1439                                        (bc_v2i64 (v4i32 immAllOnesV))),
1440                                   (memopv2i64 addr:$src2))))],
1441     // double r+m
1442     [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1443                            (memopv2i64 addr:$src2)))]]>;
1444
1445 //===----------------------------------------------------------------------===//
1446 // SSE 1 & 2 - Arithmetic Instructions
1447 //===----------------------------------------------------------------------===//
1448
1449 /// basic_sse12_fp_binop_xxx - SSE 1 & 2 binops come in both scalar and
1450 /// vector forms.
1451 ///
1452 /// In addition, we also have a special variant of the scalar form here to
1453 /// represent the associated intrinsic operation.  This form is unlike the
1454 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
1455 /// and leaves the top elements unmodified (therefore these cannot be commuted).
1456 ///
1457 /// These three forms can each be reg+reg or reg+mem.
1458 ///
1459 multiclass basic_sse12_fp_binop_s<bits<8> opc, string OpcodeStr, SDNode OpNode,
1460                                   bit Is2Addr = 1> {
1461   defm SS : sse12_fp_scalar<opc, !strconcat(OpcodeStr, "ss"),
1462                             OpNode, FR32, f32mem, Is2Addr>, XS;
1463   defm SD : sse12_fp_scalar<opc, !strconcat(OpcodeStr, "sd"),
1464                             OpNode, FR64, f64mem, Is2Addr>, XD;
1465 }
1466
1467 multiclass basic_sse12_fp_binop_p<bits<8> opc, string OpcodeStr, SDNode OpNode,
1468                                    bit Is2Addr = 1> {
1469   let mayLoad = 0 in {
1470   defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, VR128,
1471               v4f32, f128mem, memopv4f32, SSEPackedSingle, Is2Addr>, TB;
1472   defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, VR128,
1473               v2f64, f128mem, memopv2f64, SSEPackedDouble, Is2Addr>, TB, OpSize;
1474   }
1475 }
1476
1477 multiclass basic_sse12_fp_binop_p_y<bits<8> opc, string OpcodeStr,
1478                                     SDNode OpNode> {
1479   let mayLoad = 0 in {
1480     defm PSY : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, VR256,
1481                 v8f32, f256mem, memopv8f32, SSEPackedSingle, 0>, TB;
1482     defm PDY : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, VR256,
1483                 v4f64, f256mem, memopv4f64, SSEPackedDouble, 0>, TB, OpSize;
1484   }
1485 }
1486
1487 multiclass basic_sse12_fp_binop_s_int<bits<8> opc, string OpcodeStr,
1488                                    bit Is2Addr = 1> {
1489   defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1490      !strconcat(OpcodeStr, "ss"), "", "_ss", ssmem, sse_load_f32, Is2Addr>, XS;
1491   defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1492      !strconcat(OpcodeStr, "sd"), "2", "_sd", sdmem, sse_load_f64, Is2Addr>, XD;
1493 }
1494
1495 multiclass basic_sse12_fp_binop_p_int<bits<8> opc, string OpcodeStr,
1496                                    bit Is2Addr = 1> {
1497   defm PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1498      !strconcat(OpcodeStr, "ps"), "", "_ps", f128mem, memopv4f32,
1499                                               SSEPackedSingle, Is2Addr>, TB;
1500
1501   defm PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1502      !strconcat(OpcodeStr, "pd"), "2", "_pd", f128mem, memopv2f64,
1503                                       SSEPackedDouble, Is2Addr>, TB, OpSize;
1504 }
1505
1506 // Binary Arithmetic instructions
1507 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
1508   defm VADD : basic_sse12_fp_binop_s<0x58, "add", fadd, 0>,
1509               basic_sse12_fp_binop_p<0x58, "add", fadd, 0>,
1510               basic_sse12_fp_binop_p_y<0x58, "add", fadd>, VEX_4V;
1511   defm VMUL : basic_sse12_fp_binop_s<0x59, "mul", fmul, 0>,
1512               basic_sse12_fp_binop_p<0x59, "mul", fmul, 0>,
1513               basic_sse12_fp_binop_p_y<0x59, "mul", fmul>, VEX_4V;
1514
1515   let isCommutable = 0 in {
1516     defm VSUB : basic_sse12_fp_binop_s<0x5C, "sub", fsub, 0>,
1517                 basic_sse12_fp_binop_p<0x5C, "sub", fsub, 0>,
1518                 basic_sse12_fp_binop_p_y<0x5C, "sub", fsub>, VEX_4V;
1519     defm VDIV : basic_sse12_fp_binop_s<0x5E, "div", fdiv, 0>,
1520                 basic_sse12_fp_binop_p<0x5E, "div", fdiv, 0>,
1521                 basic_sse12_fp_binop_p_y<0x5E, "div", fdiv>, VEX_4V;
1522     defm VMAX : basic_sse12_fp_binop_s<0x5F, "max", X86fmax, 0>,
1523                 basic_sse12_fp_binop_p<0x5F, "max", X86fmax, 0>,
1524                 basic_sse12_fp_binop_p_y<0x5F, "max", X86fmax>, VEX_4V;
1525     defm VMIN : basic_sse12_fp_binop_s<0x5D, "min", X86fmin, 0>,
1526                 basic_sse12_fp_binop_p<0x5D, "min", X86fmin, 0>,
1527                 basic_sse12_fp_binop_p_y<0x5D, "min", X86fmin>, VEX_4V;
1528   }
1529 }
1530
1531 let Constraints = "$src1 = $dst" in {
1532   defm ADD : basic_sse12_fp_binop_s<0x58, "add", fadd>,
1533              basic_sse12_fp_binop_p<0x58, "add", fadd>,
1534              basic_sse12_fp_binop_s_int<0x58, "add">;
1535   defm MUL : basic_sse12_fp_binop_s<0x59, "mul", fmul>,
1536              basic_sse12_fp_binop_p<0x59, "mul", fmul>,
1537              basic_sse12_fp_binop_s_int<0x59, "mul">;
1538
1539   let isCommutable = 0 in {
1540     defm SUB : basic_sse12_fp_binop_s<0x5C, "sub", fsub>,
1541                basic_sse12_fp_binop_p<0x5C, "sub", fsub>,
1542                basic_sse12_fp_binop_s_int<0x5C, "sub">;
1543     defm DIV : basic_sse12_fp_binop_s<0x5E, "div", fdiv>,
1544                basic_sse12_fp_binop_p<0x5E, "div", fdiv>,
1545                basic_sse12_fp_binop_s_int<0x5E, "div">;
1546     defm MAX : basic_sse12_fp_binop_s<0x5F, "max", X86fmax>,
1547                basic_sse12_fp_binop_p<0x5F, "max", X86fmax>,
1548                basic_sse12_fp_binop_s_int<0x5F, "max">,
1549                basic_sse12_fp_binop_p_int<0x5F, "max">;
1550     defm MIN : basic_sse12_fp_binop_s<0x5D, "min", X86fmin>,
1551                basic_sse12_fp_binop_p<0x5D, "min", X86fmin>,
1552                basic_sse12_fp_binop_s_int<0x5D, "min">,
1553                basic_sse12_fp_binop_p_int<0x5D, "min">;
1554   }
1555 }
1556
1557 /// Unop Arithmetic
1558 /// In addition, we also have a special variant of the scalar form here to
1559 /// represent the associated intrinsic operation.  This form is unlike the
1560 /// plain scalar form, in that it takes an entire vector (instead of a
1561 /// scalar) and leaves the top elements undefined.
1562 ///
1563 /// And, we have a special variant form for a full-vector intrinsic form.
1564
1565 /// sse1_fp_unop_s - SSE1 unops in scalar form.
1566 multiclass sse1_fp_unop_s<bits<8> opc, string OpcodeStr,
1567                           SDNode OpNode, Intrinsic F32Int> {
1568   def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1569                 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1570                 [(set FR32:$dst, (OpNode FR32:$src))]>;
1571   // For scalar unary operations, fold a load into the operation
1572   // only in OptForSize mode. It eliminates an instruction, but it also
1573   // eliminates a whole-register clobber (the load), so it introduces a
1574   // partial register update condition.
1575   def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
1576                 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1577                 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
1578             Requires<[HasSSE1, OptForSize]>;
1579   def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1580                     !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1581                     [(set VR128:$dst, (F32Int VR128:$src))]>;
1582   def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
1583                     !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1584                     [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1585 }
1586
1587 /// sse1_fp_unop_p - SSE1 unops in scalar form.
1588 multiclass sse1_fp_unop_p<bits<8> opc, string OpcodeStr,
1589                           SDNode OpNode, Intrinsic V4F32Int> {
1590   def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1591               !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1592               [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]>;
1593   def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1594                 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1595                 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
1596   def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1597                     !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1598                     [(set VR128:$dst, (V4F32Int VR128:$src))]>;
1599   def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1600                     !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1601                     [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
1602 }
1603
1604 /// sse1_fp_unop_s_avx - AVX SSE1 unops in scalar form.
1605 multiclass sse1_fp_unop_s_avx<bits<8> opc, string OpcodeStr,
1606                               SDNode OpNode, Intrinsic F32Int> {
1607   def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
1608                 !strconcat(!strconcat("v", OpcodeStr),
1609                            "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
1610   def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
1611                 !strconcat(!strconcat("v", OpcodeStr),
1612                            "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1613                 []>, XS, Requires<[HasAVX, HasSSE1, OptForSize]>;
1614   def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
1615                 (ins VR128:$src1, VR128:$src2),
1616                 !strconcat(!strconcat("v", OpcodeStr),
1617                            "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
1618   def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
1619                 (ins VR128:$src1, ssmem:$src2),
1620                 !strconcat(!strconcat("v", OpcodeStr),
1621                            "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
1622 }
1623
1624 /// sse2_fp_unop_s - SSE2 unops in scalar form.
1625 multiclass sse2_fp_unop_s<bits<8> opc, string OpcodeStr,
1626                           SDNode OpNode, Intrinsic F64Int> {
1627   def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1628                 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1629                 [(set FR64:$dst, (OpNode FR64:$src))]>;
1630   // See the comments in sse1_fp_unop_s for why this is OptForSize.
1631   def SDm : I<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1632                 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1633                 [(set FR64:$dst, (OpNode (load addr:$src)))]>, XD,
1634             Requires<[HasSSE2, OptForSize]>;
1635   def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1636                     !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1637                     [(set VR128:$dst, (F64Int VR128:$src))]>;
1638   def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1639                     !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1640                     [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1641 }
1642
1643 /// sse2_fp_unop_p - SSE2 unops in vector forms.
1644 multiclass sse2_fp_unop_p<bits<8> opc, string OpcodeStr,
1645                           SDNode OpNode, Intrinsic V2F64Int> {
1646   def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1647               !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1648               [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]>;
1649   def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1650                 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1651                 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
1652   def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1653                     !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1654                     [(set VR128:$dst, (V2F64Int VR128:$src))]>;
1655   def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1656                     !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1657                     [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
1658 }
1659
1660 /// sse2_fp_unop_s_avx - AVX SSE2 unops in scalar form.
1661 multiclass sse2_fp_unop_s_avx<bits<8> opc, string OpcodeStr,
1662                               SDNode OpNode, Intrinsic F64Int> {
1663   def SDr : VSDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1664                 !strconcat(OpcodeStr,
1665                            "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
1666   def SDm : VSDI<opc, MRMSrcMem, (outs FR64:$dst),
1667                 (ins FR64:$src1, f64mem:$src2),
1668                 !strconcat(OpcodeStr,
1669                            "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
1670   def SDr_Int : VSDI<opc, MRMSrcReg, (outs VR128:$dst),
1671            (ins VR128:$src1, VR128:$src2),
1672            !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1673                     []>;
1674   def SDm_Int : VSDI<opc, MRMSrcMem, (outs VR128:$dst),
1675            (ins VR128:$src1, sdmem:$src2),
1676            !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1677                     []>;
1678 }
1679
1680 let isAsmParserOnly = 1 in {
1681   // Square root.
1682   let Predicates = [HasAVX, HasSSE2] in {
1683   defm VSQRT  : sse2_fp_unop_s_avx<0x51, "sqrt", fsqrt, int_x86_sse2_sqrt_sd>,
1684                   VEX_4V;
1685
1686   defm VSQRT  : sse2_fp_unop_p<0x51, "vsqrt", fsqrt, int_x86_sse2_sqrt_pd>, VEX;
1687   }
1688
1689   let Predicates = [HasAVX, HasSSE1] in {
1690   defm VSQRT  : sse1_fp_unop_s_avx<0x51, "sqrt", fsqrt, int_x86_sse_sqrt_ss>,
1691                   VEX_4V;
1692   defm VSQRT  : sse1_fp_unop_p<0x51, "vsqrt", fsqrt, int_x86_sse_sqrt_ps>, VEX;
1693   // Reciprocal approximations. Note that these typically require refinement
1694   // in order to obtain suitable precision.
1695   defm VRSQRT : sse1_fp_unop_s_avx<0x52, "rsqrt", X86frsqrt,
1696                                    int_x86_sse_rsqrt_ss>, VEX_4V;
1697   defm VRSQRT : sse1_fp_unop_p<0x52, "vrsqrt", X86frsqrt, int_x86_sse_rsqrt_ps>,
1698                                    VEX;
1699   defm VRCP   : sse1_fp_unop_s_avx<0x53, "rcp", X86frcp, int_x86_sse_rcp_ss>,
1700                                    VEX_4V;
1701   defm VRCP   : sse1_fp_unop_p<0x53, "vrcp", X86frcp, int_x86_sse_rcp_ps>,
1702                                    VEX;
1703   }
1704 }
1705
1706 // Square root.
1707 defm SQRT  : sse1_fp_unop_s<0x51, "sqrt",  fsqrt, int_x86_sse_sqrt_ss>,
1708              sse1_fp_unop_p<0x51, "sqrt",  fsqrt, int_x86_sse_sqrt_ps>,
1709              sse2_fp_unop_s<0x51, "sqrt",  fsqrt, int_x86_sse2_sqrt_sd>,
1710              sse2_fp_unop_p<0x51, "sqrt",  fsqrt, int_x86_sse2_sqrt_pd>;
1711
1712 // Reciprocal approximations. Note that these typically require refinement
1713 // in order to obtain suitable precision.
1714 defm RSQRT : sse1_fp_unop_s<0x52, "rsqrt", X86frsqrt, int_x86_sse_rsqrt_ss>,
1715              sse1_fp_unop_p<0x52, "rsqrt", X86frsqrt, int_x86_sse_rsqrt_ps>;
1716 defm RCP   : sse1_fp_unop_s<0x53, "rcp", X86frcp, int_x86_sse_rcp_ss>,
1717              sse1_fp_unop_p<0x53, "rcp", X86frcp, int_x86_sse_rcp_ps>;
1718
1719 // There is no f64 version of the reciprocal approximation instructions.
1720
1721 //===----------------------------------------------------------------------===//
1722 // SSE 1 & 2 - Non-temporal stores
1723 //===----------------------------------------------------------------------===//
1724
1725 let isAsmParserOnly = 1 in {
1726   def VMOVNTPSmr_Int : VPSI<0x2B, MRMDestMem, (outs),
1727                          (ins i128mem:$dst, VR128:$src),
1728                          "movntps\t{$src, $dst|$dst, $src}",
1729                          [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>, VEX;
1730   def VMOVNTPDmr_Int : VPDI<0x2B, MRMDestMem, (outs),
1731                          (ins i128mem:$dst, VR128:$src),
1732                          "movntpd\t{$src, $dst|$dst, $src}",
1733                          [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>, VEX;
1734
1735   let ExeDomain = SSEPackedInt in
1736     def VMOVNTDQmr_Int : VPDI<0xE7, MRMDestMem, (outs),
1737                        (ins f128mem:$dst, VR128:$src),
1738                        "movntdq\t{$src, $dst|$dst, $src}",
1739                        [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>, VEX;
1740
1741   let AddedComplexity = 400 in { // Prefer non-temporal versions
1742     def VMOVNTPSmr : VPSI<0x2B, MRMDestMem, (outs),
1743                          (ins f128mem:$dst, VR128:$src),
1744                          "movntps\t{$src, $dst|$dst, $src}",
1745                          [(alignednontemporalstore (v4f32 VR128:$src),
1746                                                    addr:$dst)]>, VEX;
1747     def VMOVNTPDmr : VPDI<0x2B, MRMDestMem, (outs),
1748                          (ins f128mem:$dst, VR128:$src),
1749                          "movntpd\t{$src, $dst|$dst, $src}",
1750                          [(alignednontemporalstore (v2f64 VR128:$src),
1751                                                    addr:$dst)]>, VEX;
1752     def VMOVNTDQ_64mr : VPDI<0xE7, MRMDestMem, (outs),
1753                           (ins f128mem:$dst, VR128:$src),
1754                           "movntdq\t{$src, $dst|$dst, $src}",
1755                           [(alignednontemporalstore (v2f64 VR128:$src),
1756                                                     addr:$dst)]>, VEX;
1757     let ExeDomain = SSEPackedInt in
1758     def VMOVNTDQmr : VPDI<0xE7, MRMDestMem, (outs),
1759                         (ins f128mem:$dst, VR128:$src),
1760                         "movntdq\t{$src, $dst|$dst, $src}",
1761                         [(alignednontemporalstore (v4f32 VR128:$src),
1762                                                   addr:$dst)]>, VEX;
1763
1764     def VMOVNTPSYmr : VPSI<0x2B, MRMDestMem, (outs),
1765                          (ins f256mem:$dst, VR256:$src),
1766                          "movntps\t{$src, $dst|$dst, $src}",
1767                          [(alignednontemporalstore (v8f32 VR256:$src),
1768                                                    addr:$dst)]>, VEX;
1769     def VMOVNTPDYmr : VPDI<0x2B, MRMDestMem, (outs),
1770                          (ins f256mem:$dst, VR256:$src),
1771                          "movntpd\t{$src, $dst|$dst, $src}",
1772                          [(alignednontemporalstore (v4f64 VR256:$src),
1773                                                    addr:$dst)]>, VEX;
1774     def VMOVNTDQY_64mr : VPDI<0xE7, MRMDestMem, (outs),
1775                           (ins f256mem:$dst, VR256:$src),
1776                           "movntdq\t{$src, $dst|$dst, $src}",
1777                           [(alignednontemporalstore (v4f64 VR256:$src),
1778                                                     addr:$dst)]>, VEX;
1779     let ExeDomain = SSEPackedInt in
1780     def VMOVNTDQYmr : VPDI<0xE7, MRMDestMem, (outs),
1781                         (ins f256mem:$dst, VR256:$src),
1782                         "movntdq\t{$src, $dst|$dst, $src}",
1783                         [(alignednontemporalstore (v8f32 VR256:$src),
1784                                                   addr:$dst)]>, VEX;
1785   }
1786 }
1787
1788 def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1789                     "movntps\t{$src, $dst|$dst, $src}",
1790                     [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
1791 def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1792                         "movntpd\t{$src, $dst|$dst, $src}",
1793                         [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
1794
1795 let ExeDomain = SSEPackedInt in
1796 def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1797                         "movntdq\t{$src, $dst|$dst, $src}",
1798                         [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
1799
1800 let AddedComplexity = 400 in { // Prefer non-temporal versions
1801 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1802                     "movntps\t{$src, $dst|$dst, $src}",
1803                     [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1804 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1805                     "movntpd\t{$src, $dst|$dst, $src}",
1806                     [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
1807
1808 def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1809                     "movntdq\t{$src, $dst|$dst, $src}",
1810                     [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
1811
1812 let ExeDomain = SSEPackedInt in
1813 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1814                     "movntdq\t{$src, $dst|$dst, $src}",
1815                     [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1816
1817 // There is no AVX form for instructions below this point
1818 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1819                  "movnti\t{$src, $dst|$dst, $src}",
1820                  [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
1821                TB, Requires<[HasSSE2]>;
1822
1823 def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1824                      "movnti\t{$src, $dst|$dst, $src}",
1825                      [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
1826                   TB, Requires<[HasSSE2]>;
1827
1828 }
1829 def MOVNTImr_Int  :   I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1830                     "movnti\t{$src, $dst|$dst, $src}",
1831                     [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
1832                   TB, Requires<[HasSSE2]>;
1833
1834 //===----------------------------------------------------------------------===//
1835 // SSE 1 & 2 - Misc Instructions (No AVX form)
1836 //===----------------------------------------------------------------------===//
1837
1838 // Prefetch intrinsic.
1839 def PREFETCHT0   : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
1840     "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
1841 def PREFETCHT1   : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
1842     "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
1843 def PREFETCHT2   : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
1844     "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
1845 def PREFETCHNTA  : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
1846     "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
1847
1848 // Load, store, and memory fence
1849 def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
1850              TB, Requires<[HasSSE1]>;
1851
1852 // Alias instructions that map zero vector to pxor / xorp* for sse.
1853 // We set canFoldAsLoad because this can be converted to a constant-pool
1854 // load of an all-zeros value if folding it would be beneficial.
1855 // FIXME: Change encoding to pseudo!
1856 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
1857     isCodeGenOnly = 1 in {
1858 def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1859                  [(set VR128:$dst, (v4f32 immAllZerosV))]>;
1860 def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1861                  [(set VR128:$dst, (v2f64 immAllZerosV))]>;
1862 let ExeDomain = SSEPackedInt in
1863 def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
1864                  [(set VR128:$dst, (v4i32 immAllZerosV))]>;
1865 }
1866
1867 def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
1868 def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
1869 def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
1870
1871 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
1872           (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1873
1874 //===----------------------------------------------------------------------===//
1875 // SSE 1 & 2 - Load/Store XCSR register
1876 //===----------------------------------------------------------------------===//
1877
1878 let isAsmParserOnly = 1 in {
1879   def VLDMXCSR : VPSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
1880                     "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>, VEX;
1881   def VSTMXCSR : VPSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
1882                     "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>, VEX;
1883 }
1884
1885 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
1886                   "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
1887 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
1888                   "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
1889
1890 //===---------------------------------------------------------------------===//
1891 // SSE2 - Move Aligned/Unaligned Packed Integer Instructions
1892 //===---------------------------------------------------------------------===//
1893 let ExeDomain = SSEPackedInt in { // SSE integer instructions
1894
1895 let isAsmParserOnly = 1 in {
1896   let neverHasSideEffects = 1 in
1897   def VMOVDQArr : VPDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1898                      "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
1899   def VMOVDQUrr : VPDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1900                      "movdqu\t{$src, $dst|$dst, $src}", []>, XS, VEX;
1901
1902   let canFoldAsLoad = 1, mayLoad = 1 in {
1903   def VMOVDQArm : VPDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1904                      "movdqa\t{$src, $dst|$dst, $src}",
1905                      [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>,
1906                      VEX;
1907   def VMOVDQUrm :  I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1908                      "vmovdqu\t{$src, $dst|$dst, $src}",
1909                      [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
1910                    XS, VEX, Requires<[HasAVX, HasSSE2]>;
1911   }
1912
1913   let mayStore = 1 in {
1914   def VMOVDQAmr : VPDI<0x7F, MRMDestMem, (outs),
1915                      (ins i128mem:$dst, VR128:$src),
1916                      "movdqa\t{$src, $dst|$dst, $src}",
1917                      [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>, VEX;
1918   def VMOVDQUmr :  I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1919                      "vmovdqu\t{$src, $dst|$dst, $src}",
1920                      [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
1921                    XS, VEX, Requires<[HasAVX, HasSSE2]>;
1922   }
1923 }
1924
1925 let neverHasSideEffects = 1 in
1926 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1927                    "movdqa\t{$src, $dst|$dst, $src}", []>;
1928
1929 let canFoldAsLoad = 1, mayLoad = 1 in {
1930 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1931                    "movdqa\t{$src, $dst|$dst, $src}",
1932                    [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
1933 def MOVDQUrm :   I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1934                    "movdqu\t{$src, $dst|$dst, $src}",
1935                    [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
1936                  XS, Requires<[HasSSE2]>;
1937 }
1938
1939 let mayStore = 1 in {
1940 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1941                    "movdqa\t{$src, $dst|$dst, $src}",
1942                    [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
1943 def MOVDQUmr :   I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1944                    "movdqu\t{$src, $dst|$dst, $src}",
1945                    [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
1946                  XS, Requires<[HasSSE2]>;
1947 }
1948
1949 // Intrinsic forms of MOVDQU load and store
1950 let isAsmParserOnly = 1 in {
1951 let canFoldAsLoad = 1 in
1952 def VMOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1953                        "vmovdqu\t{$src, $dst|$dst, $src}",
1954                        [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1955                      XS, VEX, Requires<[HasAVX, HasSSE2]>;
1956 def VMOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1957                        "vmovdqu\t{$src, $dst|$dst, $src}",
1958                        [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1959                      XS, VEX, Requires<[HasAVX, HasSSE2]>;
1960 }
1961
1962 let canFoldAsLoad = 1 in
1963 def MOVDQUrm_Int :   I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1964                        "movdqu\t{$src, $dst|$dst, $src}",
1965                        [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1966                  XS, Requires<[HasSSE2]>;
1967 def MOVDQUmr_Int :   I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1968                        "movdqu\t{$src, $dst|$dst, $src}",
1969                        [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1970                      XS, Requires<[HasSSE2]>;
1971
1972 } // ExeDomain = SSEPackedInt
1973
1974 //===---------------------------------------------------------------------===//
1975 // SSE2 - Packed Integer Arithmetic Instructions
1976 //===---------------------------------------------------------------------===//
1977
1978 let ExeDomain = SSEPackedInt in { // SSE integer instructions
1979
1980 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1981                             bit IsCommutable = 0, bit Is2Addr = 1> {
1982   let isCommutable = IsCommutable in
1983   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1984        (ins VR128:$src1, VR128:$src2),
1985        !if(Is2Addr,
1986            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1987            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
1988        [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
1989   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1990        (ins VR128:$src1, i128mem:$src2),
1991        !if(Is2Addr,
1992            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1993            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
1994        [(set VR128:$dst, (IntId VR128:$src1,
1995                                 (bitconvert (memopv2i64 addr:$src2))))]>;
1996 }
1997
1998 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1999                              string OpcodeStr, Intrinsic IntId,
2000                              Intrinsic IntId2, bit Is2Addr = 1> {
2001   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2002        (ins VR128:$src1, VR128:$src2),
2003        !if(Is2Addr,
2004            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2005            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2006        [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
2007   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2008        (ins VR128:$src1, i128mem:$src2),
2009        !if(Is2Addr,
2010            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2011            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2012        [(set VR128:$dst, (IntId VR128:$src1,
2013                                       (bitconvert (memopv2i64 addr:$src2))))]>;
2014   def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
2015        (ins VR128:$src1, i32i8imm:$src2),
2016        !if(Is2Addr,
2017            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2018            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2019        [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
2020 }
2021
2022 /// PDI_binop_rm - Simple SSE2 binary operator.
2023 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
2024                         ValueType OpVT, bit IsCommutable = 0, bit Is2Addr = 1> {
2025   let isCommutable = IsCommutable in
2026   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2027        (ins VR128:$src1, VR128:$src2),
2028        !if(Is2Addr,
2029            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2030            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2031        [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>;
2032   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2033        (ins VR128:$src1, i128mem:$src2),
2034        !if(Is2Addr,
2035            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2036            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2037        [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
2038                                      (bitconvert (memopv2i64 addr:$src2)))))]>;
2039 }
2040
2041 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
2042 ///
2043 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
2044 /// to collapse (bitconvert VT to VT) into its operand.
2045 ///
2046 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
2047                               bit IsCommutable = 0, bit Is2Addr = 1> {
2048   let isCommutable = IsCommutable in
2049   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2050        (ins VR128:$src1, VR128:$src2),
2051        !if(Is2Addr,
2052            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2053            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2054        [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]>;
2055   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2056        (ins VR128:$src1, i128mem:$src2),
2057        !if(Is2Addr,
2058            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2059            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2060        [(set VR128:$dst, (OpNode VR128:$src1, (memopv2i64 addr:$src2)))]>;
2061 }
2062
2063 } // ExeDomain = SSEPackedInt
2064
2065 // 128-bit Integer Arithmetic
2066
2067 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE2] in {
2068 defm VPADDB  : PDI_binop_rm<0xFC, "vpaddb", add, v16i8, 1, 0 /*3addr*/>, VEX_4V;
2069 defm VPADDW  : PDI_binop_rm<0xFD, "vpaddw", add, v8i16, 1, 0>, VEX_4V;
2070 defm VPADDD  : PDI_binop_rm<0xFE, "vpaddd", add, v4i32, 1, 0>, VEX_4V;
2071 defm VPADDQ  : PDI_binop_rm_v2i64<0xD4, "vpaddq", add, 1, 0>, VEX_4V;
2072 defm VPMULLW : PDI_binop_rm<0xD5, "vpmullw", mul, v8i16, 1, 0>, VEX_4V;
2073 defm VPSUBB : PDI_binop_rm<0xF8, "vpsubb", sub, v16i8, 0, 0>, VEX_4V;
2074 defm VPSUBW : PDI_binop_rm<0xF9, "vpsubw", sub, v8i16, 0, 0>, VEX_4V;
2075 defm VPSUBD : PDI_binop_rm<0xFA, "vpsubd", sub, v4i32, 0, 0>, VEX_4V;
2076 defm VPSUBQ : PDI_binop_rm_v2i64<0xFB, "vpsubq", sub, 0, 0>, VEX_4V;
2077
2078 // Intrinsic forms
2079 defm VPSUBSB  : PDI_binop_rm_int<0xE8, "vpsubsb" , int_x86_sse2_psubs_b, 0, 0>,
2080                                  VEX_4V;
2081 defm VPSUBSW  : PDI_binop_rm_int<0xE9, "vpsubsw" , int_x86_sse2_psubs_w, 0, 0>,
2082                                  VEX_4V;
2083 defm VPSUBUSB : PDI_binop_rm_int<0xD8, "vpsubusb", int_x86_sse2_psubus_b, 0, 0>,
2084                                  VEX_4V;
2085 defm VPSUBUSW : PDI_binop_rm_int<0xD9, "vpsubusw", int_x86_sse2_psubus_w, 0, 0>,
2086                                  VEX_4V;
2087 defm VPADDSB  : PDI_binop_rm_int<0xEC, "vpaddsb" , int_x86_sse2_padds_b, 1, 0>,
2088                                  VEX_4V;
2089 defm VPADDSW  : PDI_binop_rm_int<0xED, "vpaddsw" , int_x86_sse2_padds_w, 1, 0>,
2090                                  VEX_4V;
2091 defm VPADDUSB : PDI_binop_rm_int<0xDC, "vpaddusb", int_x86_sse2_paddus_b, 1, 0>,
2092                                  VEX_4V;
2093 defm VPADDUSW : PDI_binop_rm_int<0xDD, "vpaddusw", int_x86_sse2_paddus_w, 1, 0>,
2094                                  VEX_4V;
2095 defm VPMULHUW : PDI_binop_rm_int<0xE4, "vpmulhuw", int_x86_sse2_pmulhu_w, 1, 0>,
2096                                  VEX_4V;
2097 defm VPMULHW  : PDI_binop_rm_int<0xE5, "vpmulhw" , int_x86_sse2_pmulh_w, 1, 0>,
2098                                  VEX_4V;
2099 defm VPMULUDQ : PDI_binop_rm_int<0xF4, "vpmuludq", int_x86_sse2_pmulu_dq, 1, 0>,
2100                                  VEX_4V;
2101 defm VPMADDWD : PDI_binop_rm_int<0xF5, "vpmaddwd", int_x86_sse2_pmadd_wd, 1, 0>,
2102                                  VEX_4V;
2103 defm VPAVGB   : PDI_binop_rm_int<0xE0, "vpavgb", int_x86_sse2_pavg_b, 1, 0>,
2104                                  VEX_4V;
2105 defm VPAVGW   : PDI_binop_rm_int<0xE3, "vpavgw", int_x86_sse2_pavg_w, 1, 0>,
2106                                  VEX_4V;
2107 defm VPMINUB  : PDI_binop_rm_int<0xDA, "vpminub", int_x86_sse2_pminu_b, 1, 0>,
2108                                  VEX_4V;
2109 defm VPMINSW  : PDI_binop_rm_int<0xEA, "vpminsw", int_x86_sse2_pmins_w, 1, 0>,
2110                                  VEX_4V;
2111 defm VPMAXUB  : PDI_binop_rm_int<0xDE, "vpmaxub", int_x86_sse2_pmaxu_b, 1, 0>,
2112                                  VEX_4V;
2113 defm VPMAXSW  : PDI_binop_rm_int<0xEE, "vpmaxsw", int_x86_sse2_pmaxs_w, 1, 0>,
2114                                  VEX_4V;
2115 defm VPSADBW  : PDI_binop_rm_int<0xF6, "vpsadbw", int_x86_sse2_psad_bw, 1, 0>,
2116                                  VEX_4V;
2117 }
2118
2119 let Constraints = "$src1 = $dst" in {
2120 defm PADDB  : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
2121 defm PADDW  : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
2122 defm PADDD  : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
2123 defm PADDQ  : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
2124 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
2125 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
2126 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
2127 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
2128 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
2129
2130 // Intrinsic forms
2131 defm PSUBSB  : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
2132 defm PSUBSW  : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
2133 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
2134 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
2135 defm PADDSB  : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
2136 defm PADDSW  : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
2137 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
2138 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
2139 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
2140 defm PMULHW  : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w, 1>;
2141 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
2142 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
2143 defm PAVGB   : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
2144 defm PAVGW   : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
2145 defm PMINUB  : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
2146 defm PMINSW  : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
2147 defm PMAXUB  : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
2148 defm PMAXSW  : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
2149 defm PSADBW  : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
2150
2151 } // Constraints = "$src1 = $dst"
2152
2153 //===---------------------------------------------------------------------===//
2154 // SSE2 - Packed Integer Logical Instructions
2155 //===---------------------------------------------------------------------===//
2156
2157 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE2] in {
2158 defm VPSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "vpsllw",
2159                                 int_x86_sse2_psll_w, int_x86_sse2_pslli_w, 0>,
2160                                 VEX_4V;
2161 defm VPSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "vpslld",
2162                                 int_x86_sse2_psll_d, int_x86_sse2_pslli_d, 0>,
2163                                 VEX_4V;
2164 defm VPSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "vpsllq",
2165                                 int_x86_sse2_psll_q, int_x86_sse2_pslli_q, 0>,
2166                                 VEX_4V;
2167
2168 defm VPSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "vpsrlw",
2169                                 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w, 0>,
2170                                 VEX_4V;
2171 defm VPSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "vpsrld",
2172                                 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d, 0>,
2173                                 VEX_4V;
2174 defm VPSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "vpsrlq",
2175                                 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q, 0>,
2176                                 VEX_4V;
2177
2178 defm VPSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "vpsraw",
2179                                 int_x86_sse2_psra_w, int_x86_sse2_psrai_w, 0>,
2180                                 VEX_4V;
2181 defm VPSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "vpsrad",
2182                                 int_x86_sse2_psra_d, int_x86_sse2_psrai_d, 0>,
2183                                 VEX_4V;
2184
2185 defm VPAND : PDI_binop_rm_v2i64<0xDB, "vpand", and, 1, 0>, VEX_4V;
2186 defm VPOR  : PDI_binop_rm_v2i64<0xEB, "vpor" , or, 1, 0>, VEX_4V;
2187 defm VPXOR : PDI_binop_rm_v2i64<0xEF, "vpxor", xor, 1, 0>, VEX_4V;
2188
2189 let ExeDomain = SSEPackedInt in {
2190   let neverHasSideEffects = 1 in {
2191     // 128-bit logical shifts.
2192     def VPSLLDQri : PDIi8<0x73, MRM7r,
2193                       (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2194                       "vpslldq\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
2195                       VEX_4V;
2196     def VPSRLDQri : PDIi8<0x73, MRM3r,
2197                       (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2198                       "vpsrldq\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
2199                       VEX_4V;
2200     // PSRADQri doesn't exist in SSE[1-3].
2201   }
2202   def VPANDNrr : PDI<0xDF, MRMSrcReg,
2203                     (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2204                     "vpandn\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2205                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2206                                               VR128:$src2)))]>, VEX_4V;
2207
2208   def VPANDNrm : PDI<0xDF, MRMSrcMem,
2209                     (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2210                     "vpandn\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2211                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2212                                               (memopv2i64 addr:$src2))))]>,
2213                                               VEX_4V;
2214 }
2215 }
2216
2217 let Constraints = "$src1 = $dst" in {
2218 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
2219                                int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
2220 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
2221                                int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
2222 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2223                                int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
2224
2225 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2226                                int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2227 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2228                                int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
2229 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
2230                                int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
2231
2232 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2233                                int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
2234 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
2235                                int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
2236
2237 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2238 defm POR  : PDI_binop_rm_v2i64<0xEB, "por" , or, 1>;
2239 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2240
2241 let ExeDomain = SSEPackedInt in {
2242   let neverHasSideEffects = 1 in {
2243     // 128-bit logical shifts.
2244     def PSLLDQri : PDIi8<0x73, MRM7r,
2245                          (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2246                          "pslldq\t{$src2, $dst|$dst, $src2}", []>;
2247     def PSRLDQri : PDIi8<0x73, MRM3r,
2248                          (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2249                          "psrldq\t{$src2, $dst|$dst, $src2}", []>;
2250     // PSRADQri doesn't exist in SSE[1-3].
2251   }
2252   def PANDNrr : PDI<0xDF, MRMSrcReg,
2253                     (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2254                     "pandn\t{$src2, $dst|$dst, $src2}",
2255                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2256                                               VR128:$src2)))]>;
2257
2258   def PANDNrm : PDI<0xDF, MRMSrcMem,
2259                     (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2260                     "pandn\t{$src2, $dst|$dst, $src2}",
2261                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2262                                               (memopv2i64 addr:$src2))))]>;
2263 }
2264 } // Constraints = "$src1 = $dst"
2265
2266 let Predicates = [HasSSE2] in {
2267   def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
2268             (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2269   def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2270             (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2271   def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2272             (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2273   def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2274             (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
2275   def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2276             (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2277
2278   // Shift up / down and insert zero's.
2279   def : Pat<(v2i64 (X86vshl  VR128:$src, (i8 imm:$amt))),
2280             (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2281   def : Pat<(v2i64 (X86vshr  VR128:$src, (i8 imm:$amt))),
2282             (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2283 }
2284
2285 //===---------------------------------------------------------------------===//
2286 // SSE2 - Packed Integer Comparison Instructions
2287 //===---------------------------------------------------------------------===//
2288
2289 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE2] in {
2290   defm VPCMPEQB  : PDI_binop_rm_int<0x74, "vpcmpeqb", int_x86_sse2_pcmpeq_b, 1,
2291                                     0>, VEX_4V;
2292   defm VPCMPEQW  : PDI_binop_rm_int<0x75, "vpcmpeqw", int_x86_sse2_pcmpeq_w, 1,
2293                                     0>, VEX_4V;
2294   defm VPCMPEQD  : PDI_binop_rm_int<0x76, "vpcmpeqd", int_x86_sse2_pcmpeq_d, 1,
2295                                     0>, VEX_4V;
2296   defm VPCMPGTB  : PDI_binop_rm_int<0x64, "vpcmpgtb", int_x86_sse2_pcmpgt_b, 0,
2297                                     0>, VEX_4V;
2298   defm VPCMPGTW  : PDI_binop_rm_int<0x65, "vpcmpgtw", int_x86_sse2_pcmpgt_w, 0,
2299                                     0>, VEX_4V;
2300   defm VPCMPGTD  : PDI_binop_rm_int<0x66, "vpcmpgtd", int_x86_sse2_pcmpgt_d, 0,
2301                                     0>, VEX_4V;
2302 }
2303
2304 let Constraints = "$src1 = $dst" in {
2305   defm PCMPEQB  : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b, 1>;
2306   defm PCMPEQW  : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w, 1>;
2307   defm PCMPEQD  : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d, 1>;
2308   defm PCMPGTB  : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2309   defm PCMPGTW  : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2310   defm PCMPGTD  : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2311 } // Constraints = "$src1 = $dst"
2312
2313 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
2314           (PCMPEQBrr VR128:$src1, VR128:$src2)>;
2315 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
2316           (PCMPEQBrm VR128:$src1, addr:$src2)>;
2317 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
2318           (PCMPEQWrr VR128:$src1, VR128:$src2)>;
2319 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
2320           (PCMPEQWrm VR128:$src1, addr:$src2)>;
2321 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
2322           (PCMPEQDrr VR128:$src1, VR128:$src2)>;
2323 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
2324           (PCMPEQDrm VR128:$src1, addr:$src2)>;
2325
2326 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
2327           (PCMPGTBrr VR128:$src1, VR128:$src2)>;
2328 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
2329           (PCMPGTBrm VR128:$src1, addr:$src2)>;
2330 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
2331           (PCMPGTWrr VR128:$src1, VR128:$src2)>;
2332 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
2333           (PCMPGTWrm VR128:$src1, addr:$src2)>;
2334 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
2335           (PCMPGTDrr VR128:$src1, VR128:$src2)>;
2336 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
2337           (PCMPGTDrm VR128:$src1, addr:$src2)>;
2338
2339 //===---------------------------------------------------------------------===//
2340 // SSE2 - Packed Integer Pack Instructions
2341 //===---------------------------------------------------------------------===//
2342
2343 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE2] in {
2344 defm VPACKSSWB : PDI_binop_rm_int<0x63, "vpacksswb", int_x86_sse2_packsswb_128,
2345                                   0, 0>, VEX_4V;
2346 defm VPACKSSDW : PDI_binop_rm_int<0x6B, "vpackssdw", int_x86_sse2_packssdw_128,
2347                                   0, 0>, VEX_4V;
2348 defm VPACKUSWB : PDI_binop_rm_int<0x67, "vpackuswb", int_x86_sse2_packuswb_128,
2349                                   0, 0>, VEX_4V;
2350 }
2351
2352 let Constraints = "$src1 = $dst" in {
2353 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2354 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2355 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2356 } // Constraints = "$src1 = $dst"
2357
2358 //===---------------------------------------------------------------------===//
2359 // SSE2 - Packed Integer Shuffle Instructions
2360 //===---------------------------------------------------------------------===//
2361
2362 let ExeDomain = SSEPackedInt in {
2363 multiclass sse2_pshuffle<string OpcodeStr, ValueType vt, PatFrag pshuf_frag,
2364                          PatFrag bc_frag> {
2365 def ri : Ii8<0x70, MRMSrcReg,
2366               (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2367               !strconcat(OpcodeStr,
2368                          "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2369               [(set VR128:$dst, (vt (pshuf_frag:$src2 VR128:$src1,
2370                                                       (undef))))]>;
2371 def mi : Ii8<0x70, MRMSrcMem,
2372               (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2373               !strconcat(OpcodeStr,
2374                          "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2375               [(set VR128:$dst, (vt (pshuf_frag:$src2
2376                                       (bc_frag (memopv2i64 addr:$src1)),
2377                                       (undef))))]>;
2378 }
2379 } // ExeDomain = SSEPackedInt
2380
2381 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE2] in {
2382   let AddedComplexity = 5 in
2383   defm VPSHUFD : sse2_pshuffle<"vpshufd", v4i32, pshufd, bc_v4i32>, OpSize,
2384                                VEX;
2385
2386   // SSE2 with ImmT == Imm8 and XS prefix.
2387   defm VPSHUFHW : sse2_pshuffle<"vpshufhw", v8i16, pshufhw, bc_v8i16>, XS,
2388                                VEX;
2389
2390   // SSE2 with ImmT == Imm8 and XD prefix.
2391   defm VPSHUFLW : sse2_pshuffle<"vpshuflw", v8i16, pshuflw, bc_v8i16>, XD,
2392                                VEX;
2393 }
2394
2395 let Predicates = [HasSSE2] in {
2396   let AddedComplexity = 5 in
2397   defm PSHUFD : sse2_pshuffle<"pshufd", v4i32, pshufd, bc_v4i32>, TB, OpSize;
2398
2399   // SSE2 with ImmT == Imm8 and XS prefix.
2400   defm PSHUFHW : sse2_pshuffle<"pshufhw", v8i16, pshufhw, bc_v8i16>, XS;
2401
2402   // SSE2 with ImmT == Imm8 and XD prefix.
2403   defm PSHUFLW : sse2_pshuffle<"pshuflw", v8i16, pshuflw, bc_v8i16>, XD;
2404 }
2405
2406 //===---------------------------------------------------------------------===//
2407 // SSE2 - Packed Integer Unpack Instructions
2408 //===---------------------------------------------------------------------===//
2409
2410 let ExeDomain = SSEPackedInt in {
2411 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2412                        PatFrag unp_frag, PatFrag bc_frag, bit Is2Addr = 1> {
2413   def rr : PDI<opc, MRMSrcReg,
2414       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2415       !if(Is2Addr,
2416           !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2417           !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2418       [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2419   def rm : PDI<opc, MRMSrcMem,
2420       (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2421       !if(Is2Addr,
2422           !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2423           !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2424       [(set VR128:$dst, (unp_frag VR128:$src1,
2425                                   (bc_frag (memopv2i64
2426                                                addr:$src2))))]>;
2427 }
2428
2429 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE2] in {
2430   defm VPUNPCKLBW  : sse2_unpack<0x60, "vpunpcklbw", v16i8, unpckl, bc_v16i8,
2431                                  0>, VEX_4V;
2432   defm VPUNPCKLWD  : sse2_unpack<0x61, "vpunpcklwd", v8i16, unpckl, bc_v8i16,
2433                                  0>, VEX_4V;
2434   defm VPUNPCKLDQ  : sse2_unpack<0x62, "vpunpckldq", v4i32, unpckl, bc_v4i32,
2435                                  0>, VEX_4V;
2436
2437   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2438   /// knew to collapse (bitconvert VT to VT) into its operand.
2439   def VPUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2440                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2441                          "vpunpcklqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2442                         [(set VR128:$dst,
2443                           (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>, VEX_4V;
2444   def VPUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2445                          (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2446                          "vpunpcklqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2447                         [(set VR128:$dst,
2448                           (v2i64 (unpckl VR128:$src1,
2449                                          (memopv2i64 addr:$src2))))]>, VEX_4V;
2450
2451   defm VPUNPCKHBW  : sse2_unpack<0x68, "vpunpckhbw", v16i8, unpckh, bc_v16i8,
2452                                  0>, VEX_4V;
2453   defm VPUNPCKHWD  : sse2_unpack<0x69, "vpunpckhwd", v8i16, unpckh, bc_v8i16,
2454                                  0>, VEX_4V;
2455   defm VPUNPCKHDQ  : sse2_unpack<0x6A, "vpunpckhdq", v4i32, unpckh, bc_v4i32,
2456                                  0>, VEX_4V;
2457
2458   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2459   /// knew to collapse (bitconvert VT to VT) into its operand.
2460   def VPUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2461                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2462                          "vpunpckhqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2463                         [(set VR128:$dst,
2464                           (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>, VEX_4V;
2465   def VPUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2466                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2467                         "vpunpckhqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2468                         [(set VR128:$dst,
2469                           (v2i64 (unpckh VR128:$src1,
2470                                          (memopv2i64 addr:$src2))))]>, VEX_4V;
2471 }
2472
2473 let Constraints = "$src1 = $dst" in {
2474   defm PUNPCKLBW  : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2475   defm PUNPCKLWD  : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2476   defm PUNPCKLDQ  : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2477
2478   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2479   /// knew to collapse (bitconvert VT to VT) into its operand.
2480   def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2481                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2482                          "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2483                         [(set VR128:$dst,
2484                           (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
2485   def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2486                          (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2487                          "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2488                         [(set VR128:$dst,
2489                           (v2i64 (unpckl VR128:$src1,
2490                                          (memopv2i64 addr:$src2))))]>;
2491
2492   defm PUNPCKHBW  : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2493   defm PUNPCKHWD  : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2494   defm PUNPCKHDQ  : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2495
2496   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2497   /// knew to collapse (bitconvert VT to VT) into its operand.
2498   def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2499                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2500                          "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2501                         [(set VR128:$dst,
2502                           (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
2503   def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2504                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2505                         "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2506                         [(set VR128:$dst,
2507                           (v2i64 (unpckh VR128:$src1,
2508                                          (memopv2i64 addr:$src2))))]>;
2509 }
2510
2511 } // ExeDomain = SSEPackedInt
2512
2513 //===---------------------------------------------------------------------===//
2514 // SSE2 - Packed Integer Extract and Insert
2515 //===---------------------------------------------------------------------===//
2516
2517 let ExeDomain = SSEPackedInt in {
2518 multiclass sse2_pinsrw<bit Is2Addr = 1> {
2519   def rri : Ii8<0xC4, MRMSrcReg,
2520        (outs VR128:$dst), (ins VR128:$src1,
2521         GR32:$src2, i32i8imm:$src3),
2522        !if(Is2Addr,
2523            "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2524            "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
2525        [(set VR128:$dst,
2526          (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
2527   def rmi : Ii8<0xC4, MRMSrcMem,
2528                        (outs VR128:$dst), (ins VR128:$src1,
2529                         i16mem:$src2, i32i8imm:$src3),
2530        !if(Is2Addr,
2531            "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2532            "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
2533        [(set VR128:$dst,
2534          (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2535                     imm:$src3))]>;
2536 }
2537
2538 // Extract
2539 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE2] in
2540 def VPEXTRWri : Ii8<0xC5, MRMSrcReg,
2541                     (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2542                     "vpextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2543                     [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2544                                                 imm:$src2))]>, OpSize, VEX;
2545 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
2546                     (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2547                     "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2548                     [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2549                                                 imm:$src2))]>;
2550
2551 // Insert
2552 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE2] in
2553   defm PINSRW : sse2_pinsrw<0>, OpSize, VEX_4V;
2554
2555 let Constraints = "$src1 = $dst" in
2556   defm VPINSRW : sse2_pinsrw, TB, OpSize;
2557
2558 } // ExeDomain = SSEPackedInt
2559
2560 //===---------------------------------------------------------------------===//
2561 // SSE2 - Packed Mask Creation
2562 //===---------------------------------------------------------------------===//
2563
2564 let ExeDomain = SSEPackedInt in {
2565
2566 let isAsmParserOnly = 1 in
2567 def VPMOVMSKBrr : VPDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2568            "pmovmskb\t{$src, $dst|$dst, $src}",
2569            [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>, VEX;
2570 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2571            "pmovmskb\t{$src, $dst|$dst, $src}",
2572            [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2573
2574 } // ExeDomain = SSEPackedInt
2575
2576 //===---------------------------------------------------------------------===//
2577 // SSE2 - Conditional Store
2578 //===---------------------------------------------------------------------===//
2579
2580 let ExeDomain = SSEPackedInt in {
2581
2582 let isAsmParserOnly = 1 in {
2583 let Uses = [EDI] in
2584 def VMASKMOVDQU : VPDI<0xF7, MRMSrcReg, (outs),
2585            (ins VR128:$src, VR128:$mask),
2586            "maskmovdqu\t{$mask, $src|$src, $mask}",
2587            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>, VEX;
2588 let Uses = [RDI] in
2589 def VMASKMOVDQU64 : VPDI<0xF7, MRMSrcReg, (outs),
2590            (ins VR128:$src, VR128:$mask),
2591            "maskmovdqu\t{$mask, $src|$src, $mask}",
2592            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>, VEX;
2593 }
2594
2595 let Uses = [EDI] in
2596 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2597            "maskmovdqu\t{$mask, $src|$src, $mask}",
2598            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
2599 let Uses = [RDI] in
2600 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2601            "maskmovdqu\t{$mask, $src|$src, $mask}",
2602            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2603
2604 } // ExeDomain = SSEPackedInt
2605
2606 //===---------------------------------------------------------------------===//
2607 // SSE2 - Move Doubleword
2608 //===---------------------------------------------------------------------===//
2609
2610 // Move Int Doubleword to Packed Double Int
2611 let isAsmParserOnly = 1 in {
2612 def VMOVDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2613                       "movd\t{$src, $dst|$dst, $src}",
2614                       [(set VR128:$dst,
2615                         (v4i32 (scalar_to_vector GR32:$src)))]>, VEX;
2616 def VMOVDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2617                       "movd\t{$src, $dst|$dst, $src}",
2618                       [(set VR128:$dst,
2619                         (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>,
2620                       VEX;
2621 }
2622 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2623                       "movd\t{$src, $dst|$dst, $src}",
2624                       [(set VR128:$dst,
2625                         (v4i32 (scalar_to_vector GR32:$src)))]>;
2626 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2627                       "movd\t{$src, $dst|$dst, $src}",
2628                       [(set VR128:$dst,
2629                         (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2630
2631
2632 // Move Int Doubleword to Single Scalar
2633 let isAsmParserOnly = 1 in {
2634 def VMOVDI2SSrr  : VPDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2635                       "movd\t{$src, $dst|$dst, $src}",
2636                       [(set FR32:$dst, (bitconvert GR32:$src))]>, VEX;
2637
2638 def VMOVDI2SSrm  : VPDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2639                       "movd\t{$src, $dst|$dst, $src}",
2640                       [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>,
2641                       VEX;
2642 }
2643 def MOVDI2SSrr  : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2644                       "movd\t{$src, $dst|$dst, $src}",
2645                       [(set FR32:$dst, (bitconvert GR32:$src))]>;
2646
2647 def MOVDI2SSrm  : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2648                       "movd\t{$src, $dst|$dst, $src}",
2649                       [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2650
2651 // Move Packed Doubleword Int to Packed Double Int
2652 let isAsmParserOnly = 1 in {
2653 def VMOVPDI2DIrr  : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2654                        "movd\t{$src, $dst|$dst, $src}",
2655                        [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2656                                         (iPTR 0)))]>, VEX;
2657 def VMOVPDI2DImr  : VPDI<0x7E, MRMDestMem, (outs),
2658                        (ins i32mem:$dst, VR128:$src),
2659                        "movd\t{$src, $dst|$dst, $src}",
2660                        [(store (i32 (vector_extract (v4i32 VR128:$src),
2661                                      (iPTR 0))), addr:$dst)]>, VEX;
2662 }
2663 def MOVPDI2DIrr  : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2664                        "movd\t{$src, $dst|$dst, $src}",
2665                        [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2666                                         (iPTR 0)))]>;
2667 def MOVPDI2DImr  : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
2668                        "movd\t{$src, $dst|$dst, $src}",
2669                        [(store (i32 (vector_extract (v4i32 VR128:$src),
2670                                      (iPTR 0))), addr:$dst)]>;
2671
2672 // Move Scalar Single to Double Int
2673 let isAsmParserOnly = 1 in {
2674 def VMOVSS2DIrr  : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2675                       "movd\t{$src, $dst|$dst, $src}",
2676                       [(set GR32:$dst, (bitconvert FR32:$src))]>, VEX;
2677 def VMOVSS2DImr  : VPDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2678                       "movd\t{$src, $dst|$dst, $src}",
2679                       [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>, VEX;
2680 }
2681 def MOVSS2DIrr  : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2682                       "movd\t{$src, $dst|$dst, $src}",
2683                       [(set GR32:$dst, (bitconvert FR32:$src))]>;
2684 def MOVSS2DImr  : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2685                       "movd\t{$src, $dst|$dst, $src}",
2686                       [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2687
2688 // movd / movq to XMM register zero-extends
2689 let AddedComplexity = 15, isAsmParserOnly = 1 in {
2690 def VMOVZDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2691                        "movd\t{$src, $dst|$dst, $src}",
2692                        [(set VR128:$dst, (v4i32 (X86vzmovl
2693                                       (v4i32 (scalar_to_vector GR32:$src)))))]>,
2694                                       VEX;
2695 def VMOVZQI2PQIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2696                        "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
2697                        [(set VR128:$dst, (v2i64 (X86vzmovl
2698                                       (v2i64 (scalar_to_vector GR64:$src)))))]>,
2699                                       VEX, VEX_W;
2700 }
2701 let AddedComplexity = 15 in {
2702 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2703                        "movd\t{$src, $dst|$dst, $src}",
2704                        [(set VR128:$dst, (v4i32 (X86vzmovl
2705                                       (v4i32 (scalar_to_vector GR32:$src)))))]>;
2706 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2707                        "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
2708                        [(set VR128:$dst, (v2i64 (X86vzmovl
2709                                       (v2i64 (scalar_to_vector GR64:$src)))))]>;
2710 }
2711
2712 let AddedComplexity = 20 in {
2713 let isAsmParserOnly = 1 in
2714 def VMOVZDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2715                        "movd\t{$src, $dst|$dst, $src}",
2716                        [(set VR128:$dst,
2717                          (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2718                                                    (loadi32 addr:$src))))))]>,
2719                                                    VEX;
2720 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2721                        "movd\t{$src, $dst|$dst, $src}",
2722                        [(set VR128:$dst,
2723                          (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2724                                                    (loadi32 addr:$src))))))]>;
2725
2726 def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2727             (MOVZDI2PDIrm addr:$src)>;
2728 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2729             (MOVZDI2PDIrm addr:$src)>;
2730 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2731             (MOVZDI2PDIrm addr:$src)>;
2732 }
2733
2734 //===---------------------------------------------------------------------===//
2735 // SSE2 - Move Quadword
2736 //===---------------------------------------------------------------------===//
2737
2738 // Move Quadword Int to Packed Quadword Int
2739 let isAsmParserOnly = 1 in
2740 def VMOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2741                     "vmovq\t{$src, $dst|$dst, $src}",
2742                     [(set VR128:$dst,
2743                       (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2744                     VEX, Requires<[HasAVX, HasSSE2]>;
2745 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2746                     "movq\t{$src, $dst|$dst, $src}",
2747                     [(set VR128:$dst,
2748                       (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2749                     Requires<[HasSSE2]>; // SSE2 instruction with XS Prefix
2750
2751 // Move Packed Quadword Int to Quadword Int
2752 let isAsmParserOnly = 1 in
2753 def VMOVPQI2QImr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2754                       "movq\t{$src, $dst|$dst, $src}",
2755                       [(store (i64 (vector_extract (v2i64 VR128:$src),
2756                                     (iPTR 0))), addr:$dst)]>, VEX;
2757 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2758                       "movq\t{$src, $dst|$dst, $src}",
2759                       [(store (i64 (vector_extract (v2i64 VR128:$src),
2760                                     (iPTR 0))), addr:$dst)]>;
2761
2762 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
2763           (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
2764
2765 // Store / copy lower 64-bits of a XMM register.
2766 let isAsmParserOnly = 1 in
2767 def VMOVLQ128mr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2768                      "movq\t{$src, $dst|$dst, $src}",
2769                      [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>, VEX;
2770 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2771                      "movq\t{$src, $dst|$dst, $src}",
2772                      [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2773
2774 let AddedComplexity = 20, isAsmParserOnly = 1 in
2775 def VMOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2776                      "vmovq\t{$src, $dst|$dst, $src}",
2777                      [(set VR128:$dst,
2778                        (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2779                                                  (loadi64 addr:$src))))))]>,
2780                      XS, VEX, Requires<[HasAVX, HasSSE2]>;
2781
2782 let AddedComplexity = 20 in {
2783 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2784                      "movq\t{$src, $dst|$dst, $src}",
2785                      [(set VR128:$dst,
2786                        (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2787                                                  (loadi64 addr:$src))))))]>,
2788                      XS, Requires<[HasSSE2]>;
2789
2790 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2791             (MOVZQI2PQIrm addr:$src)>;
2792 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2793             (MOVZQI2PQIrm addr:$src)>;
2794 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
2795 }
2796
2797 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2798 // IA32 document. movq xmm1, xmm2 does clear the high bits.
2799 let isAsmParserOnly = 1, AddedComplexity = 15 in
2800 def VMOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2801                         "vmovq\t{$src, $dst|$dst, $src}",
2802                     [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2803                       XS, VEX, Requires<[HasAVX, HasSSE2]>;
2804 let AddedComplexity = 15 in
2805 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2806                         "movq\t{$src, $dst|$dst, $src}",
2807                     [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2808                       XS, Requires<[HasSSE2]>;
2809
2810 let AddedComplexity = 20, isAsmParserOnly = 1 in
2811 def VMOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2812                         "vmovq\t{$src, $dst|$dst, $src}",
2813                     [(set VR128:$dst, (v2i64 (X86vzmovl
2814                                              (loadv2i64 addr:$src))))]>,
2815                       XS, VEX, Requires<[HasAVX, HasSSE2]>;
2816 let AddedComplexity = 20 in {
2817 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2818                         "movq\t{$src, $dst|$dst, $src}",
2819                     [(set VR128:$dst, (v2i64 (X86vzmovl
2820                                              (loadv2i64 addr:$src))))]>,
2821                       XS, Requires<[HasSSE2]>;
2822
2823 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2824             (MOVZPQILo2PQIrm addr:$src)>;
2825 }
2826
2827 // Instructions to match in the assembler
2828 let isAsmParserOnly = 1 in {
2829 // This instructions is in fact an alias to movd with 64 bit dst
2830 def VMOVQs64rr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2831                       "movq\t{$src, $dst|$dst, $src}", []>, VEX, VEX_W;
2832 def VMOVQd64rr : VPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
2833                       "movq\t{$src, $dst|$dst, $src}", []>, VEX, VEX_W;
2834 }
2835
2836 // Instructions for the disassembler
2837 // xr = XMM register
2838 // xm = mem64
2839
2840 let isAsmParserOnly = 1 in
2841 def VMOVQxrxr: I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2842                  "vmovq\t{$src, $dst|$dst, $src}", []>, VEX, XS;
2843 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2844                  "movq\t{$src, $dst|$dst, $src}", []>, XS;
2845
2846 //===---------------------------------------------------------------------===//
2847 // SSE2 - Misc Instructions
2848 //===---------------------------------------------------------------------===//
2849
2850 // Flush cache
2851 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
2852                "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
2853               TB, Requires<[HasSSE2]>;
2854
2855 // Load, store, and memory fence
2856 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
2857                "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
2858 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
2859                "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2860
2861 // Pause. This "instruction" is encoded as "rep; nop", so even though it
2862 // was introduced with SSE2, it's backward compatible.
2863 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
2864
2865 //TODO: custom lower this so as to never even generate the noop
2866 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2867            (i8 0)), (NOOP)>;
2868 def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2869 def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
2870 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2871            (i8 1)), (MFENCE)>;
2872
2873 // Alias instructions that map zero vector to pxor / xorp* for sse.
2874 // We set canFoldAsLoad because this can be converted to a constant-pool
2875 // load of an all-ones value if folding it would be beneficial.
2876 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
2877     isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
2878   // FIXME: Change encoding to pseudo.
2879   def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
2880                          [(set VR128:$dst, (v4i32 immAllOnesV))]>;
2881
2882 //===---------------------------------------------------------------------===//
2883 // SSE3 - Conversion Instructions
2884 //===---------------------------------------------------------------------===//
2885
2886 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE3] in {
2887 def VCVTPD2DQrr  : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2888                        "vcvtpd2dq\t{$src, $dst|$dst, $src}", []>, VEX;
2889 def VCVTDQ2PDrm  : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2890                        "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
2891 def VCVTDQ2PDrr  : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2892                        "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
2893 }
2894
2895 def CVTPD2DQrm  : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2896                        "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2897 def CVTPD2DQrr  : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2898                        "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2899 def CVTDQ2PDrm  : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2900                        "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2901 def CVTDQ2PDrr  : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2902                        "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2903
2904 //===---------------------------------------------------------------------===//
2905 // SSE3 - Move Instructions
2906 //===---------------------------------------------------------------------===//
2907
2908 // Replicate Single FP
2909 multiclass sse3_replicate_sfp<bits<8> op, PatFrag rep_frag, string OpcodeStr> {
2910 def rr : S3SI<op, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2911                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2912                       [(set VR128:$dst, (v4f32 (rep_frag
2913                                                 VR128:$src, (undef))))]>;
2914 def rm : S3SI<op, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2915                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2916                       [(set VR128:$dst, (rep_frag
2917                                          (memopv4f32 addr:$src), (undef)))]>;
2918 }
2919
2920 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE3] in {
2921 defm VMOVSHDUP : sse3_replicate_sfp<0x16, movshdup, "vmovshdup">, VEX;
2922 defm VMOVSLDUP : sse3_replicate_sfp<0x12, movsldup, "vmovsldup">, VEX;
2923 }
2924 defm MOVSHDUP : sse3_replicate_sfp<0x16, movshdup, "movshdup">;
2925 defm MOVSLDUP : sse3_replicate_sfp<0x12, movsldup, "movsldup">;
2926
2927 // Replicate Double FP
2928 multiclass sse3_replicate_dfp<string OpcodeStr> {
2929 def rr  : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2930                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2931                     [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
2932 def rm  : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2933                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2934                     [(set VR128:$dst,
2935                       (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2936                                       (undef))))]>;
2937 }
2938
2939 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE3] in
2940   defm VMOVDDUP : sse3_replicate_dfp<"vmovddup">, VEX;
2941 defm MOVDDUP : sse3_replicate_dfp<"movddup">;
2942
2943 // Move Unaligned Integer
2944 let isAsmParserOnly = 1 in
2945   def VLDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2946                      "vlddqu\t{$src, $dst|$dst, $src}",
2947                      [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>, VEX;
2948 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2949                    "lddqu\t{$src, $dst|$dst, $src}",
2950                    [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2951
2952 def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2953                    (undef)),
2954           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2955
2956 // Several Move patterns
2957 let AddedComplexity = 5 in {
2958 def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
2959           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2960 def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2961           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2962 def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2963           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2964 def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2965           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2966 }
2967
2968 // vector_shuffle v1, <undef> <1, 1, 3, 3>
2969 let AddedComplexity = 15 in
2970 def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
2971           (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2972 let AddedComplexity = 20 in
2973 def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2974           (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2975
2976 // vector_shuffle v1, <undef> <0, 0, 2, 2>
2977 let AddedComplexity = 15 in
2978   def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
2979             (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2980 let AddedComplexity = 20 in
2981   def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2982             (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2983
2984 //===---------------------------------------------------------------------===//
2985 // SSE3 - Arithmetic
2986 //===---------------------------------------------------------------------===//
2987
2988 multiclass sse3_addsub<Intrinsic Int, string OpcodeStr, bit Is2Addr = 1> {
2989   def rr : I<0xD0, MRMSrcReg,
2990        (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2991        !if(Is2Addr,
2992            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2993            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2994        [(set VR128:$dst, (Int VR128:$src1,
2995                           VR128:$src2))]>;
2996   def rm : I<0xD0, MRMSrcMem,
2997        (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2998        !if(Is2Addr,
2999            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3000            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3001        [(set VR128:$dst, (Int VR128:$src1,
3002                           (memop addr:$src2)))]>;
3003
3004 }
3005
3006 let isAsmParserOnly = 1, Predicates = [HasSSE3, HasAVX],
3007   ExeDomain = SSEPackedDouble in {
3008   defm VADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "vaddsubps", 0>, XD,
3009                               VEX_4V;
3010   defm VADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "vaddsubpd", 0>, OpSize,
3011                               VEX_4V;
3012 }
3013 let Constraints = "$src1 = $dst", Predicates = [HasSSE3],
3014     ExeDomain = SSEPackedDouble in {
3015   defm ADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "addsubps">, XD;
3016   defm ADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "addsubpd">, TB, OpSize;
3017 }
3018
3019 //===---------------------------------------------------------------------===//
3020 // SSE3 Instructions
3021 //===---------------------------------------------------------------------===//
3022
3023 // Horizontal ops
3024 class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId, bit Is2Addr = 1>
3025   : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
3026        !if(Is2Addr,
3027          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3028          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3029          [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
3030 class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId, bit Is2Addr = 1>
3031   : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
3032        !if(Is2Addr,
3033          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3034          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3035          [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
3036 class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId, bit Is2Addr = 1>
3037   : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
3038        !if(Is2Addr,
3039          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3040          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3041         [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
3042 class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId, bit Is2Addr = 1>
3043   : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
3044        !if(Is2Addr,
3045          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3046          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3047       [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
3048
3049 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE3] in {
3050   def VHADDPSrr : S3D_Intrr<0x7C, "vhaddps", int_x86_sse3_hadd_ps, 0>, VEX_4V;
3051   def VHADDPSrm : S3D_Intrm<0x7C, "vhaddps", int_x86_sse3_hadd_ps, 0>, VEX_4V;
3052   def VHADDPDrr : S3_Intrr <0x7C, "vhaddpd", int_x86_sse3_hadd_pd, 0>, VEX_4V;
3053   def VHADDPDrm : S3_Intrm <0x7C, "vhaddpd", int_x86_sse3_hadd_pd, 0>, VEX_4V;
3054   def VHSUBPSrr : S3D_Intrr<0x7D, "vhsubps", int_x86_sse3_hsub_ps, 0>, VEX_4V;
3055   def VHSUBPSrm : S3D_Intrm<0x7D, "vhsubps", int_x86_sse3_hsub_ps, 0>, VEX_4V;
3056   def VHSUBPDrr : S3_Intrr <0x7D, "vhsubpd", int_x86_sse3_hsub_pd, 0>, VEX_4V;
3057   def VHSUBPDrm : S3_Intrm <0x7D, "vhsubpd", int_x86_sse3_hsub_pd, 0>, VEX_4V;
3058 }
3059
3060 let Constraints = "$src1 = $dst" in {
3061   def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
3062   def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
3063   def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
3064   def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
3065   def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
3066   def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
3067   def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
3068   def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
3069 }
3070
3071 //===---------------------------------------------------------------------===//
3072 // SSSE3 - Packed Absolute Instructions
3073 //===---------------------------------------------------------------------===//
3074
3075 /// SS3I_unop_rm_int - Simple SSSE3 unary op whose type can be v*{i8,i16,i32}.
3076 multiclass SS3I_unop_rm_int<bits<8> opc, string OpcodeStr,
3077                             PatFrag mem_frag64, PatFrag mem_frag128,
3078                             Intrinsic IntId64, Intrinsic IntId128> {
3079   def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
3080                    !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3081                    [(set VR64:$dst, (IntId64 VR64:$src))]>;
3082
3083   def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
3084                    !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3085                    [(set VR64:$dst,
3086                      (IntId64 (bitconvert (mem_frag64 addr:$src))))]>;
3087
3088   def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
3089                     (ins VR128:$src),
3090                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3091                     [(set VR128:$dst, (IntId128 VR128:$src))]>,
3092                     OpSize;
3093
3094   def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
3095                     (ins i128mem:$src),
3096                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3097                     [(set VR128:$dst,
3098                       (IntId128
3099                        (bitconvert (mem_frag128 addr:$src))))]>, OpSize;
3100 }
3101
3102 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE3] in {
3103   defm VPABSB  : SS3I_unop_rm_int<0x1C, "vpabsb", memopv8i8, memopv16i8,
3104                                   int_x86_ssse3_pabs_b,
3105                                   int_x86_ssse3_pabs_b_128>, VEX;
3106   defm VPABSW  : SS3I_unop_rm_int<0x1D, "vpabsw", memopv4i16, memopv8i16,
3107                                   int_x86_ssse3_pabs_w,
3108                                   int_x86_ssse3_pabs_w_128>, VEX;
3109   defm VPABSD  : SS3I_unop_rm_int<0x1E, "vpabsd", memopv2i32, memopv4i32,
3110                                   int_x86_ssse3_pabs_d,
3111                                   int_x86_ssse3_pabs_d_128>, VEX;
3112 }
3113
3114 defm PABSB       : SS3I_unop_rm_int<0x1C, "pabsb", memopv8i8, memopv16i8,
3115                                     int_x86_ssse3_pabs_b,
3116                                     int_x86_ssse3_pabs_b_128>;
3117 defm PABSW       : SS3I_unop_rm_int<0x1D, "pabsw", memopv4i16, memopv8i16,
3118                                     int_x86_ssse3_pabs_w,
3119                                     int_x86_ssse3_pabs_w_128>;
3120 defm PABSD       : SS3I_unop_rm_int<0x1E, "pabsd", memopv2i32, memopv4i32,
3121                                     int_x86_ssse3_pabs_d,
3122                                     int_x86_ssse3_pabs_d_128>;
3123
3124 //===---------------------------------------------------------------------===//
3125 // SSSE3 - Packed Binary Operator Instructions
3126 //===---------------------------------------------------------------------===//
3127
3128 /// SS3I_binop_rm_int - Simple SSSE3 bin op whose type can be v*{i8,i16,i32}.
3129 multiclass SS3I_binop_rm_int<bits<8> opc, string OpcodeStr,
3130                              PatFrag mem_frag64, PatFrag mem_frag128,
3131                              Intrinsic IntId64, Intrinsic IntId128,
3132                              bit Is2Addr = 1> {
3133   let isCommutable = 1 in
3134   def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
3135        (ins VR64:$src1, VR64:$src2),
3136        !if(Is2Addr,
3137          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3138          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3139        [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]>;
3140   def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
3141        (ins VR64:$src1, i64mem:$src2),
3142        !if(Is2Addr,
3143          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3144          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3145        [(set VR64:$dst,
3146          (IntId64 VR64:$src1,
3147           (bitconvert (memopv8i8 addr:$src2))))]>;
3148
3149   let isCommutable = 1 in
3150   def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
3151        (ins VR128:$src1, VR128:$src2),
3152        !if(Is2Addr,
3153          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3154          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3155        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3156        OpSize;
3157   def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
3158        (ins VR128:$src1, i128mem:$src2),
3159        !if(Is2Addr,
3160          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3161          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3162        [(set VR128:$dst,
3163          (IntId128 VR128:$src1,
3164           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3165 }
3166
3167 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE3] in {
3168 let isCommutable = 0 in {
3169   defm VPHADDW    : SS3I_binop_rm_int<0x01, "vphaddw", memopv4i16, memopv8i16,
3170                                       int_x86_ssse3_phadd_w,
3171                                       int_x86_ssse3_phadd_w_128, 0>, VEX_4V;
3172   defm VPHADDD    : SS3I_binop_rm_int<0x02, "vphaddd", memopv2i32, memopv4i32,
3173                                       int_x86_ssse3_phadd_d,
3174                                       int_x86_ssse3_phadd_d_128, 0>, VEX_4V;
3175   defm VPHADDSW   : SS3I_binop_rm_int<0x03, "vphaddsw", memopv4i16, memopv8i16,
3176                                       int_x86_ssse3_phadd_sw,
3177                                       int_x86_ssse3_phadd_sw_128, 0>, VEX_4V;
3178   defm VPHSUBW    : SS3I_binop_rm_int<0x05, "vphsubw", memopv4i16, memopv8i16,
3179                                       int_x86_ssse3_phsub_w,
3180                                       int_x86_ssse3_phsub_w_128, 0>, VEX_4V;
3181   defm VPHSUBD    : SS3I_binop_rm_int<0x06, "vphsubd", memopv2i32, memopv4i32,
3182                                       int_x86_ssse3_phsub_d,
3183                                       int_x86_ssse3_phsub_d_128, 0>, VEX_4V;
3184   defm VPHSUBSW   : SS3I_binop_rm_int<0x07, "vphsubsw", memopv4i16, memopv8i16,
3185                                       int_x86_ssse3_phsub_sw,
3186                                       int_x86_ssse3_phsub_sw_128, 0>, VEX_4V;
3187   defm VPMADDUBSW : SS3I_binop_rm_int<0x04, "vpmaddubsw", memopv8i8, memopv16i8,
3188                                       int_x86_ssse3_pmadd_ub_sw,
3189                                       int_x86_ssse3_pmadd_ub_sw_128, 0>, VEX_4V;
3190   defm VPSHUFB    : SS3I_binop_rm_int<0x00, "vpshufb", memopv8i8, memopv16i8,
3191                                       int_x86_ssse3_pshuf_b,
3192                                       int_x86_ssse3_pshuf_b_128, 0>, VEX_4V;
3193   defm VPSIGNB    : SS3I_binop_rm_int<0x08, "vpsignb", memopv8i8, memopv16i8,
3194                                       int_x86_ssse3_psign_b,
3195                                       int_x86_ssse3_psign_b_128, 0>, VEX_4V;
3196   defm VPSIGNW    : SS3I_binop_rm_int<0x09, "vpsignw", memopv4i16, memopv8i16,
3197                                       int_x86_ssse3_psign_w,
3198                                       int_x86_ssse3_psign_w_128, 0>, VEX_4V;
3199   defm VPSIGND    : SS3I_binop_rm_int<0x0A, "vpsignd", memopv2i32, memopv4i32,
3200                                       int_x86_ssse3_psign_d,
3201                                       int_x86_ssse3_psign_d_128, 0>, VEX_4V;
3202 }
3203 defm VPMULHRSW    : SS3I_binop_rm_int<0x0B, "vpmulhrsw", memopv4i16, memopv8i16,
3204                                       int_x86_ssse3_pmul_hr_sw,
3205                                       int_x86_ssse3_pmul_hr_sw_128, 0>, VEX_4V;
3206 }
3207
3208 // None of these have i8 immediate fields.
3209 let ImmT = NoImm, Constraints = "$src1 = $dst" in {
3210 let isCommutable = 0 in {
3211   defm PHADDW    : SS3I_binop_rm_int<0x01, "phaddw", memopv4i16, memopv8i16,
3212                                      int_x86_ssse3_phadd_w,
3213                                      int_x86_ssse3_phadd_w_128>;
3214   defm PHADDD    : SS3I_binop_rm_int<0x02, "phaddd", memopv2i32, memopv4i32,
3215                                      int_x86_ssse3_phadd_d,
3216                                      int_x86_ssse3_phadd_d_128>;
3217   defm PHADDSW   : SS3I_binop_rm_int<0x03, "phaddsw", memopv4i16, memopv8i16,
3218                                      int_x86_ssse3_phadd_sw,
3219                                      int_x86_ssse3_phadd_sw_128>;
3220   defm PHSUBW    : SS3I_binop_rm_int<0x05, "phsubw", memopv4i16, memopv8i16,
3221                                      int_x86_ssse3_phsub_w,
3222                                      int_x86_ssse3_phsub_w_128>;
3223   defm PHSUBD    : SS3I_binop_rm_int<0x06, "phsubd", memopv2i32, memopv4i32,
3224                                      int_x86_ssse3_phsub_d,
3225                                      int_x86_ssse3_phsub_d_128>;
3226   defm PHSUBSW   : SS3I_binop_rm_int<0x07, "phsubsw", memopv4i16, memopv8i16,
3227                                      int_x86_ssse3_phsub_sw,
3228                                      int_x86_ssse3_phsub_sw_128>;
3229   defm PMADDUBSW : SS3I_binop_rm_int<0x04, "pmaddubsw", memopv8i8, memopv16i8,
3230                                      int_x86_ssse3_pmadd_ub_sw,
3231                                      int_x86_ssse3_pmadd_ub_sw_128>;
3232   defm PSHUFB    : SS3I_binop_rm_int<0x00, "pshufb", memopv8i8, memopv16i8,
3233                                      int_x86_ssse3_pshuf_b,
3234                                      int_x86_ssse3_pshuf_b_128>;
3235   defm PSIGNB    : SS3I_binop_rm_int<0x08, "psignb", memopv8i8, memopv16i8,
3236                                      int_x86_ssse3_psign_b,
3237                                      int_x86_ssse3_psign_b_128>;
3238   defm PSIGNW    : SS3I_binop_rm_int<0x09, "psignw", memopv4i16, memopv8i16,
3239                                      int_x86_ssse3_psign_w,
3240                                      int_x86_ssse3_psign_w_128>;
3241   defm PSIGND    : SS3I_binop_rm_int<0x0A, "psignd", memopv2i32, memopv4i32,
3242                                        int_x86_ssse3_psign_d,
3243                                        int_x86_ssse3_psign_d_128>;
3244 }
3245 defm PMULHRSW    : SS3I_binop_rm_int<0x0B, "pmulhrsw", memopv4i16, memopv8i16,
3246                                      int_x86_ssse3_pmul_hr_sw,
3247                                      int_x86_ssse3_pmul_hr_sw_128>;
3248 }
3249
3250 def : Pat<(X86pshufb VR128:$src, VR128:$mask),
3251           (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
3252 def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
3253           (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
3254
3255 //===---------------------------------------------------------------------===//
3256 // SSSE3 - Packed Align Instruction Patterns
3257 //===---------------------------------------------------------------------===//
3258
3259 multiclass sse3_palign<string asm, bit Is2Addr = 1> {
3260   def R64rr  : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
3261       (ins VR64:$src1, VR64:$src2, i8imm:$src3),
3262       !if(Is2Addr,
3263         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3264         !strconcat(asm,
3265                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3266       []>;
3267   def R64rm  : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
3268       (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
3269       !if(Is2Addr,
3270         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3271         !strconcat(asm,
3272                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3273       []>;
3274
3275   def R128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
3276       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3277       !if(Is2Addr,
3278         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3279         !strconcat(asm,
3280                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3281       []>, OpSize;
3282   def R128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
3283       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3284       !if(Is2Addr,
3285         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3286         !strconcat(asm,
3287                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3288       []>, OpSize;
3289 }
3290
3291 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE3] in
3292   defm VPALIGN : sse3_palign<"vpalignr", 0>, VEX_4V;
3293 let Constraints = "$src1 = $dst" in
3294   defm PALIGN : sse3_palign<"palignr">;
3295
3296 let AddedComplexity = 5 in {
3297
3298 def : Pat<(v1i64 (palign:$src3 VR64:$src1, VR64:$src2)),
3299           (PALIGNR64rr VR64:$src2, VR64:$src1,
3300                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3301           Requires<[HasSSSE3]>;
3302 def : Pat<(v2i32 (palign:$src3 VR64:$src1, VR64:$src2)),
3303           (PALIGNR64rr VR64:$src2, VR64:$src1,
3304                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3305           Requires<[HasSSSE3]>;
3306 def : Pat<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
3307           (PALIGNR64rr VR64:$src2, VR64:$src1,
3308                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3309           Requires<[HasSSSE3]>;
3310 def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
3311           (PALIGNR64rr VR64:$src2, VR64:$src1,
3312                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3313           Requires<[HasSSSE3]>;
3314
3315 def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
3316           (PALIGNR128rr VR128:$src2, VR128:$src1,
3317                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3318       Requires<[HasSSSE3]>;
3319 def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
3320           (PALIGNR128rr VR128:$src2, VR128:$src1,
3321                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3322       Requires<[HasSSSE3]>;
3323 def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
3324           (PALIGNR128rr VR128:$src2, VR128:$src1,
3325                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3326       Requires<[HasSSSE3]>;
3327 def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
3328           (PALIGNR128rr VR128:$src2, VR128:$src1,
3329                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3330       Requires<[HasSSSE3]>;
3331 }
3332
3333 //===---------------------------------------------------------------------===//
3334 // SSSE3 Misc Instructions
3335 //===---------------------------------------------------------------------===//
3336
3337 // Thread synchronization
3338 def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
3339                 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
3340 def MWAIT   : I<0x01, MRM_C9, (outs), (ins), "mwait",
3341                 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
3342
3343 //===---------------------------------------------------------------------===//
3344 // Non-Instruction Patterns
3345 //===---------------------------------------------------------------------===//
3346
3347 // extload f32 -> f64.  This matches load+fextend because we have a hack in
3348 // the isel (PreprocessForFPConvert) that can introduce loads after dag
3349 // combine.
3350 // Since these loads aren't folded into the fextend, we have to match it
3351 // explicitly here.
3352 let Predicates = [HasSSE2] in
3353  def : Pat<(fextend (loadf32 addr:$src)),
3354            (CVTSS2SDrm addr:$src)>;
3355
3356 // bit_convert
3357 let Predicates = [HasSSE2] in {
3358   def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
3359   def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
3360   def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
3361   def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
3362   def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
3363   def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
3364   def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
3365   def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
3366   def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
3367   def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
3368   def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
3369   def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
3370   def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
3371   def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
3372   def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
3373   def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
3374   def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
3375   def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
3376   def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
3377   def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
3378   def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
3379   def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
3380   def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
3381   def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
3382   def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
3383   def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
3384   def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
3385   def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
3386   def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
3387   def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
3388 }
3389
3390 // Move scalar to XMM zero-extended
3391 // movd to XMM register zero-extends
3392 let AddedComplexity = 15 in {
3393 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
3394 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
3395           (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
3396 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
3397           (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
3398 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
3399           (MOVSSrr (v4f32 (V_SET0PS)),
3400                    (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
3401 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
3402           (MOVSSrr (v4i32 (V_SET0PI)),
3403                    (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
3404 }
3405
3406 // Splat v2f64 / v2i64
3407 let AddedComplexity = 10 in {
3408 def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
3409           (UNPCKLPDrr VR128:$src, VR128:$src)>,   Requires<[HasSSE2]>;
3410 def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
3411           (UNPCKHPDrr VR128:$src, VR128:$src)>,   Requires<[HasSSE2]>;
3412 def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
3413           (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3414 def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
3415           (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3416 }
3417
3418 // Special unary SHUFPSrri case.
3419 def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
3420           (SHUFPSrri VR128:$src1, VR128:$src1,
3421                      (SHUFFLE_get_shuf_imm VR128:$src3))>;
3422 let AddedComplexity = 5 in
3423 def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
3424           (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3425       Requires<[HasSSE2]>;
3426 // Special unary SHUFPDrri case.
3427 def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
3428           (SHUFPDrri VR128:$src1, VR128:$src1,
3429                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3430       Requires<[HasSSE2]>;
3431 // Special unary SHUFPDrri case.
3432 def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
3433           (SHUFPDrri VR128:$src1, VR128:$src1,
3434                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3435       Requires<[HasSSE2]>;
3436 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
3437 def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
3438           (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3439       Requires<[HasSSE2]>;
3440
3441 // Special binary v4i32 shuffle cases with SHUFPS.
3442 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
3443           (SHUFPSrri VR128:$src1, VR128:$src2,
3444                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3445            Requires<[HasSSE2]>;
3446 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
3447           (SHUFPSrmi VR128:$src1, addr:$src2,
3448                     (SHUFFLE_get_shuf_imm VR128:$src3))>,
3449            Requires<[HasSSE2]>;
3450 // Special binary v2i64 shuffle cases using SHUFPDrri.
3451 def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
3452           (SHUFPDrri VR128:$src1, VR128:$src2,
3453                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3454           Requires<[HasSSE2]>;
3455
3456 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
3457 let AddedComplexity = 15 in {
3458 def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
3459           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3460           Requires<[OptForSpeed, HasSSE2]>;
3461 def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
3462           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3463           Requires<[OptForSpeed, HasSSE2]>;
3464 }
3465 let AddedComplexity = 10 in {
3466 def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
3467           (UNPCKLPSrr VR128:$src, VR128:$src)>;
3468 def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
3469           (PUNPCKLBWrr VR128:$src, VR128:$src)>;
3470 def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
3471           (PUNPCKLWDrr VR128:$src, VR128:$src)>;
3472 def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
3473           (PUNPCKLDQrr VR128:$src, VR128:$src)>;
3474 }
3475
3476 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
3477 let AddedComplexity = 15 in {
3478 def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
3479           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3480           Requires<[OptForSpeed, HasSSE2]>;
3481 def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
3482           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3483           Requires<[OptForSpeed, HasSSE2]>;
3484 }
3485 let AddedComplexity = 10 in {
3486 def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
3487           (UNPCKHPSrr VR128:$src, VR128:$src)>;
3488 def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
3489           (PUNPCKHBWrr VR128:$src, VR128:$src)>;
3490 def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
3491           (PUNPCKHWDrr VR128:$src, VR128:$src)>;
3492 def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
3493           (PUNPCKHDQrr VR128:$src, VR128:$src)>;
3494 }
3495
3496 let AddedComplexity = 20 in {
3497 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
3498 def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
3499           (MOVLHPSrr VR128:$src1, VR128:$src2)>;
3500
3501 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
3502 def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
3503           (MOVHLPSrr VR128:$src1, VR128:$src2)>;
3504
3505 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
3506 def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
3507           (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3508 def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
3509           (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3510 }
3511
3512 let AddedComplexity = 20 in {
3513 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
3514 def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
3515           (MOVLPSrm VR128:$src1, addr:$src2)>;
3516 def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
3517           (MOVLPDrm VR128:$src1, addr:$src2)>;
3518 def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
3519           (MOVLPSrm VR128:$src1, addr:$src2)>;
3520 def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
3521           (MOVLPDrm VR128:$src1, addr:$src2)>;
3522 }
3523
3524 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3525 def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3526           (MOVLPSmr addr:$src1, VR128:$src2)>;
3527 def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3528           (MOVLPDmr addr:$src1, VR128:$src2)>;
3529 def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3530                  addr:$src1),
3531           (MOVLPSmr addr:$src1, VR128:$src2)>;
3532 def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3533           (MOVLPDmr addr:$src1, VR128:$src2)>;
3534
3535 let AddedComplexity = 15 in {
3536 // Setting the lowest element in the vector.
3537 def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
3538           (MOVSSrr (v4i32 VR128:$src1),
3539                    (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
3540 def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
3541           (MOVSDrr (v2i64 VR128:$src1),
3542                    (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
3543
3544 // vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
3545 def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
3546           (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3547       Requires<[HasSSE2]>;
3548 def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
3549           (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3550       Requires<[HasSSE2]>;
3551 }
3552
3553 // vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3554 // fall back to this for SSE1)
3555 def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
3556           (SHUFPSrri VR128:$src2, VR128:$src1,
3557                      (SHUFFLE_get_shuf_imm VR128:$src3))>;
3558
3559 // Set lowest element and zero upper elements.
3560 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
3561           (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3562
3563 // Some special case pandn patterns.
3564 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3565                   VR128:$src2)),
3566           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3567 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3568                   VR128:$src2)),
3569           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3570 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3571                   VR128:$src2)),
3572           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3573
3574 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3575                   (memop addr:$src2))),
3576           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3577 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3578                   (memop addr:$src2))),
3579           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3580 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3581                   (memop addr:$src2))),
3582           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3583
3584 // vector -> vector casts
3585 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3586           (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3587 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3588           (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3589 def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3590           (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3591 def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3592           (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
3593
3594 // Use movaps / movups for SSE integer load / store (one byte shorter).
3595 def : Pat<(alignedloadv4i32 addr:$src),
3596           (MOVAPSrm addr:$src)>;
3597 def : Pat<(loadv4i32 addr:$src),
3598           (MOVUPSrm addr:$src)>;
3599 def : Pat<(alignedloadv2i64 addr:$src),
3600           (MOVAPSrm addr:$src)>;
3601 def : Pat<(loadv2i64 addr:$src),
3602           (MOVUPSrm addr:$src)>;
3603
3604 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3605           (MOVAPSmr addr:$dst, VR128:$src)>;
3606 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3607           (MOVAPSmr addr:$dst, VR128:$src)>;
3608 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3609           (MOVAPSmr addr:$dst, VR128:$src)>;
3610 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3611           (MOVAPSmr addr:$dst, VR128:$src)>;
3612 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3613           (MOVUPSmr addr:$dst, VR128:$src)>;
3614 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3615           (MOVUPSmr addr:$dst, VR128:$src)>;
3616 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3617           (MOVUPSmr addr:$dst, VR128:$src)>;
3618 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3619           (MOVUPSmr addr:$dst, VR128:$src)>;
3620
3621 //===----------------------------------------------------------------------===//
3622 // SSE4.1 - Packed Move with Sign/Zero Extend
3623 //===----------------------------------------------------------------------===//
3624
3625 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3626   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3627                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3628                  [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3629
3630   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3631                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3632        [(set VR128:$dst,
3633          (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3634        OpSize;
3635 }
3636
3637 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in {
3638 defm VPMOVSXBW : SS41I_binop_rm_int8<0x20, "vpmovsxbw", int_x86_sse41_pmovsxbw>,
3639                                      VEX;
3640 defm VPMOVSXWD : SS41I_binop_rm_int8<0x23, "vpmovsxwd", int_x86_sse41_pmovsxwd>,
3641                                      VEX;
3642 defm VPMOVSXDQ : SS41I_binop_rm_int8<0x25, "vpmovsxdq", int_x86_sse41_pmovsxdq>,
3643                                      VEX;
3644 defm VPMOVZXBW : SS41I_binop_rm_int8<0x30, "vpmovzxbw", int_x86_sse41_pmovzxbw>,
3645                                      VEX;
3646 defm VPMOVZXWD : SS41I_binop_rm_int8<0x33, "vpmovzxwd", int_x86_sse41_pmovzxwd>,
3647                                      VEX;
3648 defm VPMOVZXDQ : SS41I_binop_rm_int8<0x35, "vpmovzxdq", int_x86_sse41_pmovzxdq>,
3649                                      VEX;
3650 }
3651
3652 defm PMOVSXBW   : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3653 defm PMOVSXWD   : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3654 defm PMOVSXDQ   : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3655 defm PMOVZXBW   : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3656 defm PMOVZXWD   : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3657 defm PMOVZXDQ   : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3658
3659 // Common patterns involving scalar load.
3660 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3661           (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3662 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3663           (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3664
3665 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3666           (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3667 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3668           (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3669
3670 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3671           (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3672 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3673           (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3674
3675 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3676           (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3677 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3678           (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3679
3680 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3681           (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3682 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3683           (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3684
3685 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3686           (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3687 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3688           (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3689
3690
3691 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3692   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3693                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3694                  [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3695
3696   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3697                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3698        [(set VR128:$dst,
3699          (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3700           OpSize;
3701 }
3702
3703 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in {
3704 defm VPMOVSXBD : SS41I_binop_rm_int4<0x21, "vpmovsxbd", int_x86_sse41_pmovsxbd>,
3705                                      VEX;
3706 defm VPMOVSXWQ : SS41I_binop_rm_int4<0x24, "vpmovsxwq", int_x86_sse41_pmovsxwq>,
3707                                      VEX;
3708 defm VPMOVZXBD : SS41I_binop_rm_int4<0x31, "vpmovzxbd", int_x86_sse41_pmovzxbd>,
3709                                      VEX;
3710 defm VPMOVZXWQ : SS41I_binop_rm_int4<0x34, "vpmovzxwq", int_x86_sse41_pmovzxwq>,
3711                                      VEX;
3712 }
3713
3714 defm PMOVSXBD   : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3715 defm PMOVSXWQ   : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3716 defm PMOVZXBD   : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3717 defm PMOVZXWQ   : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3718
3719 // Common patterns involving scalar load
3720 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
3721           (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
3722 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
3723           (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
3724
3725 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
3726           (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
3727 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
3728           (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
3729
3730
3731 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3732   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3733                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3734                  [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3735
3736   // Expecting a i16 load any extended to i32 value.
3737   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3738                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3739                  [(set VR128:$dst, (IntId (bitconvert
3740                      (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3741                  OpSize;
3742 }
3743
3744 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in {
3745 defm VPMOVSXBQ : SS41I_binop_rm_int2<0x22, "vpmovsxbq", int_x86_sse41_pmovsxbq>,
3746                                      VEX;
3747 defm VPMOVZXBQ : SS41I_binop_rm_int2<0x32, "vpmovzxbq", int_x86_sse41_pmovzxbq>,
3748                                      VEX;
3749 }
3750 defm PMOVSXBQ   : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3751 defm PMOVZXBQ   : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
3752
3753 // Common patterns involving scalar load
3754 def : Pat<(int_x86_sse41_pmovsxbq
3755             (bitconvert (v4i32 (X86vzmovl
3756                              (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3757           (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
3758
3759 def : Pat<(int_x86_sse41_pmovzxbq
3760             (bitconvert (v4i32 (X86vzmovl
3761                              (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3762           (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
3763
3764 //===----------------------------------------------------------------------===//
3765 // SSE4.1 - Extract Instructions
3766 //===----------------------------------------------------------------------===//
3767
3768 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3769 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
3770   def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3771                  (ins VR128:$src1, i32i8imm:$src2),
3772                  !strconcat(OpcodeStr,
3773                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3774                  [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3775                  OpSize;
3776   def mr : SS4AIi8<opc, MRMDestMem, (outs),
3777                  (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
3778                  !strconcat(OpcodeStr,
3779                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3780                  []>, OpSize;
3781 // FIXME:
3782 // There's an AssertZext in the way of writing the store pattern
3783 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3784 }
3785
3786 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
3787   defm VPEXTRB : SS41I_extract8<0x14, "vpextrb">, VEX;
3788
3789 defm PEXTRB      : SS41I_extract8<0x14, "pextrb">;
3790
3791
3792 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3793 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
3794   def mr : SS4AIi8<opc, MRMDestMem, (outs),
3795                  (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
3796                  !strconcat(OpcodeStr,
3797                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3798                  []>, OpSize;
3799 // FIXME:
3800 // There's an AssertZext in the way of writing the store pattern
3801 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3802 }
3803
3804 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
3805   defm VPEXTRW : SS41I_extract16<0x15, "vpextrw">, VEX;
3806
3807 defm PEXTRW      : SS41I_extract16<0x15, "pextrw">;
3808
3809
3810 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3811 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
3812   def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3813                  (ins VR128:$src1, i32i8imm:$src2),
3814                  !strconcat(OpcodeStr,
3815                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3816                  [(set GR32:$dst,
3817                   (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
3818   def mr : SS4AIi8<opc, MRMDestMem, (outs),
3819                  (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
3820                  !strconcat(OpcodeStr,
3821                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3822                  [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3823                           addr:$dst)]>, OpSize;
3824 }
3825
3826 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
3827   defm VPEXTRD : SS41I_extract32<0x16, "vpextrd">, VEX;
3828
3829 defm PEXTRD      : SS41I_extract32<0x16, "pextrd">;
3830
3831 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3832 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
3833   def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
3834                  (ins VR128:$src1, i32i8imm:$src2),
3835                  !strconcat(OpcodeStr,
3836                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3837                  [(set GR64:$dst,
3838                   (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
3839   def mr : SS4AIi8<opc, MRMDestMem, (outs),
3840                  (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
3841                  !strconcat(OpcodeStr,
3842                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3843                  [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
3844                           addr:$dst)]>, OpSize, REX_W;
3845 }
3846
3847 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
3848   defm VPEXTRQ : SS41I_extract64<0x16, "vpextrq">, VEX, VEX_W;
3849
3850 defm PEXTRQ      : SS41I_extract64<0x16, "pextrq">;
3851
3852 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3853 /// destination
3854 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
3855   def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3856                  (ins VR128:$src1, i32i8imm:$src2),
3857                  !strconcat(OpcodeStr,
3858                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3859                  [(set GR32:$dst,
3860                     (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
3861            OpSize;
3862   def mr : SS4AIi8<opc, MRMDestMem, (outs),
3863                  (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
3864                  !strconcat(OpcodeStr,
3865                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3866                  [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
3867                           addr:$dst)]>, OpSize;
3868 }
3869
3870 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
3871   defm VEXTRACTPS : SS41I_extractf32<0x17, "vextractps">, VEX;
3872 defm EXTRACTPS   : SS41I_extractf32<0x17, "extractps">;
3873
3874 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3875 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3876                                               imm:$src2))),
3877                  addr:$dst),
3878           (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3879          Requires<[HasSSE41]>;
3880
3881 //===----------------------------------------------------------------------===//
3882 // SSE4.1 - Insert Instructions
3883 //===----------------------------------------------------------------------===//
3884
3885 multiclass SS41I_insert8<bits<8> opc, string asm, bit Is2Addr = 1> {
3886   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3887       (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3888       !if(Is2Addr,
3889         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3890         !strconcat(asm,
3891                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3892       [(set VR128:$dst,
3893         (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
3894   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3895       (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3896       !if(Is2Addr,
3897         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3898         !strconcat(asm,
3899                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3900       [(set VR128:$dst,
3901         (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3902                    imm:$src3))]>, OpSize;
3903 }
3904
3905 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
3906   defm VPINSRB : SS41I_insert8<0x20, "vpinsrb", 0>, VEX_4V;
3907 let Constraints = "$src1 = $dst" in
3908   defm PINSRB  : SS41I_insert8<0x20, "pinsrb">;
3909
3910 multiclass SS41I_insert32<bits<8> opc, string asm, bit Is2Addr = 1> {
3911   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3912       (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3913       !if(Is2Addr,
3914         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3915         !strconcat(asm,
3916                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3917       [(set VR128:$dst,
3918         (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3919       OpSize;
3920   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3921       (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3922       !if(Is2Addr,
3923         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3924         !strconcat(asm,
3925                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3926       [(set VR128:$dst,
3927         (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3928                           imm:$src3)))]>, OpSize;
3929 }
3930
3931 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
3932   defm VPINSRD : SS41I_insert32<0x22, "vpinsrd", 0>, VEX_4V;
3933 let Constraints = "$src1 = $dst" in
3934   defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3935
3936 multiclass SS41I_insert64<bits<8> opc, string asm, bit Is2Addr = 1> {
3937   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3938       (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
3939       !if(Is2Addr,
3940         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3941         !strconcat(asm,
3942                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3943       [(set VR128:$dst,
3944         (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
3945       OpSize;
3946   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3947       (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
3948       !if(Is2Addr,
3949         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3950         !strconcat(asm,
3951                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3952       [(set VR128:$dst,
3953         (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
3954                           imm:$src3)))]>, OpSize;
3955 }
3956
3957 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
3958   defm VPINSRQ : SS41I_insert64<0x22, "vpinsrq", 0>, VEX_4V, VEX_W;
3959 let Constraints = "$src1 = $dst" in
3960   defm PINSRQ : SS41I_insert64<0x22, "pinsrq">, REX_W;
3961
3962 // insertps has a few different modes, there's the first two here below which
3963 // are optimized inserts that won't zero arbitrary elements in the destination
3964 // vector. The next one matches the intrinsic and could zero arbitrary elements
3965 // in the target vector.
3966 multiclass SS41I_insertf32<bits<8> opc, string asm, bit Is2Addr = 1> {
3967   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3968       (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3969       !if(Is2Addr,
3970         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3971         !strconcat(asm,
3972                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3973       [(set VR128:$dst,
3974         (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
3975       OpSize;
3976   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3977       (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3978       !if(Is2Addr,
3979         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3980         !strconcat(asm,
3981                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3982       [(set VR128:$dst,
3983         (X86insrtps VR128:$src1,
3984                    (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
3985                     imm:$src3))]>, OpSize;
3986 }
3987
3988 let Constraints = "$src1 = $dst" in
3989   defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
3990 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
3991   defm VINSERTPS : SS41I_insertf32<0x21, "vinsertps", 0>, VEX_4V;
3992
3993 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3994           (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3995
3996 //===----------------------------------------------------------------------===//
3997 // SSE4.1 - Round Instructions
3998 //===----------------------------------------------------------------------===//
3999
4000 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
4001                             string OpcodeStr,
4002                             Intrinsic V4F32Int,
4003                             Intrinsic V2F64Int> {
4004   // Intrinsic operation, reg.
4005   // Vector intrinsic operation, reg
4006   def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
4007                     (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
4008                     !strconcat(OpcodeStr,
4009                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4010                     [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
4011                     OpSize;
4012
4013   // Vector intrinsic operation, mem
4014   def PSm_Int : Ii8<opcps, MRMSrcMem,
4015                     (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
4016                     !strconcat(OpcodeStr,
4017                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4018                     [(set VR128:$dst,
4019                           (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
4020                     TA, OpSize,
4021                 Requires<[HasSSE41]>;
4022
4023   // Vector intrinsic operation, reg
4024   def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
4025                     (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
4026                     !strconcat(OpcodeStr,
4027                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4028                     [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
4029                     OpSize;
4030
4031   // Vector intrinsic operation, mem
4032   def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
4033                     (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
4034                     !strconcat(OpcodeStr,
4035                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4036                     [(set VR128:$dst,
4037                           (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
4038                     OpSize;
4039 }
4040
4041 multiclass sse41_fp_unop_rm_avx<bits<8> opcps, bits<8> opcpd,
4042                                 string OpcodeStr> {
4043   // Intrinsic operation, reg.
4044   // Vector intrinsic operation, reg
4045   def PSr : SS4AIi8<opcps, MRMSrcReg,
4046                     (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
4047                     !strconcat(OpcodeStr,
4048                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4049                     []>, OpSize;
4050
4051   // Vector intrinsic operation, mem
4052   def PSm : Ii8<opcps, MRMSrcMem,
4053                     (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
4054                     !strconcat(OpcodeStr,
4055                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4056                     []>, TA, OpSize, Requires<[HasSSE41]>;
4057
4058   // Vector intrinsic operation, reg
4059   def PDr : SS4AIi8<opcpd, MRMSrcReg,
4060                     (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
4061                     !strconcat(OpcodeStr,
4062                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4063                     []>, OpSize;
4064
4065   // Vector intrinsic operation, mem
4066   def PDm : SS4AIi8<opcpd, MRMSrcMem,
4067                     (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
4068                     !strconcat(OpcodeStr,
4069                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4070                     []>, OpSize;
4071 }
4072
4073 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
4074                             string OpcodeStr,
4075                             Intrinsic F32Int,
4076                             Intrinsic F64Int, bit Is2Addr = 1> {
4077   // Intrinsic operation, reg.
4078   def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
4079         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4080         !if(Is2Addr,
4081             !strconcat(OpcodeStr,
4082                 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4083             !strconcat(OpcodeStr,
4084                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4085         [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
4086         OpSize;
4087
4088   // Intrinsic operation, mem.
4089   def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
4090         (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
4091         !if(Is2Addr,
4092             !strconcat(OpcodeStr,
4093                 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4094             !strconcat(OpcodeStr,
4095                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4096         [(set VR128:$dst,
4097              (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
4098         OpSize;
4099
4100   // Intrinsic operation, reg.
4101   def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
4102         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4103         !if(Is2Addr,
4104             !strconcat(OpcodeStr,
4105                 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4106             !strconcat(OpcodeStr,
4107                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4108         [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
4109         OpSize;
4110
4111   // Intrinsic operation, mem.
4112   def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
4113         (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
4114         !if(Is2Addr,
4115             !strconcat(OpcodeStr,
4116                 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4117             !strconcat(OpcodeStr,
4118                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4119         [(set VR128:$dst,
4120               (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
4121         OpSize;
4122 }
4123
4124 multiclass sse41_fp_binop_rm_avx<bits<8> opcss, bits<8> opcsd,
4125                                  string OpcodeStr> {
4126   // Intrinsic operation, reg.
4127   def SSr : SS4AIi8<opcss, MRMSrcReg,
4128         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4129         !strconcat(OpcodeStr,
4130                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4131         []>, OpSize;
4132
4133   // Intrinsic operation, mem.
4134   def SSm : SS4AIi8<opcss, MRMSrcMem,
4135         (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
4136         !strconcat(OpcodeStr,
4137                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4138         []>, OpSize;
4139
4140   // Intrinsic operation, reg.
4141   def SDr : SS4AIi8<opcsd, MRMSrcReg,
4142         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4143             !strconcat(OpcodeStr,
4144                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4145         []>, OpSize;
4146
4147   // Intrinsic operation, mem.
4148   def SDm : SS4AIi8<opcsd, MRMSrcMem,
4149         (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
4150             !strconcat(OpcodeStr,
4151                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4152         []>, OpSize;
4153 }
4154
4155 // FP round - roundss, roundps, roundsd, roundpd
4156 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in {
4157   // Intrinsic form
4158   defm VROUND  : sse41_fp_unop_rm<0x08, 0x09, "vround",
4159                                 int_x86_sse41_round_ps, int_x86_sse41_round_pd>,
4160                                 VEX;
4161   defm VROUND  : sse41_fp_binop_rm<0x0A, 0x0B, "vround",
4162                                 int_x86_sse41_round_ss, int_x86_sse41_round_sd,
4163                                 0>, VEX_4V;
4164   // Instructions for the assembler
4165   defm VROUND  : sse41_fp_unop_rm_avx<0x08, 0x09, "vround">, VEX;
4166   defm VROUND  : sse41_fp_binop_rm_avx<0x0A, 0x0B, "vround">, VEX_4V;
4167 }
4168
4169 defm ROUND  : sse41_fp_unop_rm<0x08, 0x09, "round",
4170                                int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
4171 let Constraints = "$src1 = $dst" in
4172 defm ROUND  : sse41_fp_binop_rm<0x0A, 0x0B, "round",
4173                                int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
4174
4175 //===----------------------------------------------------------------------===//
4176 // SSE4.1 - Misc Instructions
4177 //===----------------------------------------------------------------------===//
4178
4179 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
4180 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
4181                                  Intrinsic IntId128> {
4182   def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4183                     (ins VR128:$src),
4184                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4185                     [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
4186   def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4187                      (ins i128mem:$src),
4188                      !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4189                      [(set VR128:$dst,
4190                        (IntId128
4191                        (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
4192 }
4193
4194 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
4195 defm VPHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "vphminposuw",
4196                                          int_x86_sse41_phminposuw>, VEX;
4197 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
4198                                          int_x86_sse41_phminposuw>;
4199
4200 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
4201 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
4202                               Intrinsic IntId128, bit Is2Addr = 1> {
4203   let isCommutable = 1 in
4204   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4205        (ins VR128:$src1, VR128:$src2),
4206        !if(Is2Addr,
4207            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4208            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4209        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>, OpSize;
4210   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4211        (ins VR128:$src1, i128mem:$src2),
4212        !if(Is2Addr,
4213            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4214            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4215        [(set VR128:$dst,
4216          (IntId128 VR128:$src1,
4217           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
4218 }
4219
4220 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in {
4221   let isCommutable = 0 in
4222   defm VPACKUSDW : SS41I_binop_rm_int<0x2B, "vpackusdw", int_x86_sse41_packusdw,
4223                                                          0>, VEX_4V;
4224   defm VPCMPEQQ  : SS41I_binop_rm_int<0x29, "vpcmpeqq",  int_x86_sse41_pcmpeqq,
4225                                                          0>, VEX_4V;
4226   defm VPMINSB   : SS41I_binop_rm_int<0x38, "vpminsb",   int_x86_sse41_pminsb,
4227                                                          0>, VEX_4V;
4228   defm VPMINSD   : SS41I_binop_rm_int<0x39, "vpminsd",   int_x86_sse41_pminsd,
4229                                                          0>, VEX_4V;
4230   defm VPMINUD   : SS41I_binop_rm_int<0x3B, "vpminud",   int_x86_sse41_pminud,
4231                                                          0>, VEX_4V;
4232   defm VPMINUW   : SS41I_binop_rm_int<0x3A, "vpminuw",   int_x86_sse41_pminuw,
4233                                                          0>, VEX_4V;
4234   defm VPMAXSB   : SS41I_binop_rm_int<0x3C, "vpmaxsb",   int_x86_sse41_pmaxsb,
4235                                                          0>, VEX_4V;
4236   defm VPMAXSD   : SS41I_binop_rm_int<0x3D, "vpmaxsd",   int_x86_sse41_pmaxsd,
4237                                                          0>, VEX_4V;
4238   defm VPMAXUD   : SS41I_binop_rm_int<0x3F, "vpmaxud",   int_x86_sse41_pmaxud,
4239                                                          0>, VEX_4V;
4240   defm VPMAXUW   : SS41I_binop_rm_int<0x3E, "vpmaxuw",   int_x86_sse41_pmaxuw,
4241                                                          0>, VEX_4V;
4242   defm VPMULDQ   : SS41I_binop_rm_int<0x28, "vpmuldq",   int_x86_sse41_pmuldq,
4243                                                          0>, VEX_4V;
4244 }
4245
4246 let Constraints = "$src1 = $dst" in {
4247   let isCommutable = 0 in
4248   defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw", int_x86_sse41_packusdw>;
4249   defm PCMPEQQ  : SS41I_binop_rm_int<0x29, "pcmpeqq",  int_x86_sse41_pcmpeqq>;
4250   defm PMINSB   : SS41I_binop_rm_int<0x38, "pminsb",   int_x86_sse41_pminsb>;
4251   defm PMINSD   : SS41I_binop_rm_int<0x39, "pminsd",   int_x86_sse41_pminsd>;
4252   defm PMINUD   : SS41I_binop_rm_int<0x3B, "pminud",   int_x86_sse41_pminud>;
4253   defm PMINUW   : SS41I_binop_rm_int<0x3A, "pminuw",   int_x86_sse41_pminuw>;
4254   defm PMAXSB   : SS41I_binop_rm_int<0x3C, "pmaxsb",   int_x86_sse41_pmaxsb>;
4255   defm PMAXSD   : SS41I_binop_rm_int<0x3D, "pmaxsd",   int_x86_sse41_pmaxsd>;
4256   defm PMAXUD   : SS41I_binop_rm_int<0x3F, "pmaxud",   int_x86_sse41_pmaxud>;
4257   defm PMAXUW   : SS41I_binop_rm_int<0x3E, "pmaxuw",   int_x86_sse41_pmaxuw>;
4258   defm PMULDQ   : SS41I_binop_rm_int<0x28, "pmuldq",   int_x86_sse41_pmuldq>;
4259 }
4260
4261 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
4262           (PCMPEQQrr VR128:$src1, VR128:$src2)>;
4263 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
4264           (PCMPEQQrm VR128:$src1, addr:$src2)>;
4265
4266 /// SS48I_binop_rm - Simple SSE41 binary operator.
4267 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
4268                         ValueType OpVT, bit Is2Addr = 1> {
4269   let isCommutable = 1 in
4270   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4271        (ins VR128:$src1, VR128:$src2),
4272        !if(Is2Addr,
4273            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4274            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4275        [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
4276        OpSize;
4277   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4278        (ins VR128:$src1, i128mem:$src2),
4279        !if(Is2Addr,
4280            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4281            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4282        [(set VR128:$dst, (OpNode VR128:$src1,
4283                                   (bc_v4i32 (memopv2i64 addr:$src2))))]>,
4284        OpSize;
4285 }
4286
4287 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
4288   defm VPMULLD : SS48I_binop_rm<0x40, "vpmulld", mul, v4i32, 0>, VEX_4V;
4289 let Constraints = "$src1 = $dst" in
4290   defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32>;
4291
4292 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
4293 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
4294                                Intrinsic IntId128, bit Is2Addr = 1> {
4295   let isCommutable = 1 in
4296   def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
4297         (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4298         !if(Is2Addr,
4299             !strconcat(OpcodeStr,
4300                 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4301             !strconcat(OpcodeStr,
4302                 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4303         [(set VR128:$dst,
4304           (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
4305         OpSize;
4306   def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
4307         (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
4308         !if(Is2Addr,
4309             !strconcat(OpcodeStr,
4310                 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4311             !strconcat(OpcodeStr,
4312                 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4313         [(set VR128:$dst,
4314           (IntId128 VR128:$src1,
4315            (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
4316         OpSize;
4317 }
4318
4319 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in {
4320   let isCommutable = 0 in {
4321   defm VBLENDPS : SS41I_binop_rmi_int<0x0C, "vblendps", int_x86_sse41_blendps,
4322                                                         0>, VEX_4V;
4323   defm VBLENDPD : SS41I_binop_rmi_int<0x0D, "vblendpd", int_x86_sse41_blendpd,
4324                                                         0>, VEX_4V;
4325   defm VPBLENDW : SS41I_binop_rmi_int<0x0E, "vpblendw", int_x86_sse41_pblendw,
4326                                                         0>, VEX_4V;
4327   defm VMPSADBW : SS41I_binop_rmi_int<0x42, "vmpsadbw", int_x86_sse41_mpsadbw,
4328                                                         0>, VEX_4V;
4329   }
4330   defm VDPPS : SS41I_binop_rmi_int<0x40, "vdpps", int_x86_sse41_dpps,
4331                                                         0>, VEX_4V;
4332   defm VDPPD : SS41I_binop_rmi_int<0x41, "vdppd", int_x86_sse41_dppd,
4333                                                         0>, VEX_4V;
4334 }
4335
4336 let Constraints = "$src1 = $dst" in {
4337   let isCommutable = 0 in {
4338   defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps", int_x86_sse41_blendps>;
4339   defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd", int_x86_sse41_blendpd>;
4340   defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw", int_x86_sse41_pblendw>;
4341   defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw", int_x86_sse41_mpsadbw>;
4342   }
4343   defm DPPS : SS41I_binop_rmi_int<0x40, "dpps", int_x86_sse41_dpps>;
4344   defm DPPD : SS41I_binop_rmi_int<0x41, "dppd", int_x86_sse41_dppd>;
4345 }
4346
4347 /// SS41I_quaternary_int_avx - AVX SSE 4.1 with 4 operators
4348 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in {
4349   multiclass SS41I_quaternary_int_avx<bits<8> opc, string OpcodeStr> {
4350     def rr : I<opc, MRMSrcReg, (outs VR128:$dst),
4351                     (ins VR128:$src1, VR128:$src2, VR128:$src3),
4352                     !strconcat(OpcodeStr,
4353                      "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4354                      [], SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
4355
4356     def rm : I<opc, MRMSrcMem, (outs VR128:$dst),
4357                     (ins VR128:$src1, i128mem:$src2, VR128:$src3),
4358                     !strconcat(OpcodeStr,
4359                      "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4360                      [], SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
4361   }
4362 }
4363
4364 defm VBLENDVPD : SS41I_quaternary_int_avx<0x4B, "vblendvpd">;
4365 defm VBLENDVPS : SS41I_quaternary_int_avx<0x4A, "vblendvps">;
4366 defm VPBLENDVB : SS41I_quaternary_int_avx<0x4C, "vpblendvb">;
4367
4368 /// SS41I_ternary_int - SSE 4.1 ternary operator
4369 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
4370   multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
4371     def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4372                     (ins VR128:$src1, VR128:$src2),
4373                     !strconcat(OpcodeStr,
4374                      "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
4375                     [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
4376                     OpSize;
4377
4378     def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4379                     (ins VR128:$src1, i128mem:$src2),
4380                     !strconcat(OpcodeStr,
4381                      "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
4382                     [(set VR128:$dst,
4383                       (IntId VR128:$src1,
4384                        (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
4385   }
4386 }
4387
4388 defm BLENDVPD     : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
4389 defm BLENDVPS     : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
4390 defm PBLENDVB     : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
4391
4392 // ptest instruction we'll lower to this in X86ISelLowering primarily from
4393 // the intel intrinsic that corresponds to this.
4394 let Defs = [EFLAGS], isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in {
4395 def VPTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
4396                     "vptest\t{$src2, $src1|$src1, $src2}",
4397                     [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
4398               OpSize, VEX;
4399 def VPTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
4400                     "vptest\t{$src2, $src1|$src1, $src2}",
4401                     [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
4402               OpSize, VEX;
4403 }
4404
4405 let Defs = [EFLAGS] in {
4406 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
4407                     "ptest \t{$src2, $src1|$src1, $src2}",
4408                     [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
4409               OpSize;
4410 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
4411                     "ptest \t{$src2, $src1|$src1, $src2}",
4412                     [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
4413               OpSize;
4414 }
4415
4416 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE41] in
4417 def VMOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4418                        "vmovntdqa\t{$src, $dst|$dst, $src}",
4419                        [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
4420                        OpSize, VEX;
4421 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4422                        "movntdqa\t{$src, $dst|$dst, $src}",
4423                        [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
4424                        OpSize;
4425
4426 //===----------------------------------------------------------------------===//
4427 // SSE4.2 - Compare Instructions
4428 //===----------------------------------------------------------------------===//
4429
4430 /// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
4431 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
4432                               Intrinsic IntId128, bit Is2Addr = 1> {
4433   def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
4434        (ins VR128:$src1, VR128:$src2),
4435        !if(Is2Addr,
4436            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4437            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4438        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
4439        OpSize;
4440   def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
4441        (ins VR128:$src1, i128mem:$src2),
4442        !if(Is2Addr,
4443            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4444            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4445        [(set VR128:$dst,
4446          (IntId128 VR128:$src1,
4447           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
4448 }
4449
4450 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE42] in
4451   defm VPCMPGTQ : SS42I_binop_rm_int<0x37, "vpcmpgtq", int_x86_sse42_pcmpgtq,
4452                                      0>, VEX_4V;
4453 let Constraints = "$src1 = $dst" in
4454   defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
4455
4456 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
4457           (PCMPGTQrr VR128:$src1, VR128:$src2)>;
4458 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
4459           (PCMPGTQrm VR128:$src1, addr:$src2)>;
4460
4461 //===----------------------------------------------------------------------===//
4462 // SSE4.2 - String/text Processing Instructions
4463 //===----------------------------------------------------------------------===//
4464
4465 // Packed Compare Implicit Length Strings, Return Mask
4466 let Defs = [EFLAGS], usesCustomInserter = 1 in {
4467   def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
4468     (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4469     "#PCMPISTRM128rr PSEUDO!",
4470     [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
4471                                                   imm:$src3))]>, OpSize;
4472   def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
4473     (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
4474     "#PCMPISTRM128rm PSEUDO!",
4475     [(set VR128:$dst, (int_x86_sse42_pcmpistrm128
4476                           VR128:$src1, (load addr:$src2), imm:$src3))]>, OpSize;
4477 }
4478
4479 let Defs = [XMM0, EFLAGS], isAsmParserOnly = 1,
4480     Predicates = [HasAVX, HasSSE42] in {
4481   def VPCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
4482       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4483       "vpcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize, VEX;
4484   def VPCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
4485       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
4486       "vpcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize, VEX;
4487 }
4488
4489 let Defs = [XMM0, EFLAGS] in {
4490   def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
4491       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4492       "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
4493   def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
4494       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
4495       "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
4496 }
4497
4498 // Packed Compare Explicit Length Strings, Return Mask
4499 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
4500   def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
4501     (ins VR128:$src1, VR128:$src3, i8imm:$src5),
4502     "#PCMPESTRM128rr PSEUDO!",
4503     [(set VR128:$dst,
4504           (int_x86_sse42_pcmpestrm128
4505            VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
4506
4507   def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
4508     (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
4509     "#PCMPESTRM128rm PSEUDO!",
4510     [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
4511                        VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
4512     OpSize;
4513 }
4514
4515 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE42],
4516     Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
4517   def VPCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
4518       (ins VR128:$src1, VR128:$src3, i8imm:$src5),
4519       "vpcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize, VEX;
4520   def VPCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
4521       (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
4522       "vpcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize, VEX;
4523 }
4524
4525 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
4526   def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
4527       (ins VR128:$src1, VR128:$src3, i8imm:$src5),
4528       "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
4529   def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
4530       (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
4531       "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
4532 }
4533
4534 // Packed Compare Implicit Length Strings, Return Index
4535 let Defs = [ECX, EFLAGS] in {
4536   multiclass SS42AI_pcmpistri<Intrinsic IntId128, string asm = "pcmpistri"> {
4537     def rr : SS42AI<0x63, MRMSrcReg, (outs),
4538       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4539       !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
4540       [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
4541        (implicit EFLAGS)]>, OpSize;
4542     def rm : SS42AI<0x63, MRMSrcMem, (outs),
4543       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
4544       !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
4545       [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
4546        (implicit EFLAGS)]>, OpSize;
4547   }
4548 }
4549
4550 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE42] in {
4551 defm VPCMPISTRI  : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128, "vpcmpistri">,
4552                                     VEX;
4553 defm VPCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128, "vpcmpistri">,
4554                                     VEX;
4555 defm VPCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128, "vpcmpistri">,
4556                                     VEX;
4557 defm VPCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128, "vpcmpistri">,
4558                                     VEX;
4559 defm VPCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128, "vpcmpistri">,
4560                                     VEX;
4561 defm VPCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128, "vpcmpistri">,
4562                                     VEX;
4563 }
4564
4565 defm PCMPISTRI  : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
4566 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
4567 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
4568 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
4569 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
4570 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
4571
4572 // Packed Compare Explicit Length Strings, Return Index
4573 let Defs = [ECX, EFLAGS], Uses = [EAX, EDX] in {
4574   multiclass SS42AI_pcmpestri<Intrinsic IntId128, string asm = "pcmpestri"> {
4575     def rr : SS42AI<0x61, MRMSrcReg, (outs),
4576       (ins VR128:$src1, VR128:$src3, i8imm:$src5),
4577       !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
4578       [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
4579        (implicit EFLAGS)]>, OpSize;
4580     def rm : SS42AI<0x61, MRMSrcMem, (outs),
4581       (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
4582       !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
4583        [(set ECX,
4584              (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
4585         (implicit EFLAGS)]>, OpSize;
4586   }
4587 }
4588
4589 let isAsmParserOnly = 1, Predicates = [HasAVX, HasSSE42] in {
4590 defm VPCMPESTRI  : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128, "vpcmpestri">,
4591                                     VEX;
4592 defm VPCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128, "vpcmpestri">,
4593                                     VEX;
4594 defm VPCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128, "vpcmpestri">,
4595                                     VEX;
4596 defm VPCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128, "vpcmpestri">,
4597                                     VEX;
4598 defm VPCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128, "vpcmpestri">,
4599                                     VEX;
4600 defm VPCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128, "vpcmpestri">,
4601                                     VEX;
4602 }
4603
4604 defm PCMPESTRI  : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
4605 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
4606 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
4607 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
4608 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
4609 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
4610
4611 //===----------------------------------------------------------------------===//
4612 // SSE4.2 - CRC Instructions
4613 //===----------------------------------------------------------------------===//
4614
4615 // No CRC instructions have AVX equivalents
4616
4617 // crc intrinsic instruction
4618 // This set of instructions are only rm, the only difference is the size
4619 // of r and m.
4620 let Constraints = "$src1 = $dst" in {
4621   def CRC32m8  : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
4622                       (ins GR32:$src1, i8mem:$src2),
4623                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
4624                        [(set GR32:$dst,
4625                          (int_x86_sse42_crc32_8 GR32:$src1,
4626                          (load addr:$src2)))]>;
4627   def CRC32r8  : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
4628                       (ins GR32:$src1, GR8:$src2),
4629                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
4630                        [(set GR32:$dst,
4631                          (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
4632   def CRC32m16  : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
4633                       (ins GR32:$src1, i16mem:$src2),
4634                       "crc32{w} \t{$src2, $src1|$src1, $src2}",
4635                        [(set GR32:$dst,
4636                          (int_x86_sse42_crc32_16 GR32:$src1,
4637                          (load addr:$src2)))]>,
4638                          OpSize;
4639   def CRC32r16  : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
4640                       (ins GR32:$src1, GR16:$src2),
4641                       "crc32{w} \t{$src2, $src1|$src1, $src2}",
4642                        [(set GR32:$dst,
4643                          (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
4644                          OpSize;
4645   def CRC32m32  : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
4646                       (ins GR32:$src1, i32mem:$src2),
4647                       "crc32{l} \t{$src2, $src1|$src1, $src2}",
4648                        [(set GR32:$dst,
4649                          (int_x86_sse42_crc32_32 GR32:$src1,
4650                          (load addr:$src2)))]>;
4651   def CRC32r32  : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
4652                       (ins GR32:$src1, GR32:$src2),
4653                       "crc32{l} \t{$src2, $src1|$src1, $src2}",
4654                        [(set GR32:$dst,
4655                          (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
4656   def CRC64m8  : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
4657                       (ins GR64:$src1, i8mem:$src2),
4658                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
4659                        [(set GR64:$dst,
4660                          (int_x86_sse42_crc64_8 GR64:$src1,
4661                          (load addr:$src2)))]>,
4662                          REX_W;
4663   def CRC64r8  : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
4664                       (ins GR64:$src1, GR8:$src2),
4665                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
4666                        [(set GR64:$dst,
4667                          (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
4668                          REX_W;
4669   def CRC64m64  : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
4670                       (ins GR64:$src1, i64mem:$src2),
4671                       "crc32{q} \t{$src2, $src1|$src1, $src2}",
4672                        [(set GR64:$dst,
4673                          (int_x86_sse42_crc64_64 GR64:$src1,
4674                          (load addr:$src2)))]>,
4675                          REX_W;
4676   def CRC64r64  : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
4677                       (ins GR64:$src1, GR64:$src2),
4678                       "crc32{q} \t{$src2, $src1|$src1, $src2}",
4679                        [(set GR64:$dst,
4680                          (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
4681                          REX_W;
4682 }
4683
4684 //===----------------------------------------------------------------------===//
4685 // AES-NI Instructions
4686 //===----------------------------------------------------------------------===//
4687
4688 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
4689                               Intrinsic IntId128, bit Is2Addr = 1> {
4690   def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
4691        (ins VR128:$src1, VR128:$src2),
4692        !if(Is2Addr,
4693            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4694            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4695        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
4696        OpSize;
4697   def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
4698        (ins VR128:$src1, i128mem:$src2),
4699        !if(Is2Addr,
4700            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4701            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4702        [(set VR128:$dst,
4703          (IntId128 VR128:$src1,
4704           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
4705 }
4706
4707 // Perform One Round of an AES Encryption/Decryption Flow
4708 let isAsmParserOnly = 1, Predicates = [HasAVX, HasAES] in {
4709   defm VAESENC          : AESI_binop_rm_int<0xDC, "vaesenc",
4710                          int_x86_aesni_aesenc, 0>, VEX_4V;
4711   defm VAESENCLAST      : AESI_binop_rm_int<0xDD, "vaesenclast",
4712                          int_x86_aesni_aesenclast, 0>, VEX_4V;
4713   defm VAESDEC          : AESI_binop_rm_int<0xDE, "vaesdec",
4714                          int_x86_aesni_aesdec, 0>, VEX_4V;
4715   defm VAESDECLAST      : AESI_binop_rm_int<0xDF, "vaesdeclast",
4716                          int_x86_aesni_aesdeclast, 0>, VEX_4V;
4717 }
4718
4719 let Constraints = "$src1 = $dst" in {
4720   defm AESENC          : AESI_binop_rm_int<0xDC, "aesenc",
4721                          int_x86_aesni_aesenc>;
4722   defm AESENCLAST      : AESI_binop_rm_int<0xDD, "aesenclast",
4723                          int_x86_aesni_aesenclast>;
4724   defm AESDEC          : AESI_binop_rm_int<0xDE, "aesdec",
4725                          int_x86_aesni_aesdec>;
4726   defm AESDECLAST      : AESI_binop_rm_int<0xDF, "aesdeclast",
4727                          int_x86_aesni_aesdeclast>;
4728 }
4729
4730 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
4731           (AESENCrr VR128:$src1, VR128:$src2)>;
4732 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
4733           (AESENCrm VR128:$src1, addr:$src2)>;
4734 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
4735           (AESENCLASTrr VR128:$src1, VR128:$src2)>;
4736 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
4737           (AESENCLASTrm VR128:$src1, addr:$src2)>;
4738 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
4739           (AESDECrr VR128:$src1, VR128:$src2)>;
4740 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
4741           (AESDECrm VR128:$src1, addr:$src2)>;
4742 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
4743           (AESDECLASTrr VR128:$src1, VR128:$src2)>;
4744 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
4745           (AESDECLASTrm VR128:$src1, addr:$src2)>;
4746
4747 // Perform the AES InvMixColumn Transformation
4748 let isAsmParserOnly = 1, Predicates = [HasAVX, HasAES] in {
4749   def VAESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
4750       (ins VR128:$src1),
4751       "vaesimc\t{$src1, $dst|$dst, $src1}",
4752       [(set VR128:$dst,
4753         (int_x86_aesni_aesimc VR128:$src1))]>,
4754       OpSize, VEX;
4755   def VAESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
4756       (ins i128mem:$src1),
4757       "vaesimc\t{$src1, $dst|$dst, $src1}",
4758       [(set VR128:$dst,
4759         (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
4760       OpSize, VEX;
4761 }
4762 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
4763   (ins VR128:$src1),
4764   "aesimc\t{$src1, $dst|$dst, $src1}",
4765   [(set VR128:$dst,
4766     (int_x86_aesni_aesimc VR128:$src1))]>,
4767   OpSize;
4768 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
4769   (ins i128mem:$src1),
4770   "aesimc\t{$src1, $dst|$dst, $src1}",
4771   [(set VR128:$dst,
4772     (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
4773   OpSize;
4774
4775 // AES Round Key Generation Assist
4776 let isAsmParserOnly = 1, Predicates = [HasAVX, HasAES] in {
4777   def VAESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
4778       (ins VR128:$src1, i8imm:$src2),
4779       "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
4780       [(set VR128:$dst,
4781         (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
4782       OpSize, VEX;
4783   def VAESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
4784       (ins i128mem:$src1, i8imm:$src2),
4785       "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
4786       [(set VR128:$dst,
4787         (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),
4788                                         imm:$src2))]>,
4789       OpSize, VEX;
4790 }
4791 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
4792   (ins VR128:$src1, i8imm:$src2),
4793   "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
4794   [(set VR128:$dst,
4795     (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
4796   OpSize;
4797 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
4798   (ins i128mem:$src1, i8imm:$src2),
4799   "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
4800   [(set VR128:$dst,
4801     (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),
4802                                     imm:$src2))]>,
4803   OpSize;