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