804d0592322bf3ecf684dde7e1589a27a55d236a
[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
2005 // Alias instructions that map zero vector to pxor / xorp* for sse.
2006 // We set canFoldAsLoad because this can be converted to a constant-pool
2007 // load of an all-zeros value if folding it would be beneficial.
2008 // FIXME: Change encoding to pseudo!
2009 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
2010     isCodeGenOnly = 1 in {
2011 def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
2012                  [(set VR128:$dst, (v4f32 immAllZerosV))]>;
2013 def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
2014                  [(set VR128:$dst, (v2f64 immAllZerosV))]>;
2015 let ExeDomain = SSEPackedInt in
2016 def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
2017                  [(set VR128:$dst, (v4i32 immAllZerosV))]>;
2018 }
2019
2020 def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
2021 def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
2022 def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
2023
2024 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2025           (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
2026
2027 //===----------------------------------------------------------------------===//
2028 // SSE 1 & 2 - Load/Store XCSR register
2029 //===----------------------------------------------------------------------===//
2030
2031 let isAsmParserOnly = 1 in {
2032   def VLDMXCSR : VPSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
2033                     "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>, VEX;
2034   def VSTMXCSR : VPSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
2035                     "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>, VEX;
2036 }
2037
2038 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
2039                   "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
2040 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
2041                   "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
2042
2043 //===---------------------------------------------------------------------===//
2044 // SSE2 - Move Aligned/Unaligned Packed Integer Instructions
2045 //===---------------------------------------------------------------------===//
2046
2047 let ExeDomain = SSEPackedInt in { // SSE integer instructions
2048
2049 let isAsmParserOnly = 1 in {
2050   let neverHasSideEffects = 1 in {
2051   def VMOVDQArr  : VPDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2052                       "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2053   def VMOVDQAYrr : VPDI<0x6F, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
2054                       "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2055   }
2056   def VMOVDQUrr  : VPDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2057                       "movdqu\t{$src, $dst|$dst, $src}", []>, XS, VEX;
2058   def VMOVDQUYrr : VPDI<0x6F, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
2059                       "movdqu\t{$src, $dst|$dst, $src}", []>, XS, VEX;
2060
2061   let canFoldAsLoad = 1, mayLoad = 1 in {
2062   def VMOVDQArm  : VPDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2063                      "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2064   def VMOVDQAYrm : VPDI<0x6F, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
2065                      "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2066   let Predicates = [HasAVX] in {
2067     def VMOVDQUrm  : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2068                       "vmovdqu\t{$src, $dst|$dst, $src}",[]>, XS, VEX;
2069     def VMOVDQUYrm : I<0x6F, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
2070                       "vmovdqu\t{$src, $dst|$dst, $src}",[]>, XS, VEX;
2071   }
2072   }
2073
2074   let mayStore = 1 in {
2075   def VMOVDQAmr  : VPDI<0x7F, MRMDestMem, (outs),
2076                        (ins i128mem:$dst, VR128:$src),
2077                        "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2078   def VMOVDQAYmr : VPDI<0x7F, MRMDestMem, (outs),
2079                        (ins i256mem:$dst, VR256:$src),
2080                        "movdqa\t{$src, $dst|$dst, $src}", []>, VEX;
2081   let Predicates = [HasAVX] in {
2082   def VMOVDQUmr  : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2083                     "vmovdqu\t{$src, $dst|$dst, $src}",[]>, XS, VEX;
2084   def VMOVDQUYmr : I<0x7F, MRMDestMem, (outs), (ins i256mem:$dst, VR256:$src),
2085                     "vmovdqu\t{$src, $dst|$dst, $src}",[]>, XS, VEX;
2086   }
2087   }
2088 }
2089
2090 let neverHasSideEffects = 1 in
2091 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2092                    "movdqa\t{$src, $dst|$dst, $src}", []>;
2093
2094 let canFoldAsLoad = 1, mayLoad = 1 in {
2095 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2096                    "movdqa\t{$src, $dst|$dst, $src}",
2097                    [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
2098 def MOVDQUrm :   I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2099                    "movdqu\t{$src, $dst|$dst, $src}",
2100                    [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
2101                  XS, Requires<[HasSSE2]>;
2102 }
2103
2104 let mayStore = 1 in {
2105 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2106                    "movdqa\t{$src, $dst|$dst, $src}",
2107                    [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
2108 def MOVDQUmr :   I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2109                    "movdqu\t{$src, $dst|$dst, $src}",
2110                    [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
2111                  XS, Requires<[HasSSE2]>;
2112 }
2113
2114 // Intrinsic forms of MOVDQU load and store
2115 let isAsmParserOnly = 1 in {
2116 let canFoldAsLoad = 1 in
2117 def VMOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2118                        "vmovdqu\t{$src, $dst|$dst, $src}",
2119                        [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
2120                      XS, VEX, Requires<[HasAVX]>;
2121 def VMOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2122                        "vmovdqu\t{$src, $dst|$dst, $src}",
2123                        [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
2124                      XS, VEX, Requires<[HasAVX]>;
2125 }
2126
2127 let canFoldAsLoad = 1 in
2128 def MOVDQUrm_Int :   I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2129                        "movdqu\t{$src, $dst|$dst, $src}",
2130                        [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
2131                  XS, Requires<[HasSSE2]>;
2132 def MOVDQUmr_Int :   I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2133                        "movdqu\t{$src, $dst|$dst, $src}",
2134                        [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
2135                      XS, Requires<[HasSSE2]>;
2136
2137 } // ExeDomain = SSEPackedInt
2138
2139 //===---------------------------------------------------------------------===//
2140 // SSE2 - Packed Integer Arithmetic Instructions
2141 //===---------------------------------------------------------------------===//
2142
2143 let ExeDomain = SSEPackedInt in { // SSE integer instructions
2144
2145 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
2146                             bit IsCommutable = 0, bit Is2Addr = 1> {
2147   let isCommutable = IsCommutable in
2148   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2149        (ins VR128:$src1, VR128:$src2),
2150        !if(Is2Addr,
2151            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2152            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2153        [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
2154   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2155        (ins VR128:$src1, i128mem:$src2),
2156        !if(Is2Addr,
2157            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2158            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2159        [(set VR128:$dst, (IntId VR128:$src1,
2160                                 (bitconvert (memopv2i64 addr:$src2))))]>;
2161 }
2162
2163 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
2164                              string OpcodeStr, Intrinsic IntId,
2165                              Intrinsic IntId2, bit Is2Addr = 1> {
2166   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2167        (ins VR128:$src1, VR128:$src2),
2168        !if(Is2Addr,
2169            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2170            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2171        [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
2172   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2173        (ins VR128:$src1, i128mem:$src2),
2174        !if(Is2Addr,
2175            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2176            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2177        [(set VR128:$dst, (IntId VR128:$src1,
2178                                       (bitconvert (memopv2i64 addr:$src2))))]>;
2179   def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
2180        (ins VR128:$src1, i32i8imm:$src2),
2181        !if(Is2Addr,
2182            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2183            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2184        [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
2185 }
2186
2187 /// PDI_binop_rm - Simple SSE2 binary operator.
2188 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
2189                         ValueType OpVT, bit IsCommutable = 0, bit Is2Addr = 1> {
2190   let isCommutable = IsCommutable in
2191   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2192        (ins VR128:$src1, VR128:$src2),
2193        !if(Is2Addr,
2194            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2195            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2196        [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>;
2197   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2198        (ins VR128:$src1, i128mem:$src2),
2199        !if(Is2Addr,
2200            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2201            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2202        [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
2203                                      (bitconvert (memopv2i64 addr:$src2)))))]>;
2204 }
2205
2206 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
2207 ///
2208 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
2209 /// to collapse (bitconvert VT to VT) into its operand.
2210 ///
2211 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
2212                               bit IsCommutable = 0, bit Is2Addr = 1> {
2213   let isCommutable = IsCommutable in
2214   def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
2215        (ins VR128:$src1, VR128:$src2),
2216        !if(Is2Addr,
2217            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2218            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2219        [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]>;
2220   def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
2221        (ins VR128:$src1, i128mem:$src2),
2222        !if(Is2Addr,
2223            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2224            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2225        [(set VR128:$dst, (OpNode VR128:$src1, (memopv2i64 addr:$src2)))]>;
2226 }
2227
2228 } // ExeDomain = SSEPackedInt
2229
2230 // 128-bit Integer Arithmetic
2231
2232 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2233 defm VPADDB  : PDI_binop_rm<0xFC, "vpaddb", add, v16i8, 1, 0 /*3addr*/>, VEX_4V;
2234 defm VPADDW  : PDI_binop_rm<0xFD, "vpaddw", add, v8i16, 1, 0>, VEX_4V;
2235 defm VPADDD  : PDI_binop_rm<0xFE, "vpaddd", add, v4i32, 1, 0>, VEX_4V;
2236 defm VPADDQ  : PDI_binop_rm_v2i64<0xD4, "vpaddq", add, 1, 0>, VEX_4V;
2237 defm VPMULLW : PDI_binop_rm<0xD5, "vpmullw", mul, v8i16, 1, 0>, VEX_4V;
2238 defm VPSUBB : PDI_binop_rm<0xF8, "vpsubb", sub, v16i8, 0, 0>, VEX_4V;
2239 defm VPSUBW : PDI_binop_rm<0xF9, "vpsubw", sub, v8i16, 0, 0>, VEX_4V;
2240 defm VPSUBD : PDI_binop_rm<0xFA, "vpsubd", sub, v4i32, 0, 0>, VEX_4V;
2241 defm VPSUBQ : PDI_binop_rm_v2i64<0xFB, "vpsubq", sub, 0, 0>, VEX_4V;
2242
2243 // Intrinsic forms
2244 defm VPSUBSB  : PDI_binop_rm_int<0xE8, "vpsubsb" , int_x86_sse2_psubs_b, 0, 0>,
2245                                  VEX_4V;
2246 defm VPSUBSW  : PDI_binop_rm_int<0xE9, "vpsubsw" , int_x86_sse2_psubs_w, 0, 0>,
2247                                  VEX_4V;
2248 defm VPSUBUSB : PDI_binop_rm_int<0xD8, "vpsubusb", int_x86_sse2_psubus_b, 0, 0>,
2249                                  VEX_4V;
2250 defm VPSUBUSW : PDI_binop_rm_int<0xD9, "vpsubusw", int_x86_sse2_psubus_w, 0, 0>,
2251                                  VEX_4V;
2252 defm VPADDSB  : PDI_binop_rm_int<0xEC, "vpaddsb" , int_x86_sse2_padds_b, 1, 0>,
2253                                  VEX_4V;
2254 defm VPADDSW  : PDI_binop_rm_int<0xED, "vpaddsw" , int_x86_sse2_padds_w, 1, 0>,
2255                                  VEX_4V;
2256 defm VPADDUSB : PDI_binop_rm_int<0xDC, "vpaddusb", int_x86_sse2_paddus_b, 1, 0>,
2257                                  VEX_4V;
2258 defm VPADDUSW : PDI_binop_rm_int<0xDD, "vpaddusw", int_x86_sse2_paddus_w, 1, 0>,
2259                                  VEX_4V;
2260 defm VPMULHUW : PDI_binop_rm_int<0xE4, "vpmulhuw", int_x86_sse2_pmulhu_w, 1, 0>,
2261                                  VEX_4V;
2262 defm VPMULHW  : PDI_binop_rm_int<0xE5, "vpmulhw" , int_x86_sse2_pmulh_w, 1, 0>,
2263                                  VEX_4V;
2264 defm VPMULUDQ : PDI_binop_rm_int<0xF4, "vpmuludq", int_x86_sse2_pmulu_dq, 1, 0>,
2265                                  VEX_4V;
2266 defm VPMADDWD : PDI_binop_rm_int<0xF5, "vpmaddwd", int_x86_sse2_pmadd_wd, 1, 0>,
2267                                  VEX_4V;
2268 defm VPAVGB   : PDI_binop_rm_int<0xE0, "vpavgb", int_x86_sse2_pavg_b, 1, 0>,
2269                                  VEX_4V;
2270 defm VPAVGW   : PDI_binop_rm_int<0xE3, "vpavgw", int_x86_sse2_pavg_w, 1, 0>,
2271                                  VEX_4V;
2272 defm VPMINUB  : PDI_binop_rm_int<0xDA, "vpminub", int_x86_sse2_pminu_b, 1, 0>,
2273                                  VEX_4V;
2274 defm VPMINSW  : PDI_binop_rm_int<0xEA, "vpminsw", int_x86_sse2_pmins_w, 1, 0>,
2275                                  VEX_4V;
2276 defm VPMAXUB  : PDI_binop_rm_int<0xDE, "vpmaxub", int_x86_sse2_pmaxu_b, 1, 0>,
2277                                  VEX_4V;
2278 defm VPMAXSW  : PDI_binop_rm_int<0xEE, "vpmaxsw", int_x86_sse2_pmaxs_w, 1, 0>,
2279                                  VEX_4V;
2280 defm VPSADBW  : PDI_binop_rm_int<0xF6, "vpsadbw", int_x86_sse2_psad_bw, 1, 0>,
2281                                  VEX_4V;
2282 }
2283
2284 let Constraints = "$src1 = $dst" in {
2285 defm PADDB  : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
2286 defm PADDW  : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
2287 defm PADDD  : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
2288 defm PADDQ  : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
2289 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
2290 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
2291 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
2292 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
2293 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
2294
2295 // Intrinsic forms
2296 defm PSUBSB  : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
2297 defm PSUBSW  : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
2298 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
2299 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
2300 defm PADDSB  : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
2301 defm PADDSW  : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
2302 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
2303 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
2304 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
2305 defm PMULHW  : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w, 1>;
2306 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
2307 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
2308 defm PAVGB   : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
2309 defm PAVGW   : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
2310 defm PMINUB  : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
2311 defm PMINSW  : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
2312 defm PMAXUB  : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
2313 defm PMAXSW  : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
2314 defm PSADBW  : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
2315
2316 } // Constraints = "$src1 = $dst"
2317
2318 //===---------------------------------------------------------------------===//
2319 // SSE2 - Packed Integer Logical Instructions
2320 //===---------------------------------------------------------------------===//
2321
2322 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2323 defm VPSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "vpsllw",
2324                                 int_x86_sse2_psll_w, int_x86_sse2_pslli_w, 0>,
2325                                 VEX_4V;
2326 defm VPSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "vpslld",
2327                                 int_x86_sse2_psll_d, int_x86_sse2_pslli_d, 0>,
2328                                 VEX_4V;
2329 defm VPSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "vpsllq",
2330                                 int_x86_sse2_psll_q, int_x86_sse2_pslli_q, 0>,
2331                                 VEX_4V;
2332
2333 defm VPSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "vpsrlw",
2334                                 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w, 0>,
2335                                 VEX_4V;
2336 defm VPSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "vpsrld",
2337                                 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d, 0>,
2338                                 VEX_4V;
2339 defm VPSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "vpsrlq",
2340                                 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q, 0>,
2341                                 VEX_4V;
2342
2343 defm VPSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "vpsraw",
2344                                 int_x86_sse2_psra_w, int_x86_sse2_psrai_w, 0>,
2345                                 VEX_4V;
2346 defm VPSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "vpsrad",
2347                                 int_x86_sse2_psra_d, int_x86_sse2_psrai_d, 0>,
2348                                 VEX_4V;
2349
2350 defm VPAND : PDI_binop_rm_v2i64<0xDB, "vpand", and, 1, 0>, VEX_4V;
2351 defm VPOR  : PDI_binop_rm_v2i64<0xEB, "vpor" , or, 1, 0>, VEX_4V;
2352 defm VPXOR : PDI_binop_rm_v2i64<0xEF, "vpxor", xor, 1, 0>, VEX_4V;
2353
2354 let ExeDomain = SSEPackedInt in {
2355   let neverHasSideEffects = 1 in {
2356     // 128-bit logical shifts.
2357     def VPSLLDQri : PDIi8<0x73, MRM7r,
2358                       (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2359                       "vpslldq\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
2360                       VEX_4V;
2361     def VPSRLDQri : PDIi8<0x73, MRM3r,
2362                       (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2363                       "vpsrldq\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
2364                       VEX_4V;
2365     // PSRADQri doesn't exist in SSE[1-3].
2366   }
2367   def VPANDNrr : PDI<0xDF, MRMSrcReg,
2368                     (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2369                     "vpandn\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2370                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2371                                               VR128:$src2)))]>, VEX_4V;
2372
2373   def VPANDNrm : PDI<0xDF, MRMSrcMem,
2374                     (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2375                     "vpandn\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2376                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2377                                               (memopv2i64 addr:$src2))))]>,
2378                                               VEX_4V;
2379 }
2380 }
2381
2382 let Constraints = "$src1 = $dst" in {
2383 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
2384                                int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
2385 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
2386                                int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
2387 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2388                                int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
2389
2390 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2391                                int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2392 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2393                                int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
2394 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
2395                                int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
2396
2397 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2398                                int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
2399 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
2400                                int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
2401
2402 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2403 defm POR  : PDI_binop_rm_v2i64<0xEB, "por" , or, 1>;
2404 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2405
2406 let ExeDomain = SSEPackedInt in {
2407   let neverHasSideEffects = 1 in {
2408     // 128-bit logical shifts.
2409     def PSLLDQri : PDIi8<0x73, MRM7r,
2410                          (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2411                          "pslldq\t{$src2, $dst|$dst, $src2}", []>;
2412     def PSRLDQri : PDIi8<0x73, MRM3r,
2413                          (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2414                          "psrldq\t{$src2, $dst|$dst, $src2}", []>;
2415     // PSRADQri doesn't exist in SSE[1-3].
2416   }
2417   def PANDNrr : PDI<0xDF, MRMSrcReg,
2418                     (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2419                     "pandn\t{$src2, $dst|$dst, $src2}",
2420                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2421                                               VR128:$src2)))]>;
2422
2423   def PANDNrm : PDI<0xDF, MRMSrcMem,
2424                     (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2425                     "pandn\t{$src2, $dst|$dst, $src2}",
2426                     [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2427                                               (memopv2i64 addr:$src2))))]>;
2428 }
2429 } // Constraints = "$src1 = $dst"
2430
2431 let Predicates = [HasSSE2] in {
2432   def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
2433             (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2434   def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2435             (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2436   def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2437             (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2438   def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2439             (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
2440   def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2441             (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2442
2443   // Shift up / down and insert zero's.
2444   def : Pat<(v2i64 (X86vshl  VR128:$src, (i8 imm:$amt))),
2445             (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2446   def : Pat<(v2i64 (X86vshr  VR128:$src, (i8 imm:$amt))),
2447             (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2448 }
2449
2450 //===---------------------------------------------------------------------===//
2451 // SSE2 - Packed Integer Comparison Instructions
2452 //===---------------------------------------------------------------------===//
2453
2454 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2455   defm VPCMPEQB  : PDI_binop_rm_int<0x74, "vpcmpeqb", int_x86_sse2_pcmpeq_b, 1,
2456                                     0>, VEX_4V;
2457   defm VPCMPEQW  : PDI_binop_rm_int<0x75, "vpcmpeqw", int_x86_sse2_pcmpeq_w, 1,
2458                                     0>, VEX_4V;
2459   defm VPCMPEQD  : PDI_binop_rm_int<0x76, "vpcmpeqd", int_x86_sse2_pcmpeq_d, 1,
2460                                     0>, VEX_4V;
2461   defm VPCMPGTB  : PDI_binop_rm_int<0x64, "vpcmpgtb", int_x86_sse2_pcmpgt_b, 0,
2462                                     0>, VEX_4V;
2463   defm VPCMPGTW  : PDI_binop_rm_int<0x65, "vpcmpgtw", int_x86_sse2_pcmpgt_w, 0,
2464                                     0>, VEX_4V;
2465   defm VPCMPGTD  : PDI_binop_rm_int<0x66, "vpcmpgtd", int_x86_sse2_pcmpgt_d, 0,
2466                                     0>, VEX_4V;
2467 }
2468
2469 let Constraints = "$src1 = $dst" in {
2470   defm PCMPEQB  : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b, 1>;
2471   defm PCMPEQW  : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w, 1>;
2472   defm PCMPEQD  : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d, 1>;
2473   defm PCMPGTB  : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2474   defm PCMPGTW  : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2475   defm PCMPGTD  : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2476 } // Constraints = "$src1 = $dst"
2477
2478 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
2479           (PCMPEQBrr VR128:$src1, VR128:$src2)>;
2480 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
2481           (PCMPEQBrm VR128:$src1, addr:$src2)>;
2482 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
2483           (PCMPEQWrr VR128:$src1, VR128:$src2)>;
2484 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
2485           (PCMPEQWrm VR128:$src1, addr:$src2)>;
2486 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
2487           (PCMPEQDrr VR128:$src1, VR128:$src2)>;
2488 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
2489           (PCMPEQDrm VR128:$src1, addr:$src2)>;
2490
2491 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
2492           (PCMPGTBrr VR128:$src1, VR128:$src2)>;
2493 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
2494           (PCMPGTBrm VR128:$src1, addr:$src2)>;
2495 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
2496           (PCMPGTWrr VR128:$src1, VR128:$src2)>;
2497 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
2498           (PCMPGTWrm VR128:$src1, addr:$src2)>;
2499 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
2500           (PCMPGTDrr VR128:$src1, VR128:$src2)>;
2501 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
2502           (PCMPGTDrm VR128:$src1, addr:$src2)>;
2503
2504 //===---------------------------------------------------------------------===//
2505 // SSE2 - Packed Integer Pack Instructions
2506 //===---------------------------------------------------------------------===//
2507
2508 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2509 defm VPACKSSWB : PDI_binop_rm_int<0x63, "vpacksswb", int_x86_sse2_packsswb_128,
2510                                   0, 0>, VEX_4V;
2511 defm VPACKSSDW : PDI_binop_rm_int<0x6B, "vpackssdw", int_x86_sse2_packssdw_128,
2512                                   0, 0>, VEX_4V;
2513 defm VPACKUSWB : PDI_binop_rm_int<0x67, "vpackuswb", int_x86_sse2_packuswb_128,
2514                                   0, 0>, VEX_4V;
2515 }
2516
2517 let Constraints = "$src1 = $dst" in {
2518 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2519 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2520 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2521 } // Constraints = "$src1 = $dst"
2522
2523 //===---------------------------------------------------------------------===//
2524 // SSE2 - Packed Integer Shuffle Instructions
2525 //===---------------------------------------------------------------------===//
2526
2527 let ExeDomain = SSEPackedInt in {
2528 multiclass sse2_pshuffle<string OpcodeStr, ValueType vt, PatFrag pshuf_frag,
2529                          PatFrag bc_frag> {
2530 def ri : Ii8<0x70, MRMSrcReg,
2531               (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2532               !strconcat(OpcodeStr,
2533                          "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2534               [(set VR128:$dst, (vt (pshuf_frag:$src2 VR128:$src1,
2535                                                       (undef))))]>;
2536 def mi : Ii8<0x70, MRMSrcMem,
2537               (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2538               !strconcat(OpcodeStr,
2539                          "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2540               [(set VR128:$dst, (vt (pshuf_frag:$src2
2541                                       (bc_frag (memopv2i64 addr:$src1)),
2542                                       (undef))))]>;
2543 }
2544 } // ExeDomain = SSEPackedInt
2545
2546 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2547   let AddedComplexity = 5 in
2548   defm VPSHUFD : sse2_pshuffle<"vpshufd", v4i32, pshufd, bc_v4i32>, OpSize,
2549                                VEX;
2550
2551   // SSE2 with ImmT == Imm8 and XS prefix.
2552   defm VPSHUFHW : sse2_pshuffle<"vpshufhw", v8i16, pshufhw, bc_v8i16>, XS,
2553                                VEX;
2554
2555   // SSE2 with ImmT == Imm8 and XD prefix.
2556   defm VPSHUFLW : sse2_pshuffle<"vpshuflw", v8i16, pshuflw, bc_v8i16>, XD,
2557                                VEX;
2558 }
2559
2560 let Predicates = [HasSSE2] in {
2561   let AddedComplexity = 5 in
2562   defm PSHUFD : sse2_pshuffle<"pshufd", v4i32, pshufd, bc_v4i32>, TB, OpSize;
2563
2564   // SSE2 with ImmT == Imm8 and XS prefix.
2565   defm PSHUFHW : sse2_pshuffle<"pshufhw", v8i16, pshufhw, bc_v8i16>, XS;
2566
2567   // SSE2 with ImmT == Imm8 and XD prefix.
2568   defm PSHUFLW : sse2_pshuffle<"pshuflw", v8i16, pshuflw, bc_v8i16>, XD;
2569 }
2570
2571 //===---------------------------------------------------------------------===//
2572 // SSE2 - Packed Integer Unpack Instructions
2573 //===---------------------------------------------------------------------===//
2574
2575 let ExeDomain = SSEPackedInt in {
2576 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2577                        PatFrag unp_frag, PatFrag bc_frag, bit Is2Addr = 1> {
2578   def rr : PDI<opc, MRMSrcReg,
2579       (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2580       !if(Is2Addr,
2581           !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2582           !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2583       [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2584   def rm : PDI<opc, MRMSrcMem,
2585       (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2586       !if(Is2Addr,
2587           !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2588           !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2589       [(set VR128:$dst, (unp_frag VR128:$src1,
2590                                   (bc_frag (memopv2i64
2591                                                addr:$src2))))]>;
2592 }
2593
2594 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
2595   defm VPUNPCKLBW  : sse2_unpack<0x60, "vpunpcklbw", v16i8, unpckl, bc_v16i8,
2596                                  0>, VEX_4V;
2597   defm VPUNPCKLWD  : sse2_unpack<0x61, "vpunpcklwd", v8i16, unpckl, bc_v8i16,
2598                                  0>, VEX_4V;
2599   defm VPUNPCKLDQ  : sse2_unpack<0x62, "vpunpckldq", v4i32, unpckl, bc_v4i32,
2600                                  0>, VEX_4V;
2601
2602   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2603   /// knew to collapse (bitconvert VT to VT) into its operand.
2604   def VPUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2605                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2606                          "vpunpcklqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2607                         [(set VR128:$dst,
2608                           (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>, VEX_4V;
2609   def VPUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2610                          (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2611                          "vpunpcklqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2612                         [(set VR128:$dst,
2613                           (v2i64 (unpckl VR128:$src1,
2614                                          (memopv2i64 addr:$src2))))]>, VEX_4V;
2615
2616   defm VPUNPCKHBW  : sse2_unpack<0x68, "vpunpckhbw", v16i8, unpckh, bc_v16i8,
2617                                  0>, VEX_4V;
2618   defm VPUNPCKHWD  : sse2_unpack<0x69, "vpunpckhwd", v8i16, unpckh, bc_v8i16,
2619                                  0>, VEX_4V;
2620   defm VPUNPCKHDQ  : sse2_unpack<0x6A, "vpunpckhdq", v4i32, unpckh, bc_v4i32,
2621                                  0>, VEX_4V;
2622
2623   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2624   /// knew to collapse (bitconvert VT to VT) into its operand.
2625   def VPUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2626                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2627                          "vpunpckhqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2628                         [(set VR128:$dst,
2629                           (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>, VEX_4V;
2630   def VPUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2631                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2632                         "vpunpckhqdq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2633                         [(set VR128:$dst,
2634                           (v2i64 (unpckh VR128:$src1,
2635                                          (memopv2i64 addr:$src2))))]>, VEX_4V;
2636 }
2637
2638 let Constraints = "$src1 = $dst" in {
2639   defm PUNPCKLBW  : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2640   defm PUNPCKLWD  : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2641   defm PUNPCKLDQ  : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2642
2643   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2644   /// knew to collapse (bitconvert VT to VT) into its operand.
2645   def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2646                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2647                          "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2648                         [(set VR128:$dst,
2649                           (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
2650   def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2651                          (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2652                          "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2653                         [(set VR128:$dst,
2654                           (v2i64 (unpckl VR128:$src1,
2655                                          (memopv2i64 addr:$src2))))]>;
2656
2657   defm PUNPCKHBW  : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2658   defm PUNPCKHWD  : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2659   defm PUNPCKHDQ  : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2660
2661   /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2662   /// knew to collapse (bitconvert VT to VT) into its operand.
2663   def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2664                          (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2665                          "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2666                         [(set VR128:$dst,
2667                           (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
2668   def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2669                         (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2670                         "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2671                         [(set VR128:$dst,
2672                           (v2i64 (unpckh VR128:$src1,
2673                                          (memopv2i64 addr:$src2))))]>;
2674 }
2675
2676 } // ExeDomain = SSEPackedInt
2677
2678 //===---------------------------------------------------------------------===//
2679 // SSE2 - Packed Integer Extract and Insert
2680 //===---------------------------------------------------------------------===//
2681
2682 let ExeDomain = SSEPackedInt in {
2683 multiclass sse2_pinsrw<bit Is2Addr = 1> {
2684   def rri : Ii8<0xC4, MRMSrcReg,
2685        (outs VR128:$dst), (ins VR128:$src1,
2686         GR32:$src2, i32i8imm:$src3),
2687        !if(Is2Addr,
2688            "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2689            "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
2690        [(set VR128:$dst,
2691          (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
2692   def rmi : Ii8<0xC4, MRMSrcMem,
2693                        (outs VR128:$dst), (ins VR128:$src1,
2694                         i16mem:$src2, i32i8imm:$src3),
2695        !if(Is2Addr,
2696            "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2697            "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
2698        [(set VR128:$dst,
2699          (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2700                     imm:$src3))]>;
2701 }
2702
2703 // Extract
2704 let isAsmParserOnly = 1, Predicates = [HasAVX] in
2705 def VPEXTRWri : Ii8<0xC5, MRMSrcReg,
2706                     (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2707                     "vpextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2708                     [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2709                                                 imm:$src2))]>, OpSize, VEX;
2710 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
2711                     (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2712                     "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2713                     [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2714                                                 imm:$src2))]>;
2715
2716 // Insert
2717 let isAsmParserOnly = 1, Predicates = [HasAVX] in
2718   defm PINSRW : sse2_pinsrw<0>, OpSize, VEX_4V;
2719
2720 let Constraints = "$src1 = $dst" in
2721   defm VPINSRW : sse2_pinsrw, TB, OpSize;
2722
2723 } // ExeDomain = SSEPackedInt
2724
2725 //===---------------------------------------------------------------------===//
2726 // SSE2 - Packed Mask Creation
2727 //===---------------------------------------------------------------------===//
2728
2729 let ExeDomain = SSEPackedInt in {
2730
2731 let isAsmParserOnly = 1 in
2732 def VPMOVMSKBrr : VPDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2733            "pmovmskb\t{$src, $dst|$dst, $src}",
2734            [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>, VEX;
2735 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2736            "pmovmskb\t{$src, $dst|$dst, $src}",
2737            [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2738
2739 } // ExeDomain = SSEPackedInt
2740
2741 //===---------------------------------------------------------------------===//
2742 // SSE2 - Conditional Store
2743 //===---------------------------------------------------------------------===//
2744
2745 let ExeDomain = SSEPackedInt in {
2746
2747 let isAsmParserOnly = 1 in {
2748 let Uses = [EDI] in
2749 def VMASKMOVDQU : VPDI<0xF7, MRMSrcReg, (outs),
2750            (ins VR128:$src, VR128:$mask),
2751            "maskmovdqu\t{$mask, $src|$src, $mask}",
2752            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>, VEX;
2753 let Uses = [RDI] in
2754 def VMASKMOVDQU64 : VPDI<0xF7, MRMSrcReg, (outs),
2755            (ins VR128:$src, VR128:$mask),
2756            "maskmovdqu\t{$mask, $src|$src, $mask}",
2757            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>, VEX;
2758 }
2759
2760 let Uses = [EDI] in
2761 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2762            "maskmovdqu\t{$mask, $src|$src, $mask}",
2763            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
2764 let Uses = [RDI] in
2765 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2766            "maskmovdqu\t{$mask, $src|$src, $mask}",
2767            [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2768
2769 } // ExeDomain = SSEPackedInt
2770
2771 //===---------------------------------------------------------------------===//
2772 // SSE2 - Move Doubleword
2773 //===---------------------------------------------------------------------===//
2774
2775 // Move Int Doubleword to Packed Double Int
2776 let isAsmParserOnly = 1 in {
2777 def VMOVDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2778                       "movd\t{$src, $dst|$dst, $src}",
2779                       [(set VR128:$dst,
2780                         (v4i32 (scalar_to_vector GR32:$src)))]>, VEX;
2781 def VMOVDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2782                       "movd\t{$src, $dst|$dst, $src}",
2783                       [(set VR128:$dst,
2784                         (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>,
2785                       VEX;
2786 }
2787 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2788                       "movd\t{$src, $dst|$dst, $src}",
2789                       [(set VR128:$dst,
2790                         (v4i32 (scalar_to_vector GR32:$src)))]>;
2791 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2792                       "movd\t{$src, $dst|$dst, $src}",
2793                       [(set VR128:$dst,
2794                         (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2795
2796
2797 // Move Int Doubleword to Single Scalar
2798 let isAsmParserOnly = 1 in {
2799 def VMOVDI2SSrr  : VPDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2800                       "movd\t{$src, $dst|$dst, $src}",
2801                       [(set FR32:$dst, (bitconvert GR32:$src))]>, VEX;
2802
2803 def VMOVDI2SSrm  : VPDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2804                       "movd\t{$src, $dst|$dst, $src}",
2805                       [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>,
2806                       VEX;
2807 }
2808 def MOVDI2SSrr  : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2809                       "movd\t{$src, $dst|$dst, $src}",
2810                       [(set FR32:$dst, (bitconvert GR32:$src))]>;
2811
2812 def MOVDI2SSrm  : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2813                       "movd\t{$src, $dst|$dst, $src}",
2814                       [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2815
2816 // Move Packed Doubleword Int to Packed Double Int
2817 let isAsmParserOnly = 1 in {
2818 def VMOVPDI2DIrr  : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2819                        "movd\t{$src, $dst|$dst, $src}",
2820                        [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2821                                         (iPTR 0)))]>, VEX;
2822 def VMOVPDI2DImr  : VPDI<0x7E, MRMDestMem, (outs),
2823                        (ins i32mem:$dst, VR128:$src),
2824                        "movd\t{$src, $dst|$dst, $src}",
2825                        [(store (i32 (vector_extract (v4i32 VR128:$src),
2826                                      (iPTR 0))), addr:$dst)]>, VEX;
2827 }
2828 def MOVPDI2DIrr  : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2829                        "movd\t{$src, $dst|$dst, $src}",
2830                        [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2831                                         (iPTR 0)))]>;
2832 def MOVPDI2DImr  : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
2833                        "movd\t{$src, $dst|$dst, $src}",
2834                        [(store (i32 (vector_extract (v4i32 VR128:$src),
2835                                      (iPTR 0))), addr:$dst)]>;
2836
2837 // Move Scalar Single to Double Int
2838 let isAsmParserOnly = 1 in {
2839 def VMOVSS2DIrr  : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2840                       "movd\t{$src, $dst|$dst, $src}",
2841                       [(set GR32:$dst, (bitconvert FR32:$src))]>, VEX;
2842 def VMOVSS2DImr  : VPDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2843                       "movd\t{$src, $dst|$dst, $src}",
2844                       [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>, VEX;
2845 }
2846 def MOVSS2DIrr  : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2847                       "movd\t{$src, $dst|$dst, $src}",
2848                       [(set GR32:$dst, (bitconvert FR32:$src))]>;
2849 def MOVSS2DImr  : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2850                       "movd\t{$src, $dst|$dst, $src}",
2851                       [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2852
2853 // movd / movq to XMM register zero-extends
2854 let AddedComplexity = 15, isAsmParserOnly = 1 in {
2855 def VMOVZDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2856                        "movd\t{$src, $dst|$dst, $src}",
2857                        [(set VR128:$dst, (v4i32 (X86vzmovl
2858                                       (v4i32 (scalar_to_vector GR32:$src)))))]>,
2859                                       VEX;
2860 def VMOVZQI2PQIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2861                        "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
2862                        [(set VR128:$dst, (v2i64 (X86vzmovl
2863                                       (v2i64 (scalar_to_vector GR64:$src)))))]>,
2864                                       VEX, VEX_W;
2865 }
2866 let AddedComplexity = 15 in {
2867 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2868                        "movd\t{$src, $dst|$dst, $src}",
2869                        [(set VR128:$dst, (v4i32 (X86vzmovl
2870                                       (v4i32 (scalar_to_vector GR32:$src)))))]>;
2871 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2872                        "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
2873                        [(set VR128:$dst, (v2i64 (X86vzmovl
2874                                       (v2i64 (scalar_to_vector GR64:$src)))))]>;
2875 }
2876
2877 let AddedComplexity = 20 in {
2878 let isAsmParserOnly = 1 in
2879 def VMOVZDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2880                        "movd\t{$src, $dst|$dst, $src}",
2881                        [(set VR128:$dst,
2882                          (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2883                                                    (loadi32 addr:$src))))))]>,
2884                                                    VEX;
2885 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2886                        "movd\t{$src, $dst|$dst, $src}",
2887                        [(set VR128:$dst,
2888                          (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2889                                                    (loadi32 addr:$src))))))]>;
2890
2891 def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2892             (MOVZDI2PDIrm addr:$src)>;
2893 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2894             (MOVZDI2PDIrm addr:$src)>;
2895 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2896             (MOVZDI2PDIrm addr:$src)>;
2897 }
2898
2899 //===---------------------------------------------------------------------===//
2900 // SSE2 - Move Quadword
2901 //===---------------------------------------------------------------------===//
2902
2903 // Move Quadword Int to Packed Quadword Int
2904 let isAsmParserOnly = 1 in
2905 def VMOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2906                     "vmovq\t{$src, $dst|$dst, $src}",
2907                     [(set VR128:$dst,
2908                       (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2909                     VEX, Requires<[HasAVX]>;
2910 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2911                     "movq\t{$src, $dst|$dst, $src}",
2912                     [(set VR128:$dst,
2913                       (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2914                     Requires<[HasSSE2]>; // SSE2 instruction with XS Prefix
2915
2916 // Move Packed Quadword Int to Quadword Int
2917 let isAsmParserOnly = 1 in
2918 def VMOVPQI2QImr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2919                       "movq\t{$src, $dst|$dst, $src}",
2920                       [(store (i64 (vector_extract (v2i64 VR128:$src),
2921                                     (iPTR 0))), addr:$dst)]>, VEX;
2922 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2923                       "movq\t{$src, $dst|$dst, $src}",
2924                       [(store (i64 (vector_extract (v2i64 VR128:$src),
2925                                     (iPTR 0))), addr:$dst)]>;
2926
2927 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
2928           (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
2929
2930 // Store / copy lower 64-bits of a XMM register.
2931 let isAsmParserOnly = 1 in
2932 def VMOVLQ128mr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2933                      "movq\t{$src, $dst|$dst, $src}",
2934                      [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>, VEX;
2935 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2936                      "movq\t{$src, $dst|$dst, $src}",
2937                      [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2938
2939 let AddedComplexity = 20, isAsmParserOnly = 1 in
2940 def VMOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2941                      "vmovq\t{$src, $dst|$dst, $src}",
2942                      [(set VR128:$dst,
2943                        (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2944                                                  (loadi64 addr:$src))))))]>,
2945                      XS, VEX, Requires<[HasAVX]>;
2946
2947 let AddedComplexity = 20 in {
2948 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2949                      "movq\t{$src, $dst|$dst, $src}",
2950                      [(set VR128:$dst,
2951                        (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2952                                                  (loadi64 addr:$src))))))]>,
2953                      XS, Requires<[HasSSE2]>;
2954
2955 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2956             (MOVZQI2PQIrm addr:$src)>;
2957 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2958             (MOVZQI2PQIrm addr:$src)>;
2959 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
2960 }
2961
2962 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2963 // IA32 document. movq xmm1, xmm2 does clear the high bits.
2964 let isAsmParserOnly = 1, AddedComplexity = 15 in
2965 def VMOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2966                         "vmovq\t{$src, $dst|$dst, $src}",
2967                     [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2968                       XS, VEX, Requires<[HasAVX]>;
2969 let AddedComplexity = 15 in
2970 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2971                         "movq\t{$src, $dst|$dst, $src}",
2972                     [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2973                       XS, Requires<[HasSSE2]>;
2974
2975 let AddedComplexity = 20, isAsmParserOnly = 1 in
2976 def VMOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2977                         "vmovq\t{$src, $dst|$dst, $src}",
2978                     [(set VR128:$dst, (v2i64 (X86vzmovl
2979                                              (loadv2i64 addr:$src))))]>,
2980                       XS, VEX, Requires<[HasAVX]>;
2981 let AddedComplexity = 20 in {
2982 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2983                         "movq\t{$src, $dst|$dst, $src}",
2984                     [(set VR128:$dst, (v2i64 (X86vzmovl
2985                                              (loadv2i64 addr:$src))))]>,
2986                       XS, Requires<[HasSSE2]>;
2987
2988 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2989             (MOVZPQILo2PQIrm addr:$src)>;
2990 }
2991
2992 // Instructions to match in the assembler
2993 let isAsmParserOnly = 1 in {
2994 def VMOVQs64rr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2995                       "movq\t{$src, $dst|$dst, $src}", []>, VEX, VEX_W;
2996 def VMOVQd64rr : VPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
2997                       "movq\t{$src, $dst|$dst, $src}", []>, VEX, VEX_W;
2998 // Recognize "movd" with GR64 destination, but encode as a "movq"
2999 def VMOVQd64rr_alt : VPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
3000                           "movd\t{$src, $dst|$dst, $src}", []>, VEX, VEX_W;
3001 }
3002
3003 // Instructions for the disassembler
3004 // xr = XMM register
3005 // xm = mem64
3006
3007 let isAsmParserOnly = 1 in
3008 def VMOVQxrxr: I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3009                  "vmovq\t{$src, $dst|$dst, $src}", []>, VEX, XS;
3010 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3011                  "movq\t{$src, $dst|$dst, $src}", []>, XS;
3012
3013 //===---------------------------------------------------------------------===//
3014 // SSE2 - Misc Instructions
3015 //===---------------------------------------------------------------------===//
3016
3017 // Flush cache
3018 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
3019                "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
3020               TB, Requires<[HasSSE2]>;
3021
3022 // Load, store, and memory fence
3023 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
3024                "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
3025 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
3026                "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
3027
3028 // Pause. This "instruction" is encoded as "rep; nop", so even though it
3029 // was introduced with SSE2, it's backward compatible.
3030 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
3031
3032 //TODO: custom lower this so as to never even generate the noop
3033 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
3034            (i8 0)), (NOOP)>;
3035 def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
3036 def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
3037 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
3038            (i8 1)), (MFENCE)>;
3039
3040 // Alias instructions that map zero vector to pxor / xorp* for sse.
3041 // We set canFoldAsLoad because this can be converted to a constant-pool
3042 // load of an all-ones value if folding it would be beneficial.
3043 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
3044     isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
3045   // FIXME: Change encoding to pseudo.
3046   def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
3047                          [(set VR128:$dst, (v4i32 immAllOnesV))]>;
3048
3049 //===---------------------------------------------------------------------===//
3050 // SSE3 - Conversion Instructions
3051 //===---------------------------------------------------------------------===//
3052
3053 // Convert Packed Double FP to Packed DW Integers
3054 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3055 // The assembler can recognize rr 256-bit instructions by seeing a ymm
3056 // register, but the same isn't true when using memory operands instead.
3057 // Provide other assembly rr and rm forms to address this explicitly.
3058 def VCVTPD2DQrr  : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3059                        "vcvtpd2dq\t{$src, $dst|$dst, $src}", []>, VEX;
3060 def VCVTPD2DQXrYr  : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
3061                        "vcvtpd2dq\t{$src, $dst|$dst, $src}", []>, VEX;
3062
3063 // XMM only
3064 def VCVTPD2DQXrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3065                       "vcvtpd2dqx\t{$src, $dst|$dst, $src}", []>, VEX;
3066 def VCVTPD2DQXrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3067                       "vcvtpd2dqx\t{$src, $dst|$dst, $src}", []>, VEX;
3068
3069 // YMM only
3070 def VCVTPD2DQYrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
3071                       "vcvtpd2dqy\t{$src, $dst|$dst, $src}", []>, VEX;
3072 def VCVTPD2DQYrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
3073                       "vcvtpd2dqy\t{$src, $dst|$dst, $src}", []>, VEX, VEX_L;
3074 }
3075
3076 def CVTPD2DQrm  : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3077                        "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
3078 def CVTPD2DQrr  : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3079                        "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
3080
3081 // Convert Packed DW Integers to Packed Double FP
3082 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3083 def VCVTDQ2PDrm  : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3084                        "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
3085 def VCVTDQ2PDrr  : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3086                        "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
3087 def VCVTDQ2PDYrm  : S3SI<0xE6, MRMSrcMem, (outs VR256:$dst), (ins f128mem:$src),
3088                        "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
3089 def VCVTDQ2PDYrr  : S3SI<0xE6, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
3090                        "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
3091 }
3092
3093 def CVTDQ2PDrm  : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3094                        "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
3095 def CVTDQ2PDrr  : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3096                        "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
3097
3098 //===---------------------------------------------------------------------===//
3099 // SSE3 - Move Instructions
3100 //===---------------------------------------------------------------------===//
3101
3102 // Replicate Single FP
3103 multiclass sse3_replicate_sfp<bits<8> op, PatFrag rep_frag, string OpcodeStr> {
3104 def rr : S3SI<op, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3105                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3106                       [(set VR128:$dst, (v4f32 (rep_frag
3107                                                 VR128:$src, (undef))))]>;
3108 def rm : S3SI<op, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3109                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3110                       [(set VR128:$dst, (rep_frag
3111                                          (memopv4f32 addr:$src), (undef)))]>;
3112 }
3113
3114 multiclass sse3_replicate_sfp_y<bits<8> op, PatFrag rep_frag,
3115                                 string OpcodeStr> {
3116 def rr : S3SI<op, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3117               !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"), []>;
3118 def rm : S3SI<op, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3119               !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"), []>;
3120 }
3121
3122 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3123   // FIXME: Merge above classes when we have patterns for the ymm version
3124   defm VMOVSHDUP  : sse3_replicate_sfp<0x16, movshdup, "vmovshdup">, VEX;
3125   defm VMOVSLDUP  : sse3_replicate_sfp<0x12, movsldup, "vmovsldup">, VEX;
3126   defm VMOVSHDUPY : sse3_replicate_sfp_y<0x16, movshdup, "vmovshdup">, VEX;
3127   defm VMOVSLDUPY : sse3_replicate_sfp_y<0x12, movsldup, "vmovsldup">, VEX;
3128 }
3129 defm MOVSHDUP : sse3_replicate_sfp<0x16, movshdup, "movshdup">;
3130 defm MOVSLDUP : sse3_replicate_sfp<0x12, movsldup, "movsldup">;
3131
3132 // Replicate Double FP
3133 multiclass sse3_replicate_dfp<string OpcodeStr> {
3134 def rr  : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3135                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3136                     [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
3137 def rm  : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
3138                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3139                     [(set VR128:$dst,
3140                       (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
3141                                       (undef))))]>;
3142 }
3143
3144 multiclass sse3_replicate_dfp_y<string OpcodeStr> {
3145 def rr  : S3DI<0x12, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3146                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3147                     []>;
3148 def rm  : S3DI<0x12, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3149                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3150                     []>;
3151 }
3152
3153 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3154   // FIXME: Merge above classes when we have patterns for the ymm version
3155   defm VMOVDDUP  : sse3_replicate_dfp<"vmovddup">, VEX;
3156   defm VMOVDDUPY : sse3_replicate_dfp_y<"vmovddup">, VEX;
3157 }
3158 defm MOVDDUP : sse3_replicate_dfp<"movddup">;
3159
3160 // Move Unaligned Integer
3161 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3162   def VLDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3163                      "vlddqu\t{$src, $dst|$dst, $src}",
3164                      [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>, VEX;
3165   def VLDDQUYrm : S3DI<0xF0, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
3166                      "vlddqu\t{$src, $dst|$dst, $src}", []>, VEX;
3167 }
3168 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3169                    "lddqu\t{$src, $dst|$dst, $src}",
3170                    [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
3171
3172 def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
3173                    (undef)),
3174           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3175
3176 // Several Move patterns
3177 let AddedComplexity = 5 in {
3178 def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
3179           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3180 def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
3181           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3182 def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
3183           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3184 def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
3185           (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
3186 }
3187
3188 // vector_shuffle v1, <undef> <1, 1, 3, 3>
3189 let AddedComplexity = 15 in
3190 def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
3191           (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
3192 let AddedComplexity = 20 in
3193 def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
3194           (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
3195
3196 // vector_shuffle v1, <undef> <0, 0, 2, 2>
3197 let AddedComplexity = 15 in
3198   def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
3199             (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
3200 let AddedComplexity = 20 in
3201   def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
3202             (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
3203
3204 //===---------------------------------------------------------------------===//
3205 // SSE3 - Arithmetic
3206 //===---------------------------------------------------------------------===//
3207
3208 multiclass sse3_addsub<Intrinsic Int, string OpcodeStr, RegisterClass RC,
3209                        X86MemOperand x86memop, bit Is2Addr = 1> {
3210   def rr : I<0xD0, MRMSrcReg,
3211        (outs RC:$dst), (ins RC:$src1, RC:$src2),
3212        !if(Is2Addr,
3213            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3214            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3215        [(set RC:$dst, (Int RC:$src1, RC:$src2))]>;
3216   def rm : I<0xD0, MRMSrcMem,
3217        (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
3218        !if(Is2Addr,
3219            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3220            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3221        [(set RC:$dst, (Int RC:$src1, (memop addr:$src2)))]>;
3222 }
3223
3224 let isAsmParserOnly = 1, Predicates = [HasAVX],
3225   ExeDomain = SSEPackedDouble in {
3226   defm VADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "vaddsubps", VR128,
3227                                f128mem, 0>, XD, VEX_4V;
3228   defm VADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "vaddsubpd", VR128,
3229                                f128mem, 0>, OpSize, VEX_4V;
3230   let Pattern = []<dag> in {
3231   defm VADDSUBPSY : sse3_addsub<int_x86_sse3_addsub_ps, "vaddsubps", VR256,
3232                                f256mem, 0>, XD, VEX_4V;
3233   defm VADDSUBPDY : sse3_addsub<int_x86_sse3_addsub_pd, "vaddsubpd", VR256,
3234                                f256mem, 0>, OpSize, VEX_4V;
3235   }
3236 }
3237 let Constraints = "$src1 = $dst", Predicates = [HasSSE3],
3238     ExeDomain = SSEPackedDouble in {
3239   defm ADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "addsubps", VR128,
3240                               f128mem>, XD;
3241   defm ADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "addsubpd", VR128,
3242                               f128mem>, TB, OpSize;
3243 }
3244
3245 //===---------------------------------------------------------------------===//
3246 // SSE3 Instructions
3247 //===---------------------------------------------------------------------===//
3248
3249 // Horizontal ops
3250 multiclass S3D_Int<bits<8> o, string OpcodeStr, ValueType vt, RegisterClass RC,
3251                    X86MemOperand x86memop, Intrinsic IntId, bit Is2Addr = 1> {
3252   def rr : S3DI<o, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
3253        !if(Is2Addr,
3254          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3255          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3256       [(set RC:$dst, (vt (IntId RC:$src1, RC:$src2)))]>;
3257
3258   def rm : S3DI<o, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
3259        !if(Is2Addr,
3260          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3261          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3262       [(set RC:$dst, (vt (IntId RC:$src1, (memop addr:$src2))))]>;
3263 }
3264 multiclass S3_Int<bits<8> o, string OpcodeStr, ValueType vt, RegisterClass RC,
3265                   X86MemOperand x86memop, Intrinsic IntId, bit Is2Addr = 1> {
3266   def rr : S3I<o, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
3267        !if(Is2Addr,
3268          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3269          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3270       [(set RC:$dst, (vt (IntId RC:$src1, RC:$src2)))]>;
3271
3272   def rm : S3I<o, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
3273        !if(Is2Addr,
3274          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3275          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3276       [(set RC:$dst, (vt (IntId RC:$src1, (memop addr:$src2))))]>;
3277 }
3278
3279 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3280   defm VHADDPS : S3D_Int<0x7C, "vhaddps", v4f32, VR128, f128mem,
3281                          int_x86_sse3_hadd_ps, 0>, VEX_4V;
3282   defm VHADDPD : S3_Int <0x7C, "vhaddpd", v2f64, VR128, f128mem,
3283                          int_x86_sse3_hadd_pd, 0>, VEX_4V;
3284   defm VHSUBPS : S3D_Int<0x7D, "vhsubps", v4f32, VR128, f128mem,
3285                          int_x86_sse3_hsub_ps, 0>, VEX_4V;
3286   defm VHSUBPD : S3_Int <0x7D, "vhsubpd", v2f64, VR128, f128mem,
3287                          int_x86_sse3_hsub_pd, 0>, VEX_4V;
3288   let Pattern = []<dag> in {
3289   defm VHADDPSY : S3D_Int<0x7C, "vhaddps", v8f32, VR256, f256mem,
3290                           int_x86_sse3_hadd_ps, 0>, VEX_4V;
3291   defm VHADDPDY : S3_Int <0x7C, "vhaddpd", v4f64, VR256, f256mem,
3292                           int_x86_sse3_hadd_pd, 0>, VEX_4V;
3293   defm VHSUBPSY : S3D_Int<0x7D, "vhsubps", v8f32, VR256, f256mem,
3294                           int_x86_sse3_hsub_ps, 0>, VEX_4V;
3295   defm VHSUBPDY : S3_Int <0x7D, "vhsubpd", v4f64, VR256, f256mem,
3296                           int_x86_sse3_hsub_pd, 0>, VEX_4V;
3297   }
3298 }
3299
3300 let Constraints = "$src1 = $dst" in {
3301   defm HADDPS : S3D_Int<0x7C, "haddps", v4f32, VR128, f128mem,
3302                         int_x86_sse3_hadd_ps>;
3303   defm HADDPD : S3_Int<0x7C, "haddpd", v2f64, VR128, f128mem,
3304                        int_x86_sse3_hadd_pd>;
3305   defm HSUBPS : S3D_Int<0x7D, "hsubps", v4f32, VR128, f128mem,
3306                         int_x86_sse3_hsub_ps>;
3307   defm HSUBPD : S3_Int<0x7D, "hsubpd", v2f64, VR128, f128mem,
3308                        int_x86_sse3_hsub_pd>;
3309 }
3310
3311 //===---------------------------------------------------------------------===//
3312 // SSSE3 - Packed Absolute Instructions
3313 //===---------------------------------------------------------------------===//
3314
3315 /// SS3I_unop_rm_int - Simple SSSE3 unary op whose type can be v*{i8,i16,i32}.
3316 multiclass SS3I_unop_rm_int<bits<8> opc, string OpcodeStr,
3317                             PatFrag mem_frag64, PatFrag mem_frag128,
3318                             Intrinsic IntId64, Intrinsic IntId128> {
3319   def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
3320                    !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3321                    [(set VR64:$dst, (IntId64 VR64:$src))]>;
3322
3323   def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
3324                    !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3325                    [(set VR64:$dst,
3326                      (IntId64 (bitconvert (mem_frag64 addr:$src))))]>;
3327
3328   def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
3329                     (ins VR128:$src),
3330                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3331                     [(set VR128:$dst, (IntId128 VR128:$src))]>,
3332                     OpSize;
3333
3334   def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
3335                     (ins i128mem:$src),
3336                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3337                     [(set VR128:$dst,
3338                       (IntId128
3339                        (bitconvert (mem_frag128 addr:$src))))]>, OpSize;
3340 }
3341
3342 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3343   defm VPABSB  : SS3I_unop_rm_int<0x1C, "vpabsb", memopv8i8, memopv16i8,
3344                                   int_x86_ssse3_pabs_b,
3345                                   int_x86_ssse3_pabs_b_128>, VEX;
3346   defm VPABSW  : SS3I_unop_rm_int<0x1D, "vpabsw", memopv4i16, memopv8i16,
3347                                   int_x86_ssse3_pabs_w,
3348                                   int_x86_ssse3_pabs_w_128>, VEX;
3349   defm VPABSD  : SS3I_unop_rm_int<0x1E, "vpabsd", memopv2i32, memopv4i32,
3350                                   int_x86_ssse3_pabs_d,
3351                                   int_x86_ssse3_pabs_d_128>, VEX;
3352 }
3353
3354 defm PABSB       : SS3I_unop_rm_int<0x1C, "pabsb", memopv8i8, memopv16i8,
3355                                     int_x86_ssse3_pabs_b,
3356                                     int_x86_ssse3_pabs_b_128>;
3357 defm PABSW       : SS3I_unop_rm_int<0x1D, "pabsw", memopv4i16, memopv8i16,
3358                                     int_x86_ssse3_pabs_w,
3359                                     int_x86_ssse3_pabs_w_128>;
3360 defm PABSD       : SS3I_unop_rm_int<0x1E, "pabsd", memopv2i32, memopv4i32,
3361                                     int_x86_ssse3_pabs_d,
3362                                     int_x86_ssse3_pabs_d_128>;
3363
3364 //===---------------------------------------------------------------------===//
3365 // SSSE3 - Packed Binary Operator Instructions
3366 //===---------------------------------------------------------------------===//
3367
3368 /// SS3I_binop_rm_int - Simple SSSE3 bin op whose type can be v*{i8,i16,i32}.
3369 multiclass SS3I_binop_rm_int<bits<8> opc, string OpcodeStr,
3370                              PatFrag mem_frag64, PatFrag mem_frag128,
3371                              Intrinsic IntId64, Intrinsic IntId128,
3372                              bit Is2Addr = 1> {
3373   let isCommutable = 1 in
3374   def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
3375        (ins VR64:$src1, VR64:$src2),
3376        !if(Is2Addr,
3377          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3378          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3379        [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]>;
3380   def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
3381        (ins VR64:$src1, i64mem:$src2),
3382        !if(Is2Addr,
3383          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3384          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3385        [(set VR64:$dst,
3386          (IntId64 VR64:$src1,
3387           (bitconvert (memopv8i8 addr:$src2))))]>;
3388
3389   let isCommutable = 1 in
3390   def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
3391        (ins VR128:$src1, VR128:$src2),
3392        !if(Is2Addr,
3393          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3394          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3395        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3396        OpSize;
3397   def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
3398        (ins VR128:$src1, i128mem:$src2),
3399        !if(Is2Addr,
3400          !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3401          !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3402        [(set VR128:$dst,
3403          (IntId128 VR128:$src1,
3404           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3405 }
3406
3407 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3408 let isCommutable = 0 in {
3409   defm VPHADDW    : SS3I_binop_rm_int<0x01, "vphaddw", memopv4i16, memopv8i16,
3410                                       int_x86_ssse3_phadd_w,
3411                                       int_x86_ssse3_phadd_w_128, 0>, VEX_4V;
3412   defm VPHADDD    : SS3I_binop_rm_int<0x02, "vphaddd", memopv2i32, memopv4i32,
3413                                       int_x86_ssse3_phadd_d,
3414                                       int_x86_ssse3_phadd_d_128, 0>, VEX_4V;
3415   defm VPHADDSW   : SS3I_binop_rm_int<0x03, "vphaddsw", memopv4i16, memopv8i16,
3416                                       int_x86_ssse3_phadd_sw,
3417                                       int_x86_ssse3_phadd_sw_128, 0>, VEX_4V;
3418   defm VPHSUBW    : SS3I_binop_rm_int<0x05, "vphsubw", memopv4i16, memopv8i16,
3419                                       int_x86_ssse3_phsub_w,
3420                                       int_x86_ssse3_phsub_w_128, 0>, VEX_4V;
3421   defm VPHSUBD    : SS3I_binop_rm_int<0x06, "vphsubd", memopv2i32, memopv4i32,
3422                                       int_x86_ssse3_phsub_d,
3423                                       int_x86_ssse3_phsub_d_128, 0>, VEX_4V;
3424   defm VPHSUBSW   : SS3I_binop_rm_int<0x07, "vphsubsw", memopv4i16, memopv8i16,
3425                                       int_x86_ssse3_phsub_sw,
3426                                       int_x86_ssse3_phsub_sw_128, 0>, VEX_4V;
3427   defm VPMADDUBSW : SS3I_binop_rm_int<0x04, "vpmaddubsw", memopv8i8, memopv16i8,
3428                                       int_x86_ssse3_pmadd_ub_sw,
3429                                       int_x86_ssse3_pmadd_ub_sw_128, 0>, VEX_4V;
3430   defm VPSHUFB    : SS3I_binop_rm_int<0x00, "vpshufb", memopv8i8, memopv16i8,
3431                                       int_x86_ssse3_pshuf_b,
3432                                       int_x86_ssse3_pshuf_b_128, 0>, VEX_4V;
3433   defm VPSIGNB    : SS3I_binop_rm_int<0x08, "vpsignb", memopv8i8, memopv16i8,
3434                                       int_x86_ssse3_psign_b,
3435                                       int_x86_ssse3_psign_b_128, 0>, VEX_4V;
3436   defm VPSIGNW    : SS3I_binop_rm_int<0x09, "vpsignw", memopv4i16, memopv8i16,
3437                                       int_x86_ssse3_psign_w,
3438                                       int_x86_ssse3_psign_w_128, 0>, VEX_4V;
3439   defm VPSIGND    : SS3I_binop_rm_int<0x0A, "vpsignd", memopv2i32, memopv4i32,
3440                                       int_x86_ssse3_psign_d,
3441                                       int_x86_ssse3_psign_d_128, 0>, VEX_4V;
3442 }
3443 defm VPMULHRSW    : SS3I_binop_rm_int<0x0B, "vpmulhrsw", memopv4i16, memopv8i16,
3444                                       int_x86_ssse3_pmul_hr_sw,
3445                                       int_x86_ssse3_pmul_hr_sw_128, 0>, VEX_4V;
3446 }
3447
3448 // None of these have i8 immediate fields.
3449 let ImmT = NoImm, Constraints = "$src1 = $dst" in {
3450 let isCommutable = 0 in {
3451   defm PHADDW    : SS3I_binop_rm_int<0x01, "phaddw", memopv4i16, memopv8i16,
3452                                      int_x86_ssse3_phadd_w,
3453                                      int_x86_ssse3_phadd_w_128>;
3454   defm PHADDD    : SS3I_binop_rm_int<0x02, "phaddd", memopv2i32, memopv4i32,
3455                                      int_x86_ssse3_phadd_d,
3456                                      int_x86_ssse3_phadd_d_128>;
3457   defm PHADDSW   : SS3I_binop_rm_int<0x03, "phaddsw", memopv4i16, memopv8i16,
3458                                      int_x86_ssse3_phadd_sw,
3459                                      int_x86_ssse3_phadd_sw_128>;
3460   defm PHSUBW    : SS3I_binop_rm_int<0x05, "phsubw", memopv4i16, memopv8i16,
3461                                      int_x86_ssse3_phsub_w,
3462                                      int_x86_ssse3_phsub_w_128>;
3463   defm PHSUBD    : SS3I_binop_rm_int<0x06, "phsubd", memopv2i32, memopv4i32,
3464                                      int_x86_ssse3_phsub_d,
3465                                      int_x86_ssse3_phsub_d_128>;
3466   defm PHSUBSW   : SS3I_binop_rm_int<0x07, "phsubsw", memopv4i16, memopv8i16,
3467                                      int_x86_ssse3_phsub_sw,
3468                                      int_x86_ssse3_phsub_sw_128>;
3469   defm PMADDUBSW : SS3I_binop_rm_int<0x04, "pmaddubsw", memopv8i8, memopv16i8,
3470                                      int_x86_ssse3_pmadd_ub_sw,
3471                                      int_x86_ssse3_pmadd_ub_sw_128>;
3472   defm PSHUFB    : SS3I_binop_rm_int<0x00, "pshufb", memopv8i8, memopv16i8,
3473                                      int_x86_ssse3_pshuf_b,
3474                                      int_x86_ssse3_pshuf_b_128>;
3475   defm PSIGNB    : SS3I_binop_rm_int<0x08, "psignb", memopv8i8, memopv16i8,
3476                                      int_x86_ssse3_psign_b,
3477                                      int_x86_ssse3_psign_b_128>;
3478   defm PSIGNW    : SS3I_binop_rm_int<0x09, "psignw", memopv4i16, memopv8i16,
3479                                      int_x86_ssse3_psign_w,
3480                                      int_x86_ssse3_psign_w_128>;
3481   defm PSIGND    : SS3I_binop_rm_int<0x0A, "psignd", memopv2i32, memopv4i32,
3482                                        int_x86_ssse3_psign_d,
3483                                        int_x86_ssse3_psign_d_128>;
3484 }
3485 defm PMULHRSW    : SS3I_binop_rm_int<0x0B, "pmulhrsw", memopv4i16, memopv8i16,
3486                                      int_x86_ssse3_pmul_hr_sw,
3487                                      int_x86_ssse3_pmul_hr_sw_128>;
3488 }
3489
3490 def : Pat<(X86pshufb VR128:$src, VR128:$mask),
3491           (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
3492 def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
3493           (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
3494
3495 //===---------------------------------------------------------------------===//
3496 // SSSE3 - Packed Align Instruction Patterns
3497 //===---------------------------------------------------------------------===//
3498
3499 multiclass sse3_palign<string asm, bit Is2Addr = 1> {
3500   def R64rr  : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
3501       (ins VR64:$src1, VR64:$src2, i8imm:$src3),
3502       !if(Is2Addr,
3503         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3504         !strconcat(asm,
3505                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3506       []>;
3507   def R64rm  : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
3508       (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
3509       !if(Is2Addr,
3510         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3511         !strconcat(asm,
3512                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3513       []>;
3514
3515   def R128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
3516       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3517       !if(Is2Addr,
3518         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3519         !strconcat(asm,
3520                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3521       []>, OpSize;
3522   def R128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
3523       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3524       !if(Is2Addr,
3525         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3526         !strconcat(asm,
3527                   "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
3528       []>, OpSize;
3529 }
3530
3531 let isAsmParserOnly = 1, Predicates = [HasAVX] in
3532   defm VPALIGN : sse3_palign<"vpalignr", 0>, VEX_4V;
3533 let Constraints = "$src1 = $dst" in
3534   defm PALIGN : sse3_palign<"palignr">;
3535
3536 let AddedComplexity = 5 in {
3537
3538 def : Pat<(v1i64 (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<(v2i32 (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<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
3547           (PALIGNR64rr VR64:$src2, VR64:$src1,
3548                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3549           Requires<[HasSSSE3]>;
3550 def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
3551           (PALIGNR64rr VR64:$src2, VR64:$src1,
3552                        (SHUFFLE_get_palign_imm VR64:$src3))>,
3553           Requires<[HasSSSE3]>;
3554
3555 def : Pat<(v4i32 (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<(v4f32 (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<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
3564           (PALIGNR128rr VR128:$src2, VR128:$src1,
3565                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3566       Requires<[HasSSSE3]>;
3567 def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
3568           (PALIGNR128rr VR128:$src2, VR128:$src1,
3569                         (SHUFFLE_get_palign_imm VR128:$src3))>,
3570       Requires<[HasSSSE3]>;
3571 }
3572
3573 //===---------------------------------------------------------------------===//
3574 // SSSE3 Misc Instructions
3575 //===---------------------------------------------------------------------===//
3576
3577 // Thread synchronization
3578 def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
3579                 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
3580 def MWAIT   : I<0x01, MRM_C9, (outs), (ins), "mwait",
3581                 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
3582
3583 //===---------------------------------------------------------------------===//
3584 // Non-Instruction Patterns
3585 //===---------------------------------------------------------------------===//
3586
3587 // extload f32 -> f64.  This matches load+fextend because we have a hack in
3588 // the isel (PreprocessForFPConvert) that can introduce loads after dag
3589 // combine.
3590 // Since these loads aren't folded into the fextend, we have to match it
3591 // explicitly here.
3592 let Predicates = [HasSSE2] in
3593  def : Pat<(fextend (loadf32 addr:$src)),
3594            (CVTSS2SDrm addr:$src)>;
3595
3596 // bit_convert
3597 let Predicates = [HasSSE2] in {
3598   def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
3599   def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
3600   def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
3601   def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
3602   def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
3603   def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
3604   def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
3605   def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
3606   def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
3607   def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
3608   def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
3609   def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
3610   def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
3611   def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
3612   def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
3613   def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
3614   def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
3615   def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
3616   def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
3617   def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
3618   def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
3619   def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
3620   def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
3621   def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
3622   def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
3623   def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
3624   def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
3625   def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
3626   def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
3627   def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
3628 }
3629
3630 // Move scalar to XMM zero-extended
3631 // movd to XMM register zero-extends
3632 let AddedComplexity = 15 in {
3633 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
3634 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
3635           (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
3636 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
3637           (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
3638 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
3639           (MOVSSrr (v4f32 (V_SET0PS)),
3640                    (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
3641 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
3642           (MOVSSrr (v4i32 (V_SET0PI)),
3643                    (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
3644 }
3645
3646 // Splat v2f64 / v2i64
3647 let AddedComplexity = 10 in {
3648 def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
3649           (UNPCKLPDrr VR128:$src, VR128:$src)>,   Requires<[HasSSE2]>;
3650 def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
3651           (UNPCKHPDrr VR128:$src, VR128:$src)>,   Requires<[HasSSE2]>;
3652 def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
3653           (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3654 def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
3655           (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
3656 }
3657
3658 // Special unary SHUFPSrri case.
3659 def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
3660           (SHUFPSrri VR128:$src1, VR128:$src1,
3661                      (SHUFFLE_get_shuf_imm VR128:$src3))>;
3662 let AddedComplexity = 5 in
3663 def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
3664           (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3665       Requires<[HasSSE2]>;
3666 // Special unary SHUFPDrri case.
3667 def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
3668           (SHUFPDrri VR128:$src1, VR128:$src1,
3669                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3670       Requires<[HasSSE2]>;
3671 // Special unary SHUFPDrri case.
3672 def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
3673           (SHUFPDrri VR128:$src1, VR128:$src1,
3674                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3675       Requires<[HasSSE2]>;
3676 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
3677 def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
3678           (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3679       Requires<[HasSSE2]>;
3680
3681 // Special binary v4i32 shuffle cases with SHUFPS.
3682 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
3683           (SHUFPSrri VR128:$src1, VR128:$src2,
3684                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3685            Requires<[HasSSE2]>;
3686 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
3687           (SHUFPSrmi VR128:$src1, addr:$src2,
3688                     (SHUFFLE_get_shuf_imm VR128:$src3))>,
3689            Requires<[HasSSE2]>;
3690 // Special binary v2i64 shuffle cases using SHUFPDrri.
3691 def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
3692           (SHUFPDrri VR128:$src1, VR128:$src2,
3693                      (SHUFFLE_get_shuf_imm VR128:$src3))>,
3694           Requires<[HasSSE2]>;
3695
3696 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
3697 let AddedComplexity = 15 in {
3698 def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
3699           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3700           Requires<[OptForSpeed, HasSSE2]>;
3701 def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
3702           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3703           Requires<[OptForSpeed, HasSSE2]>;
3704 }
3705 let AddedComplexity = 10 in {
3706 def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
3707           (UNPCKLPSrr VR128:$src, VR128:$src)>;
3708 def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
3709           (PUNPCKLBWrr VR128:$src, VR128:$src)>;
3710 def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
3711           (PUNPCKLWDrr VR128:$src, VR128:$src)>;
3712 def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
3713           (PUNPCKLDQrr VR128:$src, VR128:$src)>;
3714 }
3715
3716 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
3717 let AddedComplexity = 15 in {
3718 def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
3719           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3720           Requires<[OptForSpeed, HasSSE2]>;
3721 def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
3722           (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3723           Requires<[OptForSpeed, HasSSE2]>;
3724 }
3725 let AddedComplexity = 10 in {
3726 def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
3727           (UNPCKHPSrr VR128:$src, VR128:$src)>;
3728 def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
3729           (PUNPCKHBWrr VR128:$src, VR128:$src)>;
3730 def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
3731           (PUNPCKHWDrr VR128:$src, VR128:$src)>;
3732 def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
3733           (PUNPCKHDQrr VR128:$src, VR128:$src)>;
3734 }
3735
3736 let AddedComplexity = 20 in {
3737 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
3738 def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
3739           (MOVLHPSrr VR128:$src1, VR128:$src2)>;
3740
3741 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
3742 def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
3743           (MOVHLPSrr VR128:$src1, VR128:$src2)>;
3744
3745 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
3746 def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
3747           (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3748 def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
3749           (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3750 }
3751
3752 let AddedComplexity = 20 in {
3753 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
3754 def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
3755           (MOVLPSrm VR128:$src1, addr:$src2)>;
3756 def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
3757           (MOVLPDrm VR128:$src1, addr:$src2)>;
3758 def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
3759           (MOVLPSrm VR128:$src1, addr:$src2)>;
3760 def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
3761           (MOVLPDrm VR128:$src1, addr:$src2)>;
3762 }
3763
3764 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3765 def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3766           (MOVLPSmr addr:$src1, VR128:$src2)>;
3767 def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3768           (MOVLPDmr addr:$src1, VR128:$src2)>;
3769 def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3770                  addr:$src1),
3771           (MOVLPSmr addr:$src1, VR128:$src2)>;
3772 def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3773           (MOVLPDmr addr:$src1, VR128:$src2)>;
3774
3775 let AddedComplexity = 15 in {
3776 // Setting the lowest element in the vector.
3777 def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
3778           (MOVSSrr (v4i32 VR128:$src1),
3779                    (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
3780 def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
3781           (MOVSDrr (v2i64 VR128:$src1),
3782                    (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
3783
3784 // vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
3785 def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
3786           (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3787       Requires<[HasSSE2]>;
3788 def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
3789           (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3790       Requires<[HasSSE2]>;
3791 }
3792
3793 // vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3794 // fall back to this for SSE1)
3795 def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
3796           (SHUFPSrri VR128:$src2, VR128:$src1,
3797                      (SHUFFLE_get_shuf_imm VR128:$src3))>;
3798
3799 // Set lowest element and zero upper elements.
3800 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
3801           (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3802
3803 // Some special case pandn patterns.
3804 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3805                   VR128:$src2)),
3806           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3807 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3808                   VR128:$src2)),
3809           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3810 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3811                   VR128:$src2)),
3812           (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3813
3814 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3815                   (memop addr:$src2))),
3816           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3817 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3818                   (memop addr:$src2))),
3819           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3820 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3821                   (memop addr:$src2))),
3822           (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3823
3824 // vector -> vector casts
3825 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3826           (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3827 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3828           (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3829 def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3830           (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3831 def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3832           (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
3833
3834 // Use movaps / movups for SSE integer load / store (one byte shorter).
3835 def : Pat<(alignedloadv4i32 addr:$src),
3836           (MOVAPSrm addr:$src)>;
3837 def : Pat<(loadv4i32 addr:$src),
3838           (MOVUPSrm addr:$src)>;
3839 def : Pat<(alignedloadv2i64 addr:$src),
3840           (MOVAPSrm addr:$src)>;
3841 def : Pat<(loadv2i64 addr:$src),
3842           (MOVUPSrm addr:$src)>;
3843
3844 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3845           (MOVAPSmr addr:$dst, VR128:$src)>;
3846 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3847           (MOVAPSmr addr:$dst, VR128:$src)>;
3848 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3849           (MOVAPSmr addr:$dst, VR128:$src)>;
3850 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3851           (MOVAPSmr addr:$dst, VR128:$src)>;
3852 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3853           (MOVUPSmr addr:$dst, VR128:$src)>;
3854 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3855           (MOVUPSmr addr:$dst, VR128:$src)>;
3856 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3857           (MOVUPSmr addr:$dst, VR128:$src)>;
3858 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3859           (MOVUPSmr addr:$dst, VR128:$src)>;
3860
3861 //===----------------------------------------------------------------------===//
3862 // SSE4.1 - Packed Move with Sign/Zero Extend
3863 //===----------------------------------------------------------------------===//
3864
3865 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3866   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3867                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3868                  [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3869
3870   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3871                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3872        [(set VR128:$dst,
3873          (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3874        OpSize;
3875 }
3876
3877 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3878 defm VPMOVSXBW : SS41I_binop_rm_int8<0x20, "vpmovsxbw", int_x86_sse41_pmovsxbw>,
3879                                      VEX;
3880 defm VPMOVSXWD : SS41I_binop_rm_int8<0x23, "vpmovsxwd", int_x86_sse41_pmovsxwd>,
3881                                      VEX;
3882 defm VPMOVSXDQ : SS41I_binop_rm_int8<0x25, "vpmovsxdq", int_x86_sse41_pmovsxdq>,
3883                                      VEX;
3884 defm VPMOVZXBW : SS41I_binop_rm_int8<0x30, "vpmovzxbw", int_x86_sse41_pmovzxbw>,
3885                                      VEX;
3886 defm VPMOVZXWD : SS41I_binop_rm_int8<0x33, "vpmovzxwd", int_x86_sse41_pmovzxwd>,
3887                                      VEX;
3888 defm VPMOVZXDQ : SS41I_binop_rm_int8<0x35, "vpmovzxdq", int_x86_sse41_pmovzxdq>,
3889                                      VEX;
3890 }
3891
3892 defm PMOVSXBW   : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3893 defm PMOVSXWD   : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3894 defm PMOVSXDQ   : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3895 defm PMOVZXBW   : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3896 defm PMOVZXWD   : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3897 defm PMOVZXDQ   : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3898
3899 // Common patterns involving scalar load.
3900 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3901           (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3902 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3903           (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3904
3905 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3906           (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3907 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3908           (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3909
3910 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3911           (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3912 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3913           (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3914
3915 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3916           (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3917 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3918           (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3919
3920 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3921           (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3922 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3923           (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3924
3925 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3926           (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3927 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3928           (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3929
3930
3931 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3932   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3933                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3934                  [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3935
3936   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3937                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3938        [(set VR128:$dst,
3939          (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3940           OpSize;
3941 }
3942
3943 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3944 defm VPMOVSXBD : SS41I_binop_rm_int4<0x21, "vpmovsxbd", int_x86_sse41_pmovsxbd>,
3945                                      VEX;
3946 defm VPMOVSXWQ : SS41I_binop_rm_int4<0x24, "vpmovsxwq", int_x86_sse41_pmovsxwq>,
3947                                      VEX;
3948 defm VPMOVZXBD : SS41I_binop_rm_int4<0x31, "vpmovzxbd", int_x86_sse41_pmovzxbd>,
3949                                      VEX;
3950 defm VPMOVZXWQ : SS41I_binop_rm_int4<0x34, "vpmovzxwq", int_x86_sse41_pmovzxwq>,
3951                                      VEX;
3952 }
3953
3954 defm PMOVSXBD   : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3955 defm PMOVSXWQ   : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3956 defm PMOVZXBD   : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3957 defm PMOVZXWQ   : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3958
3959 // Common patterns involving scalar load
3960 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
3961           (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
3962 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
3963           (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
3964
3965 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
3966           (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
3967 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
3968           (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
3969
3970
3971 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3972   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3973                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3974                  [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3975
3976   // Expecting a i16 load any extended to i32 value.
3977   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3978                  !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3979                  [(set VR128:$dst, (IntId (bitconvert
3980                      (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3981                  OpSize;
3982 }
3983
3984 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
3985 defm VPMOVSXBQ : SS41I_binop_rm_int2<0x22, "vpmovsxbq", int_x86_sse41_pmovsxbq>,
3986                                      VEX;
3987 defm VPMOVZXBQ : SS41I_binop_rm_int2<0x32, "vpmovzxbq", int_x86_sse41_pmovzxbq>,
3988                                      VEX;
3989 }
3990 defm PMOVSXBQ   : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3991 defm PMOVZXBQ   : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
3992
3993 // Common patterns involving scalar load
3994 def : Pat<(int_x86_sse41_pmovsxbq
3995             (bitconvert (v4i32 (X86vzmovl
3996                              (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3997           (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
3998
3999 def : Pat<(int_x86_sse41_pmovzxbq
4000             (bitconvert (v4i32 (X86vzmovl
4001                              (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
4002           (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
4003
4004 //===----------------------------------------------------------------------===//
4005 // SSE4.1 - Extract Instructions
4006 //===----------------------------------------------------------------------===//
4007
4008 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
4009 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
4010   def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
4011                  (ins VR128:$src1, i32i8imm:$src2),
4012                  !strconcat(OpcodeStr,
4013                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4014                  [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
4015                  OpSize;
4016   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4017                  (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
4018                  !strconcat(OpcodeStr,
4019                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4020                  []>, OpSize;
4021 // FIXME:
4022 // There's an AssertZext in the way of writing the store pattern
4023 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
4024 }
4025
4026 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4027   defm VPEXTRB : SS41I_extract8<0x14, "vpextrb">, VEX;
4028
4029 defm PEXTRB      : SS41I_extract8<0x14, "pextrb">;
4030
4031
4032 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
4033 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
4034   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4035                  (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
4036                  !strconcat(OpcodeStr,
4037                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4038                  []>, OpSize;
4039 // FIXME:
4040 // There's an AssertZext in the way of writing the store pattern
4041 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
4042 }
4043
4044 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4045   defm VPEXTRW : SS41I_extract16<0x15, "vpextrw">, VEX;
4046
4047 defm PEXTRW      : SS41I_extract16<0x15, "pextrw">;
4048
4049
4050 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
4051 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
4052   def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
4053                  (ins VR128:$src1, i32i8imm:$src2),
4054                  !strconcat(OpcodeStr,
4055                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4056                  [(set GR32:$dst,
4057                   (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
4058   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4059                  (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
4060                  !strconcat(OpcodeStr,
4061                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4062                  [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
4063                           addr:$dst)]>, OpSize;
4064 }
4065
4066 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4067   defm VPEXTRD : SS41I_extract32<0x16, "vpextrd">, VEX;
4068
4069 defm PEXTRD      : SS41I_extract32<0x16, "pextrd">;
4070
4071 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
4072 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
4073   def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
4074                  (ins VR128:$src1, i32i8imm:$src2),
4075                  !strconcat(OpcodeStr,
4076                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4077                  [(set GR64:$dst,
4078                   (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
4079   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4080                  (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
4081                  !strconcat(OpcodeStr,
4082                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4083                  [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
4084                           addr:$dst)]>, OpSize, REX_W;
4085 }
4086
4087 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4088   defm VPEXTRQ : SS41I_extract64<0x16, "vpextrq">, VEX, VEX_W;
4089
4090 defm PEXTRQ      : SS41I_extract64<0x16, "pextrq">;
4091
4092 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
4093 /// destination
4094 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
4095   def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
4096                  (ins VR128:$src1, i32i8imm:$src2),
4097                  !strconcat(OpcodeStr,
4098                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4099                  [(set GR32:$dst,
4100                     (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
4101            OpSize;
4102   def mr : SS4AIi8<opc, MRMDestMem, (outs),
4103                  (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
4104                  !strconcat(OpcodeStr,
4105                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4106                  [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
4107                           addr:$dst)]>, OpSize;
4108 }
4109
4110 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4111   defm VEXTRACTPS : SS41I_extractf32<0x17, "vextractps">, VEX;
4112   def VEXTRACTPSrr64 : SS4AIi8<0x17, MRMDestReg, (outs GR64:$dst),
4113                   (ins VR128:$src1, i32i8imm:$src2),
4114                   "vextractps \t{$src2, $src1, $dst|$dst, $src1, $src2}",
4115                   []>, OpSize, VEX;
4116 }
4117 defm EXTRACTPS   : SS41I_extractf32<0x17, "extractps">;
4118
4119 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
4120 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
4121                                               imm:$src2))),
4122                  addr:$dst),
4123           (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
4124          Requires<[HasSSE41]>;
4125
4126 //===----------------------------------------------------------------------===//
4127 // SSE4.1 - Insert Instructions
4128 //===----------------------------------------------------------------------===//
4129
4130 multiclass SS41I_insert8<bits<8> opc, string asm, bit Is2Addr = 1> {
4131   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
4132       (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
4133       !if(Is2Addr,
4134         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4135         !strconcat(asm,
4136                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4137       [(set VR128:$dst,
4138         (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
4139   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
4140       (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
4141       !if(Is2Addr,
4142         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4143         !strconcat(asm,
4144                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4145       [(set VR128:$dst,
4146         (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
4147                    imm:$src3))]>, OpSize;
4148 }
4149
4150 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4151   defm VPINSRB : SS41I_insert8<0x20, "vpinsrb", 0>, VEX_4V;
4152 let Constraints = "$src1 = $dst" in
4153   defm PINSRB  : SS41I_insert8<0x20, "pinsrb">;
4154
4155 multiclass SS41I_insert32<bits<8> opc, string asm, bit Is2Addr = 1> {
4156   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
4157       (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
4158       !if(Is2Addr,
4159         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4160         !strconcat(asm,
4161                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4162       [(set VR128:$dst,
4163         (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
4164       OpSize;
4165   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
4166       (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
4167       !if(Is2Addr,
4168         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4169         !strconcat(asm,
4170                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4171       [(set VR128:$dst,
4172         (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
4173                           imm:$src3)))]>, OpSize;
4174 }
4175
4176 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4177   defm VPINSRD : SS41I_insert32<0x22, "vpinsrd", 0>, VEX_4V;
4178 let Constraints = "$src1 = $dst" in
4179   defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
4180
4181 multiclass SS41I_insert64<bits<8> opc, string asm, bit Is2Addr = 1> {
4182   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
4183       (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
4184       !if(Is2Addr,
4185         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4186         !strconcat(asm,
4187                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4188       [(set VR128:$dst,
4189         (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
4190       OpSize;
4191   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
4192       (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
4193       !if(Is2Addr,
4194         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4195         !strconcat(asm,
4196                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4197       [(set VR128:$dst,
4198         (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
4199                           imm:$src3)))]>, OpSize;
4200 }
4201
4202 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4203   defm VPINSRQ : SS41I_insert64<0x22, "vpinsrq", 0>, VEX_4V, VEX_W;
4204 let Constraints = "$src1 = $dst" in
4205   defm PINSRQ : SS41I_insert64<0x22, "pinsrq">, REX_W;
4206
4207 // insertps has a few different modes, there's the first two here below which
4208 // are optimized inserts that won't zero arbitrary elements in the destination
4209 // vector. The next one matches the intrinsic and could zero arbitrary elements
4210 // in the target vector.
4211 multiclass SS41I_insertf32<bits<8> opc, string asm, bit Is2Addr = 1> {
4212   def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
4213       (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4214       !if(Is2Addr,
4215         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4216         !strconcat(asm,
4217                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4218       [(set VR128:$dst,
4219         (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
4220       OpSize;
4221   def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
4222       (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
4223       !if(Is2Addr,
4224         !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4225         !strconcat(asm,
4226                    "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4227       [(set VR128:$dst,
4228         (X86insrtps VR128:$src1,
4229                    (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
4230                     imm:$src3))]>, OpSize;
4231 }
4232
4233 let Constraints = "$src1 = $dst" in
4234   defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
4235 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4236   defm VINSERTPS : SS41I_insertf32<0x21, "vinsertps", 0>, VEX_4V;
4237
4238 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
4239           (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
4240
4241 //===----------------------------------------------------------------------===//
4242 // SSE4.1 - Round Instructions
4243 //===----------------------------------------------------------------------===//
4244
4245 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
4246                             string OpcodeStr,
4247                             Intrinsic V4F32Int,
4248                             Intrinsic V2F64Int> {
4249   // Intrinsic operation, reg.
4250   // Vector intrinsic operation, reg
4251   def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
4252                     (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
4253                     !strconcat(OpcodeStr,
4254                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4255                     [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
4256                     OpSize;
4257
4258   // Vector intrinsic operation, mem
4259   def PSm_Int : Ii8<opcps, MRMSrcMem,
4260                     (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
4261                     !strconcat(OpcodeStr,
4262                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4263                     [(set VR128:$dst,
4264                           (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
4265                     TA, OpSize,
4266                 Requires<[HasSSE41]>;
4267
4268   // Vector intrinsic operation, reg
4269   def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
4270                     (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
4271                     !strconcat(OpcodeStr,
4272                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4273                     [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
4274                     OpSize;
4275
4276   // Vector intrinsic operation, mem
4277   def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
4278                     (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
4279                     !strconcat(OpcodeStr,
4280                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4281                     [(set VR128:$dst,
4282                           (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
4283                     OpSize;
4284 }
4285
4286 multiclass sse41_fp_unop_rm_avx_p<bits<8> opcps, bits<8> opcpd,
4287                    RegisterClass RC, X86MemOperand x86memop, string OpcodeStr> {
4288   // Intrinsic operation, reg.
4289   // Vector intrinsic operation, reg
4290   def PSr : SS4AIi8<opcps, MRMSrcReg,
4291                     (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
4292                     !strconcat(OpcodeStr,
4293                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4294                     []>, OpSize;
4295
4296   // Vector intrinsic operation, mem
4297   def PSm : Ii8<opcps, MRMSrcMem,
4298                     (outs RC:$dst), (ins x86memop:$src1, i32i8imm:$src2),
4299                     !strconcat(OpcodeStr,
4300                     "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4301                     []>, TA, OpSize, Requires<[HasSSE41]>;
4302
4303   // Vector intrinsic operation, reg
4304   def PDr : SS4AIi8<opcpd, MRMSrcReg,
4305                     (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
4306                     !strconcat(OpcodeStr,
4307                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4308                     []>, OpSize;
4309
4310   // Vector intrinsic operation, mem
4311   def PDm : SS4AIi8<opcpd, MRMSrcMem,
4312                     (outs RC:$dst), (ins x86memop:$src1, i32i8imm:$src2),
4313                     !strconcat(OpcodeStr,
4314                     "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4315                     []>, OpSize;
4316 }
4317
4318 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
4319                             string OpcodeStr,
4320                             Intrinsic F32Int,
4321                             Intrinsic F64Int, bit Is2Addr = 1> {
4322   // Intrinsic operation, reg.
4323   def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
4324         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4325         !if(Is2Addr,
4326             !strconcat(OpcodeStr,
4327                 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4328             !strconcat(OpcodeStr,
4329                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4330         [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
4331         OpSize;
4332
4333   // Intrinsic operation, mem.
4334   def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
4335         (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
4336         !if(Is2Addr,
4337             !strconcat(OpcodeStr,
4338                 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4339             !strconcat(OpcodeStr,
4340                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4341         [(set VR128:$dst,
4342              (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
4343         OpSize;
4344
4345   // Intrinsic operation, reg.
4346   def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
4347         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4348         !if(Is2Addr,
4349             !strconcat(OpcodeStr,
4350                 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4351             !strconcat(OpcodeStr,
4352                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4353         [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
4354         OpSize;
4355
4356   // Intrinsic operation, mem.
4357   def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
4358         (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
4359         !if(Is2Addr,
4360             !strconcat(OpcodeStr,
4361                 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4362             !strconcat(OpcodeStr,
4363                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4364         [(set VR128:$dst,
4365               (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
4366         OpSize;
4367 }
4368
4369 multiclass sse41_fp_binop_rm_avx_s<bits<8> opcss, bits<8> opcsd,
4370                                    string OpcodeStr> {
4371   // Intrinsic operation, reg.
4372   def SSr : SS4AIi8<opcss, MRMSrcReg,
4373         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4374         !strconcat(OpcodeStr,
4375                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4376         []>, OpSize;
4377
4378   // Intrinsic operation, mem.
4379   def SSm : SS4AIi8<opcss, MRMSrcMem,
4380         (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
4381         !strconcat(OpcodeStr,
4382                 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4383         []>, OpSize;
4384
4385   // Intrinsic operation, reg.
4386   def SDr : SS4AIi8<opcsd, MRMSrcReg,
4387         (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
4388             !strconcat(OpcodeStr,
4389                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4390         []>, OpSize;
4391
4392   // Intrinsic operation, mem.
4393   def SDm : SS4AIi8<opcsd, MRMSrcMem,
4394         (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
4395             !strconcat(OpcodeStr,
4396                 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4397         []>, OpSize;
4398 }
4399
4400 // FP round - roundss, roundps, roundsd, roundpd
4401 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4402   // Intrinsic form
4403   defm VROUND  : sse41_fp_unop_rm<0x08, 0x09, "vround",
4404                                 int_x86_sse41_round_ps, int_x86_sse41_round_pd>,
4405                                 VEX;
4406   defm VROUND  : sse41_fp_binop_rm<0x0A, 0x0B, "vround",
4407                                 int_x86_sse41_round_ss, int_x86_sse41_round_sd,
4408                                 0>, VEX_4V;
4409   // Instructions for the assembler
4410   defm VROUND  : sse41_fp_unop_rm_avx_p<0x08, 0x09, VR128, f128mem, "vround">,
4411                                         VEX;
4412   defm VROUNDY : sse41_fp_unop_rm_avx_p<0x08, 0x09, VR256, f256mem, "vround">,
4413                                         VEX;
4414   defm VROUND  : sse41_fp_binop_rm_avx_s<0x0A, 0x0B, "vround">, VEX_4V;
4415 }
4416
4417 defm ROUND  : sse41_fp_unop_rm<0x08, 0x09, "round",
4418                                int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
4419 let Constraints = "$src1 = $dst" in
4420 defm ROUND  : sse41_fp_binop_rm<0x0A, 0x0B, "round",
4421                                int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
4422
4423 //===----------------------------------------------------------------------===//
4424 // SSE4.1 - Packed Bit Test
4425 //===----------------------------------------------------------------------===//
4426
4427 // ptest instruction we'll lower to this in X86ISelLowering primarily from
4428 // the intel intrinsic that corresponds to this.
4429 let Defs = [EFLAGS], isAsmParserOnly = 1, Predicates = [HasAVX] in {
4430 def VPTESTrr  : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
4431                       "vptest\t{$src2, $src1|$src1, $src2}",
4432                       [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
4433                       OpSize, VEX;
4434 def VPTESTYrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR256:$src1, VR256:$src2),
4435                       "vptest\t{$src2, $src1|$src1, $src2}", []>, OpSize, VEX;
4436
4437 def VPTESTrm  : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
4438                      "vptest\t{$src2, $src1|$src1, $src2}",
4439                      [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
4440                      OpSize, VEX;
4441 def VPTESTYrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR256:$src1, i256mem:$src2),
4442                      "vptest\t{$src2, $src1|$src1, $src2}", []>, OpSize, VEX;
4443 }
4444
4445 let Defs = [EFLAGS] in {
4446 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
4447                     "ptest \t{$src2, $src1|$src1, $src2}",
4448                     [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
4449               OpSize;
4450 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
4451                     "ptest \t{$src2, $src1|$src1, $src2}",
4452                     [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
4453               OpSize;
4454 }
4455
4456 // The bit test instructions below are AVX only
4457 multiclass avx_bittest<bits<8> opc, string OpcodeStr, RegisterClass RC,
4458                        X86MemOperand x86memop> {
4459   def rr : SS48I<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src),
4460             !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4461             []>, OpSize, VEX;
4462   def rm : SS48I<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
4463             !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4464             []>, OpSize, VEX;
4465 }
4466
4467 let Defs = [EFLAGS], isAsmParserOnly = 1, Predicates = [HasAVX] in {
4468   defm VTESTPS  : avx_bittest<0x0E, "vtestps", VR128, f128mem>;
4469   defm VTESTPSY : avx_bittest<0x0E, "vtestps", VR256, f256mem>;
4470   defm VTESTPD  : avx_bittest<0x0F, "vtestpd", VR128, f128mem>;
4471   defm VTESTPDY : avx_bittest<0x0F, "vtestpd", VR256, f256mem>;
4472 }
4473
4474 //===----------------------------------------------------------------------===//
4475 // SSE4.1 - Misc Instructions
4476 //===----------------------------------------------------------------------===//
4477
4478 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
4479 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
4480                                  Intrinsic IntId128> {
4481   def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4482                     (ins VR128:$src),
4483                     !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4484                     [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
4485   def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4486                      (ins i128mem:$src),
4487                      !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4488                      [(set VR128:$dst,
4489                        (IntId128
4490                        (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
4491 }
4492
4493 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4494 defm VPHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "vphminposuw",
4495                                          int_x86_sse41_phminposuw>, VEX;
4496 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
4497                                          int_x86_sse41_phminposuw>;
4498
4499 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
4500 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
4501                               Intrinsic IntId128, bit Is2Addr = 1> {
4502   let isCommutable = 1 in
4503   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4504        (ins VR128:$src1, VR128:$src2),
4505        !if(Is2Addr,
4506            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4507            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4508        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>, OpSize;
4509   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4510        (ins VR128:$src1, i128mem:$src2),
4511        !if(Is2Addr,
4512            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4513            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4514        [(set VR128:$dst,
4515          (IntId128 VR128:$src1,
4516           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
4517 }
4518
4519 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4520   let isCommutable = 0 in
4521   defm VPACKUSDW : SS41I_binop_rm_int<0x2B, "vpackusdw", int_x86_sse41_packusdw,
4522                                                          0>, VEX_4V;
4523   defm VPCMPEQQ  : SS41I_binop_rm_int<0x29, "vpcmpeqq",  int_x86_sse41_pcmpeqq,
4524                                                          0>, VEX_4V;
4525   defm VPMINSB   : SS41I_binop_rm_int<0x38, "vpminsb",   int_x86_sse41_pminsb,
4526                                                          0>, VEX_4V;
4527   defm VPMINSD   : SS41I_binop_rm_int<0x39, "vpminsd",   int_x86_sse41_pminsd,
4528                                                          0>, VEX_4V;
4529   defm VPMINUD   : SS41I_binop_rm_int<0x3B, "vpminud",   int_x86_sse41_pminud,
4530                                                          0>, VEX_4V;
4531   defm VPMINUW   : SS41I_binop_rm_int<0x3A, "vpminuw",   int_x86_sse41_pminuw,
4532                                                          0>, VEX_4V;
4533   defm VPMAXSB   : SS41I_binop_rm_int<0x3C, "vpmaxsb",   int_x86_sse41_pmaxsb,
4534                                                          0>, VEX_4V;
4535   defm VPMAXSD   : SS41I_binop_rm_int<0x3D, "vpmaxsd",   int_x86_sse41_pmaxsd,
4536                                                          0>, VEX_4V;
4537   defm VPMAXUD   : SS41I_binop_rm_int<0x3F, "vpmaxud",   int_x86_sse41_pmaxud,
4538                                                          0>, VEX_4V;
4539   defm VPMAXUW   : SS41I_binop_rm_int<0x3E, "vpmaxuw",   int_x86_sse41_pmaxuw,
4540                                                          0>, VEX_4V;
4541   defm VPMULDQ   : SS41I_binop_rm_int<0x28, "vpmuldq",   int_x86_sse41_pmuldq,
4542                                                          0>, VEX_4V;
4543 }
4544
4545 let Constraints = "$src1 = $dst" in {
4546   let isCommutable = 0 in
4547   defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw", int_x86_sse41_packusdw>;
4548   defm PCMPEQQ  : SS41I_binop_rm_int<0x29, "pcmpeqq",  int_x86_sse41_pcmpeqq>;
4549   defm PMINSB   : SS41I_binop_rm_int<0x38, "pminsb",   int_x86_sse41_pminsb>;
4550   defm PMINSD   : SS41I_binop_rm_int<0x39, "pminsd",   int_x86_sse41_pminsd>;
4551   defm PMINUD   : SS41I_binop_rm_int<0x3B, "pminud",   int_x86_sse41_pminud>;
4552   defm PMINUW   : SS41I_binop_rm_int<0x3A, "pminuw",   int_x86_sse41_pminuw>;
4553   defm PMAXSB   : SS41I_binop_rm_int<0x3C, "pmaxsb",   int_x86_sse41_pmaxsb>;
4554   defm PMAXSD   : SS41I_binop_rm_int<0x3D, "pmaxsd",   int_x86_sse41_pmaxsd>;
4555   defm PMAXUD   : SS41I_binop_rm_int<0x3F, "pmaxud",   int_x86_sse41_pmaxud>;
4556   defm PMAXUW   : SS41I_binop_rm_int<0x3E, "pmaxuw",   int_x86_sse41_pmaxuw>;
4557   defm PMULDQ   : SS41I_binop_rm_int<0x28, "pmuldq",   int_x86_sse41_pmuldq>;
4558 }
4559
4560 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
4561           (PCMPEQQrr VR128:$src1, VR128:$src2)>;
4562 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
4563           (PCMPEQQrm VR128:$src1, addr:$src2)>;
4564
4565 /// SS48I_binop_rm - Simple SSE41 binary operator.
4566 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
4567                         ValueType OpVT, bit Is2Addr = 1> {
4568   let isCommutable = 1 in
4569   def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4570        (ins VR128:$src1, VR128:$src2),
4571        !if(Is2Addr,
4572            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4573            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4574        [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
4575        OpSize;
4576   def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4577        (ins VR128:$src1, i128mem:$src2),
4578        !if(Is2Addr,
4579            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4580            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4581        [(set VR128:$dst, (OpNode VR128:$src1,
4582                                   (bc_v4i32 (memopv2i64 addr:$src2))))]>,
4583        OpSize;
4584 }
4585
4586 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4587   defm VPMULLD : SS48I_binop_rm<0x40, "vpmulld", mul, v4i32, 0>, VEX_4V;
4588 let Constraints = "$src1 = $dst" in
4589   defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32>;
4590
4591 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
4592 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
4593                  Intrinsic IntId, RegisterClass RC, PatFrag memop_frag,
4594                  X86MemOperand x86memop, bit Is2Addr = 1> {
4595   let isCommutable = 1 in
4596   def rri : SS4AIi8<opc, MRMSrcReg, (outs RC:$dst),
4597         (ins RC:$src1, RC:$src2, i32i8imm:$src3),
4598         !if(Is2Addr,
4599             !strconcat(OpcodeStr,
4600                 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4601             !strconcat(OpcodeStr,
4602                 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4603         [(set RC:$dst, (IntId RC:$src1, RC:$src2, imm:$src3))]>,
4604         OpSize;
4605   def rmi : SS4AIi8<opc, MRMSrcMem, (outs RC:$dst),
4606         (ins RC:$src1, x86memop:$src2, i32i8imm:$src3),
4607         !if(Is2Addr,
4608             !strconcat(OpcodeStr,
4609                 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
4610             !strconcat(OpcodeStr,
4611                 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
4612         [(set RC:$dst,
4613           (IntId RC:$src1,
4614            (bitconvert (memop_frag addr:$src2)), imm:$src3))]>,
4615         OpSize;
4616 }
4617
4618 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4619   let isCommutable = 0 in {
4620   defm VBLENDPS : SS41I_binop_rmi_int<0x0C, "vblendps", int_x86_sse41_blendps,
4621                                       VR128, memopv16i8, i128mem, 0>, VEX_4V;
4622   defm VBLENDPD : SS41I_binop_rmi_int<0x0D, "vblendpd", int_x86_sse41_blendpd,
4623                                       VR128, memopv16i8, i128mem, 0>, VEX_4V;
4624   let Pattern = []<dag> in {
4625   defm VBLENDPSY : SS41I_binop_rmi_int<0x0C, "vblendps", int_x86_sse41_blendps,
4626                                       VR256, memopv32i8, i256mem, 0>, VEX_4V;
4627   defm VBLENDPDY : SS41I_binop_rmi_int<0x0D, "vblendpd", int_x86_sse41_blendpd,
4628                                       VR256, memopv32i8, i256mem, 0>, VEX_4V;
4629   }
4630   defm VPBLENDW : SS41I_binop_rmi_int<0x0E, "vpblendw", int_x86_sse41_pblendw,
4631                                       VR128, memopv16i8, i128mem, 0>, VEX_4V;
4632   defm VMPSADBW : SS41I_binop_rmi_int<0x42, "vmpsadbw", int_x86_sse41_mpsadbw,
4633                                       VR128, memopv16i8, i128mem, 0>, VEX_4V;
4634   }
4635   defm VDPPS : SS41I_binop_rmi_int<0x40, "vdpps", int_x86_sse41_dpps,
4636                                    VR128, memopv16i8, i128mem, 0>, VEX_4V;
4637   defm VDPPD : SS41I_binop_rmi_int<0x41, "vdppd", int_x86_sse41_dppd,
4638                                    VR128, memopv16i8, i128mem, 0>, VEX_4V;
4639   let Pattern = []<dag> in
4640   defm VDPPSY : SS41I_binop_rmi_int<0x40, "vdpps", int_x86_sse41_dpps,
4641                                     VR256, memopv32i8, i256mem, 0>, VEX_4V;
4642 }
4643
4644 let Constraints = "$src1 = $dst" in {
4645   let isCommutable = 0 in {
4646   defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps", int_x86_sse41_blendps,
4647                                      VR128, memopv16i8, i128mem>;
4648   defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd", int_x86_sse41_blendpd,
4649                                      VR128, memopv16i8, i128mem>;
4650   defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw", int_x86_sse41_pblendw,
4651                                      VR128, memopv16i8, i128mem>;
4652   defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw", int_x86_sse41_mpsadbw,
4653                                      VR128, memopv16i8, i128mem>;
4654   }
4655   defm DPPS : SS41I_binop_rmi_int<0x40, "dpps", int_x86_sse41_dpps,
4656                                   VR128, memopv16i8, i128mem>;
4657   defm DPPD : SS41I_binop_rmi_int<0x41, "dppd", int_x86_sse41_dppd,
4658                                   VR128, memopv16i8, i128mem>;
4659 }
4660
4661 /// SS41I_quaternary_int_avx - AVX SSE 4.1 with 4 operators
4662 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4663 multiclass SS41I_quaternary_int_avx<bits<8> opc, string OpcodeStr,
4664                                     RegisterClass RC, X86MemOperand x86memop> {
4665   def rr : I<opc, MRMSrcReg, (outs RC:$dst),
4666                   (ins RC:$src1, RC:$src2, RC:$src3),
4667                   !strconcat(OpcodeStr,
4668                     "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4669                   [], SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
4670
4671   def rm : I<opc, MRMSrcMem, (outs RC:$dst),
4672                   (ins RC:$src1, x86memop:$src2, RC:$src3),
4673                   !strconcat(OpcodeStr,
4674                     "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4675                   [], SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
4676 }
4677 }
4678
4679 defm VBLENDVPD  : SS41I_quaternary_int_avx<0x4B, "vblendvpd", VR128, i128mem>;
4680 defm VBLENDVPS  : SS41I_quaternary_int_avx<0x4A, "vblendvps", VR128, i128mem>;
4681 defm VBLENDVPDY : SS41I_quaternary_int_avx<0x4B, "vblendvpd", VR256, i256mem>;
4682 defm VBLENDVPSY : SS41I_quaternary_int_avx<0x4A, "vblendvps", VR256, i256mem>;
4683
4684 defm VPBLENDVB : SS41I_quaternary_int_avx<0x4C, "vpblendvb", VR128, i128mem>;
4685
4686 /// SS41I_ternary_int - SSE 4.1 ternary operator
4687 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
4688   multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
4689     def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
4690                     (ins VR128:$src1, VR128:$src2),
4691                     !strconcat(OpcodeStr,
4692                      "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
4693                     [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
4694                     OpSize;
4695
4696     def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
4697                     (ins VR128:$src1, i128mem:$src2),
4698                     !strconcat(OpcodeStr,
4699                      "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
4700                     [(set VR128:$dst,
4701                       (IntId VR128:$src1,
4702                        (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
4703   }
4704 }
4705
4706 defm BLENDVPD     : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
4707 defm BLENDVPS     : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
4708 defm PBLENDVB     : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
4709
4710 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4711 def VMOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4712                        "vmovntdqa\t{$src, $dst|$dst, $src}",
4713                        [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
4714                        OpSize, VEX;
4715 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4716                        "movntdqa\t{$src, $dst|$dst, $src}",
4717                        [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
4718                        OpSize;
4719
4720 //===----------------------------------------------------------------------===//
4721 // SSE4.2 - Compare Instructions
4722 //===----------------------------------------------------------------------===//
4723
4724 /// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
4725 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
4726                               Intrinsic IntId128, bit Is2Addr = 1> {
4727   def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
4728        (ins VR128:$src1, VR128:$src2),
4729        !if(Is2Addr,
4730            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4731            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4732        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
4733        OpSize;
4734   def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
4735        (ins VR128:$src1, i128mem:$src2),
4736        !if(Is2Addr,
4737            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4738            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4739        [(set VR128:$dst,
4740          (IntId128 VR128:$src1,
4741           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
4742 }
4743
4744 let isAsmParserOnly = 1, Predicates = [HasAVX] in
4745   defm VPCMPGTQ : SS42I_binop_rm_int<0x37, "vpcmpgtq", int_x86_sse42_pcmpgtq,
4746                                      0>, VEX_4V;
4747 let Constraints = "$src1 = $dst" in
4748   defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
4749
4750 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
4751           (PCMPGTQrr VR128:$src1, VR128:$src2)>;
4752 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
4753           (PCMPGTQrm VR128:$src1, addr:$src2)>;
4754
4755 //===----------------------------------------------------------------------===//
4756 // SSE4.2 - String/text Processing Instructions
4757 //===----------------------------------------------------------------------===//
4758
4759 // Packed Compare Implicit Length Strings, Return Mask
4760 let Defs = [EFLAGS], usesCustomInserter = 1 in {
4761   def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
4762     (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4763     "#PCMPISTRM128rr PSEUDO!",
4764     [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
4765                                                   imm:$src3))]>, OpSize;
4766   def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
4767     (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
4768     "#PCMPISTRM128rm PSEUDO!",
4769     [(set VR128:$dst, (int_x86_sse42_pcmpistrm128
4770                           VR128:$src1, (load addr:$src2), imm:$src3))]>, OpSize;
4771 }
4772
4773 let Defs = [XMM0, EFLAGS], isAsmParserOnly = 1,
4774     Predicates = [HasAVX] in {
4775   def VPCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
4776       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4777       "vpcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize, VEX;
4778   def VPCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
4779       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
4780       "vpcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize, VEX;
4781 }
4782
4783 let Defs = [XMM0, EFLAGS] in {
4784   def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
4785       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4786       "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
4787   def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
4788       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
4789       "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
4790 }
4791
4792 // Packed Compare Explicit Length Strings, Return Mask
4793 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
4794   def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
4795     (ins VR128:$src1, VR128:$src3, i8imm:$src5),
4796     "#PCMPESTRM128rr PSEUDO!",
4797     [(set VR128:$dst,
4798           (int_x86_sse42_pcmpestrm128
4799            VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
4800
4801   def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
4802     (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
4803     "#PCMPESTRM128rm PSEUDO!",
4804     [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
4805                        VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
4806     OpSize;
4807 }
4808
4809 let isAsmParserOnly = 1, Predicates = [HasAVX],
4810     Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
4811   def VPCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
4812       (ins VR128:$src1, VR128:$src3, i8imm:$src5),
4813       "vpcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize, VEX;
4814   def VPCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
4815       (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
4816       "vpcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize, VEX;
4817 }
4818
4819 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
4820   def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
4821       (ins VR128:$src1, VR128:$src3, i8imm:$src5),
4822       "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
4823   def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
4824       (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
4825       "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
4826 }
4827
4828 // Packed Compare Implicit Length Strings, Return Index
4829 let Defs = [ECX, EFLAGS] in {
4830   multiclass SS42AI_pcmpistri<Intrinsic IntId128, string asm = "pcmpistri"> {
4831     def rr : SS42AI<0x63, MRMSrcReg, (outs),
4832       (ins VR128:$src1, VR128:$src2, i8imm:$src3),
4833       !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
4834       [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
4835        (implicit EFLAGS)]>, OpSize;
4836     def rm : SS42AI<0x63, MRMSrcMem, (outs),
4837       (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
4838       !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
4839       [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
4840        (implicit EFLAGS)]>, OpSize;
4841   }
4842 }
4843
4844 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4845 defm VPCMPISTRI  : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128, "vpcmpistri">,
4846                                     VEX;
4847 defm VPCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128, "vpcmpistri">,
4848                                     VEX;
4849 defm VPCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128, "vpcmpistri">,
4850                                     VEX;
4851 defm VPCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128, "vpcmpistri">,
4852                                     VEX;
4853 defm VPCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128, "vpcmpistri">,
4854                                     VEX;
4855 defm VPCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128, "vpcmpistri">,
4856                                     VEX;
4857 }
4858
4859 defm PCMPISTRI  : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
4860 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
4861 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
4862 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
4863 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
4864 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
4865
4866 // Packed Compare Explicit Length Strings, Return Index
4867 let Defs = [ECX, EFLAGS], Uses = [EAX, EDX] in {
4868   multiclass SS42AI_pcmpestri<Intrinsic IntId128, string asm = "pcmpestri"> {
4869     def rr : SS42AI<0x61, MRMSrcReg, (outs),
4870       (ins VR128:$src1, VR128:$src3, i8imm:$src5),
4871       !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
4872       [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
4873        (implicit EFLAGS)]>, OpSize;
4874     def rm : SS42AI<0x61, MRMSrcMem, (outs),
4875       (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
4876       !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
4877        [(set ECX,
4878              (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
4879         (implicit EFLAGS)]>, OpSize;
4880   }
4881 }
4882
4883 let isAsmParserOnly = 1, Predicates = [HasAVX] in {
4884 defm VPCMPESTRI  : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128, "vpcmpestri">,
4885                                     VEX;
4886 defm VPCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128, "vpcmpestri">,
4887                                     VEX;
4888 defm VPCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128, "vpcmpestri">,
4889                                     VEX;
4890 defm VPCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128, "vpcmpestri">,
4891                                     VEX;
4892 defm VPCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128, "vpcmpestri">,
4893                                     VEX;
4894 defm VPCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128, "vpcmpestri">,
4895                                     VEX;
4896 }
4897
4898 defm PCMPESTRI  : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
4899 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
4900 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
4901 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
4902 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
4903 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
4904
4905 //===----------------------------------------------------------------------===//
4906 // SSE4.2 - CRC Instructions
4907 //===----------------------------------------------------------------------===//
4908
4909 // No CRC instructions have AVX equivalents
4910
4911 // crc intrinsic instruction
4912 // This set of instructions are only rm, the only difference is the size
4913 // of r and m.
4914 let Constraints = "$src1 = $dst" in {
4915   def CRC32m8  : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
4916                       (ins GR32:$src1, i8mem:$src2),
4917                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
4918                        [(set GR32:$dst,
4919                          (int_x86_sse42_crc32_8 GR32:$src1,
4920                          (load addr:$src2)))]>;
4921   def CRC32r8  : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
4922                       (ins GR32:$src1, GR8:$src2),
4923                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
4924                        [(set GR32:$dst,
4925                          (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
4926   def CRC32m16  : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
4927                       (ins GR32:$src1, i16mem:$src2),
4928                       "crc32{w} \t{$src2, $src1|$src1, $src2}",
4929                        [(set GR32:$dst,
4930                          (int_x86_sse42_crc32_16 GR32:$src1,
4931                          (load addr:$src2)))]>,
4932                          OpSize;
4933   def CRC32r16  : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
4934                       (ins GR32:$src1, GR16:$src2),
4935                       "crc32{w} \t{$src2, $src1|$src1, $src2}",
4936                        [(set GR32:$dst,
4937                          (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
4938                          OpSize;
4939   def CRC32m32  : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
4940                       (ins GR32:$src1, i32mem:$src2),
4941                       "crc32{l} \t{$src2, $src1|$src1, $src2}",
4942                        [(set GR32:$dst,
4943                          (int_x86_sse42_crc32_32 GR32:$src1,
4944                          (load addr:$src2)))]>;
4945   def CRC32r32  : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
4946                       (ins GR32:$src1, GR32:$src2),
4947                       "crc32{l} \t{$src2, $src1|$src1, $src2}",
4948                        [(set GR32:$dst,
4949                          (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
4950   def CRC64m8  : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
4951                       (ins GR64:$src1, i8mem:$src2),
4952                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
4953                        [(set GR64:$dst,
4954                          (int_x86_sse42_crc64_8 GR64:$src1,
4955                          (load addr:$src2)))]>,
4956                          REX_W;
4957   def CRC64r8  : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
4958                       (ins GR64:$src1, GR8:$src2),
4959                       "crc32{b} \t{$src2, $src1|$src1, $src2}",
4960                        [(set GR64:$dst,
4961                          (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
4962                          REX_W;
4963   def CRC64m64  : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
4964                       (ins GR64:$src1, i64mem:$src2),
4965                       "crc32{q} \t{$src2, $src1|$src1, $src2}",
4966                        [(set GR64:$dst,
4967                          (int_x86_sse42_crc64_64 GR64:$src1,
4968                          (load addr:$src2)))]>,
4969                          REX_W;
4970   def CRC64r64  : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
4971                       (ins GR64:$src1, GR64:$src2),
4972                       "crc32{q} \t{$src2, $src1|$src1, $src2}",
4973                        [(set GR64:$dst,
4974                          (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
4975                          REX_W;
4976 }
4977
4978 //===----------------------------------------------------------------------===//
4979 // AES-NI Instructions
4980 //===----------------------------------------------------------------------===//
4981
4982 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
4983                               Intrinsic IntId128, bit Is2Addr = 1> {
4984   def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
4985        (ins VR128:$src1, VR128:$src2),
4986        !if(Is2Addr,
4987            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4988            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4989        [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
4990        OpSize;
4991   def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
4992        (ins VR128:$src1, i128mem:$src2),
4993        !if(Is2Addr,
4994            !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4995            !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4996        [(set VR128:$dst,
4997          (IntId128 VR128:$src1,
4998           (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
4999 }
5000
5001 // Perform One Round of an AES Encryption/Decryption Flow
5002 let isAsmParserOnly = 1, Predicates = [HasAVX, HasAES] in {
5003   defm VAESENC          : AESI_binop_rm_int<0xDC, "vaesenc",
5004                          int_x86_aesni_aesenc, 0>, VEX_4V;
5005   defm VAESENCLAST      : AESI_binop_rm_int<0xDD, "vaesenclast",
5006                          int_x86_aesni_aesenclast, 0>, VEX_4V;
5007   defm VAESDEC          : AESI_binop_rm_int<0xDE, "vaesdec",
5008                          int_x86_aesni_aesdec, 0>, VEX_4V;
5009   defm VAESDECLAST      : AESI_binop_rm_int<0xDF, "vaesdeclast",
5010                          int_x86_aesni_aesdeclast, 0>, VEX_4V;
5011 }
5012
5013 let Constraints = "$src1 = $dst" in {
5014   defm AESENC          : AESI_binop_rm_int<0xDC, "aesenc",
5015                          int_x86_aesni_aesenc>;
5016   defm AESENCLAST      : AESI_binop_rm_int<0xDD, "aesenclast",
5017                          int_x86_aesni_aesenclast>;
5018   defm AESDEC          : AESI_binop_rm_int<0xDE, "aesdec",
5019                          int_x86_aesni_aesdec>;
5020   defm AESDECLAST      : AESI_binop_rm_int<0xDF, "aesdeclast",
5021                          int_x86_aesni_aesdeclast>;
5022 }
5023
5024 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
5025           (AESENCrr VR128:$src1, VR128:$src2)>;
5026 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
5027           (AESENCrm VR128:$src1, addr:$src2)>;
5028 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
5029           (AESENCLASTrr VR128:$src1, VR128:$src2)>;
5030 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
5031           (AESENCLASTrm VR128:$src1, addr:$src2)>;
5032 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
5033           (AESDECrr VR128:$src1, VR128:$src2)>;
5034 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
5035           (AESDECrm VR128:$src1, addr:$src2)>;
5036 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
5037           (AESDECLASTrr VR128:$src1, VR128:$src2)>;
5038 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
5039           (AESDECLASTrm VR128:$src1, addr:$src2)>;
5040
5041 // Perform the AES InvMixColumn Transformation
5042 let isAsmParserOnly = 1, Predicates = [HasAVX, HasAES] in {
5043   def VAESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
5044       (ins VR128:$src1),
5045       "vaesimc\t{$src1, $dst|$dst, $src1}",
5046       [(set VR128:$dst,
5047         (int_x86_aesni_aesimc VR128:$src1))]>,
5048       OpSize, VEX;
5049   def VAESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
5050       (ins i128mem:$src1),
5051       "vaesimc\t{$src1, $dst|$dst, $src1}",
5052       [(set VR128:$dst,
5053         (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
5054       OpSize, VEX;
5055 }
5056 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
5057   (ins VR128:$src1),
5058   "aesimc\t{$src1, $dst|$dst, $src1}",
5059   [(set VR128:$dst,
5060     (int_x86_aesni_aesimc VR128:$src1))]>,
5061   OpSize;
5062 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
5063   (ins i128mem:$src1),
5064   "aesimc\t{$src1, $dst|$dst, $src1}",
5065   [(set VR128:$dst,
5066     (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
5067   OpSize;
5068
5069 // AES Round Key Generation Assist
5070 let isAsmParserOnly = 1, Predicates = [HasAVX, HasAES] in {
5071   def VAESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
5072       (ins VR128:$src1, i8imm:$src2),
5073       "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5074       [(set VR128:$dst,
5075         (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
5076       OpSize, VEX;
5077   def VAESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
5078       (ins i128mem:$src1, i8imm:$src2),
5079       "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5080       [(set VR128:$dst,
5081         (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),
5082                                         imm:$src2))]>,
5083       OpSize, VEX;
5084 }
5085 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
5086   (ins VR128:$src1, i8imm:$src2),
5087   "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5088   [(set VR128:$dst,
5089     (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
5090   OpSize;
5091 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
5092   (ins i128mem:$src1, i8imm:$src2),
5093   "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5094   [(set VR128:$dst,
5095     (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),
5096                                     imm:$src2))]>,
5097   OpSize;
5098
5099 //===----------------------------------------------------------------------===//
5100 // AVX Instructions
5101 //===----------------------------------------------------------------------===//
5102
5103 let isAsmParserOnly = 1 in {
5104
5105 // Load from memory and broadcast to all elements of the destination operand
5106 class avx_broadcast<bits<8> opc, string OpcodeStr, RegisterClass RC,
5107                     X86MemOperand x86memop> :
5108   AVX8I<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
5109         !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"), []>, VEX;
5110
5111 def VBROADCASTSS   : avx_broadcast<0x18, "vbroadcastss", VR128, f32mem>;
5112 def VBROADCASTSSY  : avx_broadcast<0x18, "vbroadcastss", VR256, f32mem>;
5113 def VBROADCASTSD   : avx_broadcast<0x19, "vbroadcastsd", VR256, f64mem>;
5114 def VBROADCASTF128 : avx_broadcast<0x1A, "vbroadcastf128", VR256, f128mem>;
5115
5116 // Insert packed floating-point values
5117 def VINSERTF128rr : AVXAIi8<0x18, MRMSrcReg, (outs VR256:$dst),
5118           (ins VR256:$src1, VR128:$src2, i8imm:$src3),
5119           "vinsertf128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5120           []>, VEX_4V;
5121 def VINSERTF128rm : AVXAIi8<0x18, MRMSrcMem, (outs VR256:$dst),
5122           (ins VR256:$src1, f128mem:$src2, i8imm:$src3),
5123           "vinsertf128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5124           []>, VEX_4V;
5125
5126 // Extract packed floating-point values
5127 def VEXTRACTF128rr : AVXAIi8<0x19, MRMDestReg, (outs VR128:$dst),
5128           (ins VR256:$src1, i8imm:$src2),
5129           "vextractf128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5130           []>, VEX;
5131 def VEXTRACTF128mr : AVXAIi8<0x19, MRMDestMem, (outs),
5132           (ins f128mem:$dst, VR256:$src1, i8imm:$src2),
5133           "vextractf128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
5134           []>, VEX;
5135
5136 // Conditional SIMD Packed Loads and Stores
5137 multiclass avx_movmask_rm<bits<8> opc_rm, bits<8> opc_mr, string OpcodeStr> {
5138   def rm  : AVX8I<opc_rm, MRMSrcMem, (outs VR128:$dst),
5139              (ins VR128:$src1, f128mem:$src2),
5140              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5141              []>, VEX_4V;
5142   def Yrm : AVX8I<opc_rm, MRMSrcMem, (outs VR256:$dst),
5143              (ins VR256:$src1, f256mem:$src2),
5144              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5145              []>, VEX_4V;
5146   def mr  : AVX8I<opc_mr, MRMDestMem, (outs),
5147              (ins f128mem:$dst, VR128:$src1, VR128:$src2),
5148              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5149              []>, VEX_4V;
5150   def Ymr : AVX8I<opc_mr, MRMDestMem, (outs),
5151              (ins f256mem:$dst, VR256:$src1, VR256:$src2),
5152              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5153              []>, VEX_4V;
5154 }
5155
5156 defm VMASKMOVPS : avx_movmask_rm<0x2C, 0x2E, "vmaskmovps">;
5157 defm VMASKMOVPD : avx_movmask_rm<0x2D, 0x2F, "vmaskmovpd">;
5158
5159 // Permute Floating-Point Values
5160 multiclass avx_permil<bits<8> opc_rm, bits<8> opc_rmi, string OpcodeStr,
5161                       RegisterClass RC, X86MemOperand x86memop> {
5162   def rr  : AVX8I<opc_rm, MRMSrcReg, (outs RC:$dst),
5163              (ins RC:$src1, RC:$src2),
5164              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5165              []>, VEX_4V;
5166   def rm  : AVX8I<opc_rm, MRMSrcMem, (outs RC:$dst),
5167              (ins RC:$src1, x86memop:$src2),
5168              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5169              []>, VEX_4V;
5170   def ri  : AVXAIi8<opc_rmi, MRMSrcReg, (outs RC:$dst),
5171              (ins RC:$src1, i8imm:$src2),
5172              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5173              []>, VEX;
5174   def mi  : AVXAIi8<opc_rmi, MRMSrcMem, (outs RC:$dst),
5175              (ins x86memop:$src1, i8imm:$src2),
5176              !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5177              []>, VEX;
5178 }
5179
5180 defm VPERMILPS  : avx_permil<0x0C, 0x04, "vpermilps", VR128, f128mem>;
5181 defm VPERMILPSY : avx_permil<0x0C, 0x04, "vpermilps", VR256, f256mem>;
5182 defm VPERMILPD  : avx_permil<0x0D, 0x05, "vpermilpd", VR128, f128mem>;
5183 defm VPERMILPDY : avx_permil<0x0D, 0x05, "vpermilpd", VR256, f256mem>;
5184
5185 def VPERM2F128rr : AVXAIi8<0x06, MRMSrcReg, (outs VR256:$dst),
5186           (ins VR256:$src1, VR256:$src2, i8imm:$src3),
5187           "vperm2f128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5188           []>, VEX_4V;
5189 def VPERM2F128rm : AVXAIi8<0x06, MRMSrcMem, (outs VR256:$dst),
5190           (ins VR256:$src1, f256mem:$src2, i8imm:$src3),
5191           "vperm2f128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
5192           []>, VEX_4V;
5193
5194 // Zero All YMM registers
5195 def VZEROALL : I<0x77, RawFrm, (outs), (ins), "vzeroall", []>, VEX, VEX_L;
5196
5197 // Zero Upper bits of YMM registers
5198 def VZEROUPPER : I<0x77, RawFrm, (outs), (ins), "vzeroupper", []>, VEX;
5199
5200 } // isAsmParserOnly