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