Add matching patterns for vblend AVX intrinsics
[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_",
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_",
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;
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;
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_s_np<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
520                           X86MemOperand x86memop, string asm> {
521   def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
522                         []>;
523   def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
524                         []>;
525 }
526
527 multiclass sse12_cvt_p<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
528                          SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
529                          string asm, Domain d> {
530   def rr : PI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
531                         [(set DstRC:$dst, (OpNode SrcRC:$src))], d>;
532   def rm : PI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
533                         [(set DstRC:$dst, (OpNode (ld_frag addr:$src)))], d>;
534 }
535
536 multiclass sse12_vcvt_avx<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
537                           X86MemOperand x86memop, string asm> {
538   def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src),
539               !strconcat(asm,"\t{$src, $src1, $dst|$dst, $src1, $src}"), []>;
540   def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
541               (ins DstRC:$src1, x86memop:$src),
542               !strconcat(asm,"\t{$src, $src1, $dst|$dst, $src1, $src}"), []>;
543 }
544
545 let isAsmParserOnly = 1 in {
546 defm VCVTTSS2SI   : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
547                                 "cvttss2si\t{$src, $dst|$dst, $src}">, XS, VEX;
548 defm VCVTTSS2SI64 : sse12_cvt_s<0x2C, FR32, GR64, fp_to_sint, f32mem, loadf32,
549                                 "cvttss2si\t{$src, $dst|$dst, $src}">, XS, VEX,
550                                 VEX_W;
551 defm VCVTTSD2SI   : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
552                                 "cvttsd2si\t{$src, $dst|$dst, $src}">, XD, VEX;
553 defm VCVTTSD2SI64 : sse12_cvt_s<0x2C, FR64, GR64, fp_to_sint, f64mem, loadf64,
554                                 "cvttsd2si\t{$src, $dst|$dst, $src}">, XD,
555                                 VEX, VEX_W;
556
557 // The assembler can recognize rr 64-bit instructions by seeing a rxx
558 // register, but the same isn't true when only using memory operands,
559 // provide other assembly "l" and "q" forms to address this explicitly
560 // where appropriate to do so.
561 defm VCVTSI2SS   : sse12_vcvt_avx<0x2A, GR32, FR32, i32mem, "cvtsi2ss">, XS,
562                                   VEX_4V;
563 defm VCVTSI2SS64 : sse12_vcvt_avx<0x2A, GR64, FR32, i64mem, "cvtsi2ss{q}">, XS,
564                                   VEX_4V, VEX_W;
565 defm VCVTSI2SD   : sse12_vcvt_avx<0x2A, GR32, FR64, i32mem, "cvtsi2sd">, XD,
566                                   VEX_4V;
567 defm VCVTSI2SDL  : sse12_vcvt_avx<0x2A, GR32, FR64, i32mem, "cvtsi2sd{l}">, XD,
568                                   VEX_4V;
569 defm VCVTSI2SD64 : sse12_vcvt_avx<0x2A, GR64, FR64, i64mem, "cvtsi2sd{q}">, XD,
570                                   VEX_4V, VEX_W;
571 }
572
573 defm CVTTSS2SI : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
574                       "cvttss2si\t{$src, $dst|$dst, $src}">, XS;
575 defm CVTTSS2SI64 : sse12_cvt_s<0x2C, FR32, GR64, fp_to_sint, f32mem, loadf32,
576                       "cvttss2si{q}\t{$src, $dst|$dst, $src}">, XS, REX_W;
577 defm CVTTSD2SI : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
578                       "cvttsd2si\t{$src, $dst|$dst, $src}">, XD;
579 defm CVTTSD2SI64 : sse12_cvt_s<0x2C, FR64, GR64, fp_to_sint, f64mem, loadf64,
580                       "cvttsd2si{q}\t{$src, $dst|$dst, $src}">, XD, REX_W;
581 defm CVTSI2SS  : sse12_cvt_s<0x2A, GR32, FR32, sint_to_fp, i32mem, loadi32,
582                       "cvtsi2ss\t{$src, $dst|$dst, $src}">, XS;
583 defm CVTSI2SS64 : sse12_cvt_s<0x2A, GR64, FR32, sint_to_fp, i64mem, loadi64,
584                       "cvtsi2ss{q}\t{$src, $dst|$dst, $src}">, XS, REX_W;
585 defm CVTSI2SD  : sse12_cvt_s<0x2A, GR32, FR64, sint_to_fp, i32mem, loadi32,
586                       "cvtsi2sd\t{$src, $dst|$dst, $src}">, XD;
587 defm CVTSI2SD64 : sse12_cvt_s<0x2A, GR64, FR64, sint_to_fp, i64mem, loadi64,
588                       "cvtsi2sd{q}\t{$src, $dst|$dst, $src}">, XD, REX_W;
589
590 // Conversion Instructions Intrinsics - Match intrinsics which expect MM
591 // and/or XMM operand(s).
592 multiclass sse12_cvt_pint<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
593                          Intrinsic Int, X86MemOperand x86memop, PatFrag ld_frag,
594                          string asm, Domain d> {
595   def rr : PI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
596                         [(set DstRC:$dst, (Int SrcRC:$src))], d>;
597   def rm : PI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
598                         [(set DstRC:$dst, (Int (ld_frag addr:$src)))], d>;
599 }
600
601 multiclass sse12_cvt_sint<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
602                          Intrinsic Int, X86MemOperand x86memop, PatFrag ld_frag,
603                          string asm> {
604   def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src),
605               !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
606               [(set DstRC:$dst, (Int SrcRC:$src))]>;
607   def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src),
608               !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
609               [(set DstRC:$dst, (Int (ld_frag addr:$src)))]>;
610 }
611
612 multiclass sse12_cvt_pint_3addr<bits<8> opc, RegisterClass SrcRC,
613                     RegisterClass DstRC, Intrinsic Int, X86MemOperand x86memop,
614                     PatFrag ld_frag, string asm, Domain d> {
615   def rr : PI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src2),
616               asm, [(set DstRC:$dst, (Int DstRC:$src1, SrcRC:$src2))], d>;
617   def rm : PI<opc, MRMSrcMem, (outs DstRC:$dst),
618                    (ins DstRC:$src1, x86memop:$src2), asm,
619               [(set DstRC:$dst, (Int DstRC:$src1, (ld_frag addr:$src2)))], d>;
620 }
621
622 multiclass sse12_cvt_sint_3addr<bits<8> opc, RegisterClass SrcRC,
623                     RegisterClass DstRC, Intrinsic Int, X86MemOperand x86memop,
624                     PatFrag ld_frag, string asm, bit Is2Addr = 1> {
625   def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src2),
626               !if(Is2Addr,
627                   !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
628                   !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
629               [(set DstRC:$dst, (Int DstRC:$src1, SrcRC:$src2))]>;
630   def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
631               (ins DstRC:$src1, x86memop:$src2),
632               !if(Is2Addr,
633                   !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
634                   !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
635               [(set DstRC:$dst, (Int DstRC:$src1, (ld_frag addr:$src2)))]>;
636 }
637
638 let isAsmParserOnly = 1 in {
639   defm Int_VCVTSS2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse_cvtss2si,
640                         f32mem, load, "cvtss2si">, XS, VEX;
641   defm Int_VCVTSS2SI64 : sse12_cvt_sint<0x2D, VR128, GR64,
642                           int_x86_sse_cvtss2si64, f32mem, load, "cvtss2si">,
643                           XS, VEX, VEX_W;
644   defm Int_VCVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse2_cvtsd2si,
645                         f128mem, load, "cvtsd2si">, XD, VEX;
646   defm Int_VCVTSD2SI64 : sse12_cvt_sint<0x2D, VR128, GR64,
647                         int_x86_sse2_cvtsd2si64, f128mem, load, "cvtsd2si">,
648                         XD, VEX, VEX_W;
649
650   // FIXME: The asm matcher has a hack to ignore instructions with _Int and Int_
651   // Get rid of this hack or rename the intrinsics, there are several
652   // intructions that only match with the intrinsic form, why create duplicates
653   // to let them be recognized by the assembler?
654   defm VCVTSD2SI_alt : sse12_cvt_s_np<0x2D, FR64, GR32, f64mem,
655                         "cvtsd2si\t{$src, $dst|$dst, $src}">, XD, VEX;
656   defm VCVTSD2SI64   : sse12_cvt_s_np<0x2D, FR64, GR64, f64mem,
657                         "cvtsd2si\t{$src, $dst|$dst, $src}">, XD, VEX, VEX_W;
658 }
659 defm Int_CVTSS2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse_cvtss2si,
660                       f32mem, load, "cvtss2si">, XS;
661 defm Int_CVTSS2SI64 : sse12_cvt_sint<0x2D, VR128, GR64, int_x86_sse_cvtss2si64,
662                       f32mem, load, "cvtss2si{q}">, XS, REX_W;
663 defm Int_CVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse2_cvtsd2si,
664                       f128mem, load, "cvtsd2si">, XD;
665 defm Int_CVTSD2SI64 : sse12_cvt_sint<0x2D, VR128, GR64, int_x86_sse2_cvtsd2si64,
666                         f128mem, load, "cvtsd2si">, XD, REX_W;
667
668 defm CVTSD2SI64 : sse12_cvt_s_np<0x2D, VR128, GR64, f64mem, "cvtsd2si{q}">, XD,
669                         REX_W;
670
671 let isAsmParserOnly = 1 in {
672   defm Int_VCVTSI2SS : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
673             int_x86_sse_cvtsi2ss, i32mem, loadi32, "cvtsi2ss", 0>, XS, VEX_4V;
674   defm Int_VCVTSI2SS64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
675             int_x86_sse_cvtsi642ss, i64mem, loadi64, "cvtsi2ss", 0>, XS, VEX_4V,
676             VEX_W;
677   defm Int_VCVTSI2SD : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
678             int_x86_sse2_cvtsi2sd, i32mem, loadi32, "cvtsi2sd", 0>, XD, VEX_4V;
679   defm Int_VCVTSI2SD64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
680             int_x86_sse2_cvtsi642sd, i64mem, loadi64, "cvtsi2sd", 0>, XD,
681             VEX_4V, VEX_W;
682 }
683
684 let Constraints = "$src1 = $dst" in {
685   defm Int_CVTSI2SS : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
686                         int_x86_sse_cvtsi2ss, i32mem, loadi32,
687                         "cvtsi2ss">, XS;
688   defm Int_CVTSI2SS64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
689                         int_x86_sse_cvtsi642ss, i64mem, loadi64,
690                         "cvtsi2ss{q}">, XS, REX_W;
691   defm Int_CVTSI2SD : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
692                         int_x86_sse2_cvtsi2sd, i32mem, loadi32,
693                         "cvtsi2sd">, XD;
694   defm Int_CVTSI2SD64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
695                         int_x86_sse2_cvtsi642sd, i64mem, loadi64,
696                         "cvtsi2sd">, XD, REX_W;
697 }
698
699 // Instructions below don't have an AVX form.
700 defm Int_CVTPS2PI : sse12_cvt_pint<0x2D, VR128, VR64, int_x86_sse_cvtps2pi,
701                       f64mem, load, "cvtps2pi\t{$src, $dst|$dst, $src}",
702                       SSEPackedSingle>, TB;
703 defm Int_CVTPD2PI : sse12_cvt_pint<0x2D, VR128, VR64, int_x86_sse_cvtpd2pi,
704                       f128mem, memop, "cvtpd2pi\t{$src, $dst|$dst, $src}",
705                       SSEPackedDouble>, TB, OpSize;
706 defm Int_CVTTPS2PI : sse12_cvt_pint<0x2C, VR128, VR64, int_x86_sse_cvttps2pi,
707                        f64mem, load, "cvttps2pi\t{$src, $dst|$dst, $src}",
708                        SSEPackedSingle>, TB;
709 defm Int_CVTTPD2PI : sse12_cvt_pint<0x2C, VR128, VR64, int_x86_sse_cvttpd2pi,
710                        f128mem, memop, "cvttpd2pi\t{$src, $dst|$dst, $src}",
711                        SSEPackedDouble>, TB, OpSize;
712 defm Int_CVTPI2PD : sse12_cvt_pint<0x2A, VR64, VR128, int_x86_sse_cvtpi2pd,
713                          i64mem, load, "cvtpi2pd\t{$src, $dst|$dst, $src}",
714                          SSEPackedDouble>, TB, OpSize;
715 let Constraints = "$src1 = $dst" in {
716   defm Int_CVTPI2PS : sse12_cvt_pint_3addr<0x2A, VR64, VR128,
717                          int_x86_sse_cvtpi2ps,
718                          i64mem, load, "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
719                          SSEPackedSingle>, TB;
720 }
721
722 /// SSE 1 Only
723
724 // Aliases for intrinsics
725 let isAsmParserOnly = 1 in {
726 defm Int_VCVTTSS2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse_cvttss2si,
727                                     f32mem, load, "cvttss2si">, XS, VEX;
728 defm Int_VCVTTSS2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
729                                     int_x86_sse_cvttss2si64, f32mem, load,
730                                     "cvttss2si">, XS, VEX, VEX_W;
731 defm Int_VCVTTSD2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse2_cvttsd2si,
732                                     f128mem, load, "cvttss2si">, XD, VEX;
733 defm Int_VCVTTSD2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
734                                     int_x86_sse2_cvttsd2si64, f128mem, load,
735                                     "cvttss2si">, XD, VEX, VEX_W;
736 }
737 defm Int_CVTTSS2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse_cvttss2si,
738                                     f32mem, load, "cvttss2si">, XS;
739 defm Int_CVTTSS2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
740                                     int_x86_sse_cvttss2si64, f32mem, load,
741                                     "cvttss2si{q}">, XS, REX_W;
742 defm Int_CVTTSD2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse2_cvttsd2si,
743                                     f128mem, load, "cvttss2si">, XD;
744 defm Int_CVTTSD2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
745                                     int_x86_sse2_cvttsd2si64, f128mem, load,
746                                     "cvttss2si{q}">, XD, REX_W;
747
748 let isAsmParserOnly = 1, Pattern = []<dag> in {
749 defm VCVTSS2SI   : sse12_cvt_s<0x2D, FR32, GR32, undef, f32mem, load,
750                                "cvtss2si{l}\t{$src, $dst|$dst, $src}">, XS, VEX;
751 defm VCVTSS2SI64 : sse12_cvt_s<0x2D, FR32, GR64, undef, f32mem, load,
752                                "cvtss2si\t{$src, $dst|$dst, $src}">, XS, VEX,
753                                VEX_W;
754 defm VCVTDQ2PS   : sse12_cvt_p<0x5B, VR128, VR128, undef, i128mem, load,
755                                "cvtdq2ps\t{$src, $dst|$dst, $src}",
756                                SSEPackedSingle>, TB, VEX;
757 defm VCVTDQ2PSY  : sse12_cvt_p<0x5B, VR256, VR256, undef, i256mem, load,
758                                "cvtdq2ps\t{$src, $dst|$dst, $src}",
759                                SSEPackedSingle>, TB, VEX;
760 }
761 let Pattern = []<dag> in {
762 defm CVTSS2SI : sse12_cvt_s<0x2D, FR32, GR32, undef, f32mem, load /*dummy*/,
763                           "cvtss2si{l}\t{$src, $dst|$dst, $src}">, XS;
764 defm CVTSS2SI64 : sse12_cvt_s<0x2D, FR32, GR64, undef, f32mem, load /*dummy*/,
765                           "cvtss2si{q}\t{$src, $dst|$dst, $src}">, XS, REX_W;
766 defm CVTDQ2PS : sse12_cvt_p<0x5B, VR128, VR128, undef, i128mem, load /*dummy*/,
767                             "cvtdq2ps\t{$src, $dst|$dst, $src}",
768                             SSEPackedSingle>, TB; /* PD SSE3 form is avaiable */
769 }
770
771 /// SSE 2 Only
772
773 // Convert scalar double to scalar single
774 let isAsmParserOnly = 1 in {
775 def VCVTSD2SSrr  : VSDI<0x5A, MRMSrcReg, (outs FR32:$dst),
776                        (ins FR64:$src1, FR64:$src2),
777                       "cvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
778                       VEX_4V;
779 def VCVTSD2SSrm  : I<0x5A, MRMSrcMem, (outs FR32:$dst),
780                        (ins FR64:$src1, f64mem:$src2),
781                       "vcvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
782                       []>, XD, Requires<[HasAVX, OptForSize]>, VEX_4V;
783 }
784 def CVTSD2SSrr  : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
785                       "cvtsd2ss\t{$src, $dst|$dst, $src}",
786                       [(set FR32:$dst, (fround FR64:$src))]>;
787 def CVTSD2SSrm  : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
788                       "cvtsd2ss\t{$src, $dst|$dst, $src}",
789                       [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
790                   Requires<[HasSSE2, OptForSize]>;
791
792 let isAsmParserOnly = 1 in
793 defm Int_VCVTSD2SS: sse12_cvt_sint_3addr<0x5A, VR128, VR128,
794                       int_x86_sse2_cvtsd2ss, f64mem, load, "cvtsd2ss", 0>,
795                       XS, VEX_4V;
796 let Constraints = "$src1 = $dst" in
797 defm Int_CVTSD2SS: sse12_cvt_sint_3addr<0x5A, VR128, VR128,
798                       int_x86_sse2_cvtsd2ss, f64mem, load, "cvtsd2ss">, XS;
799
800 // Convert scalar single to scalar double
801 let isAsmParserOnly = 1 in { // SSE2 instructions with XS prefix
802 def VCVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst),
803                     (ins FR32:$src1, FR32:$src2),
804                     "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
805                     []>, XS, Requires<[HasAVX]>, VEX_4V;
806 def VCVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst),
807                     (ins FR32:$src1, f32mem:$src2),
808                     "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
809                     []>, XS, VEX_4V, Requires<[HasAVX, OptForSize]>;
810 }
811 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
812                    "cvtss2sd\t{$src, $dst|$dst, $src}",
813                    [(set FR64:$dst, (fextend FR32:$src))]>, XS,
814                  Requires<[HasSSE2]>;
815 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
816                    "cvtss2sd\t{$src, $dst|$dst, $src}",
817                    [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
818                  Requires<[HasSSE2, OptForSize]>;
819
820 let isAsmParserOnly = 1 in {
821 def Int_VCVTSS2SDrr: I<0x5A, MRMSrcReg,
822                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
823                     "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
824                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
825                                        VR128:$src2))]>, XS, VEX_4V,
826                     Requires<[HasAVX]>;
827 def Int_VCVTSS2SDrm: I<0x5A, MRMSrcMem,
828                       (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
829                     "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
830                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
831                                        (load addr:$src2)))]>, XS, VEX_4V,
832                     Requires<[HasAVX]>;
833 }
834 let Constraints = "$src1 = $dst" in { // SSE2 instructions with XS prefix
835 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
836                       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
837                     "cvtss2sd\t{$src2, $dst|$dst, $src2}",
838                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
839                                        VR128:$src2))]>, XS,
840                     Requires<[HasSSE2]>;
841 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
842                       (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
843                     "cvtss2sd\t{$src2, $dst|$dst, $src2}",
844                     [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
845                                        (load addr:$src2)))]>, XS,
846                     Requires<[HasSSE2]>;
847 }
848
849 def : Pat<(extloadf32 addr:$src),
850           (CVTSS2SDrr (MOVSSrm addr:$src))>,
851       Requires<[HasSSE2, OptForSpeed]>;
852
853 // Convert doubleword to packed single/double fp
854 let isAsmParserOnly = 1 in { // SSE2 instructions without OpSize prefix
855 def Int_VCVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
856                        "vcvtdq2ps\t{$src, $dst|$dst, $src}",
857                        [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
858                      TB, VEX, Requires<[HasAVX]>;
859 def Int_VCVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
860                       "vcvtdq2ps\t{$src, $dst|$dst, $src}",
861                       [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
862                                         (bitconvert (memopv2i64 addr:$src))))]>,
863                      TB, VEX, Requires<[HasAVX]>;
864 }
865 def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
866                        "cvtdq2ps\t{$src, $dst|$dst, $src}",
867                        [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
868                      TB, Requires<[HasSSE2]>;
869 def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
870                       "cvtdq2ps\t{$src, $dst|$dst, $src}",
871                       [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
872                                         (bitconvert (memopv2i64 addr:$src))))]>,
873                      TB, Requires<[HasSSE2]>;
874
875 // FIXME: why the non-intrinsic version is described as SSE3?
876 let isAsmParserOnly = 1 in { // SSE2 instructions with XS prefix
877 def Int_VCVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
878                        "vcvtdq2pd\t{$src, $dst|$dst, $src}",
879                        [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
880                      XS, VEX, Requires<[HasAVX]>;
881 def Int_VCVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
882                        "vcvtdq2pd\t{$src, $dst|$dst, $src}",
883                        [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
884                                         (bitconvert (memopv2i64 addr:$src))))]>,
885                      XS, VEX, Requires<[HasAVX]>;
886 }
887 def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
888                        "cvtdq2pd\t{$src, $dst|$dst, $src}",
889                        [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
890                      XS, Requires<[HasSSE2]>;
891 def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
892                      "cvtdq2pd\t{$src, $dst|$dst, $src}",
893                      [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
894                                         (bitconvert (memopv2i64 addr:$src))))]>,
895                      XS, Requires<[HasSSE2]>;
896
897
898 // Convert packed single/double fp to doubleword
899 let isAsmParserOnly = 1 in {
900 def VCVTPS2DQrr : VPDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
901                        "cvtps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
902 def VCVTPS2DQrm : VPDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
903                        "cvtps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
904 def VCVTPS2DQYrr : VPDI<0x5B, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
905                         "cvtps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
906 def VCVTPS2DQYrm : VPDI<0x5B, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
907                         "cvtps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
908 }
909 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
910                      "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
911 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
912                      "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
913
914 let isAsmParserOnly = 1 in {
915 def Int_VCVTPS2DQrr : VPDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
916                         "cvtps2dq\t{$src, $dst|$dst, $src}",
917                         [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>,
918                         VEX;
919 def Int_VCVTPS2DQrm : VPDI<0x5B, MRMSrcMem, (outs VR128:$dst),
920                          (ins f128mem:$src),
921                          "cvtps2dq\t{$src, $dst|$dst, $src}",
922                          [(set VR128:$dst, (int_x86_sse2_cvtps2dq
923                                             (memop addr:$src)))]>, VEX;
924 }
925 def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
926                         "cvtps2dq\t{$src, $dst|$dst, $src}",
927                         [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
928 def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
929                          "cvtps2dq\t{$src, $dst|$dst, $src}",
930                          [(set VR128:$dst, (int_x86_sse2_cvtps2dq
931                                             (memop addr:$src)))]>;
932
933 let isAsmParserOnly = 1 in { // SSE2 packed instructions with XD prefix
934 def Int_VCVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
935                        "vcvtpd2dq\t{$src, $dst|$dst, $src}",
936                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
937                      XD, VEX, Requires<[HasAVX]>;
938 def Int_VCVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
939                        "vcvtpd2dq\t{$src, $dst|$dst, $src}",
940                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
941                                           (memop addr:$src)))]>,
942                      XD, VEX, Requires<[HasAVX]>;
943 }
944 def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
945                        "cvtpd2dq\t{$src, $dst|$dst, $src}",
946                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
947                      XD, Requires<[HasSSE2]>;
948 def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
949                        "cvtpd2dq\t{$src, $dst|$dst, $src}",
950                        [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
951                                           (memop addr:$src)))]>,
952                      XD, Requires<[HasSSE2]>;
953
954
955 // Convert with truncation packed single/double fp to doubleword
956 let isAsmParserOnly = 1 in { // SSE2 packed instructions with XS prefix
957 def VCVTTPS2DQrr : VSSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
958                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
959 def VCVTTPS2DQrm : VSSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
960                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
961 def VCVTTPS2DQYrr : VSSI<0x5B, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
962                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
963 def VCVTTPS2DQYrm : VSSI<0x5B, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
964                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>, VEX;
965 }
966 def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
967                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
968 def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
969                       "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
970
971
972 let isAsmParserOnly = 1 in {
973 def Int_VCVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
974                         "vcvttps2dq\t{$src, $dst|$dst, $src}",
975                         [(set VR128:$dst,
976                               (int_x86_sse2_cvttps2dq VR128:$src))]>,
977                       XS, VEX, Requires<[HasAVX]>;
978 def Int_VCVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
979                         "vcvttps2dq\t{$src, $dst|$dst, $src}",
980                         [(set VR128:$dst, (int_x86_sse2_cvttps2dq
981                                            (memop addr:$src)))]>,
982                       XS, VEX, Requires<[HasAVX]>;
983 }
984 def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
985                         "cvttps2dq\t{$src, $dst|$dst, $src}",
986                         [(set VR128:$dst,
987                               (int_x86_sse2_cvttps2dq VR128:$src))]>,
988                       XS, Requires<[HasSSE2]>;
989 def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
990                         "cvttps2dq\t{$src, $dst|$dst, $src}",
991                         [(set VR128:$dst, (int_x86_sse2_cvttps2dq
992                                            (memop addr:$src)))]>,
993                       XS, Requires<[HasSSE2]>;
994
995 let isAsmParserOnly = 1 in {
996 def Int_VCVTTPD2DQrr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst),
997                             (ins VR128:$src),
998                           "cvttpd2dq\t{$src, $dst|$dst, $src}",
999                        [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>,
1000                        VEX;
1001 def Int_VCVTTPD2DQrm : VPDI<0xE6, MRMSrcMem, (outs VR128:$dst),
1002                           (ins f128mem:$src),
1003                           "cvttpd2dq\t{$src, $dst|$dst, $src}",
1004                           [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1005                                              (memop addr:$src)))]>, VEX;
1006 }
1007 def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1008                           "cvttpd2dq\t{$src, $dst|$dst, $src}",
1009                        [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
1010 def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
1011                           "cvttpd2dq\t{$src, $dst|$dst, $src}",
1012                           [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1013                                              (memop addr:$src)))]>;
1014
1015 let isAsmParserOnly = 1 in {
1016 // The assembler can recognize rr 256-bit instructions by seeing a ymm
1017 // register, but the same isn't true when using memory operands instead.
1018 // Provide other assembly rr and rm forms to address this explicitly.
1019 def VCVTTPD2DQrr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1020                         "cvttpd2dq\t{$src, $dst|$dst, $src}", []>, VEX;
1021 def VCVTTPD2DQXrYr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
1022                           "cvttpd2dq\t{$src, $dst|$dst, $src}", []>, VEX;
1023
1024 // XMM only
1025 def VCVTTPD2DQXrr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1026                          "cvttpd2dqx\t{$src, $dst|$dst, $src}", []>, VEX;
1027 def VCVTTPD2DQXrm : VPDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1028                          "cvttpd2dqx\t{$src, $dst|$dst, $src}", []>, VEX;
1029
1030 // YMM only
1031 def VCVTTPD2DQYrr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
1032                          "cvttpd2dqy\t{$src, $dst|$dst, $src}", []>, VEX;
1033 def VCVTTPD2DQYrm : VPDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
1034                          "cvttpd2dqy\t{$src, $dst|$dst, $src}", []>, VEX, VEX_L;
1035 }
1036
1037 // Convert packed single to packed double
1038 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
1039                   // SSE2 instructions without OpSize prefix
1040 def VCVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1041                      "vcvtps2pd\t{$src, $dst|$dst, $src}", []>, VEX;
1042 def VCVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1043                      "vcvtps2pd\t{$src, $dst|$dst, $src}", []>, VEX;
1044 def VCVTPS2PDYrr : I<0x5A, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
1045                      "vcvtps2pd\t{$src, $dst|$dst, $src}", []>, VEX;
1046 def VCVTPS2PDYrm : I<0x5A, MRMSrcMem, (outs VR256:$dst), (ins f128mem:$src),
1047                      "vcvtps2pd\t{$src, $dst|$dst, $src}", []>, VEX;
1048 }
1049 def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1050                        "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1051 def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1052                        "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1053
1054 let isAsmParserOnly = 1 in {
1055 def Int_VCVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1056                        "vcvtps2pd\t{$src, $dst|$dst, $src}",
1057                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1058                      VEX, Requires<[HasAVX]>;
1059 def Int_VCVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1060                        "vcvtps2pd\t{$src, $dst|$dst, $src}",
1061                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1062                                           (load addr:$src)))]>,
1063                      VEX, Requires<[HasAVX]>;
1064 }
1065 def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1066                        "cvtps2pd\t{$src, $dst|$dst, $src}",
1067                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1068                      TB, Requires<[HasSSE2]>;
1069 def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1070                        "cvtps2pd\t{$src, $dst|$dst, $src}",
1071                        [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1072                                           (load addr:$src)))]>,
1073                      TB, Requires<[HasSSE2]>;
1074
1075 // Convert packed double to packed single
1076 let isAsmParserOnly = 1 in {
1077 // The assembler can recognize rr 256-bit instructions by seeing a ymm
1078 // register, but the same isn't true when using memory operands instead.
1079 // Provide other assembly rr and rm forms to address this explicitly.
1080 def VCVTPD2PSrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1081                        "cvtpd2ps\t{$src, $dst|$dst, $src}", []>, VEX;
1082 def VCVTPD2PSXrYr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
1083                          "cvtpd2ps\t{$src, $dst|$dst, $src}", []>, VEX;
1084
1085 // XMM only
1086 def VCVTPD2PSXrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1087                         "cvtpd2psx\t{$src, $dst|$dst, $src}", []>, VEX;
1088 def VCVTPD2PSXrm : VPDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1089                         "cvtpd2psx\t{$src, $dst|$dst, $src}", []>, VEX;
1090
1091 // YMM only
1092 def VCVTPD2PSYrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
1093                         "cvtpd2psy\t{$src, $dst|$dst, $src}", []>, VEX;
1094 def VCVTPD2PSYrm : VPDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
1095                         "cvtpd2psy\t{$src, $dst|$dst, $src}", []>, VEX, VEX_L;
1096 }
1097 def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1098                      "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1099 def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1100                      "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1101
1102
1103 let isAsmParserOnly = 1 in {
1104 def Int_VCVTPD2PSrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1105                          "cvtpd2ps\t{$src, $dst|$dst, $src}",
1106                         [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
1107 def Int_VCVTPD2PSrm : VPDI<0x5A, MRMSrcMem, (outs VR128:$dst),
1108                          (ins f128mem:$src),
1109                          "cvtpd2ps\t{$src, $dst|$dst, $src}",
1110                          [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1111                                             (memop addr:$src)))]>;
1112 }
1113 def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1114                          "cvtpd2ps\t{$src, $dst|$dst, $src}",
1115                         [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
1116 def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1117                          "cvtpd2ps\t{$src, $dst|$dst, $src}",
1118                          [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1119                                             (memop addr:$src)))]>;
1120
1121 // AVX 256-bit register conversion intrinsics
1122 // FIXME: Migrate SSE conversion intrinsics matching to use patterns as below
1123 // whenever possible to avoid declaring two versions of each one.
1124 def : Pat<(int_x86_avx_cvtdq2_ps_256 VR256:$src),
1125           (VCVTDQ2PSYrr VR256:$src)>;
1126 def : Pat<(int_x86_avx_cvtdq2_ps_256 (memopv8i32 addr:$src)),
1127           (VCVTDQ2PSYrm addr:$src)>;
1128
1129 def : Pat<(int_x86_avx_cvt_pd2_ps_256 VR256:$src),
1130           (VCVTPD2PSYrr VR256:$src)>;
1131 def : Pat<(int_x86_avx_cvt_pd2_ps_256 (memopv4f64 addr:$src)),
1132           (VCVTPD2PSYrm addr:$src)>;
1133
1134 def : Pat<(int_x86_avx_cvt_ps2dq_256 VR256:$src),
1135           (VCVTPS2DQYrr VR256:$src)>;
1136 def : Pat<(int_x86_avx_cvt_ps2dq_256 (memopv8f32 addr:$src)),
1137           (VCVTPS2DQYrm addr:$src)>;
1138
1139 def : Pat<(int_x86_avx_cvt_ps2_pd_256 VR128:$src),
1140           (VCVTPS2PDYrr VR128:$src)>;
1141 def : Pat<(int_x86_avx_cvt_ps2_pd_256 (memopv4f32 addr:$src)),
1142           (VCVTPS2PDYrm addr:$src)>;
1143
1144 def : Pat<(int_x86_avx_cvtt_pd2dq_256 VR256:$src),
1145           (VCVTTPD2DQYrr VR256:$src)>;
1146 def : Pat<(int_x86_avx_cvtt_pd2dq_256 (memopv4f64 addr:$src)),
1147           (VCVTTPD2DQYrm addr:$src)>;
1148
1149 def : Pat<(int_x86_avx_cvtt_ps2dq_256 VR256:$src),
1150           (VCVTTPS2DQYrr VR256:$src)>;
1151 def : Pat<(int_x86_avx_cvtt_ps2dq_256 (memopv8f32 addr:$src)),
1152           (VCVTTPS2DQYrm addr:$src)>;
1153
1154 //===----------------------------------------------------------------------===//
1155 // SSE 1 & 2 - Compare Instructions
1156 //===----------------------------------------------------------------------===//
1157
1158 // sse12_cmp_scalar - sse 1 & 2 compare scalar instructions
1159 multiclass sse12_cmp_scalar<RegisterClass RC, X86MemOperand x86memop,
1160                             string asm, string asm_alt> {
1161   def rr : SIi8<0xC2, MRMSrcReg,
1162                     (outs RC:$dst), (ins RC:$src1, RC:$src, SSECC:$cc),
1163                     asm, []>;
1164   let mayLoad = 1 in
1165   def rm : SIi8<0xC2, MRMSrcMem,
1166                     (outs RC:$dst), (ins RC:$src1, x86memop:$src, SSECC:$cc),
1167                     asm, []>;
1168   // Accept explicit immediate argument form instead of comparison code.
1169   let isAsmParserOnly = 1 in {
1170     def rr_alt : SIi8<0xC2, MRMSrcReg,
1171                   (outs RC:$dst), (ins RC:$src1, RC:$src, i8imm:$src2),
1172                   asm_alt, []>;
1173     let mayLoad = 1 in
1174     def rm_alt : SIi8<0xC2, MRMSrcMem,
1175                   (outs RC:$dst), (ins RC:$src1, x86memop:$src, i8imm:$src2),
1176                   asm_alt, []>;
1177   }
1178 }
1179
1180 let neverHasSideEffects = 1, isAsmParserOnly = 1 in {
1181   defm VCMPSS  : sse12_cmp_scalar<FR32, f32mem,
1182                   "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}",
1183                   "cmpss\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}">,
1184                   XS, VEX_4V;
1185   defm VCMPSD  : sse12_cmp_scalar<FR64, f64mem,
1186                   "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}",
1187                   "cmpsd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}">,
1188                   XD, VEX_4V;
1189 }
1190
1191 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
1192   defm CMPSS  : sse12_cmp_scalar<FR32, f32mem,
1193                     "cmp${cc}ss\t{$src, $dst|$dst, $src}",
1194                     "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}">, XS;
1195   defm CMPSD  : sse12_cmp_scalar<FR64, f64mem,
1196                     "cmp${cc}sd\t{$src, $dst|$dst, $src}",
1197                     "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}">, XD;
1198 }
1199
1200 multiclass sse12_cmp_scalar_int<RegisterClass RC, Operand memopr,
1201                          ComplexPattern mem_cpat, Intrinsic Int, string asm> {
1202   def rr : SIi8<0xC2, MRMSrcReg, (outs VR128:$dst),
1203                       (ins VR128:$src1, VR128:$src, SSECC:$cc), asm,
1204                         [(set VR128:$dst, (Int VR128:$src1,
1205                                                VR128:$src, imm:$cc))]>;
1206   def rm : SIi8<0xC2, MRMSrcMem, (outs VR128:$dst),
1207                       (ins VR128:$src1, memopr:$src, SSECC:$cc), asm,
1208                         [(set VR128:$dst, (Int VR128:$src1,
1209                                               mem_cpat:$src, imm:$cc))]>;
1210 }
1211
1212 // Aliases to match intrinsics which expect XMM operand(s).
1213
1214 let isAsmParserOnly = 1 in {
1215   defm Int_VCMPSS  : sse12_cmp_scalar_int<VR128, ssmem, sse_load_f32, 
1216                        int_x86_sse_cmp_ss,
1217                        "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}">,
1218                        XS, VEX_4V;
1219   defm Int_VCMPSD  : sse12_cmp_scalar_int<VR128, sdmem, sse_load_f64,
1220                        int_x86_sse2_cmp_sd,
1221                        "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}">,
1222                        XD, VEX_4V;
1223 }
1224 let Constraints = "$src1 = $dst" in {
1225   defm Int_CMPSS  : sse12_cmp_scalar_int<VR128, ssmem, sse_load_f32,
1226                        int_x86_sse_cmp_ss,
1227                        "cmp${cc}ss\t{$src, $dst|$dst, $src}">, XS;
1228   defm Int_CMPSD  : sse12_cmp_scalar_int<VR128, sdmem, sse_load_f64,
1229                        int_x86_sse2_cmp_sd,
1230                        "cmp${cc}sd\t{$src, $dst|$dst, $src}">, XD;
1231 }
1232
1233
1234 // sse12_ord_cmp - Unordered/Ordered scalar fp compare and set EFLAGS
1235 multiclass sse12_ord_cmp<bits<8> opc, RegisterClass RC, SDNode OpNode,
1236                             ValueType vt, X86MemOperand x86memop,
1237                             PatFrag ld_frag, string OpcodeStr, Domain d> {
1238   def rr: PI<opc, MRMSrcReg, (outs), (ins RC:$src1, RC:$src2),
1239                      !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
1240                      [(set EFLAGS, (OpNode (vt RC:$src1), RC:$src2))], d>;
1241   def rm: PI<opc, MRMSrcMem, (outs), (ins RC:$src1, x86memop:$src2),
1242                      !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
1243                      [(set EFLAGS, (OpNode (vt RC:$src1),
1244                                            (ld_frag addr:$src2)))], d>;
1245 }
1246
1247 let Defs = [EFLAGS] in {
1248   let isAsmParserOnly = 1 in {
1249     defm VUCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
1250                                     "ucomiss", SSEPackedSingle>, VEX;
1251     defm VUCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
1252                                     "ucomisd", SSEPackedDouble>, OpSize, VEX;
1253     let Pattern = []<dag> in {
1254       defm VCOMISS  : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
1255                                       "comiss", SSEPackedSingle>, VEX;
1256       defm VCOMISD  : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
1257                                       "comisd", SSEPackedDouble>, OpSize, VEX;
1258     }
1259
1260     defm Int_VUCOMISS  : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
1261                               load, "ucomiss", SSEPackedSingle>, VEX;
1262     defm Int_VUCOMISD  : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
1263                               load, "ucomisd", SSEPackedDouble>, OpSize, VEX;
1264
1265     defm Int_VCOMISS  : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem,
1266                               load, "comiss", SSEPackedSingle>, VEX;
1267     defm Int_VCOMISD  : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem,
1268                               load, "comisd", SSEPackedDouble>, OpSize, VEX;
1269   }
1270   defm UCOMISS  : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
1271                                   "ucomiss", SSEPackedSingle>, TB;
1272   defm UCOMISD  : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
1273                                   "ucomisd", SSEPackedDouble>, TB, OpSize;
1274
1275   let Pattern = []<dag> in {
1276     defm COMISS  : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
1277                                     "comiss", SSEPackedSingle>, TB;
1278     defm COMISD  : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
1279                                     "comisd", SSEPackedDouble>, TB, OpSize;
1280   }
1281
1282   defm Int_UCOMISS  : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
1283                               load, "ucomiss", SSEPackedSingle>, TB;
1284   defm Int_UCOMISD  : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
1285                               load, "ucomisd", SSEPackedDouble>, TB, OpSize;
1286
1287   defm Int_COMISS  : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem, load,
1288                                   "comiss", SSEPackedSingle>, TB;
1289   defm Int_COMISD  : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem, load,
1290                                   "comisd", SSEPackedDouble>, TB, OpSize;
1291 } // Defs = [EFLAGS]
1292
1293 // sse12_cmp_packed - sse 1 & 2 compared packed instructions
1294 multiclass sse12_cmp_packed<RegisterClass RC, X86MemOperand x86memop,
1295                             Intrinsic Int, string asm, string asm_alt,
1296                             Domain d> {
1297   def rri : PIi8<0xC2, MRMSrcReg,
1298              (outs RC:$dst), (ins RC:$src1, RC:$src, SSECC:$cc), asm,
1299              [(set RC:$dst, (Int RC:$src1, RC:$src, imm:$cc))], d>;
1300   def rmi : PIi8<0xC2, MRMSrcMem,
1301              (outs RC:$dst), (ins RC:$src1, f128mem:$src, SSECC:$cc), asm,
1302              [(set RC:$dst, (Int RC:$src1, (memop addr:$src), imm:$cc))], d>;
1303   // Accept explicit immediate argument form instead of comparison code.
1304   let isAsmParserOnly = 1 in {
1305     def rri_alt : PIi8<0xC2, MRMSrcReg,
1306                (outs RC:$dst), (ins RC:$src1, RC:$src, i8imm:$src2),
1307                asm_alt, [], d>;
1308     def rmi_alt : PIi8<0xC2, MRMSrcMem,
1309                (outs RC:$dst), (ins RC:$src1, f128mem:$src, i8imm:$src2),
1310                asm_alt, [], d>;
1311   }
1312 }
1313
1314 let isAsmParserOnly = 1 in {
1315   defm VCMPPS : sse12_cmp_packed<VR128, f128mem, int_x86_sse_cmp_ps,
1316                  "cmp${cc}ps\t{$src, $src1, $dst|$dst, $src1, $src}",
1317                  "cmpps\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
1318                  SSEPackedSingle>, VEX_4V;
1319   defm VCMPPD : sse12_cmp_packed<VR128, f128mem, int_x86_sse2_cmp_pd,
1320                  "cmp${cc}pd\t{$src, $src1, $dst|$dst, $src1, $src}",
1321                  "cmppd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
1322                  SSEPackedDouble>, OpSize, VEX_4V;
1323   let Pattern = []<dag> in {
1324     defm VCMPPSY : sse12_cmp_packed<VR256, f256mem, int_x86_sse_cmp_ps,
1325                    "cmp${cc}ps\t{$src, $src1, $dst|$dst, $src1, $src}",
1326                    "cmpps\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
1327                    SSEPackedSingle>, VEX_4V;
1328     defm VCMPPDY : sse12_cmp_packed<VR256, f256mem, int_x86_sse2_cmp_pd,
1329                    "cmp${cc}pd\t{$src, $src1, $dst|$dst, $src1, $src}",
1330                    "cmppd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
1331                    SSEPackedDouble>, OpSize, VEX_4V;
1332   }
1333 }
1334 let Constraints = "$src1 = $dst" in {
1335   defm CMPPS : sse12_cmp_packed<VR128, f128mem, int_x86_sse_cmp_ps,
1336                  "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1337                  "cmpps\t{$src2, $src, $dst|$dst, $src, $src2}",
1338                  SSEPackedSingle>, TB;
1339   defm CMPPD : sse12_cmp_packed<VR128, f128mem, int_x86_sse2_cmp_pd,
1340                  "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1341                  "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}",
1342                  SSEPackedDouble>, TB, OpSize;
1343 }
1344
1345 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
1346           (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
1347 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
1348           (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
1349 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
1350           (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
1351 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
1352           (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
1353
1354 //===----------------------------------------------------------------------===//
1355 // SSE 1 & 2 - Shuffle Instructions
1356 //===----------------------------------------------------------------------===//
1357
1358 /// sse12_shuffle - sse 1 & 2 shuffle instructions
1359 multiclass sse12_shuffle<RegisterClass RC, X86MemOperand x86memop,
1360                          ValueType vt, string asm, PatFrag mem_frag,
1361                          Domain d, bit IsConvertibleToThreeAddress = 0> {
1362   def rmi : PIi8<0xC6, MRMSrcMem, (outs RC:$dst),
1363                    (ins RC:$src1, f128mem:$src2, i8imm:$src3), asm,
1364                    [(set RC:$dst, (vt (shufp:$src3
1365                             RC:$src1, (mem_frag addr:$src2))))], d>;
1366   let isConvertibleToThreeAddress = IsConvertibleToThreeAddress in
1367     def rri : PIi8<0xC6, MRMSrcReg, (outs RC:$dst),
1368                    (ins RC:$src1, RC:$src2, i8imm:$src3), asm,
1369                    [(set RC:$dst,
1370                             (vt (shufp:$src3 RC:$src1, RC:$src2)))], d>;
1371 }
1372
1373 let isAsmParserOnly = 1 in {
1374   defm VSHUFPS  : sse12_shuffle<VR128, f128mem, v4f32,
1375              "shufps\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
1376              memopv4f32, SSEPackedSingle>, VEX_4V;
1377   defm VSHUFPSY : sse12_shuffle<VR256, f256mem, v8f32,
1378              "shufps\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
1379              memopv8f32, SSEPackedSingle>, VEX_4V;
1380   defm VSHUFPD  : sse12_shuffle<VR128, f128mem, v2f64,
1381              "shufpd\t{$src3, $src2, $src1, $dst|$dst, $src2, $src2, $src3}",
1382              memopv2f64, SSEPackedDouble>, OpSize, VEX_4V;
1383   defm VSHUFPDY : sse12_shuffle<VR256, f256mem, v4f64,
1384              "shufpd\t{$src3, $src2, $src1, $dst|$dst, $src2, $src2, $src3}",
1385              memopv4f64, SSEPackedDouble>, OpSize, VEX_4V;
1386 }
1387
1388 let Constraints = "$src1 = $dst" in {
1389   defm SHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
1390                     "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1391                     memopv4f32, SSEPackedSingle, 1 /* cvt to pshufd */>,
1392                     TB;
1393   defm SHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
1394                     "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1395                     memopv2f64, SSEPackedDouble>, TB, OpSize;
1396 }
1397
1398 //===----------------------------------------------------------------------===//
1399 // SSE 1 & 2 - Unpack Instructions
1400 //===----------------------------------------------------------------------===//
1401
1402 /// sse12_unpack_interleave - sse 1 & 2 unpack and interleave
1403 multiclass sse12_unpack_interleave<bits<8> opc, PatFrag OpNode, ValueType vt,
1404                                    PatFrag mem_frag, RegisterClass RC,
1405                                    X86MemOperand x86memop, string asm,
1406                                    Domain d> {
1407     def rr : PI<opc, MRMSrcReg,
1408                 (outs RC:$dst), (ins RC:$src1, RC:$src2),
1409                 asm, [(set RC:$dst,
1410                            (vt (OpNode RC:$src1, RC:$src2)))], d>;
1411     def rm : PI<opc, MRMSrcMem,
1412                 (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
1413                 asm, [(set RC:$dst,
1414                            (vt (OpNode RC:$src1,
1415                                        (mem_frag addr:$src2))))], d>;
1416 }
1417
1418 let AddedComplexity = 10 in {
1419   let isAsmParserOnly = 1 in {
1420     defm VUNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
1421           VR128, f128mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1422                          SSEPackedSingle>, VEX_4V;
1423     defm VUNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
1424           VR128, f128mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1425                          SSEPackedDouble>, OpSize, VEX_4V;
1426     defm VUNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
1427           VR128, f128mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1428                          SSEPackedSingle>, VEX_4V;
1429     defm VUNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
1430           VR128, f128mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1431                          SSEPackedDouble>, OpSize, VEX_4V;
1432
1433     defm VUNPCKHPSY: sse12_unpack_interleave<0x15, unpckh, v8f32, memopv8f32,
1434           VR256, f256mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1435                          SSEPackedSingle>, VEX_4V;
1436     defm VUNPCKHPDY: sse12_unpack_interleave<0x15, unpckh, v4f64, memopv4f64,
1437           VR256, f256mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1438                          SSEPackedDouble>, OpSize, VEX_4V;
1439     defm VUNPCKLPSY: sse12_unpack_interleave<0x14, unpckl, v8f32, memopv8f32,
1440           VR256, f256mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1441                          SSEPackedSingle>, VEX_4V;
1442     defm VUNPCKLPDY: sse12_unpack_interleave<0x14, unpckl, v4f64, memopv4f64,
1443           VR256, f256mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1444                          SSEPackedDouble>, OpSize, VEX_4V;
1445   }
1446
1447   let Constraints = "$src1 = $dst" in {
1448     defm UNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
1449           VR128, f128mem, "unpckhps\t{$src2, $dst|$dst, $src2}",
1450                          SSEPackedSingle>, TB;
1451     defm UNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
1452           VR128, f128mem, "unpckhpd\t{$src2, $dst|$dst, $src2}",
1453                          SSEPackedDouble>, TB, OpSize;
1454     defm UNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
1455           VR128, f128mem, "unpcklps\t{$src2, $dst|$dst, $src2}",
1456                          SSEPackedSingle>, TB;
1457     defm UNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
1458           VR128, f128mem, "unpcklpd\t{$src2, $dst|$dst, $src2}",
1459                          SSEPackedDouble>, TB, OpSize;
1460   } // Constraints = "$src1 = $dst"
1461 } // AddedComplexity
1462
1463 //===----------------------------------------------------------------------===//
1464 // SSE 1 & 2 - Extract Floating-Point Sign mask
1465 //===----------------------------------------------------------------------===//
1466
1467 /// sse12_extr_sign_mask - sse 1 & 2 unpack and interleave
1468 multiclass sse12_extr_sign_mask<RegisterClass RC, Intrinsic Int, string asm,
1469                                 Domain d> {
1470   def rr : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins RC:$src),
1471               !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
1472                      [(set GR32:$dst, (Int RC:$src))], d>;
1473 }
1474
1475 // Mask creation
1476 defm MOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps, "movmskps",
1477                                      SSEPackedSingle>, TB;
1478 defm MOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd, "movmskpd",
1479                                      SSEPackedDouble>, TB, OpSize;
1480
1481 let isAsmParserOnly = 1 in {
1482   defm VMOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps,
1483                                         "movmskps", SSEPackedSingle>, VEX;
1484   defm VMOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd,
1485                                         "movmskpd", SSEPackedDouble>, OpSize,
1486                                         VEX;
1487
1488   // FIXME: merge with multiclass above when the intrinsics come.
1489   def VMOVMSKPSr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1490              "movmskps\t{$src, $dst|$dst, $src}", [], SSEPackedSingle>, VEX;
1491   def VMOVMSKPDr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1492              "movmskpd\t{$src, $dst|$dst, $src}", [], SSEPackedDouble>, OpSize,
1493              VEX;
1494
1495   def VMOVMSKPSYrr : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR256:$src),
1496              "movmskps\t{$src, $dst|$dst, $src}", [], SSEPackedSingle>, VEX;
1497   def VMOVMSKPDYrr : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR256:$src),
1498              "movmskpd\t{$src, $dst|$dst, $src}", [], SSEPackedDouble>, OpSize,
1499              VEX;
1500
1501   def VMOVMSKPSYr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR256:$src),
1502              "movmskps\t{$src, $dst|$dst, $src}", [], SSEPackedSingle>, VEX;
1503   def VMOVMSKPDYr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR256:$src),
1504              "movmskpd\t{$src, $dst|$dst, $src}", [], SSEPackedDouble>, OpSize,
1505              VEX;
1506 }
1507
1508 //===----------------------------------------------------------------------===//
1509 // SSE 1 & 2 - Misc aliasing of packed SSE 1 & 2 instructions
1510 //===----------------------------------------------------------------------===//
1511
1512 // Aliases of packed SSE1 & SSE2 instructions for scalar use. These all have
1513 // names that start with 'Fs'.
1514
1515 // Alias instructions that map fld0 to pxor for sse.
1516 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
1517     canFoldAsLoad = 1 in {
1518   // FIXME: Set encoding to pseudo!
1519 def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins), "",
1520                  [(set FR32:$dst, fp32imm0)]>,
1521                  Requires<[HasSSE1]>, TB, OpSize;
1522 def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
1523                  [(set FR64:$dst, fpimm0)]>,
1524                Requires<[HasSSE2]>, TB, OpSize;
1525 }
1526
1527 // Alias instruction to do FR32 or FR64 reg-to-reg copy using movaps. Upper
1528 // bits are disregarded.
1529 let neverHasSideEffects = 1 in {
1530 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1531                      "movaps\t{$src, $dst|$dst, $src}", []>;
1532 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1533                      "movapd\t{$src, $dst|$dst, $src}", []>;
1534 }
1535
1536 // Alias instruction to load FR32 or FR64 from f128mem using movaps. Upper
1537 // bits are disregarded.
1538 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1539 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
1540                      "movaps\t{$src, $dst|$dst, $src}",
1541                      [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
1542 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1543                      "movapd\t{$src, $dst|$dst, $src}",
1544                      [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
1545 }
1546
1547 //===----------------------------------------------------------------------===//
1548 // SSE 1 & 2 - Logical Instructions
1549 //===----------------------------------------------------------------------===//
1550
1551 /// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
1552 ///
1553 multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
1554                                        SDNode OpNode> {
1555   let isAsmParserOnly = 1 in {
1556     defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode,
1557                 FR32, f32, f128mem, memopfsf32, SSEPackedSingle, 0>, VEX_4V;
1558
1559     defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode,
1560           FR64, f64, f128mem, memopfsf64, SSEPackedDouble, 0>, OpSize, VEX_4V;
1561   }
1562
1563   let Constraints = "$src1 = $dst" in {
1564     defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, FR32,
1565                 f32, f128mem, memopfsf32, SSEPackedSingle>, TB;
1566
1567     defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, FR64,
1568                 f64, f128mem, memopfsf64, SSEPackedDouble>, TB, OpSize;
1569   }
1570 }
1571
1572 // Alias bitwise logical operations using SSE logical ops on packed FP values.
1573 let mayLoad = 0 in {
1574   defm FsAND  : sse12_fp_alias_pack_logical<0x54, "and", X86fand>;
1575   defm FsOR   : sse12_fp_alias_pack_logical<0x56, "or", X86for>;
1576   defm FsXOR  : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor>;
1577 }
1578
1579 let neverHasSideEffects = 1, Pattern = []<dag>, isCommutable = 0 in
1580   defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef>;
1581
1582 /// sse12_fp_packed_logical - SSE 1 & 2 packed FP logical ops
1583 ///
1584 multiclass sse12_fp_packed_logical<bits<8> opc, string OpcodeStr,
1585                                  SDNode OpNode, int HasPat = 0,
1586                                  list<list<dag>> Pattern = []> {
1587   let isAsmParserOnly = 1, Pattern = []<dag> in {
1588     defm V#NAME#PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1589          !strconcat(OpcodeStr, "ps"), f128mem,
1590          !if(HasPat, Pattern[0], // rr
1591                      [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1592                                                       VR128:$src2)))]),
1593          !if(HasPat, Pattern[2], // rm
1594                      [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1595                                                (memopv2i64 addr:$src2)))]), 0>,
1596                                                VEX_4V;
1597
1598     defm V#NAME#PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1599          !strconcat(OpcodeStr, "pd"), f128mem,
1600          !if(HasPat, Pattern[1], // rr
1601                      [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1602                                                (bc_v2i64 (v2f64
1603                                                VR128:$src2))))]),
1604          !if(HasPat, Pattern[3], // rm
1605                      [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1606                                                (memopv2i64 addr:$src2)))]), 0>,
1607                                                                OpSize, VEX_4V;
1608   }
1609   let Constraints = "$src1 = $dst" in {
1610     defm PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1611          !strconcat(OpcodeStr, "ps"), f128mem,
1612          !if(HasPat, Pattern[0], // rr
1613                      [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1614                                                       VR128:$src2)))]),
1615          !if(HasPat, Pattern[2], // rm
1616                      [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1617                                                (memopv2i64 addr:$src2)))])>, TB;
1618
1619     defm PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1620          !strconcat(OpcodeStr, "pd"), f128mem,
1621          !if(HasPat, Pattern[1], // rr
1622                      [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1623                                                (bc_v2i64 (v2f64
1624                                                VR128:$src2))))]),
1625          !if(HasPat, Pattern[3], // rm
1626                      [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1627                                                (memopv2i64 addr:$src2)))])>,
1628                                                                     TB, OpSize;
1629   }
1630 }
1631
1632 /// sse12_fp_packed_logical_y - AVX 256-bit SSE 1 & 2 logical ops forms
1633 ///
1634 let isAsmParserOnly = 1 in {
1635 multiclass sse12_fp_packed_logical_y<bits<8> opc, string OpcodeStr> {
1636     defm PSY : sse12_fp_packed_logical_rm<opc, VR256, SSEPackedSingle,
1637           !strconcat(OpcodeStr, "ps"), f256mem, [], [], 0>, VEX_4V;
1638
1639     defm PDY : sse12_fp_packed_logical_rm<opc, VR256, SSEPackedDouble,
1640           !strconcat(OpcodeStr, "pd"), f256mem, [], [], 0>, OpSize, VEX_4V;
1641 }
1642 }
1643
1644 // AVX 256-bit packed logical ops forms
1645 defm VAND : sse12_fp_packed_logical_y<0x54, "and">;
1646 defm VOR  : sse12_fp_packed_logical_y<0x56, "or">;
1647 defm VXOR : sse12_fp_packed_logical_y<0x57, "xor">;
1648 let isCommutable = 0 in
1649   defm VANDN : sse12_fp_packed_logical_y<0x55, "andn">;
1650
1651 defm AND  : sse12_fp_packed_logical<0x54, "and", and>;
1652 defm OR   : sse12_fp_packed_logical<0x56, "or", or>;
1653 defm XOR  : sse12_fp_packed_logical<0x57, "xor", xor>;
1654 let isCommutable = 0 in
1655   defm ANDN : sse12_fp_packed_logical<0x55, "andn", undef /* dummy */, 1, [
1656     // single r+r
1657     [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
1658                                        (bc_v2i64 (v4i32 immAllOnesV))),
1659                                    VR128:$src2)))],
1660     // double r+r
1661     [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1662                                  (bc_v2i64 (v2f64 VR128:$src2))))],
1663     // single r+m
1664     [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1665                                        (bc_v2i64 (v4i32 immAllOnesV))),
1666                                   (memopv2i64 addr:$src2))))],
1667     // double r+m
1668     [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1669                            (memopv2i64 addr:$src2)))]]>;
1670
1671 //===----------------------------------------------------------------------===//
1672 // SSE 1 & 2 - Arithmetic Instructions
1673 //===----------------------------------------------------------------------===//
1674
1675 /// basic_sse12_fp_binop_xxx - SSE 1 & 2 binops come in both scalar and
1676 /// vector forms.
1677 ///
1678 /// In addition, we also have a special variant of the scalar form here to
1679 /// represent the associated intrinsic operation.  This form is unlike the
1680 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
1681 /// and leaves the top elements unmodified (therefore these cannot be commuted).
1682 ///
1683 /// These three forms can each be reg+reg or reg+mem.
1684 ///
1685
1686 /// FIXME: once all 256-bit intrinsics are matched, cleanup and refactor those
1687 /// classes below
1688 multiclass basic_sse12_fp_binop_s<bits<8> opc, string OpcodeStr, SDNode OpNode,
1689                                   bit Is2Addr = 1> {
1690   defm SS : sse12_fp_scalar<opc, !strconcat(OpcodeStr, "ss"),
1691                             OpNode, FR32, f32mem, Is2Addr>, XS;
1692   defm SD : sse12_fp_scalar<opc, !strconcat(OpcodeStr, "sd"),
1693                             OpNode, FR64, f64mem, Is2Addr>, XD;
1694 }
1695
1696 multiclass basic_sse12_fp_binop_p<bits<8> opc, string OpcodeStr, SDNode OpNode,
1697                                    bit Is2Addr = 1> {
1698   let mayLoad = 0 in {
1699   defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, VR128,
1700               v4f32, f128mem, memopv4f32, SSEPackedSingle, Is2Addr>, TB;
1701   defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, VR128,
1702               v2f64, f128mem, memopv2f64, SSEPackedDouble, Is2Addr>, TB, OpSize;
1703   }
1704 }
1705
1706 multiclass basic_sse12_fp_binop_p_y<bits<8> opc, string OpcodeStr,
1707                                     SDNode OpNode> {
1708   let mayLoad = 0 in {
1709     defm PSY : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, VR256,
1710                 v8f32, f256mem, memopv8f32, SSEPackedSingle, 0>, TB;
1711     defm PDY : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, VR256,
1712                 v4f64, f256mem, memopv4f64, SSEPackedDouble, 0>, TB, OpSize;
1713   }
1714 }
1715
1716 multiclass basic_sse12_fp_binop_s_int<bits<8> opc, string OpcodeStr,
1717                                       bit Is2Addr = 1> {
1718   defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1719      !strconcat(OpcodeStr, "ss"), "", "_ss", ssmem, sse_load_f32, Is2Addr>, XS;
1720   defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1721      !strconcat(OpcodeStr, "sd"), "2", "_sd", sdmem, sse_load_f64, Is2Addr>, XD;
1722 }
1723
1724 multiclass basic_sse12_fp_binop_p_int<bits<8> opc, string OpcodeStr,
1725                                       bit Is2Addr = 1> {
1726   defm PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1727      !strconcat(OpcodeStr, "ps"), "sse", "_ps", f128mem, memopv4f32,
1728                                               SSEPackedSingle, Is2Addr>, TB;
1729
1730   defm PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1731      !strconcat(OpcodeStr, "pd"), "sse2", "_pd", f128mem, memopv2f64,
1732                                       SSEPackedDouble, Is2Addr>, TB, OpSize;
1733 }
1734
1735 multiclass basic_sse12_fp_binop_p_y_int<bits<8> opc, string OpcodeStr> {
1736   defm PSY : sse12_fp_packed_int<opc, OpcodeStr, VR256,
1737      !strconcat(OpcodeStr, "ps"), "avx", "_ps_256", f256mem, memopv8f32,
1738       SSEPackedSingle, 0>, TB;
1739
1740   defm PDY : sse12_fp_packed_int<opc, OpcodeStr, VR256,
1741      !strconcat(OpcodeStr, "pd"), "avx", "_pd_256", f256mem, memopv4f64,
1742       SSEPackedDouble, 0>, TB, OpSize;
1743 }
1744
1745 // Binary Arithmetic instructions
1746 let isAsmParserOnly = 1 in {
1747   defm VADD : basic_sse12_fp_binop_s<0x58, "add", fadd, 0>,
1748               basic_sse12_fp_binop_s_int<0x58, "add", 0>,
1749               basic_sse12_fp_binop_p<0x58, "add", fadd, 0>,
1750               basic_sse12_fp_binop_p_y<0x58, "add", fadd>, VEX_4V;
1751   defm VMUL : basic_sse12_fp_binop_s<0x59, "mul", fmul, 0>,
1752               basic_sse12_fp_binop_s_int<0x59, "mul", 0>,
1753               basic_sse12_fp_binop_p<0x59, "mul", fmul, 0>,
1754               basic_sse12_fp_binop_p_y<0x59, "mul", fmul>, VEX_4V;
1755
1756   let isCommutable = 0 in {
1757     defm VSUB : basic_sse12_fp_binop_s<0x5C, "sub", fsub, 0>,
1758                 basic_sse12_fp_binop_s_int<0x5C, "sub", 0>,
1759                 basic_sse12_fp_binop_p<0x5C, "sub", fsub, 0>,
1760                 basic_sse12_fp_binop_p_y<0x5C, "sub", fsub>, VEX_4V;
1761     defm VDIV : basic_sse12_fp_binop_s<0x5E, "div", fdiv, 0>,
1762                 basic_sse12_fp_binop_s_int<0x5E, "div", 0>,
1763                 basic_sse12_fp_binop_p<0x5E, "div", fdiv, 0>,
1764                 basic_sse12_fp_binop_p_y<0x5E, "div", fdiv>, VEX_4V;
1765     defm VMAX : basic_sse12_fp_binop_s<0x5F, "max", X86fmax, 0>,
1766                 basic_sse12_fp_binop_s_int<0x5F, "max", 0>,
1767                 basic_sse12_fp_binop_p<0x5F, "max", X86fmax, 0>,
1768                 basic_sse12_fp_binop_p_int<0x5F, "max", 0>,
1769                 basic_sse12_fp_binop_p_y<0x5F, "max", X86fmax>,
1770                 basic_sse12_fp_binop_p_y_int<0x5F, "max">, VEX_4V;
1771     defm VMIN : basic_sse12_fp_binop_s<0x5D, "min", X86fmin, 0>,
1772                 basic_sse12_fp_binop_s_int<0x5D, "min", 0>,
1773                 basic_sse12_fp_binop_p<0x5D, "min", X86fmin, 0>,
1774                 basic_sse12_fp_binop_p_int<0x5D, "min", 0>,
1775                 basic_sse12_fp_binop_p_y_int<0x5D, "min">,
1776                 basic_sse12_fp_binop_p_y<0x5D, "min", X86fmin>, VEX_4V;
1777   }
1778 }
1779
1780 let Constraints = "$src1 = $dst" in {
1781   defm ADD : basic_sse12_fp_binop_s<0x58, "add", fadd>,
1782              basic_sse12_fp_binop_p<0x58, "add", fadd>,
1783              basic_sse12_fp_binop_s_int<0x58, "add">;
1784   defm MUL : basic_sse12_fp_binop_s<0x59, "mul", fmul>,
1785              basic_sse12_fp_binop_p<0x59, "mul", fmul>,
1786              basic_sse12_fp_binop_s_int<0x59, "mul">;
1787
1788   let isCommutable = 0 in {
1789     defm SUB : basic_sse12_fp_binop_s<0x5C, "sub", fsub>,
1790                basic_sse12_fp_binop_p<0x5C, "sub", fsub>,
1791                basic_sse12_fp_binop_s_int<0x5C, "sub">;
1792     defm DIV : basic_sse12_fp_binop_s<0x5E, "div", fdiv>,
1793                basic_sse12_fp_binop_p<0x5E, "div", fdiv>,
1794                basic_sse12_fp_binop_s_int<0x5E, "div">;
1795     defm MAX : basic_sse12_fp_binop_s<0x5F, "max", X86fmax>,
1796                basic_sse12_fp_binop_p<0x5F, "max", X86fmax>,
1797                basic_sse12_fp_binop_s_int<0x5F, "max">,
1798                basic_sse12_fp_binop_p_int<0x5F, "max">;
1799     defm MIN : basic_sse12_fp_binop_s<0x5D, "min", X86fmin>,
1800                basic_sse12_fp_binop_p<0x5D, "min", X86fmin>,
1801                basic_sse12_fp_binop_s_int<0x5D, "min">,
1802                basic_sse12_fp_binop_p_int<0x5D, "min">;
1803   }
1804 }
1805
1806 /// Unop Arithmetic
1807 /// In addition, we also have a special variant of the scalar form here to
1808 /// represent the associated intrinsic operation.  This form is unlike the
1809 /// plain scalar form, in that it takes an entire vector (instead of a
1810 /// scalar) and leaves the top elements undefined.
1811 ///
1812 /// And, we have a special variant form for a full-vector intrinsic form.
1813
1814 /// sse1_fp_unop_s - SSE1 unops in scalar form.
1815 multiclass sse1_fp_unop_s<bits<8> opc, string OpcodeStr,
1816                           SDNode OpNode, Intrinsic F32Int> {
1817   def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1818                 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1819                 [(set FR32:$dst, (OpNode FR32:$src))]>;
1820   // For scalar unary operations, fold a load into the operation
1821   // only in OptForSize mode. It eliminates an instruction, but it also
1822   // eliminates a whole-register clobber (the load), so it introduces a
1823   // partial register update condition.
1824   def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
1825                 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1826                 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
1827             Requires<[HasSSE1, OptForSize]>;
1828   def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1829                     !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1830                     [(set VR128:$dst, (F32Int VR128:$src))]>;
1831   def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
1832                     !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1833                     [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1834 }
1835
1836 /// sse1_fp_unop_s_avx - AVX SSE1 unops in scalar form.
1837 multiclass sse1_fp_unop_s_avx<bits<8> opc, string OpcodeStr,
1838                               SDNode OpNode, Intrinsic F32Int> {
1839   def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
1840                 !strconcat(OpcodeStr,
1841                            "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
1842   def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
1843                 !strconcat(OpcodeStr,
1844                            "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1845                 []>, XS, Requires<[HasAVX, OptForSize]>;
1846   def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1847                 !strconcat(OpcodeStr,
1848                            "ss\t{$src, $dst, $dst|$dst, $dst, $src}"),
1849                 [(set VR128:$dst, (F32Int VR128:$src))]>;
1850   def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
1851                 !strconcat(OpcodeStr,
1852                            "ss\t{$src, $dst, $dst|$dst, $dst, $src}"),
1853                 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1854 }
1855
1856 /// sse1_fp_unop_p - SSE1 unops in packed form.
1857 multiclass sse1_fp_unop_p<bits<8> opc, string OpcodeStr, SDNode OpNode> {
1858   def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1859               !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1860               [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]>;
1861   def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1862                 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1863                 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
1864 }
1865
1866 /// sse1_fp_unop_p_y - AVX 256-bit SSE1 unops in packed form.
1867 multiclass sse1_fp_unop_p_y<bits<8> opc, string OpcodeStr, SDNode OpNode> {
1868   def PSYr : PSI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
1869               !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1870               [(set VR256:$dst, (v8f32 (OpNode VR256:$src)))]>;
1871   def PSYm : PSI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
1872                 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1873                 [(set VR256:$dst, (OpNode (memopv8f32 addr:$src)))]>;
1874 }
1875
1876 /// sse1_fp_unop_p_int - SSE1 intrinsics unops in packed forms.
1877 multiclass sse1_fp_unop_p_int<bits<8> opc, string OpcodeStr,
1878                               Intrinsic V4F32Int> {
1879   def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1880                     !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1881                     [(set VR128:$dst, (V4F32Int VR128:$src))]>;
1882   def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1883                     !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1884                     [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
1885 }
1886
1887 /// sse1_fp_unop_p_y_int - AVX 256-bit intrinsics unops in packed forms.
1888 multiclass sse1_fp_unop_p_y_int<bits<8> opc, string OpcodeStr,
1889                                 Intrinsic V4F32Int> {
1890   def PSYr_Int : PSI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
1891                     !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1892                     [(set VR256:$dst, (V4F32Int VR256:$src))]>;
1893   def PSYm_Int : PSI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
1894                     !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1895                     [(set VR256:$dst, (V4F32Int (memopv8f32 addr:$src)))]>;
1896 }
1897
1898 /// sse2_fp_unop_s - SSE2 unops in scalar form.
1899 multiclass sse2_fp_unop_s<bits<8> opc, string OpcodeStr,
1900                           SDNode OpNode, Intrinsic F64Int> {
1901   def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1902                 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1903                 [(set FR64:$dst, (OpNode FR64:$src))]>;
1904   // See the comments in sse1_fp_unop_s for why this is OptForSize.
1905   def SDm : I<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1906                 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1907                 [(set FR64:$dst, (OpNode (load addr:$src)))]>, XD,
1908             Requires<[HasSSE2, OptForSize]>;
1909   def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1910                     !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1911                     [(set VR128:$dst, (F64Int VR128:$src))]>;
1912   def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1913                     !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1914                     [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1915 }
1916
1917 /// sse2_fp_unop_s_avx - AVX SSE2 unops in scalar form.
1918 multiclass sse2_fp_unop_s_avx<bits<8> opc, string OpcodeStr,
1919                               SDNode OpNode, Intrinsic F64Int> {
1920   def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
1921                !strconcat(OpcodeStr,
1922                           "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
1923   def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst),
1924                (ins FR64:$src1, f64mem:$src2),
1925                !strconcat(OpcodeStr,
1926                           "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
1927   def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1928            !strconcat(OpcodeStr, "sd\t{$src, $dst, $dst|$dst, $dst, $src}"),
1929            [(set VR128:$dst, (F64Int VR128:$src))]>;
1930   def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1931            !strconcat(OpcodeStr, "sd\t{$src, $dst, $dst|$dst, $dst, $src}"),
1932            [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1933 }
1934
1935 /// sse2_fp_unop_p - SSE2 unops in vector forms.
1936 multiclass sse2_fp_unop_p<bits<8> opc, string OpcodeStr,
1937                           SDNode OpNode> {
1938   def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1939               !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1940               [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]>;
1941   def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1942                 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1943                 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
1944 }
1945
1946 /// sse2_fp_unop_p_y - AVX SSE2 256-bit unops in vector forms.
1947 multiclass sse2_fp_unop_p_y<bits<8> opc, string OpcodeStr, SDNode OpNode> {
1948   def PDYr : PDI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
1949               !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1950               [(set VR256:$dst, (v4f64 (OpNode VR256:$src)))]>;
1951   def PDYm : PDI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
1952                 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1953                 [(set VR256:$dst, (OpNode (memopv4f64 addr:$src)))]>;
1954 }
1955
1956 /// sse2_fp_unop_p_int - SSE2 intrinsic unops in vector forms.
1957 multiclass sse2_fp_unop_p_int<bits<8> opc, string OpcodeStr,
1958                               Intrinsic V2F64Int> {
1959   def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1960                     !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1961                     [(set VR128:$dst, (V2F64Int VR128:$src))]>;
1962   def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1963                     !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1964                     [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
1965 }
1966
1967 /// sse2_fp_unop_p_y_int - AVX 256-bit intrinsic unops in vector forms.
1968 multiclass sse2_fp_unop_p_y_int<bits<8> opc, string OpcodeStr,
1969                                 Intrinsic V2F64Int> {
1970   def PDYr_Int : PDI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
1971                     !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1972                     [(set VR256:$dst, (V2F64Int VR256:$src))]>;
1973   def PDYm_Int : PDI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
1974                     !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1975                     [(set VR256:$dst, (V2F64Int (memopv4f64 addr:$src)))]>;
1976 }
1977
1978 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
1979   // Square root.
1980   defm VSQRT  : sse1_fp_unop_s_avx<0x51, "vsqrt", fsqrt, int_x86_sse_sqrt_ss>,
1981                 sse2_fp_unop_s_avx<0x51, "vsqrt", fsqrt, int_x86_sse2_sqrt_sd>,
1982                 VEX_4V;
1983
1984   defm VSQRT  : sse1_fp_unop_p<0x51, "vsqrt", fsqrt>,
1985                 sse2_fp_unop_p<0x51, "vsqrt", fsqrt>,
1986                 sse1_fp_unop_p_y<0x51, "vsqrt", fsqrt>,
1987                 sse2_fp_unop_p_y<0x51, "vsqrt", fsqrt>,
1988                 sse1_fp_unop_p_int<0x51, "vsqrt", int_x86_sse_sqrt_ps>,
1989                 sse2_fp_unop_p_int<0x51, "vsqrt", int_x86_sse2_sqrt_pd>,
1990                 sse1_fp_unop_p_y_int<0x51, "vsqrt", int_x86_avx_sqrt_ps_256>,
1991                 sse2_fp_unop_p_y_int<0x51, "vsqrt", int_x86_avx_sqrt_pd_256>,
1992                 VEX;
1993
1994   // Reciprocal approximations. Note that these typically require refinement
1995   // in order to obtain suitable precision.
1996   defm VRSQRT : sse1_fp_unop_s_avx<0x52, "vrsqrt", X86frsqrt,
1997                                    int_x86_sse_rsqrt_ss>, VEX_4V;
1998   defm VRSQRT : sse1_fp_unop_p<0x52, "vrsqrt", X86frsqrt>,
1999                 sse1_fp_unop_p_y<0x52, "vrsqrt", X86frsqrt>,
2000                 sse1_fp_unop_p_y_int<0x52, "vrsqrt", int_x86_avx_rsqrt_ps_256>,
2001                 sse1_fp_unop_p_int<0x52, "vrsqrt", int_x86_sse_rsqrt_ps>, VEX;
2002
2003   defm VRCP   : sse1_fp_unop_s_avx<0x53, "vrcp", X86frcp, int_x86_sse_rcp_ss>,
2004                                    VEX_4V;
2005   defm VRCP   : sse1_fp_unop_p<0x53, "vrcp", X86frcp>,
2006                 sse1_fp_unop_p_y<0x53, "vrcp", X86frcp>,
2007                 sse1_fp_unop_p_y_int<0x53, "vrcp", int_x86_avx_rcp_ps_256>,
2008                 sse1_fp_unop_p_int<0x53, "vrcp", int_x86_sse_rcp_ps>, VEX;
2009 }
2010
2011 // Square root.
2012 defm SQRT  : sse1_fp_unop_s<0x51, "sqrt",  fsqrt, int_x86_sse_sqrt_ss>,
2013              sse1_fp_unop_p<0x51, "sqrt",  fsqrt>,
2014              sse1_fp_unop_p_int<0x51, "sqrt",  int_x86_sse_sqrt_ps>,
2015              sse2_fp_unop_s<0x51, "sqrt",  fsqrt, int_x86_sse2_sqrt_sd>,
2016              sse2_fp_unop_p<0x51, "sqrt",  fsqrt>,
2017              sse2_fp_unop_p_int<0x51, "sqrt", int_x86_sse2_sqrt_pd>;
2018
2019 // Reciprocal approximations. Note that these typically require refinement
2020 // in order to obtain suitable precision.
2021 defm RSQRT : sse1_fp_unop_s<0x52, "rsqrt", X86frsqrt, int_x86_sse_rsqrt_ss>,
2022              sse1_fp_unop_p<0x52, "rsqrt", X86frsqrt>,
2023              sse1_fp_unop_p_int<0x52, "rsqrt", int_x86_sse_rsqrt_ps>;
2024 defm RCP   : sse1_fp_unop_s<0x53, "rcp", X86frcp, int_x86_sse_rcp_ss>,
2025              sse1_fp_unop_p<0x53, "rcp", X86frcp>,
2026              sse1_fp_unop_p_int<0x53, "rcp", int_x86_sse_rcp_ps>;
2027
2028 // There is no f64 version of the reciprocal approximation instructions.
2029
2030 //===----------------------------------------------------------------------===//
2031 // SSE 1 & 2 - Non-temporal stores
2032 //===----------------------------------------------------------------------===//
2033
2034 let isAsmParserOnly = 1 in {
2035   def VMOVNTPSmr_Int : VPSI<0x2B, MRMDestMem, (outs),
2036                          (ins i128mem:$dst, VR128:$src),
2037                          "movntps\t{$src, $dst|$dst, $src}",
2038                          [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>, VEX;
2039   def VMOVNTPDmr_Int : VPDI<0x2B, MRMDestMem, (outs),
2040                          (ins i128mem:$dst, VR128:$src),
2041                          "movntpd\t{$src, $dst|$dst, $src}",
2042                          [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>, VEX;
2043
2044   let ExeDomain = SSEPackedInt in
2045     def VMOVNTDQmr_Int : VPDI<0xE7, MRMDestMem, (outs),
2046                        (ins f128mem:$dst, VR128:$src),
2047                        "movntdq\t{$src, $dst|$dst, $src}",
2048                        [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>, VEX;
2049
2050   let AddedComplexity = 400 in { // Prefer non-temporal versions
2051     def VMOVNTPSmr : VPSI<0x2B, MRMDestMem, (outs),
2052                          (ins f128mem:$dst, VR128:$src),
2053                          "movntps\t{$src, $dst|$dst, $src}",
2054                          [(alignednontemporalstore (v4f32 VR128:$src),
2055                                                    addr:$dst)]>, VEX;
2056     def VMOVNTPDmr : VPDI<0x2B, MRMDestMem, (outs),
2057                          (ins f128mem:$dst, VR128:$src),
2058                          "movntpd\t{$src, $dst|$dst, $src}",
2059                          [(alignednontemporalstore (v2f64 VR128:$src),
2060                                                    addr:$dst)]>, VEX;
2061     def VMOVNTDQ_64mr : VPDI<0xE7, MRMDestMem, (outs),
2062                           (ins f128mem:$dst, VR128:$src),
2063                           "movntdq\t{$src, $dst|$dst, $src}",
2064                           [(alignednontemporalstore (v2f64 VR128:$src),
2065                                                     addr:$dst)]>, VEX;
2066     let ExeDomain = SSEPackedInt in
2067     def VMOVNTDQmr : VPDI<0xE7, MRMDestMem, (outs),
2068                         (ins f128mem:$dst, VR128:$src),
2069                         "movntdq\t{$src, $dst|$dst, $src}",
2070                         [(alignednontemporalstore (v4f32 VR128:$src),
2071                                                   addr:$dst)]>, VEX;
2072
2073     def VMOVNTPSYmr : VPSI<0x2B, MRMDestMem, (outs),
2074                          (ins f256mem:$dst, VR256:$src),
2075                          "movntps\t{$src, $dst|$dst, $src}",
2076                          [(alignednontemporalstore (v8f32 VR256:$src),
2077                                                    addr:$dst)]>, VEX;
2078     def VMOVNTPDYmr : VPDI<0x2B, MRMDestMem, (outs),
2079                          (ins f256mem:$dst, VR256:$src),
2080                          "movntpd\t{$src, $dst|$dst, $src}",
2081                          [(alignednontemporalstore (v4f64 VR256:$src),
2082                                                    addr:$dst)]>, VEX;
2083     def VMOVNTDQY_64mr : VPDI<0xE7, MRMDestMem, (outs),
2084                           (ins f256mem:$dst, VR256:$src),
2085                           "movntdq\t{$src, $dst|$dst, $src}",
2086                           [(alignednontemporalstore (v4f64 VR256:$src),
2087                                                     addr:$dst)]>, VEX;
2088     let ExeDomain = SSEPackedInt in
2089     def VMOVNTDQYmr : VPDI<0xE7, MRMDestMem, (outs),
2090                         (ins f256mem:$dst, VR256:$src),
2091                         "movntdq\t{$src, $dst|$dst, $src}",
2092                         [(alignednontemporalstore (v8f32 VR256:$src),
2093                                                   addr:$dst)]>, VEX;
2094   }
2095 }
2096
2097 def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2098                     "movntps\t{$src, $dst|$dst, $src}",
2099                     [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
2100 def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2101                         "movntpd\t{$src, $dst|$dst, $src}",
2102                         [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
2103
2104 let ExeDomain = SSEPackedInt in
2105 def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2106                         "movntdq\t{$src, $dst|$dst, $src}",
2107                         [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2108
2109 let AddedComplexity = 400 in { // Prefer non-temporal versions
2110 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2111                     "movntps\t{$src, $dst|$dst, $src}",
2112                     [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
2113 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2114                     "movntpd\t{$src, $dst|$dst, $src}",
2115                     [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
2116
2117 def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2118                     "movntdq\t{$src, $dst|$dst, $src}",
2119                     [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
2120
2121 let ExeDomain = SSEPackedInt in
2122 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2123                     "movntdq\t{$src, $dst|$dst, $src}",
2124                     [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
2125
2126 // There is no AVX form for instructions below this point
2127 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2128                  "movnti\t{$src, $dst|$dst, $src}",
2129                  [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
2130                TB, Requires<[HasSSE2]>;
2131
2132 def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
2133                      "movnti\t{$src, $dst|$dst, $src}",
2134                      [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
2135                   TB, Requires<[HasSSE2]>;
2136
2137 }
2138 def MOVNTImr_Int  :   I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2139                     "movnti\t{$src, $dst|$dst, $src}",
2140                     [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2141                   TB, Requires<[HasSSE2]>;
2142
2143 //===----------------------------------------------------------------------===//
2144 // SSE 1 & 2 - Misc Instructions (No AVX form)
2145 //===----------------------------------------------------------------------===//
2146
2147 // Prefetch intrinsic.
2148 def PREFETCHT0   : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
2149     "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
2150 def PREFETCHT1   : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
2151     "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
2152 def PREFETCHT2   : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
2153     "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
2154 def PREFETCHNTA  : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
2155     "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
2156
2157 // Load, store, and memory fence
2158 def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
2159              TB, Requires<[HasSSE1]>;
2160 def : Pat<(X86SFence), (SFENCE)>;
2161
2162 // Alias instructions that map zero vector to pxor / xorp* for sse.
2163 // We set canFoldAsLoad because this can be converted to a constant-pool
2164 // load of an all-zeros value if folding it would be beneficial.
2165 // FIXME: Change encoding to pseudo!
2166 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
2167     isCodeGenOnly = 1 in {
2168 def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
2169                  [(set VR128:$dst, (v4f32 immAllZerosV))]>;
2170 def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
2171                  [(set VR128:$dst, (v2f64 immAllZerosV))]>;
2172 let ExeDomain = SSEPackedInt in
2173 def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
2174                  [(set VR128:$dst, (v4i32 immAllZerosV))]>;
2175 }
2176
2177 def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
2178 def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
2179 def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
2180
2181 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2182           (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
2183
2184 //===----------------------------------------------------------------------===//
2185 // SSE 1 & 2 - Load/Store XCSR register
2186 //===----------------------------------------------------------------------===//
2187
2188 let isAsmParserOnly = 1 in {
2189   def VLDMXCSR : VPSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
2190                     "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>, VEX;
2191   def VSTMXCSR : VPSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
2192                     "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>, VEX;
2193 }
2194
2195 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
2196                   "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
2197 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
2198                   "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
2199
2200 //===---------------------------------------------------------------------===//
2201 // SSE2 - Move Aligned/Unaligned Packed Integer Instructions
2202 //===---------------------------------------------------------------------===//
2203
2204 let ExeDomain = SSEPackedInt in { // SSE integer instructions
2205
2206 let isAsmParserOnly = 1 in {
2207   let neverHasSideEffects = 1 in {
2208   def VMOVDQArr  : VPDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2209                       "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2210   def VMOVDQAYrr : VPDI<0x6F, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
2211                       "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2212   }
2213   def VMOVDQUrr  : VPDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2214                       "movdqu\t{$src, $dst|$dst, $src}", []>, XS, VEX;
2215   def VMOVDQUYrr : VPDI<0x6F, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
2216                       "movdqu\t{$src, $dst|$dst, $src}", []>, XS, VEX;
2217
2218   let canFoldAsLoad = 1, mayLoad = 1 in {
2219   def VMOVDQArm  : VPDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2220                      "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2221   def VMOVDQAYrm : VPDI<0x6F, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
2222                      "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2223   let Predicates = [HasAVX] in {
2224     def VMOVDQUrm  : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2225                       "vmovdqu\t{$src, $dst|$dst, $src}",[]>, XS, VEX;
2226     def VMOVDQUYrm : I<0x6F, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
2227                       "vmovdqu\t{$src, $dst|$dst, $src}",[]>, XS, VEX;
2228   }
2229   }
2230
2231   let mayStore = 1 in {
2232   def VMOVDQAmr  : VPDI<0x7F, MRMDestMem, (outs),
2233                        (ins i128mem:$dst, VR128:$src),
2234                        "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2235   def VMOVDQAYmr : VPDI<0x7F, MRMDestMem, (outs),
2236                        (ins i256mem:$dst, VR256:$src),
2237                        "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2238   let Predicates = [HasAVX] in {
2239   def VMOVDQUmr  : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2240                     "vmovdqu\t{$src, $dst|$dst, $src}",[]>, XS, VEX;
2241   def VMOVDQUYmr : I<0x7F, MRMDestMem, (outs), (ins i256mem:$dst, VR256:$src),
2242                     "vmovdqu\t{$src, $dst|$dst, $src}",[]>, XS, VEX;
2243   }
2244   }
2245 }
2246
2247 let neverHasSideEffects = 1 in
2248 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2249                    "movdqa\t{$src, $dst|$dst, $src}", []>;
2250
2251 let canFoldAsLoad = 1, mayLoad = 1 in {
2252 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2253                    "movdqa\t{$src, $dst|$dst, $src}",
2254                    [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
2255 def MOVDQUrm :   I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2256                    "movdqu\t{$src, $dst|$dst, $src}",
2257                    [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
2258                  XS, Requires<[HasSSE2]>;
2259 }
2260
2261 let mayStore = 1 in {
2262 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2263                    "movdqa\t{$src, $dst|$dst, $src}",
2264                    [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
2265 def MOVDQUmr :   I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2266                    "movdqu\t{$src, $dst|$dst, $src}",
2267                    [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
2268                  XS, Requires<[HasSSE2]>;
2269 }
2270
2271 // Intrinsic forms of MOVDQU load and store
2272 let isAsmParserOnly = 1 in {
2273 let canFoldAsLoad = 1 in
2274 def VMOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2275                        "vmovdqu\t{$src, $dst|$dst, $src}",
2276                        [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
2277                      XS, VEX, Requires<[HasAVX]>;
2278 def VMOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2279                        "vmovdqu\t{$src, $dst|$dst, $src}",
2280                        [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
2281                      XS, VEX, Requires<[HasAVX]>;
2282 }
2283
2284 let canFoldAsLoad = 1 in
2285 def MOVDQUrm_Int :   I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2286                        "movdqu\t{$src, $dst|$dst, $src}",
2287                        [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
2288                  XS, Requires<[HasSSE2]>;
2289 def MOVDQUmr_Int :   I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2290                        "movdqu\t{$src, $dst|$dst, $src}",
2291                        [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
2292                      XS, Requires<[HasSSE2]>;
2293
2294 } // ExeDomain = SSEPackedInt
2295
2296 //===---------------------------------------------------------------------===//
2297 // SSE2 - Packed Integer Arithmetic Instructions
2298 //===---------------------------------------------------------------------===//
2299
2300 let ExeDomain = SSEPackedInt in { // SSE integer instructions
2301
2302 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
2303                             bit IsCommutable = 0, bit Is2Addr = 1> {
2304   let isCommutable = IsCommutable in
2305   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2306        (ins VR128:$src1, VR128:$src2),
2307        !if(Is2Addr,
2308            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2309            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2310        [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
2311   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2312        (ins VR128:$src1, i128mem:$src2),
2313        !if(Is2Addr,
2314            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2315            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2316        [(set VR128:$dst, (IntId VR128:$src1,
2317                                 (bitconvert (memopv2i64 addr:$src2))))]>;
2318 }
2319
2320 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
2321                              string OpcodeStr, Intrinsic IntId,
2322                              Intrinsic IntId2, bit Is2Addr = 1> {
2323   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2324        (ins VR128:$src1, VR128:$src2),
2325        !if(Is2Addr,
2326            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2327            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2328        [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
2329   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2330        (ins VR128:$src1, i128mem:$src2),
2331        !if(Is2Addr,
2332            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2333            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2334        [(set VR128:$dst, (IntId VR128:$src1,
2335                                       (bitconvert (memopv2i64 addr:$src2))))]>;
2336   def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
2337        (ins VR128:$src1, i32i8imm:$src2),
2338        !if(Is2Addr,
2339            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2340            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2341        [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
2342 }
2343
2344 /// PDI_binop_rm - Simple SSE2 binary operator.
2345 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
2346                         ValueType OpVT, bit IsCommutable = 0, bit Is2Addr = 1> {
2347   let isCommutable = IsCommutable in
2348   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2349        (ins VR128:$src1, VR128:$src2),
2350        !if(Is2Addr,
2351            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2352            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2353        [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>;
2354   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2355        (ins VR128:$src1, i128mem:$src2),
2356        !if(Is2Addr,
2357            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2358            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2359        [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
2360                                      (bitconvert (memopv2i64 addr:$src2)))))]>;
2361 }
2362
2363 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
2364 ///
2365 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
2366 /// to collapse (bitconvert VT to VT) into its operand.
2367 ///
2368 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
2369                               bit IsCommutable = 0, bit Is2Addr = 1> {
2370   let isCommutable = IsCommutable in
2371   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2372        (ins VR128:$src1, VR128:$src2),
2373        !if(Is2Addr,
2374            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2375            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2376        [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]>;
2377   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2378        (ins VR128:$src1, i128mem:$src2),
2379        !if(Is2Addr,
2380            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2381            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2382        [(set VR128:$dst, (OpNode VR128:$src1, (memopv2i64 addr:$src2)))]>;
2383 }
2384
2385 } // ExeDomain = SSEPackedInt
2386
2387 // 128-bit Integer Arithmetic
2388
2389 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2390 defm VPADDB  : PDI_binop_rm<0xFC, "vpaddb", add, v16i8, 1, 0 /*3addr*/>, VEX_4V;
2391 defm VPADDW  : PDI_binop_rm<0xFD, "vpaddw", add, v8i16, 1, 0>, VEX_4V;
2392 defm VPADDD  : PDI_binop_rm<0xFE, "vpaddd", add, v4i32, 1, 0>, VEX_4V;
2393 defm VPADDQ  : PDI_binop_rm_v2i64<0xD4, "vpaddq", add, 1, 0>, VEX_4V;
2394 defm VPMULLW : PDI_binop_rm<0xD5, "vpmullw", mul, v8i16, 1, 0>, VEX_4V;
2395 defm VPSUBB : PDI_binop_rm<0xF8, "vpsubb", sub, v16i8, 0, 0>, VEX_4V;
2396 defm VPSUBW : PDI_binop_rm<0xF9, "vpsubw", sub, v8i16, 0, 0>, VEX_4V;
2397 defm VPSUBD : PDI_binop_rm<0xFA, "vpsubd", sub, v4i32, 0, 0>, VEX_4V;
2398 defm VPSUBQ : PDI_binop_rm_v2i64<0xFB, "vpsubq", sub, 0, 0>, VEX_4V;
2399
2400 // Intrinsic forms
2401 defm VPSUBSB  : PDI_binop_rm_int<0xE8, "vpsubsb" , int_x86_sse2_psubs_b, 0, 0>,
2402                                  VEX_4V;
2403 defm VPSUBSW  : PDI_binop_rm_int<0xE9, "vpsubsw" , int_x86_sse2_psubs_w, 0, 0>,
2404                                  VEX_4V;
2405 defm VPSUBUSB : PDI_binop_rm_int<0xD8, "vpsubusb", int_x86_sse2_psubus_b, 0, 0>,
2406                                  VEX_4V;
2407 defm VPSUBUSW : PDI_binop_rm_int<0xD9, "vpsubusw", int_x86_sse2_psubus_w, 0, 0>,
2408                                  VEX_4V;
2409 defm VPADDSB  : PDI_binop_rm_int<0xEC, "vpaddsb" , int_x86_sse2_padds_b, 1, 0>,
2410                                  VEX_4V;
2411 defm VPADDSW  : PDI_binop_rm_int<0xED, "vpaddsw" , int_x86_sse2_padds_w, 1, 0>,
2412                                  VEX_4V;
2413 defm VPADDUSB : PDI_binop_rm_int<0xDC, "vpaddusb", int_x86_sse2_paddus_b, 1, 0>,
2414                                  VEX_4V;
2415 defm VPADDUSW : PDI_binop_rm_int<0xDD, "vpaddusw", int_x86_sse2_paddus_w, 1, 0>,
2416                                  VEX_4V;
2417 defm VPMULHUW : PDI_binop_rm_int<0xE4, "vpmulhuw", int_x86_sse2_pmulhu_w, 1, 0>,
2418                                  VEX_4V;
2419 defm VPMULHW  : PDI_binop_rm_int<0xE5, "vpmulhw" , int_x86_sse2_pmulh_w, 1, 0>,
2420                                  VEX_4V;
2421 defm VPMULUDQ : PDI_binop_rm_int<0xF4, "vpmuludq", int_x86_sse2_pmulu_dq, 1, 0>,
2422                                  VEX_4V;
2423 defm VPMADDWD : PDI_binop_rm_int<0xF5, "vpmaddwd", int_x86_sse2_pmadd_wd, 1, 0>,
2424                                  VEX_4V;
2425 defm VPAVGB   : PDI_binop_rm_int<0xE0, "vpavgb", int_x86_sse2_pavg_b, 1, 0>,
2426                                  VEX_4V;
2427 defm VPAVGW   : PDI_binop_rm_int<0xE3, "vpavgw", int_x86_sse2_pavg_w, 1, 0>,
2428                                  VEX_4V;
2429 defm VPMINUB  : PDI_binop_rm_int<0xDA, "vpminub", int_x86_sse2_pminu_b, 1, 0>,
2430                                  VEX_4V;
2431 defm VPMINSW  : PDI_binop_rm_int<0xEA, "vpminsw", int_x86_sse2_pmins_w, 1, 0>,
2432                                  VEX_4V;
2433 defm VPMAXUB  : PDI_binop_rm_int<0xDE, "vpmaxub", int_x86_sse2_pmaxu_b, 1, 0>,
2434                                  VEX_4V;
2435 defm VPMAXSW  : PDI_binop_rm_int<0xEE, "vpmaxsw", int_x86_sse2_pmaxs_w, 1, 0>,
2436                                  VEX_4V;
2437 defm VPSADBW  : PDI_binop_rm_int<0xF6, "vpsadbw", int_x86_sse2_psad_bw, 1, 0>,
2438                                  VEX_4V;
2439 }
2440
2441 let Constraints = "$src1 = $dst" in {
2442 defm PADDB  : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
2443 defm PADDW  : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
2444 defm PADDD  : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
2445 defm PADDQ  : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
2446 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
2447 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
2448 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
2449 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
2450 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
2451
2452 // Intrinsic forms
2453 defm PSUBSB  : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
2454 defm PSUBSW  : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
2455 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
2456 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
2457 defm PADDSB  : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
2458 defm PADDSW  : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
2459 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
2460 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
2461 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
2462 defm PMULHW  : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w, 1>;
2463 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
2464 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
2465 defm PAVGB   : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
2466 defm PAVGW   : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
2467 defm PMINUB  : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
2468 defm PMINSW  : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
2469 defm PMAXUB  : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
2470 defm PMAXSW  : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
2471 defm PSADBW  : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
2472
2473 } // Constraints = "$src1 = $dst"
2474
2475 //===---------------------------------------------------------------------===//
2476 // SSE2 - Packed Integer Logical Instructions
2477 //===---------------------------------------------------------------------===//
2478
2479 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2480 defm VPSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "vpsllw",
2481                                 int_x86_sse2_psll_w, int_x86_sse2_pslli_w, 0>,
2482                                 VEX_4V;
2483 defm VPSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "vpslld",
2484                                 int_x86_sse2_psll_d, int_x86_sse2_pslli_d, 0>,
2485                                 VEX_4V;
2486 defm VPSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "vpsllq",
2487                                 int_x86_sse2_psll_q, int_x86_sse2_pslli_q, 0>,
2488                                 VEX_4V;
2489
2490 defm VPSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "vpsrlw",
2491                                 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w, 0>,
2492                                 VEX_4V;
2493 defm VPSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "vpsrld",
2494                                 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d, 0>,
2495                                 VEX_4V;
2496 defm VPSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "vpsrlq",
2497                                 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q, 0>,
2498                                 VEX_4V;
2499
2500 defm VPSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "vpsraw",
2501                                 int_x86_sse2_psra_w, int_x86_sse2_psrai_w, 0>,
2502                                 VEX_4V;
2503 defm VPSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "vpsrad",
2504                                 int_x86_sse2_psra_d, int_x86_sse2_psrai_d, 0>,
2505                                 VEX_4V;
2506
2507 defm VPAND : PDI_binop_rm_v2i64<0xDB, "vpand", and, 1, 0>, VEX_4V;
2508 defm VPOR  : PDI_binop_rm_v2i64<0xEB, "vpor" , or, 1, 0>, VEX_4V;
2509 defm VPXOR : PDI_binop_rm_v2i64<0xEF, "vpxor", xor, 1, 0>, VEX_4V;
2510
2511 let ExeDomain = SSEPackedInt in {
2512   let neverHasSideEffects = 1 in {
2513     // 128-bit logical shifts.
2514     def VPSLLDQri : PDIi8<0x73, MRM7r,
2515                       (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2516                       "vpslldq\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
2517                       VEX_4V;
2518     def VPSRLDQri : PDIi8<0x73, MRM3r,
2519                       (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2520                       "vpsrldq\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
2521                       VEX_4V;
2522     // PSRADQri doesn't exist in SSE[1-3].
2523   }
2524   def VPANDNrr : PDI<0xDF, MRMSrcReg,
2525                     (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2526                     "vpandn\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2527                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2528                                               VR128:$src2)))]>, VEX_4V;
2529
2530   def VPANDNrm : PDI<0xDF, MRMSrcMem,
2531                     (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2532                     "vpandn\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2533                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2534                                               (memopv2i64 addr:$src2))))]>,
2535                                               VEX_4V;
2536 }
2537 }
2538
2539 let Constraints = "$src1 = $dst" in {
2540 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
2541                                int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
2542 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
2543                                int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
2544 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2545                                int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
2546
2547 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2548                                int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2549 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2550                                int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
2551 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
2552                                int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
2553
2554 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2555                                int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
2556 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
2557                                int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
2558
2559 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2560 defm POR  : PDI_binop_rm_v2i64<0xEB, "por" , or, 1>;
2561 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2562
2563 let ExeDomain = SSEPackedInt in {
2564   let neverHasSideEffects = 1 in {
2565     // 128-bit logical shifts.
2566     def PSLLDQri : PDIi8<0x73, MRM7r,
2567                          (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2568                          "pslldq\t{$src2, $dst|$dst, $src2}", []>;
2569     def PSRLDQri : PDIi8<0x73, MRM3r,
2570                          (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2571                          "psrldq\t{$src2, $dst|$dst, $src2}", []>;
2572     // PSRADQri doesn't exist in SSE[1-3].
2573   }
2574   def PANDNrr : PDI<0xDF, MRMSrcReg,
2575                     (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2576                     "pandn\t{$src2, $dst|$dst, $src2}",
2577                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2578                                               VR128:$src2)))]>;
2579
2580   def PANDNrm : PDI<0xDF, MRMSrcMem,
2581                     (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2582                     "pandn\t{$src2, $dst|$dst, $src2}",
2583                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2584                                               (memopv2i64 addr:$src2))))]>;
2585 }
2586 } // Constraints = "$src1 = $dst"
2587
2588 let Predicates = [HasAVX] in {
2589   def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
2590             (v2i64 (VPSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2591   def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2592             (v2i64 (VPSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2593   def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2594             (v2i64 (VPSLLDQri VR128:$src1, imm:$src2))>;
2595   def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2596             (v2i64 (VPSRLDQri VR128:$src1, imm:$src2))>;
2597   def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2598             (v2f64 (VPSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2599
2600   // Shift up / down and insert zero's.
2601   def : Pat<(v2i64 (X86vshl  VR128:$src, (i8 imm:$amt))),
2602             (v2i64 (VPSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2603   def : Pat<(v2i64 (X86vshr  VR128:$src, (i8 imm:$amt))),
2604             (v2i64 (VPSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2605 }
2606
2607 let Predicates = [HasSSE2] in {
2608   def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
2609             (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2610   def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2611             (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2612   def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2613             (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2614   def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2615             (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
2616   def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2617             (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2618
2619   // Shift up / down and insert zero's.
2620   def : Pat<(v2i64 (X86vshl  VR128:$src, (i8 imm:$amt))),
2621             (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2622   def : Pat<(v2i64 (X86vshr  VR128:$src, (i8 imm:$amt))),
2623             (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2624 }
2625
2626 //===---------------------------------------------------------------------===//
2627 // SSE2 - Packed Integer Comparison Instructions
2628 //===---------------------------------------------------------------------===//
2629
2630 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2631   defm VPCMPEQB  : PDI_binop_rm_int<0x74, "vpcmpeqb", int_x86_sse2_pcmpeq_b, 1,
2632                                     0>, VEX_4V;
2633   defm VPCMPEQW  : PDI_binop_rm_int<0x75, "vpcmpeqw", int_x86_sse2_pcmpeq_w, 1,
2634                                     0>, VEX_4V;
2635   defm VPCMPEQD  : PDI_binop_rm_int<0x76, "vpcmpeqd", int_x86_sse2_pcmpeq_d, 1,
2636                                     0>, VEX_4V;
2637   defm VPCMPGTB  : PDI_binop_rm_int<0x64, "vpcmpgtb", int_x86_sse2_pcmpgt_b, 0,
2638                                     0>, VEX_4V;
2639   defm VPCMPGTW  : PDI_binop_rm_int<0x65, "vpcmpgtw", int_x86_sse2_pcmpgt_w, 0,
2640                                     0>, VEX_4V;
2641   defm VPCMPGTD  : PDI_binop_rm_int<0x66, "vpcmpgtd", int_x86_sse2_pcmpgt_d, 0,
2642                                     0>, VEX_4V;
2643 }
2644
2645 let Constraints = "$src1 = $dst" in {
2646   defm PCMPEQB  : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b, 1>;
2647   defm PCMPEQW  : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w, 1>;
2648   defm PCMPEQD  : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d, 1>;
2649   defm PCMPGTB  : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2650   defm PCMPGTW  : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2651   defm PCMPGTD  : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2652 } // Constraints = "$src1 = $dst"
2653
2654 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
2655           (PCMPEQBrr VR128:$src1, VR128:$src2)>;
2656 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
2657           (PCMPEQBrm VR128:$src1, addr:$src2)>;
2658 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
2659           (PCMPEQWrr VR128:$src1, VR128:$src2)>;
2660 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
2661           (PCMPEQWrm VR128:$src1, addr:$src2)>;
2662 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
2663           (PCMPEQDrr VR128:$src1, VR128:$src2)>;
2664 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
2665           (PCMPEQDrm VR128:$src1, addr:$src2)>;
2666
2667 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
2668           (PCMPGTBrr VR128:$src1, VR128:$src2)>;
2669 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
2670           (PCMPGTBrm VR128:$src1, addr:$src2)>;
2671 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
2672           (PCMPGTWrr VR128:$src1, VR128:$src2)>;
2673 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
2674           (PCMPGTWrm VR128:$src1, addr:$src2)>;
2675 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
2676           (PCMPGTDrr VR128:$src1, VR128:$src2)>;
2677 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
2678           (PCMPGTDrm VR128:$src1, addr:$src2)>;
2679
2680 //===---------------------------------------------------------------------===//
2681 // SSE2 - Packed Integer Pack Instructions
2682 //===---------------------------------------------------------------------===//
2683
2684 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2685 defm VPACKSSWB : PDI_binop_rm_int<0x63, "vpacksswb", int_x86_sse2_packsswb_128,
2686                                   0, 0>, VEX_4V;
2687 defm VPACKSSDW : PDI_binop_rm_int<0x6B, "vpackssdw", int_x86_sse2_packssdw_128,
2688                                   0, 0>, VEX_4V;
2689 defm VPACKUSWB : PDI_binop_rm_int<0x67, "vpackuswb", int_x86_sse2_packuswb_128,
2690                                   0, 0>, VEX_4V;
2691 }
2692
2693 let Constraints = "$src1 = $dst" in {
2694 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2695 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2696 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2697 } // Constraints = "$src1 = $dst"
2698
2699 //===---------------------------------------------------------------------===//
2700 // SSE2 - Packed Integer Shuffle Instructions
2701 //===---------------------------------------------------------------------===//
2702
2703 let ExeDomain = SSEPackedInt in {
2704 multiclass sse2_pshuffle<string OpcodeStr, ValueType vt, PatFrag pshuf_frag,
2705                          PatFrag bc_frag> {
2706 def ri : Ii8<0x70, MRMSrcReg,
2707               (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2708               !strconcat(OpcodeStr,
2709                          "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2710               [(set VR128:$dst, (vt (pshuf_frag:$src2 VR128:$src1,
2711                                                       (undef))))]>;
2712 def mi : Ii8<0x70, MRMSrcMem,
2713               (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2714               !strconcat(OpcodeStr,
2715                          "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2716               [(set VR128:$dst, (vt (pshuf_frag:$src2
2717                                       (bc_frag (memopv2i64 addr:$src1)),
2718                                       (undef))))]>;
2719 }
2720 } // ExeDomain = SSEPackedInt
2721
2722 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2723   let AddedComplexity = 5 in
2724   defm VPSHUFD : sse2_pshuffle<"vpshufd", v4i32, pshufd, bc_v4i32>, OpSize,
2725                                VEX;
2726
2727   // SSE2 with ImmT == Imm8 and XS prefix.
2728   defm VPSHUFHW : sse2_pshuffle<"vpshufhw", v8i16, pshufhw, bc_v8i16>, XS,
2729                                VEX;
2730
2731   // SSE2 with ImmT == Imm8 and XD prefix.
2732   defm VPSHUFLW : sse2_pshuffle<"vpshuflw", v8i16, pshuflw, bc_v8i16>, XD,
2733                                VEX;
2734 }
2735
2736 let Predicates = [HasSSE2] in {
2737   let AddedComplexity = 5 in
2738   defm PSHUFD : sse2_pshuffle<"pshufd", v4i32, pshufd, bc_v4i32>, TB, OpSize;
2739
2740   // SSE2 with ImmT == Imm8 and XS prefix.
2741   defm PSHUFHW : sse2_pshuffle<"pshufhw", v8i16, pshufhw, bc_v8i16>, XS;
2742
2743   // SSE2 with ImmT == Imm8 and XD prefix.
2744   defm PSHUFLW : sse2_pshuffle<"pshuflw", v8i16, pshuflw, bc_v8i16>, XD;
2745 }
2746
2747 //===---------------------------------------------------------------------===//
2748 // SSE2 - Packed Integer Unpack Instructions
2749 //===---------------------------------------------------------------------===//
2750
2751 let ExeDomain = SSEPackedInt in {
2752 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2753                        PatFrag unp_frag, PatFrag bc_frag, bit Is2Addr = 1> {
2754   def rr : PDI<opc, MRMSrcReg,
2755       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2756       !if(Is2Addr,
2757           !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2758           !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2759       [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2760   def rm : PDI<opc, MRMSrcMem,
2761       (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2762       !if(Is2Addr,
2763           !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2764           !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2765       [(set VR128:$dst, (unp_frag VR128:$src1,
2766                                   (bc_frag (memopv2i64
2767                                                addr:$src2))))]>;
2768 }
2769
2770 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2771   defm VPUNPCKLBW  : sse2_unpack<0x60, "vpunpcklbw", v16i8, unpckl, bc_v16i8,
2772                                  0>, VEX_4V;
2773   defm VPUNPCKLWD  : sse2_unpack<0x61, "vpunpcklwd", v8i16, unpckl, bc_v8i16,
2774                                  0>, VEX_4V;
2775   defm VPUNPCKLDQ  : sse2_unpack<0x62, "vpunpckldq", v4i32, unpckl, bc_v4i32,
2776                                  0>, VEX_4V;
2777
2778   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2779   /// knew to collapse (bitconvert VT to VT) into its operand.
2780   def VPUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2781                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2782                          "vpunpcklqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2783                         [(set VR128:$dst,
2784                           (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>, VEX_4V;
2785   def VPUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2786                          (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2787                          "vpunpcklqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2788                         [(set VR128:$dst,
2789                           (v2i64 (unpckl VR128:$src1,
2790                                          (memopv2i64 addr:$src2))))]>, VEX_4V;
2791
2792   defm VPUNPCKHBW  : sse2_unpack<0x68, "vpunpckhbw", v16i8, unpckh, bc_v16i8,
2793                                  0>, VEX_4V;
2794   defm VPUNPCKHWD  : sse2_unpack<0x69, "vpunpckhwd", v8i16, unpckh, bc_v8i16,
2795                                  0>, VEX_4V;
2796   defm VPUNPCKHDQ  : sse2_unpack<0x6A, "vpunpckhdq", v4i32, unpckh, bc_v4i32,
2797                                  0>, VEX_4V;
2798
2799   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2800   /// knew to collapse (bitconvert VT to VT) into its operand.
2801   def VPUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2802                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2803                          "vpunpckhqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2804                         [(set VR128:$dst,
2805                           (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>, VEX_4V;
2806   def VPUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2807                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2808                         "vpunpckhqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2809                         [(set VR128:$dst,
2810                           (v2i64 (unpckh VR128:$src1,
2811                                          (memopv2i64 addr:$src2))))]>, VEX_4V;
2812 }
2813
2814 let Constraints = "$src1 = $dst" in {
2815   defm PUNPCKLBW  : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2816   defm PUNPCKLWD  : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2817   defm PUNPCKLDQ  : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2818
2819   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2820   /// knew to collapse (bitconvert VT to VT) into its operand.
2821   def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2822                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2823                          "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2824                         [(set VR128:$dst,
2825                           (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
2826   def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2827                          (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2828                          "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2829                         [(set VR128:$dst,
2830                           (v2i64 (unpckl VR128:$src1,
2831                                          (memopv2i64 addr:$src2))))]>;
2832
2833   defm PUNPCKHBW  : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2834   defm PUNPCKHWD  : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2835   defm PUNPCKHDQ  : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2836
2837   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2838   /// knew to collapse (bitconvert VT to VT) into its operand.
2839   def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2840                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2841                          "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2842                         [(set VR128:$dst,
2843                           (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
2844   def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2845                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2846                         "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2847                         [(set VR128:$dst,
2848                           (v2i64 (unpckh VR128:$src1,
2849                                          (memopv2i64 addr:$src2))))]>;
2850 }
2851
2852 } // ExeDomain = SSEPackedInt
2853
2854 //===---------------------------------------------------------------------===//
2855 // SSE2 - Packed Integer Extract and Insert
2856 //===---------------------------------------------------------------------===//
2857
2858 let ExeDomain = SSEPackedInt in {
2859 multiclass sse2_pinsrw<bit Is2Addr = 1> {
2860   def rri : Ii8<0xC4, MRMSrcReg,
2861        (outs VR128:$dst), (ins VR128:$src1,
2862         GR32:$src2, i32i8imm:$src3),
2863        !if(Is2Addr,
2864            "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2865            "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
2866        [(set VR128:$dst,
2867          (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
2868   def rmi : Ii8<0xC4, MRMSrcMem,
2869                        (outs VR128:$dst), (ins VR128:$src1,
2870                         i16mem:$src2, i32i8imm:$src3),
2871        !if(Is2Addr,
2872            "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2873            "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
2874        [(set VR128:$dst,
2875          (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2876                     imm:$src3))]>;
2877 }
2878
2879 // Extract
2880 let isAsmParserOnly = 1, Predicates = [HasAVX] in
2881 def VPEXTRWri : Ii8<0xC5, MRMSrcReg,
2882                     (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2883                     "vpextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2884                     [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2885                                                 imm:$src2))]>, OpSize, VEX;
2886 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
2887                     (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2888                     "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2889                     [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2890                                                 imm:$src2))]>;
2891
2892 // Insert
2893 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2894   defm VPINSRW : sse2_pinsrw<0>, OpSize, VEX_4V;
2895   def  VPINSRWrr64i : Ii8<0xC4, MRMSrcReg, (outs VR128:$dst),
2896        (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2897        "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
2898        []>, OpSize, VEX_4V;
2899 }
2900
2901 let Constraints = "$src1 = $dst" in
2902   defm PINSRW : sse2_pinsrw, TB, OpSize, Requires<[HasSSE2]>;
2903
2904 } // ExeDomain = SSEPackedInt
2905
2906 //===---------------------------------------------------------------------===//
2907 // SSE2 - Packed Mask Creation
2908 //===---------------------------------------------------------------------===//
2909
2910 let ExeDomain = SSEPackedInt in {
2911
2912 let isAsmParserOnly = 1 in {
2913 def VPMOVMSKBrr  : VPDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2914            "pmovmskb\t{$src, $dst|$dst, $src}",
2915            [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>, VEX;
2916 def VPMOVMSKBr64r : VPDI<0xD7, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
2917            "pmovmskb\t{$src, $dst|$dst, $src}", []>, VEX;
2918 }
2919 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2920            "pmovmskb\t{$src, $dst|$dst, $src}",
2921            [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2922
2923 } // ExeDomain = SSEPackedInt
2924
2925 //===---------------------------------------------------------------------===//
2926 // SSE2 - Conditional Store
2927 //===---------------------------------------------------------------------===//
2928
2929 let ExeDomain = SSEPackedInt in {
2930
2931 let isAsmParserOnly = 1 in {
2932 let Uses = [EDI] in
2933 def VMASKMOVDQU : VPDI<0xF7, MRMSrcReg, (outs),
2934            (ins VR128:$src, VR128:$mask),
2935            "maskmovdqu\t{$mask, $src|$src, $mask}",
2936            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>, VEX;
2937 let Uses = [RDI] in
2938 def VMASKMOVDQU64 : VPDI<0xF7, MRMSrcReg, (outs),
2939            (ins VR128:$src, VR128:$mask),
2940            "maskmovdqu\t{$mask, $src|$src, $mask}",
2941            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>, VEX;
2942 }
2943
2944 let Uses = [EDI] in
2945 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2946            "maskmovdqu\t{$mask, $src|$src, $mask}",
2947            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
2948 let Uses = [RDI] in
2949 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2950            "maskmovdqu\t{$mask, $src|$src, $mask}",
2951            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2952
2953 } // ExeDomain = SSEPackedInt
2954
2955 //===---------------------------------------------------------------------===//
2956 // SSE2 - Move Doubleword
2957 //===---------------------------------------------------------------------===//
2958
2959 // Move Int Doubleword to Packed Double Int
2960 let isAsmParserOnly = 1 in {
2961 def VMOVDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2962                       "movd\t{$src, $dst|$dst, $src}",
2963                       [(set VR128:$dst,
2964                         (v4i32 (scalar_to_vector GR32:$src)))]>, VEX;
2965 def VMOVDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2966                       "movd\t{$src, $dst|$dst, $src}",
2967                       [(set VR128:$dst,
2968                         (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>,
2969                       VEX;
2970 }
2971 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2972                       "movd\t{$src, $dst|$dst, $src}",
2973                       [(set VR128:$dst,
2974                         (v4i32 (scalar_to_vector GR32:$src)))]>;
2975 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2976                       "movd\t{$src, $dst|$dst, $src}",
2977                       [(set VR128:$dst,
2978                         (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2979
2980
2981 // Move Int Doubleword to Single Scalar
2982 let isAsmParserOnly = 1 in {
2983 def VMOVDI2SSrr  : VPDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2984                       "movd\t{$src, $dst|$dst, $src}",
2985                       [(set FR32:$dst, (bitconvert GR32:$src))]>, VEX;
2986
2987 def VMOVDI2SSrm  : VPDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2988                       "movd\t{$src, $dst|$dst, $src}",
2989                       [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>,
2990                       VEX;
2991 }
2992 def MOVDI2SSrr  : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2993                       "movd\t{$src, $dst|$dst, $src}",
2994                       [(set FR32:$dst, (bitconvert GR32:$src))]>;
2995
2996 def MOVDI2SSrm  : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2997                       "movd\t{$src, $dst|$dst, $src}",
2998                       [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2999
3000 // Move Packed Doubleword Int to Packed Double Int
3001 let isAsmParserOnly = 1 in {
3002 def VMOVPDI2DIrr  : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
3003                        "movd\t{$src, $dst|$dst, $src}",
3004                        [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
3005                                         (iPTR 0)))]>, VEX;
3006 def VMOVPDI2DImr  : VPDI<0x7E, MRMDestMem, (outs),
3007                        (ins i32mem:$dst, VR128:$src),
3008                        "movd\t{$src, $dst|$dst, $src}",
3009                        [(store (i32 (vector_extract (v4i32 VR128:$src),
3010                                      (iPTR 0))), addr:$dst)]>, VEX;
3011 }
3012 def MOVPDI2DIrr  : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
3013                        "movd\t{$src, $dst|$dst, $src}",
3014                        [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
3015                                         (iPTR 0)))]>;
3016 def MOVPDI2DImr  : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
3017                        "movd\t{$src, $dst|$dst, $src}",
3018                        [(store (i32 (vector_extract (v4i32 VR128:$src),
3019                                      (iPTR 0))), addr:$dst)]>;
3020
3021 // Move Scalar Single to Double Int
3022 let isAsmParserOnly = 1 in {
3023 def VMOVSS2DIrr  : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
3024                       "movd\t{$src, $dst|$dst, $src}",
3025                       [(set GR32:$dst, (bitconvert FR32:$src))]>, VEX;
3026 def VMOVSS2DImr  : VPDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
3027                       "movd\t{$src, $dst|$dst, $src}",
3028                       [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>, VEX;
3029 }
3030 def MOVSS2DIrr  : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
3031                       "movd\t{$src, $dst|$dst, $src}",
3032                       [(set GR32:$dst, (bitconvert FR32:$src))]>;
3033 def MOVSS2DImr  : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
3034                       "movd\t{$src, $dst|$dst, $src}",
3035                       [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
3036
3037 // movd / movq to XMM register zero-extends
3038 let AddedComplexity = 15, isAsmParserOnly = 1 in {
3039 def VMOVZDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
3040                        "movd\t{$src, $dst|$dst, $src}",
3041                        [(set VR128:$dst, (v4i32 (X86vzmovl
3042                                       (v4i32 (scalar_to_vector GR32:$src)))))]>,
3043                                       VEX;
3044 def VMOVZQI2PQIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
3045                        "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
3046                        [(set VR128:$dst, (v2i64 (X86vzmovl
3047                                       (v2i64 (scalar_to_vector GR64:$src)))))]>,
3048                                       VEX, VEX_W;
3049 }
3050 let AddedComplexity = 15 in {
3051 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
3052                        "movd\t{$src, $dst|$dst, $src}",
3053                        [(set VR128:$dst, (v4i32 (X86vzmovl
3054                                       (v4i32 (scalar_to_vector GR32:$src)))))]>;
3055 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
3056                        "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
3057                        [(set VR128:$dst, (v2i64 (X86vzmovl
3058                                       (v2i64 (scalar_to_vector GR64:$src)))))]>;
3059 }
3060
3061 let AddedComplexity = 20 in {
3062 let isAsmParserOnly = 1 in
3063 def VMOVZDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3064                        "movd\t{$src, $dst|$dst, $src}",
3065                        [(set VR128:$dst,
3066                          (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
3067                                                    (loadi32 addr:$src))))))]>,
3068                                                    VEX;
3069 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3070                        "movd\t{$src, $dst|$dst, $src}",
3071                        [(set VR128:$dst,
3072                          (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
3073                                                    (loadi32 addr:$src))))))]>;
3074
3075 def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
3076             (MOVZDI2PDIrm addr:$src)>;
3077 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
3078             (MOVZDI2PDIrm addr:$src)>;
3079 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
3080             (MOVZDI2PDIrm addr:$src)>;
3081 }
3082
3083 //===---------------------------------------------------------------------===//
3084 // SSE2 - Move Quadword
3085 //===---------------------------------------------------------------------===//
3086
3087 // Move Quadword Int to Packed Quadword Int
3088 let isAsmParserOnly = 1 in
3089 def VMOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3090                     "vmovq\t{$src, $dst|$dst, $src}",
3091                     [(set VR128:$dst,
3092                       (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
3093                     VEX, Requires<[HasAVX]>;
3094 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3095                     "movq\t{$src, $dst|$dst, $src}",
3096                     [(set VR128:$dst,
3097                       (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
3098                     Requires<[HasSSE2]>; // SSE2 instruction with XS Prefix
3099
3100 // Move Packed Quadword Int to Quadword Int
3101 let isAsmParserOnly = 1 in
3102 def VMOVPQI2QImr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
3103                       "movq\t{$src, $dst|$dst, $src}",
3104                       [(store (i64 (vector_extract (v2i64 VR128:$src),
3105                                     (iPTR 0))), addr:$dst)]>, VEX;
3106 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
3107                       "movq\t{$src, $dst|$dst, $src}",
3108                       [(store (i64 (vector_extract (v2i64 VR128:$src),
3109                                     (iPTR 0))), addr:$dst)]>;
3110
3111 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
3112           (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
3113
3114 // Store / copy lower 64-bits of a XMM register.
3115 let isAsmParserOnly = 1 in
3116 def VMOVLQ128mr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
3117                      "movq\t{$src, $dst|$dst, $src}",
3118                      [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>, VEX;
3119 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
3120                      "movq\t{$src, $dst|$dst, $src}",
3121                      [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
3122
3123 let AddedComplexity = 20, isAsmParserOnly = 1 in
3124 def VMOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3125                      "vmovq\t{$src, $dst|$dst, $src}",
3126                      [(set VR128:$dst,
3127                        (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
3128                                                  (loadi64 addr:$src))))))]>,
3129                      XS, VEX, Requires<[HasAVX]>;
3130
3131 let AddedComplexity = 20 in {
3132 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3133                      "movq\t{$src, $dst|$dst, $src}",
3134                      [(set VR128:$dst,
3135                        (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
3136                                                  (loadi64 addr:$src))))))]>,
3137                      XS, Requires<[HasSSE2]>;
3138
3139 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
3140             (MOVZQI2PQIrm addr:$src)>;
3141 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
3142             (MOVZQI2PQIrm addr:$src)>;
3143 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
3144 }
3145
3146 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
3147 // IA32 document. movq xmm1, xmm2 does clear the high bits.
3148 let isAsmParserOnly = 1, AddedComplexity = 15 in
3149 def VMOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3150                         "vmovq\t{$src, $dst|$dst, $src}",
3151                     [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
3152                       XS, VEX, Requires<[HasAVX]>;
3153 let AddedComplexity = 15 in
3154 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3155                         "movq\t{$src, $dst|$dst, $src}",
3156                     [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
3157                       XS, Requires<[HasSSE2]>;
3158
3159 let AddedComplexity = 20, isAsmParserOnly = 1 in
3160 def VMOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3161                         "vmovq\t{$src, $dst|$dst, $src}",
3162                     [(set VR128:$dst, (v2i64 (X86vzmovl
3163                                              (loadv2i64 addr:$src))))]>,
3164                       XS, VEX, Requires<[HasAVX]>;
3165 let AddedComplexity = 20 in {
3166 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3167                         "movq\t{$src, $dst|$dst, $src}",
3168                     [(set VR128:$dst, (v2i64 (X86vzmovl
3169                                              (loadv2i64 addr:$src))))]>,
3170                       XS, Requires<[HasSSE2]>;
3171
3172 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
3173             (MOVZPQILo2PQIrm addr:$src)>;
3174 }
3175
3176 // Instructions to match in the assembler
3177 let isAsmParserOnly = 1 in {
3178 def VMOVQs64rr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
3179                       "movq\t{$src, $dst|$dst, $src}", []>, VEX, VEX_W;
3180 def VMOVQd64rr : VPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
3181                       "movq\t{$src, $dst|$dst, $src}", []>, VEX, VEX_W;
3182 // Recognize "movd" with GR64 destination, but encode as a "movq"
3183 def VMOVQd64rr_alt : VPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
3184                           "movd\t{$src, $dst|$dst, $src}", []>, VEX, VEX_W;
3185 }
3186
3187 // Instructions for the disassembler
3188 // xr = XMM register
3189 // xm = mem64
3190
3191 let isAsmParserOnly = 1, Predicates = [HasAVX] in
3192 def VMOVQxrxr: I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3193                  "vmovq\t{$src, $dst|$dst, $src}", []>, VEX, XS;
3194 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3195                  "movq\t{$src, $dst|$dst, $src}", []>, XS;
3196
3197 //===---------------------------------------------------------------------===//
3198 // SSE2 - Misc Instructions
3199 //===---------------------------------------------------------------------===//
3200
3201 // Flush cache
3202 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
3203                "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
3204               TB, Requires<[HasSSE2]>;
3205
3206 // Load, store, and memory fence
3207 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
3208                "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
3209 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
3210                "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
3211 def : Pat<(X86LFence), (LFENCE)>;
3212 def : Pat<(X86MFence), (MFENCE)>;
3213
3214
3215 // Pause. This "instruction" is encoded as "rep; nop", so even though it
3216 // was introduced with SSE2, it's backward compatible.
3217 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
3218
3219 // Alias instructions that map zero vector to pxor / xorp* for sse.
3220 // We set canFoldAsLoad because this can be converted to a constant-pool
3221 // load of an all-ones value if folding it would be beneficial.
3222 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
3223     isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
3224   // FIXME: Change encoding to pseudo.
3225   def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
3226                          [(set VR128:$dst, (v4i32 immAllOnesV))]>;
3227
3228 //===---------------------------------------------------------------------===//
3229 // SSE3 - Conversion Instructions
3230 //===---------------------------------------------------------------------===//
3231
3232 // Convert Packed Double FP to Packed DW Integers
3233 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3234 // The assembler can recognize rr 256-bit instructions by seeing a ymm
3235 // register, but the same isn't true when using memory operands instead.
3236 // Provide other assembly rr and rm forms to address this explicitly.
3237 def VCVTPD2DQrr  : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3238                        "vcvtpd2dq\t{$src, $dst|$dst, $src}", []>, VEX;
3239 def VCVTPD2DQXrYr  : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
3240                        "vcvtpd2dq\t{$src, $dst|$dst, $src}", []>, VEX;
3241
3242 // XMM only
3243 def VCVTPD2DQXrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3244                       "vcvtpd2dqx\t{$src, $dst|$dst, $src}", []>, VEX;
3245 def VCVTPD2DQXrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3246                       "vcvtpd2dqx\t{$src, $dst|$dst, $src}", []>, VEX;
3247
3248 // YMM only
3249 def VCVTPD2DQYrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
3250                       "vcvtpd2dqy\t{$src, $dst|$dst, $src}", []>, VEX;
3251 def VCVTPD2DQYrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
3252                       "vcvtpd2dqy\t{$src, $dst|$dst, $src}", []>, VEX, VEX_L;
3253 }
3254
3255 def CVTPD2DQrm  : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3256                        "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
3257 def CVTPD2DQrr  : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3258                        "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
3259
3260 // Convert Packed DW Integers to Packed Double FP
3261 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3262 def VCVTDQ2PDrm  : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3263                      "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
3264 def VCVTDQ2PDrr  : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3265                      "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
3266 def VCVTDQ2PDYrm  : S3SI<0xE6, MRMSrcMem, (outs VR256:$dst), (ins f128mem:$src),
3267                      "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
3268 def VCVTDQ2PDYrr  : S3SI<0xE6, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
3269                      "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
3270 }
3271
3272 def CVTDQ2PDrm  : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3273                        "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
3274 def CVTDQ2PDrr  : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3275                        "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
3276
3277 // AVX 256-bit register conversion intrinsics
3278 def : Pat<(int_x86_avx_cvtdq2_pd_256 VR128:$src),
3279            (VCVTDQ2PDYrr VR128:$src)>;
3280 def : Pat<(int_x86_avx_cvtdq2_pd_256 (memopv4i32 addr:$src)),
3281            (VCVTDQ2PDYrm addr:$src)>;
3282
3283 def : Pat<(int_x86_avx_cvt_pd2dq_256 VR256:$src),
3284           (VCVTPD2DQYrr VR256:$src)>;
3285 def : Pat<(int_x86_avx_cvt_pd2dq_256 (memopv4f64 addr:$src)),
3286           (VCVTPD2DQYrm addr:$src)>;
3287
3288 //===---------------------------------------------------------------------===//
3289 // SSE3 - Move Instructions
3290 //===---------------------------------------------------------------------===//
3291
3292 // Replicate Single FP
3293 multiclass sse3_replicate_sfp<bits<8> op, PatFrag rep_frag, string OpcodeStr> {
3294 def rr : S3SI<op, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3295                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3296                       [(set VR128:$dst, (v4f32 (rep_frag
3297                                                 VR128:$src, (undef))))]>;
3298 def rm : S3SI<op, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3299                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3300                       [(set VR128:$dst, (rep_frag
3301                                          (memopv4f32 addr:$src), (undef)))]>;
3302 }
3303
3304 multiclass sse3_replicate_sfp_y<bits<8> op, PatFrag rep_frag,
3305                                 string OpcodeStr> {
3306 def rr : S3SI<op, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3307               !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"), []>;
3308 def rm : S3SI<op, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3309               !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"), []>;
3310 }
3311
3312 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3313   // FIXME: Merge above classes when we have patterns for the ymm version
3314   defm VMOVSHDUP  : sse3_replicate_sfp<0x16, movshdup, "vmovshdup">, VEX;
3315   defm VMOVSLDUP  : sse3_replicate_sfp<0x12, movsldup, "vmovsldup">, VEX;
3316   defm VMOVSHDUPY : sse3_replicate_sfp_y<0x16, movshdup, "vmovshdup">, VEX;
3317   defm VMOVSLDUPY : sse3_replicate_sfp_y<0x12, movsldup, "vmovsldup">, VEX;
3318 }
3319 defm MOVSHDUP : sse3_replicate_sfp<0x16, movshdup, "movshdup">;
3320 defm MOVSLDUP : sse3_replicate_sfp<0x12, movsldup, "movsldup">;
3321
3322 // Replicate Double FP
3323 multiclass sse3_replicate_dfp<string OpcodeStr> {
3324 def rr  : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3325                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3326                     [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
3327 def rm  : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
3328                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3329                     [(set VR128:$dst,
3330                       (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
3331                                       (undef))))]>;
3332 }
3333
3334 multiclass sse3_replicate_dfp_y<string OpcodeStr> {
3335 def rr  : S3DI<0x12, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3336                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3337                     []>;
3338 def rm  : S3DI<0x12, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3339                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3340                     []>;
3341 }
3342
3343 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3344   // FIXME: Merge above classes when we have patterns for the ymm version
3345   defm VMOVDDUP  : sse3_replicate_dfp<"vmovddup">, VEX;
3346   defm VMOVDDUPY : sse3_replicate_dfp_y<"vmovddup">, VEX;
3347 }
3348 defm MOVDDUP : sse3_replicate_dfp<"movddup">;
3349
3350 // Move Unaligned Integer
3351 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3352   def VLDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3353                      "vlddqu\t{$src, $dst|$dst, $src}",
3354                      [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>, VEX;
3355   def VLDDQUYrm : S3DI<0xF0, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
3356                      "vlddqu\t{$src, $dst|$dst, $src}", []>, VEX;
3357 }
3358 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3359                    "lddqu\t{$src, $dst|$dst, $src}",
3360                    [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
3361
3362 def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
3363                    (undef)),
3364           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3365
3366 // Several Move patterns
3367 let AddedComplexity = 5 in {
3368 def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
3369           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3370 def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
3371           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3372 def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
3373           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3374 def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
3375           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3376 }
3377
3378 // vector_shuffle v1, <undef> <1, 1, 3, 3>
3379 let AddedComplexity = 15 in
3380 def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
3381           (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
3382 let AddedComplexity = 20 in
3383 def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
3384           (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
3385
3386 // vector_shuffle v1, <undef> <0, 0, 2, 2>
3387 let AddedComplexity = 15 in
3388   def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
3389             (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
3390 let AddedComplexity = 20 in
3391   def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
3392             (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
3393
3394 //===---------------------------------------------------------------------===//
3395 // SSE3 - Arithmetic
3396 //===---------------------------------------------------------------------===//
3397
3398 multiclass sse3_addsub<Intrinsic Int, string OpcodeStr, RegisterClass RC,
3399                        X86MemOperand x86memop, bit Is2Addr = 1> {
3400   def rr : I<0xD0, MRMSrcReg,
3401        (outs RC:$dst), (ins RC:$src1, RC:$src2),
3402        !if(Is2Addr,
3403            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3404            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3405        [(set RC:$dst, (Int RC:$src1, RC:$src2))]>;
3406   def rm : I<0xD0, MRMSrcMem,
3407        (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
3408        !if(Is2Addr,
3409            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3410            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3411        [(set RC:$dst, (Int RC:$src1, (memop addr:$src2)))]>;
3412 }
3413
3414 let isAsmParserOnly = 1, Predicates = [HasAVX],
3415   ExeDomain = SSEPackedDouble in {
3416   defm VADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "vaddsubps", VR128,
3417                                f128mem, 0>, XD, VEX_4V;
3418   defm VADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "vaddsubpd", VR128,
3419                                f128mem, 0>, OpSize, VEX_4V;
3420   defm VADDSUBPSY : sse3_addsub<int_x86_avx_addsub_ps_256, "vaddsubps", VR256,
3421                                f256mem, 0>, XD, VEX_4V;
3422   defm VADDSUBPDY : sse3_addsub<int_x86_avx_addsub_pd_256, "vaddsubpd", VR256,
3423                                f256mem, 0>, OpSize, VEX_4V;
3424 }
3425 let Constraints = "$src1 = $dst", Predicates = [HasSSE3],
3426     ExeDomain = SSEPackedDouble in {
3427   defm ADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "addsubps", VR128,
3428                               f128mem>, XD;
3429   defm ADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "addsubpd", VR128,
3430                               f128mem>, TB, OpSize;
3431 }
3432
3433 //===---------------------------------------------------------------------===//
3434 // SSE3 Instructions
3435 //===---------------------------------------------------------------------===//
3436
3437 // Horizontal ops
3438 multiclass S3D_Int<bits<8> o, string OpcodeStr, ValueType vt, RegisterClass RC,
3439                    X86MemOperand x86memop, Intrinsic IntId, bit Is2Addr = 1> {
3440   def rr : S3DI<o, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
3441        !if(Is2Addr,
3442          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3443          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3444       [(set RC:$dst, (vt (IntId RC:$src1, RC:$src2)))]>;
3445
3446   def rm : S3DI<o, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
3447        !if(Is2Addr,
3448          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3449          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3450       [(set RC:$dst, (vt (IntId RC:$src1, (memop addr:$src2))))]>;
3451 }
3452 multiclass S3_Int<bits<8> o, string OpcodeStr, ValueType vt, RegisterClass RC,
3453                   X86MemOperand x86memop, Intrinsic IntId, bit Is2Addr = 1> {
3454   def rr : S3I<o, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
3455        !if(Is2Addr,
3456          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3457          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3458       [(set RC:$dst, (vt (IntId RC:$src1, RC:$src2)))]>;
3459
3460   def rm : S3I<o, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
3461        !if(Is2Addr,
3462          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3463          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3464       [(set RC:$dst, (vt (IntId RC:$src1, (memop addr:$src2))))]>;
3465 }
3466
3467 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3468   defm VHADDPS  : S3D_Int<0x7C, "vhaddps", v4f32, VR128, f128mem,
3469                           int_x86_sse3_hadd_ps, 0>, VEX_4V;
3470   defm VHADDPD  : S3_Int <0x7C, "vhaddpd", v2f64, VR128, f128mem,
3471                           int_x86_sse3_hadd_pd, 0>, VEX_4V;
3472   defm VHSUBPS  : S3D_Int<0x7D, "vhsubps", v4f32, VR128, f128mem,
3473                           int_x86_sse3_hsub_ps, 0>, VEX_4V;
3474   defm VHSUBPD  : S3_Int <0x7D, "vhsubpd", v2f64, VR128, f128mem,
3475                           int_x86_sse3_hsub_pd, 0>, VEX_4V;
3476   defm VHADDPSY : S3D_Int<0x7C, "vhaddps", v8f32, VR256, f256mem,
3477                           int_x86_avx_hadd_ps_256, 0>, VEX_4V;
3478   defm VHADDPDY : S3_Int <0x7C, "vhaddpd", v4f64, VR256, f256mem,
3479                           int_x86_avx_hadd_pd_256, 0>, VEX_4V;
3480   defm VHSUBPSY : S3D_Int<0x7D, "vhsubps", v8f32, VR256, f256mem,
3481                           int_x86_avx_hsub_ps_256, 0>, VEX_4V;
3482   defm VHSUBPDY : S3_Int <0x7D, "vhsubpd", v4f64, VR256, f256mem,
3483                           int_x86_avx_hsub_pd_256, 0>, VEX_4V;
3484 }
3485
3486 let Constraints = "$src1 = $dst" in {
3487   defm HADDPS : S3D_Int<0x7C, "haddps", v4f32, VR128, f128mem,
3488                         int_x86_sse3_hadd_ps>;
3489   defm HADDPD : S3_Int<0x7C, "haddpd", v2f64, VR128, f128mem,
3490                        int_x86_sse3_hadd_pd>;
3491   defm HSUBPS : S3D_Int<0x7D, "hsubps", v4f32, VR128, f128mem,
3492                         int_x86_sse3_hsub_ps>;
3493   defm HSUBPD : S3_Int<0x7D, "hsubpd", v2f64, VR128, f128mem,
3494                        int_x86_sse3_hsub_pd>;
3495 }
3496
3497 //===---------------------------------------------------------------------===//
3498 // SSSE3 - Packed Absolute Instructions
3499 //===---------------------------------------------------------------------===//
3500
3501 /// SS3I_unop_rm_int - Simple SSSE3 unary op whose type can be v*{i8,i16,i32}.
3502 multiclass SS3I_unop_rm_int<bits<8> opc, string OpcodeStr,
3503                             PatFrag mem_frag64, PatFrag mem_frag128,
3504                             Intrinsic IntId64, Intrinsic IntId128> {
3505   def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
3506                    !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3507                    [(set VR64:$dst, (IntId64 VR64:$src))]>;
3508
3509   def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
3510                    !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3511                    [(set VR64:$dst,
3512                      (IntId64 (bitconvert (mem_frag64 addr:$src))))]>;
3513
3514   def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
3515                     (ins VR128:$src),
3516                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3517                     [(set VR128:$dst, (IntId128 VR128:$src))]>,
3518                     OpSize;
3519
3520   def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
3521                     (ins i128mem:$src),
3522                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3523                     [(set VR128:$dst,
3524                       (IntId128
3525                        (bitconvert (mem_frag128 addr:$src))))]>, OpSize;
3526 }
3527
3528 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3529   defm VPABSB  : SS3I_unop_rm_int<0x1C, "vpabsb", memopv8i8, memopv16i8,
3530                                   int_x86_ssse3_pabs_b,
3531                                   int_x86_ssse3_pabs_b_128>, VEX;
3532   defm VPABSW  : SS3I_unop_rm_int<0x1D, "vpabsw", memopv4i16, memopv8i16,
3533                                   int_x86_ssse3_pabs_w,
3534                                   int_x86_ssse3_pabs_w_128>, VEX;
3535   defm VPABSD  : SS3I_unop_rm_int<0x1E, "vpabsd", memopv2i32, memopv4i32,
3536                                   int_x86_ssse3_pabs_d,
3537                                   int_x86_ssse3_pabs_d_128>, VEX;
3538 }
3539
3540 defm PABSB       : SS3I_unop_rm_int<0x1C, "pabsb", memopv8i8, memopv16i8,
3541                                     int_x86_ssse3_pabs_b,
3542                                     int_x86_ssse3_pabs_b_128>;
3543 defm PABSW       : SS3I_unop_rm_int<0x1D, "pabsw", memopv4i16, memopv8i16,
3544                                     int_x86_ssse3_pabs_w,
3545                                     int_x86_ssse3_pabs_w_128>;
3546 defm PABSD       : SS3I_unop_rm_int<0x1E, "pabsd", memopv2i32, memopv4i32,
3547                                     int_x86_ssse3_pabs_d,
3548                                     int_x86_ssse3_pabs_d_128>;
3549
3550 //===---------------------------------------------------------------------===//
3551 // SSSE3 - Packed Binary Operator Instructions
3552 //===---------------------------------------------------------------------===//
3553
3554 /// SS3I_binop_rm_int - Simple SSSE3 bin op whose type can be v*{i8,i16,i32}.
3555 multiclass SS3I_binop_rm_int<bits<8> opc, string OpcodeStr,
3556                              PatFrag mem_frag64, PatFrag mem_frag128,
3557                              Intrinsic IntId64, Intrinsic IntId128,
3558                              bit Is2Addr = 1> {
3559   let isCommutable = 1 in
3560   def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
3561        (ins VR64:$src1, VR64:$src2),
3562        !if(Is2Addr,
3563          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3564          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3565        [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]>;
3566   def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
3567        (ins VR64:$src1, i64mem:$src2),
3568        !if(Is2Addr,
3569          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3570          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3571        [(set VR64:$dst,
3572          (IntId64 VR64:$src1,
3573           (bitconvert (memopv8i8 addr:$src2))))]>;
3574
3575   let isCommutable = 1 in
3576   def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
3577        (ins VR128:$src1, VR128:$src2),
3578        !if(Is2Addr,
3579          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3580          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3581        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3582        OpSize;
3583   def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
3584        (ins VR128:$src1, i128mem:$src2),
3585        !if(Is2Addr,
3586          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3587          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3588        [(set VR128:$dst,
3589          (IntId128 VR128:$src1,
3590           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3591 }
3592
3593 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3594 let isCommutable = 0 in {
3595   defm VPHADDW    : SS3I_binop_rm_int<0x01, "vphaddw", memopv4i16, memopv8i16,
3596                                       int_x86_ssse3_phadd_w,
3597                                       int_x86_ssse3_phadd_w_128, 0>, VEX_4V;
3598   defm VPHADDD    : SS3I_binop_rm_int<0x02, "vphaddd", memopv2i32, memopv4i32,
3599                                       int_x86_ssse3_phadd_d,
3600                                       int_x86_ssse3_phadd_d_128, 0>, VEX_4V;
3601   defm VPHADDSW   : SS3I_binop_rm_int<0x03, "vphaddsw", memopv4i16, memopv8i16,
3602                                       int_x86_ssse3_phadd_sw,
3603                                       int_x86_ssse3_phadd_sw_128, 0>, VEX_4V;
3604   defm VPHSUBW    : SS3I_binop_rm_int<0x05, "vphsubw", memopv4i16, memopv8i16,
3605                                       int_x86_ssse3_phsub_w,
3606                                       int_x86_ssse3_phsub_w_128, 0>, VEX_4V;
3607   defm VPHSUBD    : SS3I_binop_rm_int<0x06, "vphsubd", memopv2i32, memopv4i32,
3608                                       int_x86_ssse3_phsub_d,
3609                                       int_x86_ssse3_phsub_d_128, 0>, VEX_4V;
3610   defm VPHSUBSW   : SS3I_binop_rm_int<0x07, "vphsubsw", memopv4i16, memopv8i16,
3611                                       int_x86_ssse3_phsub_sw,
3612                                       int_x86_ssse3_phsub_sw_128, 0>, VEX_4V;
3613   defm VPMADDUBSW : SS3I_binop_rm_int<0x04, "vpmaddubsw", memopv8i8, memopv16i8,
3614                                       int_x86_ssse3_pmadd_ub_sw,
3615                                       int_x86_ssse3_pmadd_ub_sw_128, 0>, VEX_4V;
3616   defm VPSHUFB    : SS3I_binop_rm_int<0x00, "vpshufb", memopv8i8, memopv16i8,
3617                                       int_x86_ssse3_pshuf_b,
3618                                       int_x86_ssse3_pshuf_b_128, 0>, VEX_4V;
3619   defm VPSIGNB    : SS3I_binop_rm_int<0x08, "vpsignb", memopv8i8, memopv16i8,
3620                                       int_x86_ssse3_psign_b,
3621                                       int_x86_ssse3_psign_b_128, 0>, VEX_4V;
3622   defm VPSIGNW    : SS3I_binop_rm_int<0x09, "vpsignw", memopv4i16, memopv8i16,
3623                                       int_x86_ssse3_psign_w,
3624                                       int_x86_ssse3_psign_w_128, 0>, VEX_4V;
3625   defm VPSIGND    : SS3I_binop_rm_int<0x0A, "vpsignd", memopv2i32, memopv4i32,
3626                                       int_x86_ssse3_psign_d,
3627                                       int_x86_ssse3_psign_d_128, 0>, VEX_4V;
3628 }
3629 defm VPMULHRSW    : SS3I_binop_rm_int<0x0B, "vpmulhrsw", memopv4i16, memopv8i16,
3630                                       int_x86_ssse3_pmul_hr_sw,
3631                                       int_x86_ssse3_pmul_hr_sw_128, 0>, VEX_4V;
3632 }
3633
3634 // None of these have i8 immediate fields.
3635 let ImmT = NoImm, Constraints = "$src1 = $dst" in {
3636 let isCommutable = 0 in {
3637   defm PHADDW    : SS3I_binop_rm_int<0x01, "phaddw", memopv4i16, memopv8i16,
3638                                      int_x86_ssse3_phadd_w,
3639                                      int_x86_ssse3_phadd_w_128>;
3640   defm PHADDD    : SS3I_binop_rm_int<0x02, "phaddd", memopv2i32, memopv4i32,
3641                                      int_x86_ssse3_phadd_d,
3642                                      int_x86_ssse3_phadd_d_128>;
3643   defm PHADDSW   : SS3I_binop_rm_int<0x03, "phaddsw", memopv4i16, memopv8i16,
3644                                      int_x86_ssse3_phadd_sw,
3645                                      int_x86_ssse3_phadd_sw_128>;
3646   defm PHSUBW    : SS3I_binop_rm_int<0x05, "phsubw", memopv4i16, memopv8i16,
3647                                      int_x86_ssse3_phsub_w,
3648                                      int_x86_ssse3_phsub_w_128>;
3649   defm PHSUBD    : SS3I_binop_rm_int<0x06, "phsubd", memopv2i32, memopv4i32,
3650                                      int_x86_ssse3_phsub_d,
3651                                      int_x86_ssse3_phsub_d_128>;
3652   defm PHSUBSW   : SS3I_binop_rm_int<0x07, "phsubsw", memopv4i16, memopv8i16,
3653                                      int_x86_ssse3_phsub_sw,
3654                                      int_x86_ssse3_phsub_sw_128>;
3655   defm PMADDUBSW : SS3I_binop_rm_int<0x04, "pmaddubsw", memopv8i8, memopv16i8,
3656                                      int_x86_ssse3_pmadd_ub_sw,
3657                                      int_x86_ssse3_pmadd_ub_sw_128>;
3658   defm PSHUFB    : SS3I_binop_rm_int<0x00, "pshufb", memopv8i8, memopv16i8,
3659                                      int_x86_ssse3_pshuf_b,
3660                                      int_x86_ssse3_pshuf_b_128>;
3661   defm PSIGNB    : SS3I_binop_rm_int<0x08, "psignb", memopv8i8, memopv16i8,
3662                                      int_x86_ssse3_psign_b,
3663                                      int_x86_ssse3_psign_b_128>;
3664   defm PSIGNW    : SS3I_binop_rm_int<0x09, "psignw", memopv4i16, memopv8i16,
3665                                      int_x86_ssse3_psign_w,
3666                                      int_x86_ssse3_psign_w_128>;
3667   defm PSIGND    : SS3I_binop_rm_int<0x0A, "psignd", memopv2i32, memopv4i32,
3668                                        int_x86_ssse3_psign_d,
3669                                        int_x86_ssse3_psign_d_128>;
3670 }
3671 defm PMULHRSW    : SS3I_binop_rm_int<0x0B, "pmulhrsw", memopv4i16, memopv8i16,
3672                                      int_x86_ssse3_pmul_hr_sw,
3673                                      int_x86_ssse3_pmul_hr_sw_128>;
3674 }
3675
3676 def : Pat<(X86pshufb VR128:$src, VR128:$mask),
3677           (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
3678 def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
3679           (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
3680
3681 //===---------------------------------------------------------------------===//
3682 // SSSE3 - Packed Align Instruction Patterns
3683 //===---------------------------------------------------------------------===//
3684
3685 multiclass sse3_palign<string asm, bit Is2Addr = 1> {
3686   def R64rr  : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
3687       (ins VR64:$src1, VR64:$src2, i8imm:$src3),
3688       !if(Is2Addr,
3689         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3690         !strconcat(asm,
3691                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3692       []>;
3693   def R64rm  : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
3694       (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
3695       !if(Is2Addr,
3696         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3697         !strconcat(asm,
3698                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3699       []>;
3700
3701   def R128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
3702       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3703       !if(Is2Addr,
3704         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3705         !strconcat(asm,
3706                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3707       []>, OpSize;
3708   def R128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
3709       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3710       !if(Is2Addr,
3711         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3712         !strconcat(asm,
3713                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3714       []>, OpSize;
3715 }
3716
3717 let isAsmParserOnly = 1, Predicates = [HasAVX] in
3718   defm VPALIGN : sse3_palign<"vpalignr", 0>, VEX_4V;
3719 let Constraints = "$src1 = $dst" in
3720   defm PALIGN : sse3_palign<"palignr">;
3721
3722 let AddedComplexity = 5 in {
3723
3724 def : Pat<(v1i64 (palign:$src3 VR64:$src1, VR64:$src2)),
3725           (PALIGNR64rr VR64:$src2, VR64:$src1,
3726                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3727           Requires<[HasSSSE3]>;
3728 def : Pat<(v2i32 (palign:$src3 VR64:$src1, VR64:$src2)),
3729           (PALIGNR64rr VR64:$src2, VR64:$src1,
3730                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3731           Requires<[HasSSSE3]>;
3732 def : Pat<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
3733           (PALIGNR64rr VR64:$src2, VR64:$src1,
3734                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3735           Requires<[HasSSSE3]>;
3736 def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
3737           (PALIGNR64rr VR64:$src2, VR64:$src1,
3738                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3739           Requires<[HasSSSE3]>;
3740
3741 def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
3742           (PALIGNR128rr VR128:$src2, VR128:$src1,
3743                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3744       Requires<[HasSSSE3]>;
3745 def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
3746           (PALIGNR128rr VR128:$src2, VR128:$src1,
3747                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3748       Requires<[HasSSSE3]>;
3749 def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
3750           (PALIGNR128rr VR128:$src2, VR128:$src1,
3751                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3752       Requires<[HasSSSE3]>;
3753 def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
3754           (PALIGNR128rr VR128:$src2, VR128:$src1,
3755                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3756       Requires<[HasSSSE3]>;
3757 }
3758
3759 //===---------------------------------------------------------------------===//
3760 // SSSE3 Misc Instructions
3761 //===---------------------------------------------------------------------===//
3762
3763 // Thread synchronization
3764 def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
3765                 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
3766 def MWAIT   : I<0x01, MRM_C9, (outs), (ins), "mwait",
3767                 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
3768
3769 //===---------------------------------------------------------------------===//
3770 // Non-Instruction Patterns
3771 //===---------------------------------------------------------------------===//
3772
3773 // extload f32 -> f64.  This matches load+fextend because we have a hack in
3774 // the isel (PreprocessForFPConvert) that can introduce loads after dag
3775 // combine.
3776 // Since these loads aren't folded into the fextend, we have to match it
3777 // explicitly here.
3778 let Predicates = [HasSSE2] in
3779  def : Pat<(fextend (loadf32 addr:$src)),
3780            (CVTSS2SDrm addr:$src)>;
3781
3782 // bit_convert
3783 let Predicates = [HasSSE2] in {
3784   def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
3785   def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
3786   def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
3787   def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
3788   def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
3789   def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
3790   def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
3791   def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
3792   def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
3793   def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
3794   def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
3795   def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
3796   def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
3797   def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
3798   def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
3799   def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
3800   def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
3801   def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
3802   def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
3803   def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
3804   def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
3805   def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
3806   def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
3807   def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
3808   def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
3809   def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
3810   def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
3811   def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
3812   def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
3813   def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
3814 }
3815
3816 // Move scalar to XMM zero-extended
3817 // movd to XMM register zero-extends
3818 let AddedComplexity = 15 in {
3819 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
3820 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
3821           (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
3822 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
3823           (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
3824 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
3825           (MOVSSrr (v4f32 (V_SET0PS)),
3826                    (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
3827 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
3828           (MOVSSrr (v4i32 (V_SET0PI)),
3829                    (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
3830 }
3831
3832 // Splat v2f64 / v2i64
3833 let AddedComplexity = 10 in {
3834 def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
3835           (UNPCKLPDrr VR128:$src, VR128:$src)>,   Requires<[HasSSE2]>;
3836 def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
3837           (UNPCKHPDrr VR128:$src, VR128:$src)>,   Requires<[HasSSE2]>;
3838 def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
3839           (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3840 def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
3841           (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3842 }
3843
3844 // Special unary SHUFPSrri case.
3845 def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
3846           (SHUFPSrri VR128:$src1, VR128:$src1,
3847                      (SHUFFLE_get_shuf_imm VR128:$src3))>;
3848 let AddedComplexity = 5 in
3849 def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
3850           (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3851       Requires<[HasSSE2]>;
3852 // Special unary SHUFPDrri case.
3853 def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
3854           (SHUFPDrri VR128:$src1, VR128:$src1,
3855                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3856       Requires<[HasSSE2]>;
3857 // Special unary SHUFPDrri case.
3858 def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
3859           (SHUFPDrri VR128:$src1, VR128:$src1,
3860                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3861       Requires<[HasSSE2]>;
3862 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
3863 def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
3864           (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3865       Requires<[HasSSE2]>;
3866
3867 // Special binary v4i32 shuffle cases with SHUFPS.
3868 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
3869           (SHUFPSrri VR128:$src1, VR128:$src2,
3870                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3871            Requires<[HasSSE2]>;
3872 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
3873           (SHUFPSrmi VR128:$src1, addr:$src2,
3874                     (SHUFFLE_get_shuf_imm VR128:$src3))>,
3875            Requires<[HasSSE2]>;
3876 // Special binary v2i64 shuffle cases using SHUFPDrri.
3877 def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
3878           (SHUFPDrri VR128:$src1, VR128:$src2,
3879                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3880           Requires<[HasSSE2]>;
3881
3882 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
3883 let AddedComplexity = 15 in {
3884 def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
3885           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3886           Requires<[OptForSpeed, HasSSE2]>;
3887 def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
3888           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3889           Requires<[OptForSpeed, HasSSE2]>;
3890 }
3891 let AddedComplexity = 10 in {
3892 def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
3893           (UNPCKLPSrr VR128:$src, VR128:$src)>;
3894 def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
3895           (PUNPCKLBWrr VR128:$src, VR128:$src)>;
3896 def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
3897           (PUNPCKLWDrr VR128:$src, VR128:$src)>;
3898 def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
3899           (PUNPCKLDQrr VR128:$src, VR128:$src)>;
3900 }
3901
3902 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
3903 let AddedComplexity = 15 in {
3904 def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
3905           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3906           Requires<[OptForSpeed, HasSSE2]>;
3907 def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
3908           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3909           Requires<[OptForSpeed, HasSSE2]>;
3910 }
3911 let AddedComplexity = 10 in {
3912 def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
3913           (UNPCKHPSrr VR128:$src, VR128:$src)>;
3914 def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
3915           (PUNPCKHBWrr VR128:$src, VR128:$src)>;
3916 def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
3917           (PUNPCKHWDrr VR128:$src, VR128:$src)>;
3918 def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
3919           (PUNPCKHDQrr VR128:$src, VR128:$src)>;
3920 }
3921
3922 let AddedComplexity = 20 in {
3923 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
3924 def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
3925           (MOVLHPSrr VR128:$src1, VR128:$src2)>;
3926
3927 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
3928 def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
3929           (MOVHLPSrr VR128:$src1, VR128:$src2)>;
3930
3931 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
3932 def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
3933           (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3934 def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
3935           (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3936 }
3937
3938 let AddedComplexity = 20 in {
3939 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
3940 def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
3941           (MOVLPSrm VR128:$src1, addr:$src2)>;
3942 def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
3943           (MOVLPDrm VR128:$src1, addr:$src2)>;
3944 def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
3945           (MOVLPSrm VR128:$src1, addr:$src2)>;
3946 def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
3947           (MOVLPDrm VR128:$src1, addr:$src2)>;
3948 }
3949
3950 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3951 def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3952           (MOVLPSmr addr:$src1, VR128:$src2)>;
3953 def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3954           (MOVLPDmr addr:$src1, VR128:$src2)>;
3955 def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3956                  addr:$src1),
3957           (MOVLPSmr addr:$src1, VR128:$src2)>;
3958 def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3959           (MOVLPDmr addr:$src1, VR128:$src2)>;
3960
3961 let AddedComplexity = 15 in {
3962 // Setting the lowest element in the vector.
3963 def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
3964           (MOVSSrr (v4i32 VR128:$src1),
3965                    (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
3966 def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
3967           (MOVSDrr (v2i64 VR128:$src1),
3968                    (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
3969
3970 // vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
3971 def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
3972           (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3973       Requires<[HasSSE2]>;
3974 def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
3975           (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3976       Requires<[HasSSE2]>;
3977 }
3978
3979 // vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3980 // fall back to this for SSE1)
3981 def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
3982           (SHUFPSrri VR128:$src2, VR128:$src1,
3983                      (SHUFFLE_get_shuf_imm VR128:$src3))>;
3984
3985 // Set lowest element and zero upper elements.
3986 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
3987           (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3988
3989 // Some special case pandn patterns.
3990 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3991                   VR128:$src2)),
3992           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3993 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3994                   VR128:$src2)),
3995           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3996 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3997                   VR128:$src2)),
3998           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3999
4000 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
4001                   (memop addr:$src2))),
4002           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
4003 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
4004                   (memop addr:$src2))),
4005           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
4006 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
4007                   (memop addr:$src2))),
4008           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
4009
4010 // vector -> vector casts
4011 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
4012           (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
4013 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
4014           (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
4015 def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
4016           (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
4017 def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
4018           (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
4019
4020 // Use movaps / movups for SSE integer load / store (one byte shorter).
4021 def : Pat<(alignedloadv4i32 addr:$src),
4022           (MOVAPSrm addr:$src)>;
4023 def : Pat<(loadv4i32 addr:$src),
4024           (MOVUPSrm addr:$src)>;
4025 def : Pat<(alignedloadv2i64 addr:$src),
4026           (MOVAPSrm addr:$src)>;
4027 def : Pat<(loadv2i64 addr:$src),
4028           (MOVUPSrm addr:$src)>;
4029
4030 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
4031           (MOVAPSmr addr:$dst, VR128:$src)>;
4032 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
4033           (MOVAPSmr addr:$dst, VR128:$src)>;
4034 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
4035           (MOVAPSmr addr:$dst, VR128:$src)>;
4036 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
4037           (MOVAPSmr addr:$dst, VR128:$src)>;
4038 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
4039           (MOVUPSmr addr:$dst, VR128:$src)>;
4040 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
4041           (MOVUPSmr addr:$dst, VR128:$src)>;
4042 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
4043           (MOVUPSmr addr:$dst, VR128:$src)>;
4044 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
4045           (MOVUPSmr addr:$dst, VR128:$src)>;
4046
4047 //===----------------------------------------------------------------------===//
4048 // SSE4.1 - Packed Move with Sign/Zero Extend
4049 //===----------------------------------------------------------------------===//
4050
4051 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
4052   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4053                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4054                  [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
4055
4056   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
4057                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4058        [(set VR128:$dst,
4059          (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
4060        OpSize;
4061 }
4062
4063 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4064 defm VPMOVSXBW : SS41I_binop_rm_int8<0x20, "vpmovsxbw", int_x86_sse41_pmovsxbw>,
4065                                      VEX;
4066 defm VPMOVSXWD : SS41I_binop_rm_int8<0x23, "vpmovsxwd", int_x86_sse41_pmovsxwd>,
4067                                      VEX;
4068 defm VPMOVSXDQ : SS41I_binop_rm_int8<0x25, "vpmovsxdq", int_x86_sse41_pmovsxdq>,
4069                                      VEX;
4070 defm VPMOVZXBW : SS41I_binop_rm_int8<0x30, "vpmovzxbw", int_x86_sse41_pmovzxbw>,
4071                                      VEX;
4072 defm VPMOVZXWD : SS41I_binop_rm_int8<0x33, "vpmovzxwd", int_x86_sse41_pmovzxwd>,
4073                                      VEX;
4074 defm VPMOVZXDQ : SS41I_binop_rm_int8<0x35, "vpmovzxdq", int_x86_sse41_pmovzxdq>,
4075                                      VEX;
4076 }
4077
4078 defm PMOVSXBW   : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
4079 defm PMOVSXWD   : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
4080 defm PMOVSXDQ   : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
4081 defm PMOVZXBW   : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
4082 defm PMOVZXWD   : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
4083 defm PMOVZXDQ   : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
4084
4085 // Common patterns involving scalar load.
4086 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
4087           (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
4088 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
4089           (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
4090
4091 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
4092           (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
4093 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
4094           (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
4095
4096 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
4097           (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
4098 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
4099           (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
4100
4101 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
4102           (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
4103 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
4104           (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
4105
4106 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
4107           (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
4108 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
4109           (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
4110
4111 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
4112           (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
4113 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
4114           (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
4115
4116
4117 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
4118   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4119                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4120                  [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
4121
4122   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
4123                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4124        [(set VR128:$dst,
4125          (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
4126           OpSize;
4127 }
4128
4129 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4130 defm VPMOVSXBD : SS41I_binop_rm_int4<0x21, "vpmovsxbd", int_x86_sse41_pmovsxbd>,
4131                                      VEX;
4132 defm VPMOVSXWQ : SS41I_binop_rm_int4<0x24, "vpmovsxwq", int_x86_sse41_pmovsxwq>,
4133                                      VEX;
4134 defm VPMOVZXBD : SS41I_binop_rm_int4<0x31, "vpmovzxbd", int_x86_sse41_pmovzxbd>,
4135                                      VEX;
4136 defm VPMOVZXWQ : SS41I_binop_rm_int4<0x34, "vpmovzxwq", int_x86_sse41_pmovzxwq>,
4137                                      VEX;
4138 }
4139
4140 defm PMOVSXBD   : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
4141 defm PMOVSXWQ   : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
4142 defm PMOVZXBD   : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
4143 defm PMOVZXWQ   : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
4144
4145 // Common patterns involving scalar load
4146 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
4147           (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
4148 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
4149           (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
4150
4151 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
4152           (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
4153 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
4154           (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
4155
4156
4157 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
4158   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4159                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4160                  [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
4161
4162   // Expecting a i16 load any extended to i32 value.
4163   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
4164                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4165                  [(set VR128:$dst, (IntId (bitconvert
4166                      (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
4167                  OpSize;
4168 }
4169
4170 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4171 defm VPMOVSXBQ : SS41I_binop_rm_int2<0x22, "vpmovsxbq", int_x86_sse41_pmovsxbq>,
4172                                      VEX;
4173 defm VPMOVZXBQ : SS41I_binop_rm_int2<0x32, "vpmovzxbq", int_x86_sse41_pmovzxbq>,
4174                                      VEX;
4175 }
4176 defm PMOVSXBQ   : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
4177 defm PMOVZXBQ   : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
4178
4179 // Common patterns involving scalar load
4180 def : Pat<(int_x86_sse41_pmovsxbq
4181             (bitconvert (v4i32 (X86vzmovl
4182                              (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
4183           (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
4184
4185 def : Pat<(int_x86_sse41_pmovzxbq
4186             (bitconvert (v4i32 (X86vzmovl
4187                              (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
4188           (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
4189
4190 //===----------------------------------------------------------------------===//
4191 // SSE4.1 - Extract Instructions
4192 //===----------------------------------------------------------------------===//
4193
4194 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
4195 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
4196   def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
4197                  (ins VR128:$src1, i32i8imm:$src2),
4198                  !strconcat(OpcodeStr,
4199                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4200                  [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
4201                  OpSize;
4202   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4203                  (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
4204                  !strconcat(OpcodeStr,
4205                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4206                  []>, OpSize;
4207 // FIXME:
4208 // There's an AssertZext in the way of writing the store pattern
4209 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
4210 }
4211
4212 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4213   defm VPEXTRB : SS41I_extract8<0x14, "vpextrb">, VEX;
4214   def  VPEXTRBrr64 : SS4AIi8<0x14, MRMDestReg, (outs GR64:$dst),
4215          (ins VR128:$src1, i32i8imm:$src2),
4216          "vpextrb\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>, OpSize, VEX;
4217 }
4218
4219 defm PEXTRB      : SS41I_extract8<0x14, "pextrb">;
4220
4221
4222 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
4223 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
4224   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4225                  (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
4226                  !strconcat(OpcodeStr,
4227                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4228                  []>, OpSize;
4229 // FIXME:
4230 // There's an AssertZext in the way of writing the store pattern
4231 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
4232 }
4233
4234 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4235   defm VPEXTRW : SS41I_extract16<0x15, "vpextrw">, VEX;
4236
4237 defm PEXTRW      : SS41I_extract16<0x15, "pextrw">;
4238
4239
4240 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
4241 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
4242   def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
4243                  (ins VR128:$src1, i32i8imm:$src2),
4244                  !strconcat(OpcodeStr,
4245                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4246                  [(set GR32:$dst,
4247                   (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
4248   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4249                  (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
4250                  !strconcat(OpcodeStr,
4251                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4252                  [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
4253                           addr:$dst)]>, OpSize;
4254 }
4255
4256 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4257   defm VPEXTRD : SS41I_extract32<0x16, "vpextrd">, VEX;
4258
4259 defm PEXTRD      : SS41I_extract32<0x16, "pextrd">;
4260
4261 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
4262 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
4263   def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
4264                  (ins VR128:$src1, i32i8imm:$src2),
4265                  !strconcat(OpcodeStr,
4266                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4267                  [(set GR64:$dst,
4268                   (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
4269   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4270                  (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
4271                  !strconcat(OpcodeStr,
4272                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4273                  [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
4274                           addr:$dst)]>, OpSize, REX_W;
4275 }
4276
4277 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4278   defm VPEXTRQ : SS41I_extract64<0x16, "vpextrq">, VEX, VEX_W;
4279
4280 defm PEXTRQ      : SS41I_extract64<0x16, "pextrq">;
4281
4282 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
4283 /// destination
4284 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
4285   def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
4286                  (ins VR128:$src1, i32i8imm:$src2),
4287                  !strconcat(OpcodeStr,
4288                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4289                  [(set GR32:$dst,
4290                     (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
4291            OpSize;
4292   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4293                  (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
4294                  !strconcat(OpcodeStr,
4295                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4296                  [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
4297                           addr:$dst)]>, OpSize;
4298 }
4299
4300 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4301   defm VEXTRACTPS : SS41I_extractf32<0x17, "vextractps">, VEX;
4302   def VEXTRACTPSrr64 : SS4AIi8<0x17, MRMDestReg, (outs GR64:$dst),
4303                   (ins VR128:$src1, i32i8imm:$src2),
4304                   "vextractps \t{$src2, $src1, $dst|$dst, $src1, $src2}",
4305                   []>, OpSize, VEX;
4306 }
4307 defm EXTRACTPS   : SS41I_extractf32<0x17, "extractps">;
4308
4309 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
4310 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
4311                                               imm:$src2))),
4312                  addr:$dst),
4313           (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
4314          Requires<[HasSSE41]>;
4315
4316 //===----------------------------------------------------------------------===//
4317 // SSE4.1 - Insert Instructions
4318 //===----------------------------------------------------------------------===//
4319
4320 multiclass SS41I_insert8<bits<8> opc, string asm, bit Is2Addr = 1> {
4321   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
4322       (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
4323       !if(Is2Addr,
4324         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4325         !strconcat(asm,
4326                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4327       [(set VR128:$dst,
4328         (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
4329   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
4330       (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
4331       !if(Is2Addr,
4332         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4333         !strconcat(asm,
4334                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4335       [(set VR128:$dst,
4336         (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
4337                    imm:$src3))]>, OpSize;
4338 }
4339
4340 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4341   defm VPINSRB : SS41I_insert8<0x20, "vpinsrb", 0>, VEX_4V;
4342 let Constraints = "$src1 = $dst" in
4343   defm PINSRB  : SS41I_insert8<0x20, "pinsrb">;
4344
4345 multiclass SS41I_insert32<bits<8> opc, string asm, bit Is2Addr = 1> {
4346   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
4347       (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
4348       !if(Is2Addr,
4349         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4350         !strconcat(asm,
4351                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4352       [(set VR128:$dst,
4353         (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
4354       OpSize;
4355   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
4356       (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
4357       !if(Is2Addr,
4358         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4359         !strconcat(asm,
4360                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4361       [(set VR128:$dst,
4362         (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
4363                           imm:$src3)))]>, OpSize;
4364 }
4365
4366 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4367   defm VPINSRD : SS41I_insert32<0x22, "vpinsrd", 0>, VEX_4V;
4368 let Constraints = "$src1 = $dst" in
4369   defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
4370
4371 multiclass SS41I_insert64<bits<8> opc, string asm, bit Is2Addr = 1> {
4372   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
4373       (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
4374       !if(Is2Addr,
4375         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4376         !strconcat(asm,
4377                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4378       [(set VR128:$dst,
4379         (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
4380       OpSize;
4381   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
4382       (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
4383       !if(Is2Addr,
4384         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4385         !strconcat(asm,
4386                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4387       [(set VR128:$dst,
4388         (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
4389                           imm:$src3)))]>, OpSize;
4390 }
4391
4392 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4393   defm VPINSRQ : SS41I_insert64<0x22, "vpinsrq", 0>, VEX_4V, VEX_W;
4394 let Constraints = "$src1 = $dst" in
4395   defm PINSRQ : SS41I_insert64<0x22, "pinsrq">, REX_W;
4396
4397 // insertps has a few different modes, there's the first two here below which
4398 // are optimized inserts that won't zero arbitrary elements in the destination
4399 // vector. The next one matches the intrinsic and could zero arbitrary elements
4400 // in the target vector.
4401 multiclass SS41I_insertf32<bits<8> opc, string asm, bit Is2Addr = 1> {
4402   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
4403       (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4404       !if(Is2Addr,
4405         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4406         !strconcat(asm,
4407                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4408       [(set VR128:$dst,
4409         (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
4410       OpSize;
4411   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
4412       (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
4413       !if(Is2Addr,
4414         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4415         !strconcat(asm,
4416                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4417       [(set VR128:$dst,
4418         (X86insrtps VR128:$src1,
4419                    (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
4420                     imm:$src3))]>, OpSize;
4421 }
4422
4423 let Constraints = "$src1 = $dst" in
4424   defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
4425 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4426   defm VINSERTPS : SS41I_insertf32<0x21, "vinsertps", 0>, VEX_4V;
4427
4428 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
4429           (VINSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>,
4430           Requires<[HasAVX]>;
4431 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
4432           (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>,
4433           Requires<[HasSSE41]>;
4434
4435 //===----------------------------------------------------------------------===//
4436 // SSE4.1 - Round Instructions
4437 //===----------------------------------------------------------------------===//
4438
4439 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd, string OpcodeStr,
4440                             X86MemOperand x86memop, RegisterClass RC,
4441                             PatFrag mem_frag32, PatFrag mem_frag64,
4442                             Intrinsic V4F32Int, Intrinsic V2F64Int> {
4443   // Intrinsic operation, reg.
4444   // Vector intrinsic operation, reg
4445   def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
4446                     (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
4447                     !strconcat(OpcodeStr,
4448                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4449                     [(set RC:$dst, (V4F32Int RC:$src1, imm:$src2))]>,
4450                     OpSize;
4451
4452   // Vector intrinsic operation, mem
4453   def PSm_Int : Ii8<opcps, MRMSrcMem,
4454                     (outs RC:$dst), (ins f256mem:$src1, i32i8imm:$src2),
4455                     !strconcat(OpcodeStr,
4456                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4457                     [(set RC:$dst,
4458                           (V4F32Int (mem_frag32 addr:$src1),imm:$src2))]>,
4459                     TA, OpSize,
4460                 Requires<[HasSSE41]>;
4461
4462   // Vector intrinsic operation, reg
4463   def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
4464                     (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
4465                     !strconcat(OpcodeStr,
4466                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4467                     [(set RC:$dst, (V2F64Int RC:$src1, imm:$src2))]>,
4468                     OpSize;
4469
4470   // Vector intrinsic operation, mem
4471   def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
4472                     (outs RC:$dst), (ins f256mem:$src1, i32i8imm:$src2),
4473                     !strconcat(OpcodeStr,
4474                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4475                     [(set RC:$dst,
4476                           (V2F64Int (mem_frag64 addr:$src1),imm:$src2))]>,
4477                     OpSize;
4478 }
4479
4480 multiclass sse41_fp_unop_rm_avx_p<bits<8> opcps, bits<8> opcpd,
4481                    RegisterClass RC, X86MemOperand x86memop, string OpcodeStr> {
4482   // Intrinsic operation, reg.
4483   // Vector intrinsic operation, reg
4484   def PSr : SS4AIi8<opcps, MRMSrcReg,
4485                     (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
4486                     !strconcat(OpcodeStr,
4487                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4488                     []>, OpSize;
4489
4490   // Vector intrinsic operation, mem
4491   def PSm : Ii8<opcps, MRMSrcMem,
4492                     (outs RC:$dst), (ins x86memop:$src1, i32i8imm:$src2),
4493                     !strconcat(OpcodeStr,
4494                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4495                     []>, TA, OpSize, Requires<[HasSSE41]>;
4496
4497   // Vector intrinsic operation, reg
4498   def PDr : SS4AIi8<opcpd, MRMSrcReg,
4499                     (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
4500                     !strconcat(OpcodeStr,
4501                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4502                     []>, OpSize;
4503
4504   // Vector intrinsic operation, mem
4505   def PDm : SS4AIi8<opcpd, MRMSrcMem,
4506                     (outs RC:$dst), (ins x86memop:$src1, i32i8imm:$src2),
4507                     !strconcat(OpcodeStr,
4508                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4509                     []>, OpSize;
4510 }
4511
4512 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
4513                             string OpcodeStr,
4514                             Intrinsic F32Int,
4515                             Intrinsic F64Int, bit Is2Addr = 1> {
4516   // Intrinsic operation, reg.
4517   def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
4518         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4519         !if(Is2Addr,
4520             !strconcat(OpcodeStr,
4521                 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4522             !strconcat(OpcodeStr,
4523                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4524         [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
4525         OpSize;
4526
4527   // Intrinsic operation, mem.
4528   def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
4529         (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
4530         !if(Is2Addr,
4531             !strconcat(OpcodeStr,
4532                 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4533             !strconcat(OpcodeStr,
4534                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4535         [(set VR128:$dst,
4536              (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
4537         OpSize;
4538
4539   // Intrinsic operation, reg.
4540   def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
4541         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4542         !if(Is2Addr,
4543             !strconcat(OpcodeStr,
4544                 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4545             !strconcat(OpcodeStr,
4546                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4547         [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
4548         OpSize;
4549
4550   // Intrinsic operation, mem.
4551   def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
4552         (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
4553         !if(Is2Addr,
4554             !strconcat(OpcodeStr,
4555                 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4556             !strconcat(OpcodeStr,
4557                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4558         [(set VR128:$dst,
4559               (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
4560         OpSize;
4561 }
4562
4563 multiclass sse41_fp_binop_rm_avx_s<bits<8> opcss, bits<8> opcsd,
4564                                    string OpcodeStr> {
4565   // Intrinsic operation, reg.
4566   def SSr : SS4AIi8<opcss, MRMSrcReg,
4567         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4568         !strconcat(OpcodeStr,
4569                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4570         []>, OpSize;
4571
4572   // Intrinsic operation, mem.
4573   def SSm : SS4AIi8<opcss, MRMSrcMem,
4574         (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
4575         !strconcat(OpcodeStr,
4576                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4577         []>, OpSize;
4578
4579   // Intrinsic operation, reg.
4580   def SDr : SS4AIi8<opcsd, MRMSrcReg,
4581         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4582             !strconcat(OpcodeStr,
4583                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4584         []>, OpSize;
4585
4586   // Intrinsic operation, mem.
4587   def SDm : SS4AIi8<opcsd, MRMSrcMem,
4588         (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
4589             !strconcat(OpcodeStr,
4590                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4591         []>, OpSize;
4592 }
4593
4594 // FP round - roundss, roundps, roundsd, roundpd
4595 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4596   // Intrinsic form
4597   defm VROUND  : sse41_fp_unop_rm<0x08, 0x09, "vround", f128mem, VR128,
4598                                   memopv4f32, memopv2f64,
4599                                   int_x86_sse41_round_ps,
4600                                   int_x86_sse41_round_pd>, VEX;
4601   defm VROUNDY : sse41_fp_unop_rm<0x08, 0x09, "vround", f256mem, VR256,
4602                                   memopv8f32, memopv4f64,
4603                                   int_x86_avx_round_ps_256,
4604                                   int_x86_avx_round_pd_256>, VEX;
4605   defm VROUND  : sse41_fp_binop_rm<0x0A, 0x0B, "vround",
4606                                   int_x86_sse41_round_ss,
4607                                   int_x86_sse41_round_sd, 0>, VEX_4V;
4608
4609   // Instructions for the assembler
4610   defm VROUND  : sse41_fp_unop_rm_avx_p<0x08, 0x09, VR128, f128mem, "vround">,
4611                                         VEX;
4612   defm VROUNDY : sse41_fp_unop_rm_avx_p<0x08, 0x09, VR256, f256mem, "vround">,
4613                                         VEX;
4614   defm VROUND  : sse41_fp_binop_rm_avx_s<0x0A, 0x0B, "vround">, VEX_4V;
4615 }
4616
4617 defm ROUND  : sse41_fp_unop_rm<0x08, 0x09, "round", f128mem, VR128,
4618                                memopv4f32, memopv2f64,
4619                                int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
4620 let Constraints = "$src1 = $dst" in
4621 defm ROUND  : sse41_fp_binop_rm<0x0A, 0x0B, "round",
4622                                int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
4623
4624 //===----------------------------------------------------------------------===//
4625 // SSE4.1 - Packed Bit Test
4626 //===----------------------------------------------------------------------===//
4627
4628 // ptest instruction we'll lower to this in X86ISelLowering primarily from
4629 // the intel intrinsic that corresponds to this.
4630 let Defs = [EFLAGS], isAsmParserOnly = 1, Predicates = [HasAVX] in {
4631 def VPTESTrr  : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
4632                       "vptest\t{$src2, $src1|$src1, $src2}",
4633                       [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
4634                       OpSize, VEX;
4635 def VPTESTYrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR256:$src1, VR256:$src2),
4636                       "vptest\t{$src2, $src1|$src1, $src2}", []>, OpSize, VEX;
4637
4638 def VPTESTrm  : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
4639                      "vptest\t{$src2, $src1|$src1, $src2}",
4640                      [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
4641                      OpSize, VEX;
4642 def VPTESTYrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR256:$src1, i256mem:$src2),
4643                      "vptest\t{$src2, $src1|$src1, $src2}", []>, OpSize, VEX;
4644 }
4645
4646 let Defs = [EFLAGS] in {
4647 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
4648                     "ptest \t{$src2, $src1|$src1, $src2}",
4649                     [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
4650               OpSize;
4651 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
4652                     "ptest \t{$src2, $src1|$src1, $src2}",
4653                     [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
4654               OpSize;
4655 }
4656
4657 // The bit test instructions below are AVX only
4658 multiclass avx_bittest<bits<8> opc, string OpcodeStr, RegisterClass RC,
4659                        X86MemOperand x86memop> {
4660   def rr : SS48I<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src),
4661             !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4662             []>, OpSize, VEX;
4663   def rm : SS48I<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
4664             !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4665             []>, OpSize, VEX;
4666 }
4667
4668 let Defs = [EFLAGS], isAsmParserOnly = 1, Predicates = [HasAVX] in {
4669   defm VTESTPS  : avx_bittest<0x0E, "vtestps", VR128, f128mem>;
4670   defm VTESTPSY : avx_bittest<0x0E, "vtestps", VR256, f256mem>;
4671   defm VTESTPD  : avx_bittest<0x0F, "vtestpd", VR128, f128mem>;
4672   defm VTESTPDY : avx_bittest<0x0F, "vtestpd", VR256, f256mem>;
4673 }
4674
4675 //===----------------------------------------------------------------------===//
4676 // SSE4.1 - Misc Instructions
4677 //===----------------------------------------------------------------------===//
4678
4679 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
4680 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
4681                                  Intrinsic IntId128> {
4682   def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4683                     (ins VR128:$src),
4684                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4685                     [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
4686   def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4687                      (ins i128mem:$src),
4688                      !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4689                      [(set VR128:$dst,
4690                        (IntId128
4691                        (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
4692 }
4693
4694 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4695 defm VPHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "vphminposuw",
4696                                          int_x86_sse41_phminposuw>, VEX;
4697 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
4698                                          int_x86_sse41_phminposuw>;
4699
4700 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
4701 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
4702                               Intrinsic IntId128, bit Is2Addr = 1> {
4703   let isCommutable = 1 in
4704   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4705        (ins VR128:$src1, VR128:$src2),
4706        !if(Is2Addr,
4707            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4708            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4709        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>, OpSize;
4710   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4711        (ins VR128:$src1, i128mem:$src2),
4712        !if(Is2Addr,
4713            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4714            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4715        [(set VR128:$dst,
4716          (IntId128 VR128:$src1,
4717           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
4718 }
4719
4720 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4721   let isCommutable = 0 in
4722   defm VPACKUSDW : SS41I_binop_rm_int<0x2B, "vpackusdw", int_x86_sse41_packusdw,
4723                                                          0>, VEX_4V;
4724   defm VPCMPEQQ  : SS41I_binop_rm_int<0x29, "vpcmpeqq",  int_x86_sse41_pcmpeqq,
4725                                                          0>, VEX_4V;
4726   defm VPMINSB   : SS41I_binop_rm_int<0x38, "vpminsb",   int_x86_sse41_pminsb,
4727                                                          0>, VEX_4V;
4728   defm VPMINSD   : SS41I_binop_rm_int<0x39, "vpminsd",   int_x86_sse41_pminsd,
4729                                                          0>, VEX_4V;
4730   defm VPMINUD   : SS41I_binop_rm_int<0x3B, "vpminud",   int_x86_sse41_pminud,
4731                                                          0>, VEX_4V;
4732   defm VPMINUW   : SS41I_binop_rm_int<0x3A, "vpminuw",   int_x86_sse41_pminuw,
4733                                                          0>, VEX_4V;
4734   defm VPMAXSB   : SS41I_binop_rm_int<0x3C, "vpmaxsb",   int_x86_sse41_pmaxsb,
4735                                                          0>, VEX_4V;
4736   defm VPMAXSD   : SS41I_binop_rm_int<0x3D, "vpmaxsd",   int_x86_sse41_pmaxsd,
4737                                                          0>, VEX_4V;
4738   defm VPMAXUD   : SS41I_binop_rm_int<0x3F, "vpmaxud",   int_x86_sse41_pmaxud,
4739                                                          0>, VEX_4V;
4740   defm VPMAXUW   : SS41I_binop_rm_int<0x3E, "vpmaxuw",   int_x86_sse41_pmaxuw,
4741                                                          0>, VEX_4V;
4742   defm VPMULDQ   : SS41I_binop_rm_int<0x28, "vpmuldq",   int_x86_sse41_pmuldq,
4743                                                          0>, VEX_4V;
4744 }
4745
4746 let Constraints = "$src1 = $dst" in {
4747   let isCommutable = 0 in
4748   defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw", int_x86_sse41_packusdw>;
4749   defm PCMPEQQ  : SS41I_binop_rm_int<0x29, "pcmpeqq",  int_x86_sse41_pcmpeqq>;
4750   defm PMINSB   : SS41I_binop_rm_int<0x38, "pminsb",   int_x86_sse41_pminsb>;
4751   defm PMINSD   : SS41I_binop_rm_int<0x39, "pminsd",   int_x86_sse41_pminsd>;
4752   defm PMINUD   : SS41I_binop_rm_int<0x3B, "pminud",   int_x86_sse41_pminud>;
4753   defm PMINUW   : SS41I_binop_rm_int<0x3A, "pminuw",   int_x86_sse41_pminuw>;
4754   defm PMAXSB   : SS41I_binop_rm_int<0x3C, "pmaxsb",   int_x86_sse41_pmaxsb>;
4755   defm PMAXSD   : SS41I_binop_rm_int<0x3D, "pmaxsd",   int_x86_sse41_pmaxsd>;
4756   defm PMAXUD   : SS41I_binop_rm_int<0x3F, "pmaxud",   int_x86_sse41_pmaxud>;
4757   defm PMAXUW   : SS41I_binop_rm_int<0x3E, "pmaxuw",   int_x86_sse41_pmaxuw>;
4758   defm PMULDQ   : SS41I_binop_rm_int<0x28, "pmuldq",   int_x86_sse41_pmuldq>;
4759 }
4760
4761 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
4762           (PCMPEQQrr VR128:$src1, VR128:$src2)>;
4763 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
4764           (PCMPEQQrm VR128:$src1, addr:$src2)>;
4765
4766 /// SS48I_binop_rm - Simple SSE41 binary operator.
4767 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
4768                         ValueType OpVT, bit Is2Addr = 1> {
4769   let isCommutable = 1 in
4770   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4771        (ins VR128:$src1, VR128:$src2),
4772        !if(Is2Addr,
4773            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4774            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4775        [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
4776        OpSize;
4777   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4778        (ins VR128:$src1, i128mem:$src2),
4779        !if(Is2Addr,
4780            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4781            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4782        [(set VR128:$dst, (OpNode VR128:$src1,
4783                                   (bc_v4i32 (memopv2i64 addr:$src2))))]>,
4784        OpSize;
4785 }
4786
4787 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4788   defm VPMULLD : SS48I_binop_rm<0x40, "vpmulld", mul, v4i32, 0>, VEX_4V;
4789 let Constraints = "$src1 = $dst" in
4790   defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32>;
4791
4792 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
4793 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
4794                  Intrinsic IntId, RegisterClass RC, PatFrag memop_frag,
4795                  X86MemOperand x86memop, bit Is2Addr = 1> {
4796   let isCommutable = 1 in
4797   def rri : SS4AIi8<opc, MRMSrcReg, (outs RC:$dst),
4798         (ins RC:$src1, RC:$src2, i32i8imm:$src3),
4799         !if(Is2Addr,
4800             !strconcat(OpcodeStr,
4801                 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4802             !strconcat(OpcodeStr,
4803                 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4804         [(set RC:$dst, (IntId RC:$src1, RC:$src2, imm:$src3))]>,
4805         OpSize;
4806   def rmi : SS4AIi8<opc, MRMSrcMem, (outs RC:$dst),
4807         (ins RC:$src1, x86memop:$src2, i32i8imm:$src3),
4808         !if(Is2Addr,
4809             !strconcat(OpcodeStr,
4810                 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4811             !strconcat(OpcodeStr,
4812                 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4813         [(set RC:$dst,
4814           (IntId RC:$src1,
4815            (bitconvert (memop_frag addr:$src2)), imm:$src3))]>,
4816         OpSize;
4817 }
4818
4819 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4820   let isCommutable = 0 in {
4821   defm VBLENDPS : SS41I_binop_rmi_int<0x0C, "vblendps", int_x86_sse41_blendps,
4822                                       VR128, memopv16i8, i128mem, 0>, VEX_4V;
4823   defm VBLENDPD : SS41I_binop_rmi_int<0x0D, "vblendpd", int_x86_sse41_blendpd,
4824                                       VR128, memopv16i8, i128mem, 0>, VEX_4V;
4825   defm VBLENDPSY : SS41I_binop_rmi_int<0x0C, "vblendps",
4826             int_x86_avx_blend_ps_256, VR256, memopv32i8, i256mem, 0>, VEX_4V;
4827   defm VBLENDPDY : SS41I_binop_rmi_int<0x0D, "vblendpd",
4828             int_x86_avx_blend_pd_256, VR256, memopv32i8, i256mem, 0>, VEX_4V;
4829   defm VPBLENDW : SS41I_binop_rmi_int<0x0E, "vpblendw", int_x86_sse41_pblendw,
4830                                       VR128, memopv16i8, i128mem, 0>, VEX_4V;
4831   defm VMPSADBW : SS41I_binop_rmi_int<0x42, "vmpsadbw", int_x86_sse41_mpsadbw,
4832                                       VR128, memopv16i8, i128mem, 0>, VEX_4V;
4833   }
4834   defm VDPPS : SS41I_binop_rmi_int<0x40, "vdpps", int_x86_sse41_dpps,
4835                                    VR128, memopv16i8, i128mem, 0>, VEX_4V;
4836   defm VDPPD : SS41I_binop_rmi_int<0x41, "vdppd", int_x86_sse41_dppd,
4837                                    VR128, memopv16i8, i128mem, 0>, VEX_4V;
4838   let Pattern = []<dag> in
4839   defm VDPPSY : SS41I_binop_rmi_int<0x40, "vdpps", int_x86_sse41_dpps,
4840                                     VR256, memopv32i8, i256mem, 0>, VEX_4V;
4841 }
4842
4843 let Constraints = "$src1 = $dst" in {
4844   let isCommutable = 0 in {
4845   defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps", int_x86_sse41_blendps,
4846                                      VR128, memopv16i8, i128mem>;
4847   defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd", int_x86_sse41_blendpd,
4848                                      VR128, memopv16i8, i128mem>;
4849   defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw", int_x86_sse41_pblendw,
4850                                      VR128, memopv16i8, i128mem>;
4851   defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw", int_x86_sse41_mpsadbw,
4852                                      VR128, memopv16i8, i128mem>;
4853   }
4854   defm DPPS : SS41I_binop_rmi_int<0x40, "dpps", int_x86_sse41_dpps,
4855                                   VR128, memopv16i8, i128mem>;
4856   defm DPPD : SS41I_binop_rmi_int<0x41, "dppd", int_x86_sse41_dppd,
4857                                   VR128, memopv16i8, i128mem>;
4858 }
4859
4860 /// SS41I_quaternary_int_avx - AVX SSE 4.1 with 4 operators
4861 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4862 multiclass SS41I_quaternary_int_avx<bits<8> opc, string OpcodeStr,
4863                                     RegisterClass RC, X86MemOperand x86memop,
4864                                     PatFrag mem_frag, Intrinsic IntId> {
4865   def rr : I<opc, MRMSrcReg, (outs RC:$dst),
4866                   (ins RC:$src1, RC:$src2, RC:$src3),
4867                   !strconcat(OpcodeStr,
4868                     "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4869                   [(set RC:$dst, (IntId RC:$src1, RC:$src2, RC:$src3))],
4870                   SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
4871
4872   def rm : I<opc, MRMSrcMem, (outs RC:$dst),
4873                   (ins RC:$src1, x86memop:$src2, RC:$src3),
4874                   !strconcat(OpcodeStr,
4875                     "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4876                   [(set RC:$dst,
4877                         (IntId RC:$src1, (bitconvert (mem_frag addr:$src2)),
4878                                RC:$src3))],
4879                   SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
4880 }
4881 }
4882
4883 defm VBLENDVPD  : SS41I_quaternary_int_avx<0x4B, "vblendvpd", VR128, i128mem,
4884                                            memopv16i8, int_x86_sse41_blendvpd>;
4885 defm VBLENDVPS  : SS41I_quaternary_int_avx<0x4A, "vblendvps", VR128, i128mem,
4886                                            memopv16i8, int_x86_sse41_blendvps>;
4887 defm VPBLENDVB  : SS41I_quaternary_int_avx<0x4C, "vpblendvb", VR128, i128mem,
4888                                            memopv16i8, int_x86_sse41_pblendvb>;
4889 defm VBLENDVPDY : SS41I_quaternary_int_avx<0x4B, "vblendvpd", VR256, i256mem,
4890                                          memopv32i8, int_x86_avx_blendv_pd_256>;
4891 defm VBLENDVPSY : SS41I_quaternary_int_avx<0x4A, "vblendvps", VR256, i256mem,
4892                                          memopv32i8, int_x86_avx_blendv_ps_256>;
4893
4894 /// SS41I_ternary_int - SSE 4.1 ternary operator
4895 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
4896   multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
4897     def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4898                     (ins VR128:$src1, VR128:$src2),
4899                     !strconcat(OpcodeStr,
4900                      "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
4901                     [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
4902                     OpSize;
4903
4904     def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4905                     (ins VR128:$src1, i128mem:$src2),
4906                     !strconcat(OpcodeStr,
4907                      "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
4908                     [(set VR128:$dst,
4909                       (IntId VR128:$src1,
4910                        (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
4911   }
4912 }
4913
4914 defm BLENDVPD     : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
4915 defm BLENDVPS     : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
4916 defm PBLENDVB     : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
4917
4918 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4919 def VMOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4920                        "vmovntdqa\t{$src, $dst|$dst, $src}",
4921                        [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
4922                        OpSize, VEX;
4923 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4924                        "movntdqa\t{$src, $dst|$dst, $src}",
4925                        [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
4926                        OpSize;
4927
4928 //===----------------------------------------------------------------------===//
4929 // SSE4.2 - Compare Instructions
4930 //===----------------------------------------------------------------------===//
4931
4932 /// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
4933 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
4934                               Intrinsic IntId128, bit Is2Addr = 1> {
4935   def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
4936        (ins VR128:$src1, VR128:$src2),
4937        !if(Is2Addr,
4938            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4939            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4940        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
4941        OpSize;
4942   def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
4943        (ins VR128:$src1, i128mem:$src2),
4944        !if(Is2Addr,
4945            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4946            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4947        [(set VR128:$dst,
4948          (IntId128 VR128:$src1,
4949           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
4950 }
4951
4952 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4953   defm VPCMPGTQ : SS42I_binop_rm_int<0x37, "vpcmpgtq", int_x86_sse42_pcmpgtq,
4954                                      0>, VEX_4V;
4955 let Constraints = "$src1 = $dst" in
4956   defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
4957
4958 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
4959           (PCMPGTQrr VR128:$src1, VR128:$src2)>;
4960 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
4961           (PCMPGTQrm VR128:$src1, addr:$src2)>;
4962
4963 //===----------------------------------------------------------------------===//
4964 // SSE4.2 - String/text Processing Instructions
4965 //===----------------------------------------------------------------------===//
4966
4967 // Packed Compare Implicit Length Strings, Return Mask
4968 multiclass pseudo_pcmpistrm<string asm> {
4969   def REG : Ii8<0, Pseudo, (outs VR128:$dst),
4970     (ins VR128:$src1, VR128:$src2, i8imm:$src3), !strconcat(asm, "rr PSEUDO"),
4971     [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
4972                                                   imm:$src3))]>;
4973   def MEM : Ii8<0, Pseudo, (outs VR128:$dst),
4974     (ins VR128:$src1, i128mem:$src2, i8imm:$src3), !strconcat(asm, "rm PSEUDO"),
4975     [(set VR128:$dst, (int_x86_sse42_pcmpistrm128
4976                        VR128:$src1, (load addr:$src2), imm:$src3))]>;
4977 }
4978
4979 let Defs = [EFLAGS], usesCustomInserter = 1 in {
4980   defm PCMPISTRM128 : pseudo_pcmpistrm<"#PCMPISTRM128">, Requires<[HasSSE42]>;
4981   defm VPCMPISTRM128 : pseudo_pcmpistrm<"#VPCMPISTRM128">, Requires<[HasAVX]>;
4982 }
4983
4984 let Defs = [XMM0, EFLAGS], isAsmParserOnly = 1,
4985     Predicates = [HasAVX] in {
4986   def VPCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
4987       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4988       "vpcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize, VEX;
4989   def VPCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
4990       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
4991       "vpcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize, VEX;
4992 }
4993
4994 let Defs = [XMM0, EFLAGS] in {
4995   def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
4996       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4997       "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
4998   def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
4999       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
5000       "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
5001 }
5002
5003 // Packed Compare Explicit Length Strings, Return Mask
5004 multiclass pseudo_pcmpestrm<string asm> {
5005   def REG : Ii8<0, Pseudo, (outs VR128:$dst),
5006     (ins VR128:$src1, VR128:$src3, i8imm:$src5), !strconcat(asm, "rr PSEUDO"),
5007     [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
5008                        VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>;
5009   def MEM : Ii8<0, Pseudo, (outs VR128:$dst),
5010     (ins VR128:$src1, i128mem:$src3, i8imm:$src5), !strconcat(asm, "rm PSEUDO"),
5011     [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
5012                        VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>;
5013 }
5014
5015 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
5016   defm PCMPESTRM128 : pseudo_pcmpestrm<"#PCMPESTRM128">, Requires<[HasSSE42]>;
5017   defm VPCMPESTRM128 : pseudo_pcmpestrm<"#VPCMPESTRM128">, Requires<[HasAVX]>;
5018 }
5019
5020 let isAsmParserOnly = 1, Predicates = [HasAVX],
5021     Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
5022   def VPCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
5023       (ins VR128:$src1, VR128:$src3, i8imm:$src5),
5024       "vpcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize, VEX;
5025   def VPCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
5026       (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
5027       "vpcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize, VEX;
5028 }
5029
5030 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
5031   def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
5032       (ins VR128:$src1, VR128:$src3, i8imm:$src5),
5033       "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
5034   def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
5035       (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
5036       "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
5037 }
5038
5039 // Packed Compare Implicit Length Strings, Return Index
5040 let Defs = [ECX, EFLAGS] in {
5041   multiclass SS42AI_pcmpistri<Intrinsic IntId128, string asm = "pcmpistri"> {
5042     def rr : SS42AI<0x63, MRMSrcReg, (outs),
5043       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
5044       !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
5045       [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
5046        (implicit EFLAGS)]>, OpSize;
5047     def rm : SS42AI<0x63, MRMSrcMem, (outs),
5048       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
5049       !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
5050       [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
5051        (implicit EFLAGS)]>, OpSize;
5052   }
5053 }
5054
5055 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
5056 defm VPCMPISTRI  : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128, "vpcmpistri">,
5057                                     VEX;
5058 defm VPCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128, "vpcmpistri">,
5059                                     VEX;
5060 defm VPCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128, "vpcmpistri">,
5061                                     VEX;
5062 defm VPCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128, "vpcmpistri">,
5063                                     VEX;
5064 defm VPCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128, "vpcmpistri">,
5065                                     VEX;
5066 defm VPCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128, "vpcmpistri">,
5067                                     VEX;
5068 }
5069
5070 defm PCMPISTRI  : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
5071 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
5072 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
5073 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
5074 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
5075 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
5076
5077 // Packed Compare Explicit Length Strings, Return Index
5078 let Defs = [ECX, EFLAGS], Uses = [EAX, EDX] in {
5079   multiclass SS42AI_pcmpestri<Intrinsic IntId128, string asm = "pcmpestri"> {
5080     def rr : SS42AI<0x61, MRMSrcReg, (outs),
5081       (ins VR128:$src1, VR128:$src3, i8imm:$src5),
5082       !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
5083       [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
5084        (implicit EFLAGS)]>, OpSize;
5085     def rm : SS42AI<0x61, MRMSrcMem, (outs),
5086       (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
5087       !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
5088        [(set ECX,
5089              (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
5090         (implicit EFLAGS)]>, OpSize;
5091   }
5092 }
5093
5094 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
5095 defm VPCMPESTRI  : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128, "vpcmpestri">,
5096                                     VEX;
5097 defm VPCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128, "vpcmpestri">,
5098                                     VEX;
5099 defm VPCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128, "vpcmpestri">,
5100                                     VEX;
5101 defm VPCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128, "vpcmpestri">,
5102                                     VEX;
5103 defm VPCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128, "vpcmpestri">,
5104                                     VEX;
5105 defm VPCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128, "vpcmpestri">,
5106                                     VEX;
5107 }
5108
5109 defm PCMPESTRI  : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
5110 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
5111 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
5112 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
5113 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
5114 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
5115
5116 //===----------------------------------------------------------------------===//
5117 // SSE4.2 - CRC Instructions
5118 //===----------------------------------------------------------------------===//
5119
5120 // No CRC instructions have AVX equivalents
5121
5122 // crc intrinsic instruction
5123 // This set of instructions are only rm, the only difference is the size
5124 // of r and m.
5125 let Constraints = "$src1 = $dst" in {
5126   def CRC32m8  : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
5127                       (ins GR32:$src1, i8mem:$src2),
5128                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
5129                        [(set GR32:$dst,
5130                          (int_x86_sse42_crc32_8 GR32:$src1,
5131                          (load addr:$src2)))]>;
5132   def CRC32r8  : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
5133                       (ins GR32:$src1, GR8:$src2),
5134                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
5135                        [(set GR32:$dst,
5136                          (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
5137   def CRC32m16  : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
5138                       (ins GR32:$src1, i16mem:$src2),
5139                       "crc32{w} \t{$src2, $src1|$src1, $src2}",
5140                        [(set GR32:$dst,
5141                          (int_x86_sse42_crc32_16 GR32:$src1,
5142                          (load addr:$src2)))]>,
5143                          OpSize;
5144   def CRC32r16  : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
5145                       (ins GR32:$src1, GR16:$src2),
5146                       "crc32{w} \t{$src2, $src1|$src1, $src2}",
5147                        [(set GR32:$dst,
5148                          (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
5149                          OpSize;
5150   def CRC32m32  : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
5151                       (ins GR32:$src1, i32mem:$src2),
5152                       "crc32{l} \t{$src2, $src1|$src1, $src2}",
5153                        [(set GR32:$dst,
5154                          (int_x86_sse42_crc32_32 GR32:$src1,
5155                          (load addr:$src2)))]>;
5156   def CRC32r32  : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
5157                       (ins GR32:$src1, GR32:$src2),
5158                       "crc32{l} \t{$src2, $src1|$src1, $src2}",
5159                        [(set GR32:$dst,
5160                          (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
5161   def CRC64m8  : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
5162                       (ins GR64:$src1, i8mem:$src2),
5163                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
5164                        [(set GR64:$dst,
5165                          (int_x86_sse42_crc64_8 GR64:$src1,
5166                          (load addr:$src2)))]>,
5167                          REX_W;
5168   def CRC64r8  : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
5169                       (ins GR64:$src1, GR8:$src2),
5170                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
5171                        [(set GR64:$dst,
5172                          (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
5173                          REX_W;
5174   def CRC64m64  : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
5175                       (ins GR64:$src1, i64mem:$src2),
5176                       "crc32{q} \t{$src2, $src1|$src1, $src2}",
5177                        [(set GR64:$dst,
5178                          (int_x86_sse42_crc64_64 GR64:$src1,
5179                          (load addr:$src2)))]>,
5180                          REX_W;
5181   def CRC64r64  : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
5182                       (ins GR64:$src1, GR64:$src2),
5183                       "crc32{q} \t{$src2, $src1|$src1, $src2}",
5184                        [(set GR64:$dst,
5185                          (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
5186                          REX_W;
5187 }
5188
5189 //===----------------------------------------------------------------------===//
5190 // AES-NI Instructions
5191 //===----------------------------------------------------------------------===//
5192
5193 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
5194                               Intrinsic IntId128, bit Is2Addr = 1> {
5195   def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
5196        (ins VR128:$src1, VR128:$src2),
5197        !if(Is2Addr,
5198            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5199            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5200        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
5201        OpSize;
5202   def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
5203        (ins VR128:$src1, i128mem:$src2),
5204        !if(Is2Addr,
5205            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5206            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5207        [(set VR128:$dst,
5208          (IntId128 VR128:$src1,
5209           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
5210 }
5211
5212 // Perform One Round of an AES Encryption/Decryption Flow
5213 let isAsmParserOnly = 1, Predicates = [HasAVX, HasAES] in {
5214   defm VAESENC          : AESI_binop_rm_int<0xDC, "vaesenc",
5215                          int_x86_aesni_aesenc, 0>, VEX_4V;
5216   defm VAESENCLAST      : AESI_binop_rm_int<0xDD, "vaesenclast",
5217                          int_x86_aesni_aesenclast, 0>, VEX_4V;
5218   defm VAESDEC          : AESI_binop_rm_int<0xDE, "vaesdec",
5219                          int_x86_aesni_aesdec, 0>, VEX_4V;
5220   defm VAESDECLAST      : AESI_binop_rm_int<0xDF, "vaesdeclast",
5221                          int_x86_aesni_aesdeclast, 0>, VEX_4V;
5222 }
5223
5224 let Constraints = "$src1 = $dst" in {
5225   defm AESENC          : AESI_binop_rm_int<0xDC, "aesenc",
5226                          int_x86_aesni_aesenc>;
5227   defm AESENCLAST      : AESI_binop_rm_int<0xDD, "aesenclast",
5228                          int_x86_aesni_aesenclast>;
5229   defm AESDEC          : AESI_binop_rm_int<0xDE, "aesdec",
5230                          int_x86_aesni_aesdec>;
5231   defm AESDECLAST      : AESI_binop_rm_int<0xDF, "aesdeclast",
5232                          int_x86_aesni_aesdeclast>;
5233 }
5234
5235 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
5236           (AESENCrr VR128:$src1, VR128:$src2)>;
5237 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
5238           (AESENCrm VR128:$src1, addr:$src2)>;
5239 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
5240           (AESENCLASTrr VR128:$src1, VR128:$src2)>;
5241 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
5242           (AESENCLASTrm VR128:$src1, addr:$src2)>;
5243 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
5244           (AESDECrr VR128:$src1, VR128:$src2)>;
5245 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
5246           (AESDECrm VR128:$src1, addr:$src2)>;
5247 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
5248           (AESDECLASTrr VR128:$src1, VR128:$src2)>;
5249 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
5250           (AESDECLASTrm VR128:$src1, addr:$src2)>;
5251
5252 // Perform the AES InvMixColumn Transformation
5253 let isAsmParserOnly = 1, Predicates = [HasAVX, HasAES] in {
5254   def VAESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
5255       (ins VR128:$src1),
5256       "vaesimc\t{$src1, $dst|$dst, $src1}",
5257       [(set VR128:$dst,
5258         (int_x86_aesni_aesimc VR128:$src1))]>,
5259       OpSize, VEX;
5260   def VAESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
5261       (ins i128mem:$src1),
5262       "vaesimc\t{$src1, $dst|$dst, $src1}",
5263       [(set VR128:$dst,
5264         (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
5265       OpSize, VEX;
5266 }
5267 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
5268   (ins VR128:$src1),
5269   "aesimc\t{$src1, $dst|$dst, $src1}",
5270   [(set VR128:$dst,
5271     (int_x86_aesni_aesimc VR128:$src1))]>,
5272   OpSize;
5273 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
5274   (ins i128mem:$src1),
5275   "aesimc\t{$src1, $dst|$dst, $src1}",
5276   [(set VR128:$dst,
5277     (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
5278   OpSize;
5279
5280 // AES Round Key Generation Assist
5281 let isAsmParserOnly = 1, Predicates = [HasAVX, HasAES] in {
5282   def VAESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
5283       (ins VR128:$src1, i8imm:$src2),
5284       "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5285       [(set VR128:$dst,
5286         (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
5287       OpSize, VEX;
5288   def VAESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
5289       (ins i128mem:$src1, i8imm:$src2),
5290       "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5291       [(set VR128:$dst,
5292         (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),
5293                                         imm:$src2))]>,
5294       OpSize, VEX;
5295 }
5296 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
5297   (ins VR128:$src1, i8imm:$src2),
5298   "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5299   [(set VR128:$dst,
5300     (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
5301   OpSize;
5302 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
5303   (ins i128mem:$src1, i8imm:$src2),
5304   "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5305   [(set VR128:$dst,
5306     (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),
5307                                     imm:$src2))]>,
5308   OpSize;
5309
5310 //===----------------------------------------------------------------------===//
5311 // CLMUL Instructions
5312 //===----------------------------------------------------------------------===//
5313
5314 // Only the AVX version of CLMUL instructions are described here.
5315
5316 // Carry-less Multiplication instructions
5317 let isAsmParserOnly = 1 in {
5318 def VPCLMULQDQrr : CLMULIi8<0x44, MRMSrcReg, (outs VR128:$dst),
5319            (ins VR128:$src1, VR128:$src2, i8imm:$src3),
5320            "vpclmulqdq\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5321            []>;
5322
5323 def VPCLMULQDQrm : CLMULIi8<0x44, MRMSrcMem, (outs VR128:$dst),
5324            (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
5325            "vpclmulqdq\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5326            []>;
5327
5328 // Assembler Only
5329 multiclass avx_vpclmul<string asm> {
5330   def rr : I<0, Pseudo, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
5331              !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5332              []>;
5333
5334   def rm : I<0, Pseudo, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
5335              !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5336              []>;
5337 }
5338 defm VPCLMULHQHQDQ : avx_vpclmul<"vpclmulhqhqdq">;
5339 defm VPCLMULHQLQDQ : avx_vpclmul<"vpclmulhqlqdq">;
5340 defm VPCLMULLQHQDQ : avx_vpclmul<"vpclmullqhqdq">;
5341 defm VPCLMULLQLQDQ : avx_vpclmul<"vpclmullqlqdq">;
5342
5343 } // isAsmParserOnly
5344
5345 //===----------------------------------------------------------------------===//
5346 // AVX Instructions
5347 //===----------------------------------------------------------------------===//
5348
5349 let isAsmParserOnly = 1 in {
5350
5351 // Load from memory and broadcast to all elements of the destination operand
5352 class avx_broadcast<bits<8> opc, string OpcodeStr, RegisterClass RC,
5353                     X86MemOperand x86memop, Intrinsic Int> :
5354   AVX8I<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
5355         !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5356         [(set RC:$dst, (Int addr:$src))]>, VEX;
5357
5358 def VBROADCASTSS   : avx_broadcast<0x18, "vbroadcastss", VR128, f32mem,
5359                                    int_x86_avx_vbroadcastss>;
5360 def VBROADCASTSSY  : avx_broadcast<0x18, "vbroadcastss", VR256, f32mem,
5361                                    int_x86_avx_vbroadcastss_256>;
5362 def VBROADCASTSD   : avx_broadcast<0x19, "vbroadcastsd", VR256, f64mem,
5363                                    int_x86_avx_vbroadcast_sd_256>;
5364 def VBROADCASTF128 : avx_broadcast<0x1A, "vbroadcastf128", VR256, f128mem,
5365                                    int_x86_avx_vbroadcastf128_pd_256>;
5366
5367 // Insert packed floating-point values
5368 def VINSERTF128rr : AVXAIi8<0x18, MRMSrcReg, (outs VR256:$dst),
5369           (ins VR256:$src1, VR128:$src2, i8imm:$src3),
5370           "vinsertf128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5371           []>, VEX_4V;
5372 def VINSERTF128rm : AVXAIi8<0x18, MRMSrcMem, (outs VR256:$dst),
5373           (ins VR256:$src1, f128mem:$src2, i8imm:$src3),
5374           "vinsertf128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5375           []>, VEX_4V;
5376
5377 // Extract packed floating-point values
5378 def VEXTRACTF128rr : AVXAIi8<0x19, MRMDestReg, (outs VR128:$dst),
5379           (ins VR256:$src1, i8imm:$src2),
5380           "vextractf128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5381           []>, VEX;
5382 def VEXTRACTF128mr : AVXAIi8<0x19, MRMDestMem, (outs),
5383           (ins f128mem:$dst, VR256:$src1, i8imm:$src2),
5384           "vextractf128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5385           []>, VEX;
5386
5387 // Conditional SIMD Packed Loads and Stores
5388 multiclass avx_movmask_rm<bits<8> opc_rm, bits<8> opc_mr, string OpcodeStr,
5389                           Intrinsic IntLd, Intrinsic IntLd256,
5390                           Intrinsic IntSt, Intrinsic IntSt256,
5391                           PatFrag pf128, PatFrag pf256> {
5392   def rm  : AVX8I<opc_rm, MRMSrcMem, (outs VR128:$dst),
5393              (ins VR128:$src1, f128mem:$src2),
5394              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5395              [(set VR128:$dst, (IntLd addr:$src2, VR128:$src1))]>,
5396              VEX_4V;
5397   def Yrm : AVX8I<opc_rm, MRMSrcMem, (outs VR256:$dst),
5398              (ins VR256:$src1, f256mem:$src2),
5399              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5400              [(set VR256:$dst, (IntLd256 addr:$src2, VR256:$src1))]>,
5401              VEX_4V;
5402   def mr  : AVX8I<opc_mr, MRMDestMem, (outs),
5403              (ins f128mem:$dst, VR128:$src1, VR128:$src2),
5404              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5405              [(IntSt addr:$dst, VR128:$src1, VR128:$src2)]>, VEX_4V;
5406   def Ymr : AVX8I<opc_mr, MRMDestMem, (outs),
5407              (ins f256mem:$dst, VR256:$src1, VR256:$src2),
5408              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5409              [(IntSt256 addr:$dst, VR256:$src1, VR256:$src2)]>, VEX_4V;
5410 }
5411
5412 defm VMASKMOVPS : avx_movmask_rm<0x2C, 0x2E, "vmaskmovps",
5413                                  int_x86_avx_maskload_ps,
5414                                  int_x86_avx_maskload_ps_256,
5415                                  int_x86_avx_maskstore_ps,
5416                                  int_x86_avx_maskstore_ps_256,
5417                                  memopv4f32, memopv8f32>;
5418 defm VMASKMOVPD : avx_movmask_rm<0x2D, 0x2F, "vmaskmovpd",
5419                                  int_x86_avx_maskload_pd,
5420                                  int_x86_avx_maskload_pd_256,
5421                                  int_x86_avx_maskstore_pd,
5422                                  int_x86_avx_maskstore_pd_256,
5423                                  memopv2f64, memopv4f64>;
5424
5425 // Permute Floating-Point Values
5426 multiclass avx_permil<bits<8> opc_rm, bits<8> opc_rmi, string OpcodeStr,
5427                       RegisterClass RC, X86MemOperand x86memop_f,
5428                       X86MemOperand x86memop_i, PatFrag f_frag, PatFrag i_frag,
5429                       Intrinsic IntVar, Intrinsic IntImm> {
5430   def rr  : AVX8I<opc_rm, MRMSrcReg, (outs RC:$dst),
5431              (ins RC:$src1, RC:$src2),
5432              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5433              [(set RC:$dst, (IntVar RC:$src1, RC:$src2))]>, VEX_4V;
5434   def rm  : AVX8I<opc_rm, MRMSrcMem, (outs RC:$dst),
5435              (ins RC:$src1, x86memop_i:$src2),
5436              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5437              [(set RC:$dst, (IntVar RC:$src1, (i_frag addr:$src2)))]>, VEX_4V;
5438
5439   def ri  : AVXAIi8<opc_rmi, MRMSrcReg, (outs RC:$dst),
5440              (ins RC:$src1, i8imm:$src2),
5441              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5442              [(set RC:$dst, (IntImm RC:$src1, imm:$src2))]>, VEX;
5443   def mi  : AVXAIi8<opc_rmi, MRMSrcMem, (outs RC:$dst),
5444              (ins x86memop_f:$src1, i8imm:$src2),
5445              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5446              [(set RC:$dst, (IntImm (f_frag addr:$src1), imm:$src2))]>, VEX;
5447 }
5448
5449 defm VPERMILPS  : avx_permil<0x0C, 0x04, "vpermilps", VR128, f128mem, i128mem,
5450                              memopv4f32, memopv4i32,
5451                              int_x86_avx_vpermilvar_ps,
5452                              int_x86_avx_vpermil_ps>;
5453 defm VPERMILPSY : avx_permil<0x0C, 0x04, "vpermilps", VR256, f256mem, i256mem,
5454                              memopv8f32, memopv8i32,
5455                              int_x86_avx_vpermilvar_ps_256,
5456                              int_x86_avx_vpermil_ps_256>;
5457 defm VPERMILPD  : avx_permil<0x0D, 0x05, "vpermilpd", VR128, f128mem, i128mem,
5458                              memopv2f64, memopv2i64,
5459                              int_x86_avx_vpermilvar_pd,
5460                              int_x86_avx_vpermil_pd>;
5461 defm VPERMILPDY : avx_permil<0x0D, 0x05, "vpermilpd", VR256, f256mem, i256mem,
5462                              memopv4f64, memopv4i64,
5463                              int_x86_avx_vpermilvar_pd_256,
5464                              int_x86_avx_vpermil_pd_256>;
5465
5466 def VPERM2F128rr : AVXAIi8<0x06, MRMSrcReg, (outs VR256:$dst),
5467           (ins VR256:$src1, VR256:$src2, i8imm:$src3),
5468           "vperm2f128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5469           []>, VEX_4V;
5470 def VPERM2F128rm : AVXAIi8<0x06, MRMSrcMem, (outs VR256:$dst),
5471           (ins VR256:$src1, f256mem:$src2, i8imm:$src3),
5472           "vperm2f128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5473           []>, VEX_4V;
5474
5475 // Zero All YMM registers
5476 def VZEROALL : I<0x77, RawFrm, (outs), (ins), "vzeroall",
5477                  [(int_x86_avx_vzeroall)]>, VEX, VEX_L, Requires<[HasAVX]>;
5478
5479 // Zero Upper bits of YMM registers
5480 def VZEROUPPER : I<0x77, RawFrm, (outs), (ins), "vzeroupper",
5481                    [(int_x86_avx_vzeroupper)]>, VEX, Requires<[HasAVX]>;
5482
5483 } // isAsmParserOnly
5484
5485 def : Pat<(int_x86_avx_vinsertf128_pd_256 VR256:$src1, VR128:$src2, imm:$src3),
5486           (VINSERTF128rr VR256:$src1, VR128:$src2, imm:$src3)>;
5487 def : Pat<(int_x86_avx_vinsertf128_ps_256 VR256:$src1, VR128:$src2, imm:$src3),
5488           (VINSERTF128rr VR256:$src1, VR128:$src2, imm:$src3)>;
5489 def : Pat<(int_x86_avx_vinsertf128_si_256 VR256:$src1, VR128:$src2, imm:$src3),
5490           (VINSERTF128rr VR256:$src1, VR128:$src2, imm:$src3)>;
5491
5492 def : Pat<(int_x86_avx_vextractf128_pd_256 VR256:$src1, imm:$src2),
5493           (VEXTRACTF128rr VR256:$src1, imm:$src2)>;
5494 def : Pat<(int_x86_avx_vextractf128_ps_256 VR256:$src1, imm:$src2),
5495           (VEXTRACTF128rr VR256:$src1, imm:$src2)>;
5496 def : Pat<(int_x86_avx_vextractf128_si_256 VR256:$src1, imm:$src2),
5497           (VEXTRACTF128rr VR256:$src1, imm:$src2)>;
5498
5499 def : Pat<(int_x86_avx_vbroadcastf128_ps_256 addr:$src),
5500           (VBROADCASTF128 addr:$src)>;
5501
5502 def : Pat<(int_x86_avx_vperm2f128_ps_256 VR256:$src1, VR256:$src2, imm:$src3),
5503           (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$src3)>;
5504 def : Pat<(int_x86_avx_vperm2f128_pd_256 VR256:$src1, VR256:$src2, imm:$src3),
5505           (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$src3)>;
5506 def : Pat<(int_x86_avx_vperm2f128_si_256 VR256:$src1, VR256:$src2, imm:$src3),
5507           (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$src3)>;
5508
5509 def : Pat<(int_x86_avx_vperm2f128_ps_256
5510                   VR256:$src1, (memopv8f32 addr:$src2), imm:$src3),
5511           (VPERM2F128rm VR256:$src1, addr:$src2, imm:$src3)>;
5512 def : Pat<(int_x86_avx_vperm2f128_pd_256
5513                   VR256:$src1, (memopv4f64 addr:$src2), imm:$src3),
5514           (VPERM2F128rm VR256:$src1, addr:$src2, imm:$src3)>;
5515 def : Pat<(int_x86_avx_vperm2f128_si_256
5516                   VR256:$src1, (memopv8i32 addr:$src2), imm:$src3),
5517           (VPERM2F128rm VR256:$src1, addr:$src2, imm:$src3)>;
5518