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