1 //===-- X86InstrSSE.td - SSE Instruction Set ---------------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 class OpndItins<InstrItinClass arg_rr, InstrItinClass arg_rm> {
17 InstrItinClass rr = arg_rr;
18 InstrItinClass rm = arg_rm;
21 class SizeItins<OpndItins arg_s, OpndItins arg_d> {
27 class ShiftOpndItins<InstrItinClass arg_rr, InstrItinClass arg_rm,
28 InstrItinClass arg_ri> {
29 InstrItinClass rr = arg_rr;
30 InstrItinClass rm = arg_rm;
31 InstrItinClass ri = arg_ri;
36 def SSE_ALU_F32S : OpndItins<
37 IIC_SSE_ALU_F32S_RR, IIC_SSE_ALU_F32S_RM
40 def SSE_ALU_F64S : OpndItins<
41 IIC_SSE_ALU_F64S_RR, IIC_SSE_ALU_F64S_RM
44 def SSE_ALU_ITINS_S : SizeItins<
45 SSE_ALU_F32S, SSE_ALU_F64S
48 def SSE_MUL_F32S : OpndItins<
49 IIC_SSE_MUL_F32S_RR, IIC_SSE_MUL_F64S_RM
52 def SSE_MUL_F64S : OpndItins<
53 IIC_SSE_MUL_F64S_RR, IIC_SSE_MUL_F64S_RM
56 def SSE_MUL_ITINS_S : SizeItins<
57 SSE_MUL_F32S, SSE_MUL_F64S
60 def SSE_DIV_F32S : OpndItins<
61 IIC_SSE_DIV_F32S_RR, IIC_SSE_DIV_F64S_RM
64 def SSE_DIV_F64S : OpndItins<
65 IIC_SSE_DIV_F64S_RR, IIC_SSE_DIV_F64S_RM
68 def SSE_DIV_ITINS_S : SizeItins<
69 SSE_DIV_F32S, SSE_DIV_F64S
73 def SSE_ALU_F32P : OpndItins<
74 IIC_SSE_ALU_F32P_RR, IIC_SSE_ALU_F32P_RM
77 def SSE_ALU_F64P : OpndItins<
78 IIC_SSE_ALU_F64P_RR, IIC_SSE_ALU_F64P_RM
81 def SSE_ALU_ITINS_P : SizeItins<
82 SSE_ALU_F32P, SSE_ALU_F64P
85 def SSE_MUL_F32P : OpndItins<
86 IIC_SSE_MUL_F32P_RR, IIC_SSE_MUL_F64P_RM
89 def SSE_MUL_F64P : OpndItins<
90 IIC_SSE_MUL_F64P_RR, IIC_SSE_MUL_F64P_RM
93 def SSE_MUL_ITINS_P : SizeItins<
94 SSE_MUL_F32P, SSE_MUL_F64P
97 def SSE_DIV_F32P : OpndItins<
98 IIC_SSE_DIV_F32P_RR, IIC_SSE_DIV_F64P_RM
101 def SSE_DIV_F64P : OpndItins<
102 IIC_SSE_DIV_F64P_RR, IIC_SSE_DIV_F64P_RM
105 def SSE_DIV_ITINS_P : SizeItins<
106 SSE_DIV_F32P, SSE_DIV_F64P
109 def SSE_BIT_ITINS_P : OpndItins<
110 IIC_SSE_BIT_P_RR, IIC_SSE_BIT_P_RM
113 def SSE_INTALU_ITINS_P : OpndItins<
114 IIC_SSE_INTALU_P_RR, IIC_SSE_INTALU_P_RM
117 def SSE_INTALUQ_ITINS_P : OpndItins<
118 IIC_SSE_INTALUQ_P_RR, IIC_SSE_INTALUQ_P_RM
121 def SSE_INTMUL_ITINS_P : OpndItins<
122 IIC_SSE_INTMUL_P_RR, IIC_SSE_INTMUL_P_RM
125 def SSE_INTSHIFT_ITINS_P : ShiftOpndItins<
126 IIC_SSE_INTSH_P_RR, IIC_SSE_INTSH_P_RM, IIC_SSE_INTSH_P_RI
129 def SSE_MOVA_ITINS : OpndItins<
130 IIC_SSE_MOVA_P_RR, IIC_SSE_MOVA_P_RM
133 def SSE_MOVU_ITINS : OpndItins<
134 IIC_SSE_MOVU_P_RR, IIC_SSE_MOVU_P_RM
137 //===----------------------------------------------------------------------===//
138 // SSE 1 & 2 Instructions Classes
139 //===----------------------------------------------------------------------===//
141 /// sse12_fp_scalar - SSE 1 & 2 scalar instructions class
142 multiclass sse12_fp_scalar<bits<8> opc, string OpcodeStr, SDNode OpNode,
143 RegisterClass RC, X86MemOperand x86memop,
146 let isCommutable = 1 in {
147 def rr : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
149 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
150 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
151 [(set RC:$dst, (OpNode RC:$src1, RC:$src2))], itins.rr>;
153 def rm : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
155 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
156 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
157 [(set RC:$dst, (OpNode RC:$src1, (load addr:$src2)))], itins.rm>;
160 /// sse12_fp_scalar_int - SSE 1 & 2 scalar instructions intrinsics class
161 multiclass sse12_fp_scalar_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
162 string asm, string SSEVer, string FPSizeStr,
163 Operand memopr, ComplexPattern mem_cpat,
166 def rr_Int : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
168 !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
169 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
170 [(set RC:$dst, (!cast<Intrinsic>(
171 !strconcat("int_x86_sse", SSEVer, "_", OpcodeStr, FPSizeStr))
172 RC:$src1, RC:$src2))], itins.rr>;
173 def rm_Int : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, memopr:$src2),
175 !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
176 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
177 [(set RC:$dst, (!cast<Intrinsic>(!strconcat("int_x86_sse",
178 SSEVer, "_", OpcodeStr, FPSizeStr))
179 RC:$src1, mem_cpat:$src2))], itins.rm>;
182 /// sse12_fp_packed - SSE 1 & 2 packed instructions class
183 multiclass sse12_fp_packed<bits<8> opc, string OpcodeStr, SDNode OpNode,
184 RegisterClass RC, ValueType vt,
185 X86MemOperand x86memop, PatFrag mem_frag,
186 Domain d, OpndItins itins, bit Is2Addr = 1> {
187 let isCommutable = 1 in
188 def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
190 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
191 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
192 [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))], itins.rr, d>;
194 def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
196 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
197 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
198 [(set RC:$dst, (OpNode RC:$src1, (mem_frag addr:$src2)))],
202 /// sse12_fp_packed_logical_rm - SSE 1 & 2 packed instructions class
203 multiclass sse12_fp_packed_logical_rm<bits<8> opc, RegisterClass RC, Domain d,
204 string OpcodeStr, X86MemOperand x86memop,
205 list<dag> pat_rr, list<dag> pat_rm,
207 bit rr_hasSideEffects = 0> {
208 let isCommutable = 1, neverHasSideEffects = rr_hasSideEffects in
209 def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
211 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
212 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
213 pat_rr, IIC_DEFAULT, d>;
214 def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
216 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
217 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
218 pat_rm, IIC_DEFAULT, d>;
221 /// sse12_fp_packed_int - SSE 1 & 2 packed instructions intrinsics class
222 multiclass sse12_fp_packed_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
223 string asm, string SSEVer, string FPSizeStr,
224 X86MemOperand x86memop, PatFrag mem_frag,
225 Domain d, OpndItins itins, bit Is2Addr = 1> {
226 def rr_Int : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
228 !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
229 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
230 [(set RC:$dst, (!cast<Intrinsic>(
231 !strconcat("int_x86_", SSEVer, "_", OpcodeStr, FPSizeStr))
232 RC:$src1, RC:$src2))], IIC_DEFAULT, d>;
233 def rm_Int : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1,x86memop:$src2),
235 !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
236 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
237 [(set RC:$dst, (!cast<Intrinsic>(
238 !strconcat("int_x86_", SSEVer, "_", OpcodeStr, FPSizeStr))
239 RC:$src1, (mem_frag addr:$src2)))], IIC_DEFAULT, d>;
242 //===----------------------------------------------------------------------===//
243 // Non-instruction patterns
244 //===----------------------------------------------------------------------===//
246 // A vector extract of the first f32/f64 position is a subregister copy
247 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
248 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
249 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
250 (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
252 // A 128-bit subvector extract from the first 256-bit vector position
253 // is a subregister copy that needs no instruction.
254 def : Pat<(v4i32 (extract_subvector (v8i32 VR256:$src), (i32 0))),
255 (v4i32 (EXTRACT_SUBREG (v8i32 VR256:$src), sub_xmm))>;
256 def : Pat<(v4f32 (extract_subvector (v8f32 VR256:$src), (i32 0))),
257 (v4f32 (EXTRACT_SUBREG (v8f32 VR256:$src), sub_xmm))>;
259 def : Pat<(v2i64 (extract_subvector (v4i64 VR256:$src), (i32 0))),
260 (v2i64 (EXTRACT_SUBREG (v4i64 VR256:$src), sub_xmm))>;
261 def : Pat<(v2f64 (extract_subvector (v4f64 VR256:$src), (i32 0))),
262 (v2f64 (EXTRACT_SUBREG (v4f64 VR256:$src), sub_xmm))>;
264 def : Pat<(v8i16 (extract_subvector (v16i16 VR256:$src), (i32 0))),
265 (v8i16 (EXTRACT_SUBREG (v16i16 VR256:$src), sub_xmm))>;
266 def : Pat<(v16i8 (extract_subvector (v32i8 VR256:$src), (i32 0))),
267 (v16i8 (EXTRACT_SUBREG (v32i8 VR256:$src), sub_xmm))>;
269 // A 128-bit subvector insert to the first 256-bit vector position
270 // is a subregister copy that needs no instruction.
271 def : Pat<(insert_subvector undef, (v2i64 VR128:$src), (i32 0)),
272 (INSERT_SUBREG (v4i64 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
273 def : Pat<(insert_subvector undef, (v2f64 VR128:$src), (i32 0)),
274 (INSERT_SUBREG (v4f64 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
275 def : Pat<(insert_subvector undef, (v4i32 VR128:$src), (i32 0)),
276 (INSERT_SUBREG (v8i32 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
277 def : Pat<(insert_subvector undef, (v4f32 VR128:$src), (i32 0)),
278 (INSERT_SUBREG (v8f32 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
279 def : Pat<(insert_subvector undef, (v8i16 VR128:$src), (i32 0)),
280 (INSERT_SUBREG (v16i16 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
281 def : Pat<(insert_subvector undef, (v16i8 VR128:$src), (i32 0)),
282 (INSERT_SUBREG (v32i8 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
284 // Implicitly promote a 32-bit scalar to a vector.
285 def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
286 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss)>;
287 def : Pat<(v8f32 (scalar_to_vector FR32:$src)),
288 (INSERT_SUBREG (v8f32 (IMPLICIT_DEF)), FR32:$src, sub_ss)>;
289 // Implicitly promote a 64-bit scalar to a vector.
290 def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
291 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
292 def : Pat<(v4f64 (scalar_to_vector FR64:$src)),
293 (INSERT_SUBREG (v4f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
295 // Bitcasts between 128-bit vector types. Return the original type since
296 // no instruction is needed for the conversion
297 let Predicates = [HasSSE2] in {
298 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
299 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
300 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
301 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
302 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
303 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
304 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
305 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
306 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
307 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
308 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
309 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
310 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
311 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
312 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
313 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
314 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
315 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
316 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
317 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
318 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
319 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
320 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
321 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
322 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
323 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
324 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
325 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
326 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
327 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
330 // Bitcasts between 256-bit vector types. Return the original type since
331 // no instruction is needed for the conversion
332 let Predicates = [HasAVX] in {
333 def : Pat<(v4f64 (bitconvert (v8f32 VR256:$src))), (v4f64 VR256:$src)>;
334 def : Pat<(v4f64 (bitconvert (v8i32 VR256:$src))), (v4f64 VR256:$src)>;
335 def : Pat<(v4f64 (bitconvert (v4i64 VR256:$src))), (v4f64 VR256:$src)>;
336 def : Pat<(v4f64 (bitconvert (v16i16 VR256:$src))), (v4f64 VR256:$src)>;
337 def : Pat<(v4f64 (bitconvert (v32i8 VR256:$src))), (v4f64 VR256:$src)>;
338 def : Pat<(v8f32 (bitconvert (v8i32 VR256:$src))), (v8f32 VR256:$src)>;
339 def : Pat<(v8f32 (bitconvert (v4i64 VR256:$src))), (v8f32 VR256:$src)>;
340 def : Pat<(v8f32 (bitconvert (v4f64 VR256:$src))), (v8f32 VR256:$src)>;
341 def : Pat<(v8f32 (bitconvert (v32i8 VR256:$src))), (v8f32 VR256:$src)>;
342 def : Pat<(v8f32 (bitconvert (v16i16 VR256:$src))), (v8f32 VR256:$src)>;
343 def : Pat<(v4i64 (bitconvert (v8f32 VR256:$src))), (v4i64 VR256:$src)>;
344 def : Pat<(v4i64 (bitconvert (v8i32 VR256:$src))), (v4i64 VR256:$src)>;
345 def : Pat<(v4i64 (bitconvert (v4f64 VR256:$src))), (v4i64 VR256:$src)>;
346 def : Pat<(v4i64 (bitconvert (v32i8 VR256:$src))), (v4i64 VR256:$src)>;
347 def : Pat<(v4i64 (bitconvert (v16i16 VR256:$src))), (v4i64 VR256:$src)>;
348 def : Pat<(v32i8 (bitconvert (v4f64 VR256:$src))), (v32i8 VR256:$src)>;
349 def : Pat<(v32i8 (bitconvert (v4i64 VR256:$src))), (v32i8 VR256:$src)>;
350 def : Pat<(v32i8 (bitconvert (v8f32 VR256:$src))), (v32i8 VR256:$src)>;
351 def : Pat<(v32i8 (bitconvert (v8i32 VR256:$src))), (v32i8 VR256:$src)>;
352 def : Pat<(v32i8 (bitconvert (v16i16 VR256:$src))), (v32i8 VR256:$src)>;
353 def : Pat<(v8i32 (bitconvert (v32i8 VR256:$src))), (v8i32 VR256:$src)>;
354 def : Pat<(v8i32 (bitconvert (v16i16 VR256:$src))), (v8i32 VR256:$src)>;
355 def : Pat<(v8i32 (bitconvert (v8f32 VR256:$src))), (v8i32 VR256:$src)>;
356 def : Pat<(v8i32 (bitconvert (v4i64 VR256:$src))), (v8i32 VR256:$src)>;
357 def : Pat<(v8i32 (bitconvert (v4f64 VR256:$src))), (v8i32 VR256:$src)>;
358 def : Pat<(v16i16 (bitconvert (v8f32 VR256:$src))), (v16i16 VR256:$src)>;
359 def : Pat<(v16i16 (bitconvert (v8i32 VR256:$src))), (v16i16 VR256:$src)>;
360 def : Pat<(v16i16 (bitconvert (v4i64 VR256:$src))), (v16i16 VR256:$src)>;
361 def : Pat<(v16i16 (bitconvert (v4f64 VR256:$src))), (v16i16 VR256:$src)>;
362 def : Pat<(v16i16 (bitconvert (v32i8 VR256:$src))), (v16i16 VR256:$src)>;
365 // Alias instructions that map fld0 to pxor for sse.
366 // This is expanded by ExpandPostRAPseudos.
367 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
369 def FsFLD0SS : I<0, Pseudo, (outs FR32:$dst), (ins), "",
370 [(set FR32:$dst, fp32imm0)]>, Requires<[HasSSE1]>;
371 def FsFLD0SD : I<0, Pseudo, (outs FR64:$dst), (ins), "",
372 [(set FR64:$dst, fpimm0)]>, Requires<[HasSSE2]>;
375 //===----------------------------------------------------------------------===//
376 // AVX & SSE - Zero/One Vectors
377 //===----------------------------------------------------------------------===//
379 // Alias instruction that maps zero vector to pxor / xorp* for sse.
380 // This is expanded by ExpandPostRAPseudos to an xorps / vxorps, and then
381 // swizzled by ExecutionDepsFix to pxor.
382 // We set canFoldAsLoad because this can be converted to a constant-pool
383 // load of an all-zeros value if folding it would be beneficial.
384 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
385 isPseudo = 1, neverHasSideEffects = 1 in {
386 def V_SET0 : I<0, Pseudo, (outs VR128:$dst), (ins), "", []>;
389 def : Pat<(v4f32 immAllZerosV), (V_SET0)>;
390 def : Pat<(v2f64 immAllZerosV), (V_SET0)>;
391 def : Pat<(v4i32 immAllZerosV), (V_SET0)>;
392 def : Pat<(v2i64 immAllZerosV), (V_SET0)>;
393 def : Pat<(v8i16 immAllZerosV), (V_SET0)>;
394 def : Pat<(v16i8 immAllZerosV), (V_SET0)>;
397 // The same as done above but for AVX. The 256-bit ISA does not support PI,
398 // and doesn't need it because on sandy bridge the register is set to zero
399 // at the rename stage without using any execution unit, so SET0PSY
400 // and SET0PDY can be used for vector int instructions without penalty
401 // FIXME: Change encoding to pseudo! This is blocked right now by the x86
402 // JIT implementatioan, it does not expand the instructions below like
403 // X86MCInstLower does.
404 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
405 isCodeGenOnly = 1 in {
406 let Predicates = [HasAVX] in {
407 def AVX_SET0PSY : PSI<0x57, MRMInitReg, (outs VR256:$dst), (ins), "",
408 [(set VR256:$dst, (v8f32 immAllZerosV))]>, VEX_4V;
409 def AVX_SET0PDY : PDI<0x57, MRMInitReg, (outs VR256:$dst), (ins), "",
410 [(set VR256:$dst, (v4f64 immAllZerosV))]>, VEX_4V;
412 let Predicates = [HasAVX2], neverHasSideEffects = 1 in
413 def AVX2_SET0 : PDI<0xef, MRMInitReg, (outs VR256:$dst), (ins), "",
417 let Predicates = [HasAVX2], AddedComplexity = 5 in {
418 def : Pat<(v4i64 immAllZerosV), (AVX2_SET0)>;
419 def : Pat<(v8i32 immAllZerosV), (AVX2_SET0)>;
420 def : Pat<(v16i16 immAllZerosV), (AVX2_SET0)>;
421 def : Pat<(v32i8 immAllZerosV), (AVX2_SET0)>;
424 // AVX has no support for 256-bit integer instructions, but since the 128-bit
425 // VPXOR instruction writes zero to its upper part, it's safe build zeros.
426 def : Pat<(v32i8 immAllZerosV), (SUBREG_TO_REG (i8 0), (V_SET0), sub_xmm)>;
427 def : Pat<(bc_v32i8 (v8f32 immAllZerosV)),
428 (SUBREG_TO_REG (i8 0), (V_SET0), sub_xmm)>;
430 def : Pat<(v16i16 immAllZerosV), (SUBREG_TO_REG (i16 0), (V_SET0), sub_xmm)>;
431 def : Pat<(bc_v16i16 (v8f32 immAllZerosV)),
432 (SUBREG_TO_REG (i16 0), (V_SET0), sub_xmm)>;
434 def : Pat<(v8i32 immAllZerosV), (SUBREG_TO_REG (i32 0), (V_SET0), sub_xmm)>;
435 def : Pat<(bc_v8i32 (v8f32 immAllZerosV)),
436 (SUBREG_TO_REG (i32 0), (V_SET0), sub_xmm)>;
438 def : Pat<(v4i64 immAllZerosV), (SUBREG_TO_REG (i64 0), (V_SET0), sub_xmm)>;
439 def : Pat<(bc_v4i64 (v8f32 immAllZerosV)),
440 (SUBREG_TO_REG (i64 0), (V_SET0), sub_xmm)>;
442 // We set canFoldAsLoad because this can be converted to a constant-pool
443 // load of an all-ones value if folding it would be beneficial.
444 // FIXME: Change encoding to pseudo! This is blocked right now by the x86
445 // JIT implementation, it does not expand the instructions below like
446 // X86MCInstLower does.
447 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
448 isCodeGenOnly = 1, ExeDomain = SSEPackedInt in {
449 let Predicates = [HasAVX] in
450 def AVX_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
451 [(set VR128:$dst, (v4i32 immAllOnesV))]>, VEX_4V;
452 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
453 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
454 let Predicates = [HasAVX2] in
455 def AVX2_SETALLONES : PDI<0x76, MRMInitReg, (outs VR256:$dst), (ins), "",
456 [(set VR256:$dst, (v8i32 immAllOnesV))]>, VEX_4V;
460 //===----------------------------------------------------------------------===//
461 // SSE 1 & 2 - Move FP Scalar Instructions
463 // Move Instructions. Register-to-register movss/movsd is not used for FR32/64
464 // register copies because it's a partial register update; FsMOVAPSrr/FsMOVAPDrr
465 // is used instead. Register-to-register movss/movsd is not modeled as an
466 // INSERT_SUBREG because INSERT_SUBREG requires that the insert be implementable
467 // in terms of a copy, and just mentioned, we don't use movss/movsd for copies.
468 //===----------------------------------------------------------------------===//
470 class sse12_move_rr<RegisterClass RC, SDNode OpNode, ValueType vt, string asm> :
471 SI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, RC:$src2), asm,
472 [(set VR128:$dst, (vt (OpNode VR128:$src1,
473 (scalar_to_vector RC:$src2))))],
476 // Loading from memory automatically zeroing upper bits.
477 class sse12_move_rm<RegisterClass RC, X86MemOperand x86memop,
478 PatFrag mem_pat, string OpcodeStr> :
479 SI<0x10, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
480 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
481 [(set RC:$dst, (mem_pat addr:$src))],
485 def VMOVSSrr : sse12_move_rr<FR32, X86Movss, v4f32,
486 "movss\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XS, VEX_4V,
488 def VMOVSDrr : sse12_move_rr<FR64, X86Movsd, v2f64,
489 "movsd\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XD, VEX_4V,
492 // For the disassembler
493 let isCodeGenOnly = 1 in {
494 def VMOVSSrr_REV : SI<0x11, MRMDestReg, (outs VR128:$dst),
495 (ins VR128:$src1, FR32:$src2),
496 "movss\t{$src2, $src1, $dst|$dst, $src1, $src2}", [],
499 def VMOVSDrr_REV : SI<0x11, MRMDestReg, (outs VR128:$dst),
500 (ins VR128:$src1, FR64:$src2),
501 "movsd\t{$src2, $src1, $dst|$dst, $src1, $src2}", [],
506 let canFoldAsLoad = 1, isReMaterializable = 1 in {
507 def VMOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS, VEX,
509 let AddedComplexity = 20 in
510 def VMOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD, VEX,
514 def VMOVSSmr : SI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
515 "movss\t{$src, $dst|$dst, $src}",
516 [(store FR32:$src, addr:$dst)], IIC_SSE_MOV_S_MR>,
518 def VMOVSDmr : SI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
519 "movsd\t{$src, $dst|$dst, $src}",
520 [(store FR64:$src, addr:$dst)], IIC_SSE_MOV_S_MR>,
524 let Constraints = "$src1 = $dst" in {
525 def MOVSSrr : sse12_move_rr<FR32, X86Movss, v4f32,
526 "movss\t{$src2, $dst|$dst, $src2}">, XS;
527 def MOVSDrr : sse12_move_rr<FR64, X86Movsd, v2f64,
528 "movsd\t{$src2, $dst|$dst, $src2}">, XD;
530 // For the disassembler
531 let isCodeGenOnly = 1 in {
532 def MOVSSrr_REV : SI<0x11, MRMDestReg, (outs VR128:$dst),
533 (ins VR128:$src1, FR32:$src2),
534 "movss\t{$src2, $dst|$dst, $src2}", [],
535 IIC_SSE_MOV_S_RR>, XS;
536 def MOVSDrr_REV : SI<0x11, MRMDestReg, (outs VR128:$dst),
537 (ins VR128:$src1, FR64:$src2),
538 "movsd\t{$src2, $dst|$dst, $src2}", [],
539 IIC_SSE_MOV_S_RR>, XD;
543 let canFoldAsLoad = 1, isReMaterializable = 1 in {
544 def MOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS;
546 let AddedComplexity = 20 in
547 def MOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD;
550 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
551 "movss\t{$src, $dst|$dst, $src}",
552 [(store FR32:$src, addr:$dst)], IIC_SSE_MOV_S_MR>;
553 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
554 "movsd\t{$src, $dst|$dst, $src}",
555 [(store FR64:$src, addr:$dst)], IIC_SSE_MOV_S_MR>;
558 let Predicates = [HasAVX] in {
559 let AddedComplexity = 15 in {
560 // Move scalar to XMM zero-extended, zeroing a VR128 then do a
561 // MOVS{S,D} to the lower bits.
562 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
563 (VMOVSSrr (v4f32 (V_SET0)), FR32:$src)>;
564 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
565 (VMOVSSrr (v4f32 (V_SET0)),
566 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
567 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
568 (VMOVSSrr (v4i32 (V_SET0)),
569 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
570 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
571 (VMOVSDrr (v2f64 (V_SET0)), FR64:$src)>;
573 // Move low f32 and clear high bits.
574 def : Pat<(v8f32 (X86vzmovl (v8f32 VR256:$src))),
575 (SUBREG_TO_REG (i32 0),
576 (VMOVSSrr (v4f32 (V_SET0)),
577 (EXTRACT_SUBREG (v8f32 VR256:$src), sub_ss)), sub_xmm)>;
578 def : Pat<(v8i32 (X86vzmovl (v8i32 VR256:$src))),
579 (SUBREG_TO_REG (i32 0),
580 (VMOVSSrr (v4i32 (V_SET0)),
581 (EXTRACT_SUBREG (v8i32 VR256:$src), sub_ss)), sub_xmm)>;
584 let AddedComplexity = 20 in {
585 // MOVSSrm zeros the high parts of the register; represent this
586 // with SUBREG_TO_REG. The AVX versions also write: DST[255:128] <- 0
587 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
588 (SUBREG_TO_REG (i32 0), (VMOVSSrm addr:$src), sub_ss)>;
589 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
590 (SUBREG_TO_REG (i32 0), (VMOVSSrm addr:$src), sub_ss)>;
591 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
592 (SUBREG_TO_REG (i32 0), (VMOVSSrm addr:$src), sub_ss)>;
594 // MOVSDrm zeros the high parts of the register; represent this
595 // with SUBREG_TO_REG. The AVX versions also write: DST[255:128] <- 0
596 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
597 (SUBREG_TO_REG (i64 0), (VMOVSDrm addr:$src), sub_sd)>;
598 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
599 (SUBREG_TO_REG (i64 0), (VMOVSDrm addr:$src), sub_sd)>;
600 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
601 (SUBREG_TO_REG (i64 0), (VMOVSDrm addr:$src), sub_sd)>;
602 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
603 (SUBREG_TO_REG (i64 0), (VMOVSDrm addr:$src), sub_sd)>;
604 def : Pat<(v2f64 (X86vzload addr:$src)),
605 (SUBREG_TO_REG (i64 0), (VMOVSDrm addr:$src), sub_sd)>;
607 // Represent the same patterns above but in the form they appear for
609 def : Pat<(v8i32 (X86vzmovl (insert_subvector undef,
610 (v4i32 (scalar_to_vector (loadi32 addr:$src))), (i32 0)))),
611 (SUBREG_TO_REG (i32 0), (VMOVSSrm addr:$src), sub_ss)>;
612 def : Pat<(v8f32 (X86vzmovl (insert_subvector undef,
613 (v4f32 (scalar_to_vector (loadf32 addr:$src))), (i32 0)))),
614 (SUBREG_TO_REG (i32 0), (VMOVSSrm addr:$src), sub_ss)>;
615 def : Pat<(v4f64 (X86vzmovl (insert_subvector undef,
616 (v2f64 (scalar_to_vector (loadf64 addr:$src))), (i32 0)))),
617 (SUBREG_TO_REG (i32 0), (VMOVSDrm addr:$src), sub_sd)>;
619 def : Pat<(v8f32 (X86vzmovl (insert_subvector undef,
620 (v4f32 (scalar_to_vector FR32:$src)), (i32 0)))),
621 (SUBREG_TO_REG (i32 0),
622 (v4f32 (VMOVSSrr (v4f32 (V_SET0)), FR32:$src)),
624 def : Pat<(v4f64 (X86vzmovl (insert_subvector undef,
625 (v2f64 (scalar_to_vector FR64:$src)), (i32 0)))),
626 (SUBREG_TO_REG (i64 0),
627 (v2f64 (VMOVSDrr (v2f64 (V_SET0)), FR64:$src)),
629 def : Pat<(v4i64 (X86vzmovl (insert_subvector undef,
630 (v2i64 (scalar_to_vector (loadi64 addr:$src))), (i32 0)))),
631 (SUBREG_TO_REG (i64 0), (VMOVSDrm addr:$src), sub_sd)>;
633 // Move low f64 and clear high bits.
634 def : Pat<(v4f64 (X86vzmovl (v4f64 VR256:$src))),
635 (SUBREG_TO_REG (i32 0),
636 (VMOVSDrr (v2f64 (V_SET0)),
637 (EXTRACT_SUBREG (v4f64 VR256:$src), sub_sd)), sub_xmm)>;
639 def : Pat<(v4i64 (X86vzmovl (v4i64 VR256:$src))),
640 (SUBREG_TO_REG (i32 0),
641 (VMOVSDrr (v2i64 (V_SET0)),
642 (EXTRACT_SUBREG (v4i64 VR256:$src), sub_sd)), sub_xmm)>;
644 // Extract and store.
645 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
648 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
649 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
652 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
654 // Shuffle with VMOVSS
655 def : Pat<(v4i32 (X86Movss VR128:$src1, VR128:$src2)),
656 (VMOVSSrr (v4i32 VR128:$src1),
657 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
658 def : Pat<(v4f32 (X86Movss VR128:$src1, VR128:$src2)),
659 (VMOVSSrr (v4f32 VR128:$src1),
660 (EXTRACT_SUBREG (v4f32 VR128:$src2), sub_ss))>;
663 def : Pat<(v8i32 (X86Movss VR256:$src1, VR256:$src2)),
664 (SUBREG_TO_REG (i32 0),
665 (VMOVSSrr (EXTRACT_SUBREG (v8i32 VR256:$src1), sub_ss),
666 (EXTRACT_SUBREG (v8i32 VR256:$src2), sub_ss)), sub_xmm)>;
667 def : Pat<(v8f32 (X86Movss VR256:$src1, VR256:$src2)),
668 (SUBREG_TO_REG (i32 0),
669 (VMOVSSrr (EXTRACT_SUBREG (v8f32 VR256:$src1), sub_ss),
670 (EXTRACT_SUBREG (v8f32 VR256:$src2), sub_ss)), sub_xmm)>;
672 // Shuffle with VMOVSD
673 def : Pat<(v2i64 (X86Movsd VR128:$src1, VR128:$src2)),
674 (VMOVSDrr (v2i64 VR128:$src1),
675 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
676 def : Pat<(v2f64 (X86Movsd VR128:$src1, VR128:$src2)),
677 (VMOVSDrr (v2f64 VR128:$src1),
678 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
679 def : Pat<(v4f32 (X86Movsd VR128:$src1, VR128:$src2)),
680 (VMOVSDrr VR128:$src1, (EXTRACT_SUBREG (v4f32 VR128:$src2),
682 def : Pat<(v4i32 (X86Movsd VR128:$src1, VR128:$src2)),
683 (VMOVSDrr VR128:$src1, (EXTRACT_SUBREG (v4i32 VR128:$src2),
687 def : Pat<(v4i64 (X86Movsd VR256:$src1, VR256:$src2)),
688 (SUBREG_TO_REG (i32 0),
689 (VMOVSDrr (EXTRACT_SUBREG (v4i64 VR256:$src1), sub_sd),
690 (EXTRACT_SUBREG (v4i64 VR256:$src2), sub_sd)), sub_xmm)>;
691 def : Pat<(v4f64 (X86Movsd VR256:$src1, VR256:$src2)),
692 (SUBREG_TO_REG (i32 0),
693 (VMOVSDrr (EXTRACT_SUBREG (v4f64 VR256:$src1), sub_sd),
694 (EXTRACT_SUBREG (v4f64 VR256:$src2), sub_sd)), sub_xmm)>;
697 // FIXME: Instead of a X86Movlps there should be a X86Movsd here, the problem
698 // is during lowering, where it's not possible to recognize the fold cause
699 // it has two uses through a bitcast. One use disappears at isel time and the
700 // fold opportunity reappears.
701 def : Pat<(v2f64 (X86Movlpd VR128:$src1, VR128:$src2)),
702 (VMOVSDrr VR128:$src1, (EXTRACT_SUBREG (v2f64 VR128:$src2),
704 def : Pat<(v2i64 (X86Movlpd VR128:$src1, VR128:$src2)),
705 (VMOVSDrr VR128:$src1, (EXTRACT_SUBREG (v2i64 VR128:$src2),
707 def : Pat<(v4f32 (X86Movlps VR128:$src1, VR128:$src2)),
708 (VMOVSDrr VR128:$src1, (EXTRACT_SUBREG (v4f32 VR128:$src2),
710 def : Pat<(v4i32 (X86Movlps VR128:$src1, VR128:$src2)),
711 (VMOVSDrr VR128:$src1, (EXTRACT_SUBREG (v4i32 VR128:$src2),
715 let Predicates = [HasSSE1] in {
716 let AddedComplexity = 15 in {
717 // Move scalar to XMM zero-extended, zeroing a VR128 then do a
718 // MOVSS to the lower bits.
719 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
720 (MOVSSrr (v4f32 (V_SET0)), FR32:$src)>;
721 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
722 (MOVSSrr (v4f32 (V_SET0)),
723 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
724 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
725 (MOVSSrr (v4i32 (V_SET0)),
726 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
729 let AddedComplexity = 20 in {
730 // MOVSSrm zeros the high parts of the register; represent this
731 // with SUBREG_TO_REG.
732 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
733 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
734 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
735 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
736 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
737 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
740 // Extract and store.
741 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
744 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
746 // Shuffle with MOVSS
747 def : Pat<(v4i32 (X86Movss VR128:$src1, VR128:$src2)),
748 (MOVSSrr (v4i32 VR128:$src1),
749 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
750 def : Pat<(v4f32 (X86Movss VR128:$src1, VR128:$src2)),
751 (MOVSSrr (v4f32 VR128:$src1),
752 (EXTRACT_SUBREG (v4f32 VR128:$src2), sub_ss))>;
755 let Predicates = [HasSSE2] in {
756 let AddedComplexity = 15 in {
757 // Move scalar to XMM zero-extended, zeroing a VR128 then do a
758 // MOVSD to the lower bits.
759 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
760 (MOVSDrr (v2f64 (V_SET0)), FR64:$src)>;
763 let AddedComplexity = 20 in {
764 // MOVSDrm zeros the high parts of the register; represent this
765 // with SUBREG_TO_REG.
766 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
767 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
768 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
769 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
770 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
771 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
772 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
773 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
774 def : Pat<(v2f64 (X86vzload addr:$src)),
775 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
778 // Extract and store.
779 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
782 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
784 // Shuffle with MOVSD
785 def : Pat<(v2i64 (X86Movsd VR128:$src1, VR128:$src2)),
786 (MOVSDrr (v2i64 VR128:$src1),
787 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
788 def : Pat<(v2f64 (X86Movsd VR128:$src1, VR128:$src2)),
789 (MOVSDrr (v2f64 VR128:$src1),
790 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
791 def : Pat<(v4f32 (X86Movsd VR128:$src1, VR128:$src2)),
792 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG (v4f32 VR128:$src2),sub_sd))>;
793 def : Pat<(v4i32 (X86Movsd VR128:$src1, VR128:$src2)),
794 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG (v4i32 VR128:$src2),sub_sd))>;
796 // FIXME: Instead of a X86Movlps there should be a X86Movsd here, the problem
797 // is during lowering, where it's not possible to recognize the fold cause
798 // it has two uses through a bitcast. One use disappears at isel time and the
799 // fold opportunity reappears.
800 def : Pat<(v2f64 (X86Movlpd VR128:$src1, VR128:$src2)),
801 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG (v2f64 VR128:$src2),sub_sd))>;
802 def : Pat<(v2i64 (X86Movlpd VR128:$src1, VR128:$src2)),
803 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG (v2i64 VR128:$src2),sub_sd))>;
804 def : Pat<(v4f32 (X86Movlps VR128:$src1, VR128:$src2)),
805 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG (v4f32 VR128:$src2),sub_sd))>;
806 def : Pat<(v4i32 (X86Movlps VR128:$src1, VR128:$src2)),
807 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG (v4i32 VR128:$src2),sub_sd))>;
810 //===----------------------------------------------------------------------===//
811 // SSE 1 & 2 - Move Aligned/Unaligned FP Instructions
812 //===----------------------------------------------------------------------===//
814 multiclass sse12_mov_packed<bits<8> opc, RegisterClass RC,
815 X86MemOperand x86memop, PatFrag ld_frag,
816 string asm, Domain d,
818 bit IsReMaterializable = 1> {
819 let neverHasSideEffects = 1 in
820 def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src),
821 !strconcat(asm, "\t{$src, $dst|$dst, $src}"), [], itins.rr, d>;
822 let canFoldAsLoad = 1, isReMaterializable = IsReMaterializable in
823 def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
824 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
825 [(set RC:$dst, (ld_frag addr:$src))], itins.rm, d>;
828 defm VMOVAPS : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv4f32,
829 "movaps", SSEPackedSingle, SSE_MOVA_ITINS>,
831 defm VMOVAPD : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv2f64,
832 "movapd", SSEPackedDouble, SSE_MOVA_ITINS>,
834 defm VMOVUPS : sse12_mov_packed<0x10, VR128, f128mem, loadv4f32,
835 "movups", SSEPackedSingle, SSE_MOVU_ITINS>,
837 defm VMOVUPD : sse12_mov_packed<0x10, VR128, f128mem, loadv2f64,
838 "movupd", SSEPackedDouble, SSE_MOVU_ITINS, 0>,
841 defm VMOVAPSY : sse12_mov_packed<0x28, VR256, f256mem, alignedloadv8f32,
842 "movaps", SSEPackedSingle, SSE_MOVA_ITINS>,
844 defm VMOVAPDY : sse12_mov_packed<0x28, VR256, f256mem, alignedloadv4f64,
845 "movapd", SSEPackedDouble, SSE_MOVA_ITINS>,
847 defm VMOVUPSY : sse12_mov_packed<0x10, VR256, f256mem, loadv8f32,
848 "movups", SSEPackedSingle, SSE_MOVU_ITINS>,
850 defm VMOVUPDY : sse12_mov_packed<0x10, VR256, f256mem, loadv4f64,
851 "movupd", SSEPackedDouble, SSE_MOVU_ITINS, 0>,
853 defm MOVAPS : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv4f32,
854 "movaps", SSEPackedSingle, SSE_MOVA_ITINS>,
856 defm MOVAPD : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv2f64,
857 "movapd", SSEPackedDouble, SSE_MOVA_ITINS>,
859 defm MOVUPS : sse12_mov_packed<0x10, VR128, f128mem, loadv4f32,
860 "movups", SSEPackedSingle, SSE_MOVU_ITINS>,
862 defm MOVUPD : sse12_mov_packed<0x10, VR128, f128mem, loadv2f64,
863 "movupd", SSEPackedDouble, SSE_MOVU_ITINS, 0>,
866 def VMOVAPSmr : VPSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
867 "movaps\t{$src, $dst|$dst, $src}",
868 [(alignedstore (v4f32 VR128:$src), addr:$dst)],
869 IIC_SSE_MOVA_P_MR>, VEX;
870 def VMOVAPDmr : VPDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
871 "movapd\t{$src, $dst|$dst, $src}",
872 [(alignedstore (v2f64 VR128:$src), addr:$dst)],
873 IIC_SSE_MOVA_P_MR>, VEX;
874 def VMOVUPSmr : VPSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
875 "movups\t{$src, $dst|$dst, $src}",
876 [(store (v4f32 VR128:$src), addr:$dst)],
877 IIC_SSE_MOVU_P_MR>, VEX;
878 def VMOVUPDmr : VPDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
879 "movupd\t{$src, $dst|$dst, $src}",
880 [(store (v2f64 VR128:$src), addr:$dst)],
881 IIC_SSE_MOVU_P_MR>, VEX;
882 def VMOVAPSYmr : VPSI<0x29, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
883 "movaps\t{$src, $dst|$dst, $src}",
884 [(alignedstore256 (v8f32 VR256:$src), addr:$dst)],
885 IIC_SSE_MOVA_P_MR>, VEX;
886 def VMOVAPDYmr : VPDI<0x29, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
887 "movapd\t{$src, $dst|$dst, $src}",
888 [(alignedstore256 (v4f64 VR256:$src), addr:$dst)],
889 IIC_SSE_MOVA_P_MR>, VEX;
890 def VMOVUPSYmr : VPSI<0x11, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
891 "movups\t{$src, $dst|$dst, $src}",
892 [(store (v8f32 VR256:$src), addr:$dst)],
893 IIC_SSE_MOVU_P_MR>, VEX;
894 def VMOVUPDYmr : VPDI<0x11, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
895 "movupd\t{$src, $dst|$dst, $src}",
896 [(store (v4f64 VR256:$src), addr:$dst)],
897 IIC_SSE_MOVU_P_MR>, VEX;
900 let isCodeGenOnly = 1 in {
901 def VMOVAPSrr_REV : VPSI<0x29, MRMDestReg, (outs VR128:$dst),
903 "movaps\t{$src, $dst|$dst, $src}", [],
904 IIC_SSE_MOVA_P_RR>, VEX;
905 def VMOVAPDrr_REV : VPDI<0x29, MRMDestReg, (outs VR128:$dst),
907 "movapd\t{$src, $dst|$dst, $src}", [],
908 IIC_SSE_MOVA_P_RR>, VEX;
909 def VMOVUPSrr_REV : VPSI<0x11, MRMDestReg, (outs VR128:$dst),
911 "movups\t{$src, $dst|$dst, $src}", [],
912 IIC_SSE_MOVU_P_RR>, VEX;
913 def VMOVUPDrr_REV : VPDI<0x11, MRMDestReg, (outs VR128:$dst),
915 "movupd\t{$src, $dst|$dst, $src}", [],
916 IIC_SSE_MOVU_P_RR>, VEX;
917 def VMOVAPSYrr_REV : VPSI<0x29, MRMDestReg, (outs VR256:$dst),
919 "movaps\t{$src, $dst|$dst, $src}", [],
920 IIC_SSE_MOVA_P_RR>, VEX;
921 def VMOVAPDYrr_REV : VPDI<0x29, MRMDestReg, (outs VR256:$dst),
923 "movapd\t{$src, $dst|$dst, $src}", [],
924 IIC_SSE_MOVA_P_RR>, VEX;
925 def VMOVUPSYrr_REV : VPSI<0x11, MRMDestReg, (outs VR256:$dst),
927 "movups\t{$src, $dst|$dst, $src}", [],
928 IIC_SSE_MOVU_P_RR>, VEX;
929 def VMOVUPDYrr_REV : VPDI<0x11, MRMDestReg, (outs VR256:$dst),
931 "movupd\t{$src, $dst|$dst, $src}", [],
932 IIC_SSE_MOVU_P_RR>, VEX;
935 let Predicates = [HasAVX] in {
936 def : Pat<(v8i32 (X86vzmovl
937 (insert_subvector undef, (v4i32 VR128:$src), (i32 0)))),
938 (SUBREG_TO_REG (i32 0), (VMOVAPSrr VR128:$src), sub_xmm)>;
939 def : Pat<(v4i64 (X86vzmovl
940 (insert_subvector undef, (v2i64 VR128:$src), (i32 0)))),
941 (SUBREG_TO_REG (i32 0), (VMOVAPSrr VR128:$src), sub_xmm)>;
942 def : Pat<(v8f32 (X86vzmovl
943 (insert_subvector undef, (v4f32 VR128:$src), (i32 0)))),
944 (SUBREG_TO_REG (i32 0), (VMOVAPSrr VR128:$src), sub_xmm)>;
945 def : Pat<(v4f64 (X86vzmovl
946 (insert_subvector undef, (v2f64 VR128:$src), (i32 0)))),
947 (SUBREG_TO_REG (i32 0), (VMOVAPSrr VR128:$src), sub_xmm)>;
951 def : Pat<(int_x86_avx_storeu_ps_256 addr:$dst, VR256:$src),
952 (VMOVUPSYmr addr:$dst, VR256:$src)>;
953 def : Pat<(int_x86_avx_storeu_pd_256 addr:$dst, VR256:$src),
954 (VMOVUPDYmr addr:$dst, VR256:$src)>;
956 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
957 "movaps\t{$src, $dst|$dst, $src}",
958 [(alignedstore (v4f32 VR128:$src), addr:$dst)],
960 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
961 "movapd\t{$src, $dst|$dst, $src}",
962 [(alignedstore (v2f64 VR128:$src), addr:$dst)],
964 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
965 "movups\t{$src, $dst|$dst, $src}",
966 [(store (v4f32 VR128:$src), addr:$dst)],
968 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
969 "movupd\t{$src, $dst|$dst, $src}",
970 [(store (v2f64 VR128:$src), addr:$dst)],
974 let isCodeGenOnly = 1 in {
975 def MOVAPSrr_REV : PSI<0x29, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
976 "movaps\t{$src, $dst|$dst, $src}", [],
978 def MOVAPDrr_REV : PDI<0x29, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
979 "movapd\t{$src, $dst|$dst, $src}", [],
981 def MOVUPSrr_REV : PSI<0x11, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
982 "movups\t{$src, $dst|$dst, $src}", [],
984 def MOVUPDrr_REV : PDI<0x11, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
985 "movupd\t{$src, $dst|$dst, $src}", [],
989 let Predicates = [HasAVX] in {
990 def : Pat<(int_x86_sse_storeu_ps addr:$dst, VR128:$src),
991 (VMOVUPSmr addr:$dst, VR128:$src)>;
992 def : Pat<(int_x86_sse2_storeu_pd addr:$dst, VR128:$src),
993 (VMOVUPDmr addr:$dst, VR128:$src)>;
996 let Predicates = [HasSSE1] in
997 def : Pat<(int_x86_sse_storeu_ps addr:$dst, VR128:$src),
998 (MOVUPSmr addr:$dst, VR128:$src)>;
999 let Predicates = [HasSSE2] in
1000 def : Pat<(int_x86_sse2_storeu_pd addr:$dst, VR128:$src),
1001 (MOVUPDmr addr:$dst, VR128:$src)>;
1003 // Use vmovaps/vmovups for AVX integer load/store.
1004 let Predicates = [HasAVX] in {
1005 // 128-bit load/store
1006 def : Pat<(alignedloadv2i64 addr:$src),
1007 (VMOVAPSrm addr:$src)>;
1008 def : Pat<(loadv2i64 addr:$src),
1009 (VMOVUPSrm addr:$src)>;
1011 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
1012 (VMOVAPSmr addr:$dst, VR128:$src)>;
1013 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
1014 (VMOVAPSmr addr:$dst, VR128:$src)>;
1015 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
1016 (VMOVAPSmr addr:$dst, VR128:$src)>;
1017 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
1018 (VMOVAPSmr addr:$dst, VR128:$src)>;
1019 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
1020 (VMOVUPSmr addr:$dst, VR128:$src)>;
1021 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
1022 (VMOVUPSmr addr:$dst, VR128:$src)>;
1023 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
1024 (VMOVUPSmr addr:$dst, VR128:$src)>;
1025 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
1026 (VMOVUPSmr addr:$dst, VR128:$src)>;
1028 // 256-bit load/store
1029 def : Pat<(alignedloadv4i64 addr:$src),
1030 (VMOVAPSYrm addr:$src)>;
1031 def : Pat<(loadv4i64 addr:$src),
1032 (VMOVUPSYrm addr:$src)>;
1033 def : Pat<(alignedstore256 (v4i64 VR256:$src), addr:$dst),
1034 (VMOVAPSYmr addr:$dst, VR256:$src)>;
1035 def : Pat<(alignedstore256 (v8i32 VR256:$src), addr:$dst),
1036 (VMOVAPSYmr addr:$dst, VR256:$src)>;
1037 def : Pat<(alignedstore256 (v16i16 VR256:$src), addr:$dst),
1038 (VMOVAPSYmr addr:$dst, VR256:$src)>;
1039 def : Pat<(alignedstore256 (v32i8 VR256:$src), addr:$dst),
1040 (VMOVAPSYmr addr:$dst, VR256:$src)>;
1041 def : Pat<(store (v4i64 VR256:$src), addr:$dst),
1042 (VMOVUPSYmr addr:$dst, VR256:$src)>;
1043 def : Pat<(store (v8i32 VR256:$src), addr:$dst),
1044 (VMOVUPSYmr addr:$dst, VR256:$src)>;
1045 def : Pat<(store (v16i16 VR256:$src), addr:$dst),
1046 (VMOVUPSYmr addr:$dst, VR256:$src)>;
1047 def : Pat<(store (v32i8 VR256:$src), addr:$dst),
1048 (VMOVUPSYmr addr:$dst, VR256:$src)>;
1051 // Use movaps / movups for SSE integer load / store (one byte shorter).
1052 // The instructions selected below are then converted to MOVDQA/MOVDQU
1053 // during the SSE domain pass.
1054 let Predicates = [HasSSE1] in {
1055 def : Pat<(alignedloadv2i64 addr:$src),
1056 (MOVAPSrm addr:$src)>;
1057 def : Pat<(loadv2i64 addr:$src),
1058 (MOVUPSrm addr:$src)>;
1060 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
1061 (MOVAPSmr addr:$dst, VR128:$src)>;
1062 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
1063 (MOVAPSmr addr:$dst, VR128:$src)>;
1064 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
1065 (MOVAPSmr addr:$dst, VR128:$src)>;
1066 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
1067 (MOVAPSmr addr:$dst, VR128:$src)>;
1068 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
1069 (MOVUPSmr addr:$dst, VR128:$src)>;
1070 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
1071 (MOVUPSmr addr:$dst, VR128:$src)>;
1072 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
1073 (MOVUPSmr addr:$dst, VR128:$src)>;
1074 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
1075 (MOVUPSmr addr:$dst, VR128:$src)>;
1078 // Alias instruction to do FR32 or FR64 reg-to-reg copy using movaps. Upper
1079 // bits are disregarded. FIXME: Set encoding to pseudo!
1080 let neverHasSideEffects = 1 in {
1081 def FsVMOVAPSrr : VPSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1082 "movaps\t{$src, $dst|$dst, $src}", [],
1083 IIC_SSE_MOVA_P_RR>, VEX;
1084 def FsVMOVAPDrr : VPDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1085 "movapd\t{$src, $dst|$dst, $src}", [],
1086 IIC_SSE_MOVA_P_RR>, VEX;
1087 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1088 "movaps\t{$src, $dst|$dst, $src}", [],
1090 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1091 "movapd\t{$src, $dst|$dst, $src}", [],
1095 // Alias instruction to load FR32 or FR64 from f128mem using movaps. Upper
1096 // bits are disregarded. FIXME: Set encoding to pseudo!
1097 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1098 let isCodeGenOnly = 1 in {
1099 def FsVMOVAPSrm : VPSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
1100 "movaps\t{$src, $dst|$dst, $src}",
1101 [(set FR32:$dst, (alignedloadfsf32 addr:$src))],
1102 IIC_SSE_MOVA_P_RM>, VEX;
1103 def FsVMOVAPDrm : VPDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1104 "movapd\t{$src, $dst|$dst, $src}",
1105 [(set FR64:$dst, (alignedloadfsf64 addr:$src))],
1106 IIC_SSE_MOVA_P_RM>, VEX;
1108 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
1109 "movaps\t{$src, $dst|$dst, $src}",
1110 [(set FR32:$dst, (alignedloadfsf32 addr:$src))],
1112 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1113 "movapd\t{$src, $dst|$dst, $src}",
1114 [(set FR64:$dst, (alignedloadfsf64 addr:$src))],
1118 //===----------------------------------------------------------------------===//
1119 // SSE 1 & 2 - Move Low packed FP Instructions
1120 //===----------------------------------------------------------------------===//
1122 multiclass sse12_mov_hilo_packed<bits<8>opc, RegisterClass RC,
1123 SDNode psnode, SDNode pdnode, string base_opc,
1124 string asm_opr, InstrItinClass itin> {
1125 def PSrm : PI<opc, MRMSrcMem,
1126 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1127 !strconcat(base_opc, "s", asm_opr),
1130 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))],
1131 itin, SSEPackedSingle>, TB;
1133 def PDrm : PI<opc, MRMSrcMem,
1134 (outs RC:$dst), (ins RC:$src1, f64mem:$src2),
1135 !strconcat(base_opc, "d", asm_opr),
1136 [(set RC:$dst, (v2f64 (pdnode RC:$src1,
1137 (scalar_to_vector (loadf64 addr:$src2)))))],
1138 itin, SSEPackedDouble>, TB, OpSize;
1141 let AddedComplexity = 20 in {
1142 defm VMOVL : sse12_mov_hilo_packed<0x12, VR128, X86Movlps, X86Movlpd, "movlp",
1143 "\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1144 IIC_SSE_MOV_LH>, VEX_4V;
1146 let Constraints = "$src1 = $dst", AddedComplexity = 20 in {
1147 defm MOVL : sse12_mov_hilo_packed<0x12, VR128, X86Movlps, X86Movlpd, "movlp",
1148 "\t{$src2, $dst|$dst, $src2}",
1152 def VMOVLPSmr : VPSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1153 "movlps\t{$src, $dst|$dst, $src}",
1154 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
1155 (iPTR 0))), addr:$dst)],
1156 IIC_SSE_MOV_LH>, VEX;
1157 def VMOVLPDmr : VPDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1158 "movlpd\t{$src, $dst|$dst, $src}",
1159 [(store (f64 (vector_extract (v2f64 VR128:$src),
1160 (iPTR 0))), addr:$dst)],
1161 IIC_SSE_MOV_LH>, VEX;
1162 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1163 "movlps\t{$src, $dst|$dst, $src}",
1164 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
1165 (iPTR 0))), addr:$dst)],
1167 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1168 "movlpd\t{$src, $dst|$dst, $src}",
1169 [(store (f64 (vector_extract (v2f64 VR128:$src),
1170 (iPTR 0))), addr:$dst)],
1173 let Predicates = [HasAVX] in {
1174 // Shuffle with VMOVLPS
1175 def : Pat<(v4f32 (X86Movlps VR128:$src1, (load addr:$src2))),
1176 (VMOVLPSrm VR128:$src1, addr:$src2)>;
1177 def : Pat<(v4i32 (X86Movlps VR128:$src1, (load addr:$src2))),
1178 (VMOVLPSrm VR128:$src1, addr:$src2)>;
1180 // Shuffle with VMOVLPD
1181 def : Pat<(v2f64 (X86Movlpd VR128:$src1, (load addr:$src2))),
1182 (VMOVLPDrm VR128:$src1, addr:$src2)>;
1183 def : Pat<(v2i64 (X86Movlpd VR128:$src1, (load addr:$src2))),
1184 (VMOVLPDrm VR128:$src1, addr:$src2)>;
1187 def : Pat<(store (v4f32 (X86Movlps (load addr:$src1), VR128:$src2)),
1189 (VMOVLPSmr addr:$src1, VR128:$src2)>;
1190 def : Pat<(store (v4i32 (X86Movlps
1191 (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)), addr:$src1),
1192 (VMOVLPSmr addr:$src1, VR128:$src2)>;
1193 def : Pat<(store (v2f64 (X86Movlpd (load addr:$src1), VR128:$src2)),
1195 (VMOVLPDmr addr:$src1, VR128:$src2)>;
1196 def : Pat<(store (v2i64 (X86Movlpd (load addr:$src1), VR128:$src2)),
1198 (VMOVLPDmr addr:$src1, VR128:$src2)>;
1201 let Predicates = [HasSSE1] in {
1202 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
1203 def : Pat<(store (i64 (vector_extract (bc_v2i64 (v4f32 VR128:$src2)),
1204 (iPTR 0))), addr:$src1),
1205 (MOVLPSmr addr:$src1, VR128:$src2)>;
1207 // Shuffle with MOVLPS
1208 def : Pat<(v4f32 (X86Movlps VR128:$src1, (load addr:$src2))),
1209 (MOVLPSrm VR128:$src1, addr:$src2)>;
1210 def : Pat<(v4i32 (X86Movlps VR128:$src1, (load addr:$src2))),
1211 (MOVLPSrm VR128:$src1, addr:$src2)>;
1212 def : Pat<(X86Movlps VR128:$src1,
1213 (bc_v4f32 (v2i64 (scalar_to_vector (loadi64 addr:$src2))))),
1214 (MOVLPSrm VR128:$src1, addr:$src2)>;
1217 def : Pat<(store (v4f32 (X86Movlps (load addr:$src1), VR128:$src2)),
1219 (MOVLPSmr addr:$src1, VR128:$src2)>;
1220 def : Pat<(store (v4i32 (X86Movlps
1221 (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
1223 (MOVLPSmr addr:$src1, VR128:$src2)>;
1226 let Predicates = [HasSSE2] in {
1227 // Shuffle with MOVLPD
1228 def : Pat<(v2f64 (X86Movlpd VR128:$src1, (load addr:$src2))),
1229 (MOVLPDrm VR128:$src1, addr:$src2)>;
1230 def : Pat<(v2i64 (X86Movlpd VR128:$src1, (load addr:$src2))),
1231 (MOVLPDrm VR128:$src1, addr:$src2)>;
1234 def : Pat<(store (v2f64 (X86Movlpd (load addr:$src1), VR128:$src2)),
1236 (MOVLPDmr addr:$src1, VR128:$src2)>;
1237 def : Pat<(store (v2i64 (X86Movlpd (load addr:$src1), VR128:$src2)),
1239 (MOVLPDmr addr:$src1, VR128:$src2)>;
1242 //===----------------------------------------------------------------------===//
1243 // SSE 1 & 2 - Move Hi packed FP Instructions
1244 //===----------------------------------------------------------------------===//
1246 let AddedComplexity = 20 in {
1247 defm VMOVH : sse12_mov_hilo_packed<0x16, VR128, X86Movlhps, X86Movlhpd, "movhp",
1248 "\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1249 IIC_SSE_MOV_LH>, VEX_4V;
1251 let Constraints = "$src1 = $dst", AddedComplexity = 20 in {
1252 defm MOVH : sse12_mov_hilo_packed<0x16, VR128, X86Movlhps, X86Movlhpd, "movhp",
1253 "\t{$src2, $dst|$dst, $src2}",
1257 // v2f64 extract element 1 is always custom lowered to unpack high to low
1258 // and extract element 0 so the non-store version isn't too horrible.
1259 def VMOVHPSmr : VPSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1260 "movhps\t{$src, $dst|$dst, $src}",
1261 [(store (f64 (vector_extract
1262 (X86Unpckh (bc_v2f64 (v4f32 VR128:$src)),
1263 (bc_v2f64 (v4f32 VR128:$src))),
1264 (iPTR 0))), addr:$dst)], IIC_SSE_MOV_LH>, VEX;
1265 def VMOVHPDmr : VPDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1266 "movhpd\t{$src, $dst|$dst, $src}",
1267 [(store (f64 (vector_extract
1268 (v2f64 (X86Unpckh VR128:$src, VR128:$src)),
1269 (iPTR 0))), addr:$dst)], IIC_SSE_MOV_LH>, VEX;
1270 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1271 "movhps\t{$src, $dst|$dst, $src}",
1272 [(store (f64 (vector_extract
1273 (X86Unpckh (bc_v2f64 (v4f32 VR128:$src)),
1274 (bc_v2f64 (v4f32 VR128:$src))),
1275 (iPTR 0))), addr:$dst)], IIC_SSE_MOV_LH>;
1276 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1277 "movhpd\t{$src, $dst|$dst, $src}",
1278 [(store (f64 (vector_extract
1279 (v2f64 (X86Unpckh VR128:$src, VR128:$src)),
1280 (iPTR 0))), addr:$dst)], IIC_SSE_MOV_LH>;
1282 let Predicates = [HasAVX] in {
1284 def : Pat<(X86Movlhps VR128:$src1,
1285 (bc_v4f32 (v2i64 (scalar_to_vector (loadi64 addr:$src2))))),
1286 (VMOVHPSrm VR128:$src1, addr:$src2)>;
1287 def : Pat<(X86Movlhps VR128:$src1,
1288 (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
1289 (VMOVHPSrm VR128:$src1, addr:$src2)>;
1291 // FIXME: Instead of X86Unpckl, there should be a X86Movlhpd here, the problem
1292 // is during lowering, where it's not possible to recognize the load fold
1293 // cause it has two uses through a bitcast. One use disappears at isel time
1294 // and the fold opportunity reappears.
1295 def : Pat<(v2f64 (X86Unpckl VR128:$src1,
1296 (scalar_to_vector (loadf64 addr:$src2)))),
1297 (VMOVHPDrm VR128:$src1, addr:$src2)>;
1300 let Predicates = [HasSSE1] in {
1302 def : Pat<(X86Movlhps VR128:$src1,
1303 (bc_v4f32 (v2i64 (scalar_to_vector (loadi64 addr:$src2))))),
1304 (MOVHPSrm VR128:$src1, addr:$src2)>;
1305 def : Pat<(X86Movlhps VR128:$src1,
1306 (bc_v4f32 (v2i64 (X86vzload addr:$src2)))),
1307 (MOVHPSrm VR128:$src1, addr:$src2)>;
1310 let Predicates = [HasSSE2] in {
1311 // FIXME: Instead of X86Unpckl, there should be a X86Movlhpd here, the problem
1312 // is during lowering, where it's not possible to recognize the load fold
1313 // cause it has two uses through a bitcast. One use disappears at isel time
1314 // and the fold opportunity reappears.
1315 def : Pat<(v2f64 (X86Unpckl VR128:$src1,
1316 (scalar_to_vector (loadf64 addr:$src2)))),
1317 (MOVHPDrm VR128:$src1, addr:$src2)>;
1320 //===----------------------------------------------------------------------===//
1321 // SSE 1 & 2 - Move Low to High and High to Low packed FP Instructions
1322 //===----------------------------------------------------------------------===//
1324 let AddedComplexity = 20 in {
1325 def VMOVLHPSrr : VPSI<0x16, MRMSrcReg, (outs VR128:$dst),
1326 (ins VR128:$src1, VR128:$src2),
1327 "movlhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1329 (v4f32 (X86Movlhps VR128:$src1, VR128:$src2)))],
1332 def VMOVHLPSrr : VPSI<0x12, MRMSrcReg, (outs VR128:$dst),
1333 (ins VR128:$src1, VR128:$src2),
1334 "movhlps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1336 (v4f32 (X86Movhlps VR128:$src1, VR128:$src2)))],
1340 let Constraints = "$src1 = $dst", AddedComplexity = 20 in {
1341 def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
1342 (ins VR128:$src1, VR128:$src2),
1343 "movlhps\t{$src2, $dst|$dst, $src2}",
1345 (v4f32 (X86Movlhps VR128:$src1, VR128:$src2)))],
1347 def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
1348 (ins VR128:$src1, VR128:$src2),
1349 "movhlps\t{$src2, $dst|$dst, $src2}",
1351 (v4f32 (X86Movhlps VR128:$src1, VR128:$src2)))],
1355 let Predicates = [HasAVX] in {
1357 def : Pat<(v4i32 (X86Movlhps VR128:$src1, VR128:$src2)),
1358 (VMOVLHPSrr VR128:$src1, VR128:$src2)>;
1359 def : Pat<(v2i64 (X86Movlhps VR128:$src1, VR128:$src2)),
1360 (VMOVLHPSrr (v2i64 VR128:$src1), VR128:$src2)>;
1363 def : Pat<(v4i32 (X86Movhlps VR128:$src1, VR128:$src2)),
1364 (VMOVHLPSrr VR128:$src1, VR128:$src2)>;
1367 let Predicates = [HasSSE1] in {
1369 def : Pat<(v4i32 (X86Movlhps VR128:$src1, VR128:$src2)),
1370 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
1371 def : Pat<(v2i64 (X86Movlhps VR128:$src1, VR128:$src2)),
1372 (MOVLHPSrr (v2i64 VR128:$src1), VR128:$src2)>;
1375 def : Pat<(v4i32 (X86Movhlps VR128:$src1, VR128:$src2)),
1376 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
1379 //===----------------------------------------------------------------------===//
1380 // SSE 1 & 2 - Conversion Instructions
1381 //===----------------------------------------------------------------------===//
1383 def SSE_CVT_PD : OpndItins<
1384 IIC_SSE_CVT_PD_RR, IIC_SSE_CVT_PD_RM
1387 def SSE_CVT_PS : OpndItins<
1388 IIC_SSE_CVT_PS_RR, IIC_SSE_CVT_PS_RM
1391 def SSE_CVT_Scalar : OpndItins<
1392 IIC_SSE_CVT_Scalar_RR, IIC_SSE_CVT_Scalar_RM
1395 def SSE_CVT_SS2SI_32 : OpndItins<
1396 IIC_SSE_CVT_SS2SI32_RR, IIC_SSE_CVT_SS2SI32_RM
1399 def SSE_CVT_SS2SI_64 : OpndItins<
1400 IIC_SSE_CVT_SS2SI64_RR, IIC_SSE_CVT_SS2SI64_RM
1403 def SSE_CVT_SD2SI : OpndItins<
1404 IIC_SSE_CVT_SD2SI_RR, IIC_SSE_CVT_SD2SI_RM
1407 multiclass sse12_cvt_s<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
1408 SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
1409 string asm, OpndItins itins> {
1410 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
1411 [(set DstRC:$dst, (OpNode SrcRC:$src))],
1413 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
1414 [(set DstRC:$dst, (OpNode (ld_frag addr:$src)))],
1418 multiclass sse12_cvt_p<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
1419 SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
1420 string asm, Domain d, OpndItins itins> {
1421 def rr : I<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
1422 [(set DstRC:$dst, (OpNode SrcRC:$src))],
1424 def rm : I<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
1425 [(set DstRC:$dst, (OpNode (ld_frag addr:$src)))],
1429 multiclass sse12_vcvt_avx<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
1430 X86MemOperand x86memop, string asm> {
1431 let neverHasSideEffects = 1 in {
1432 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src),
1433 !strconcat(asm,"\t{$src, $src1, $dst|$dst, $src1, $src}"), []>;
1435 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
1436 (ins DstRC:$src1, x86memop:$src),
1437 !strconcat(asm,"\t{$src, $src1, $dst|$dst, $src1, $src}"), []>;
1438 } // neverHasSideEffects = 1
1441 defm VCVTTSS2SI : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
1442 "cvttss2si\t{$src, $dst|$dst, $src}",
1445 defm VCVTTSS2SI64 : sse12_cvt_s<0x2C, FR32, GR64, fp_to_sint, f32mem, loadf32,
1446 "cvttss2si\t{$src, $dst|$dst, $src}",
1448 XS, VEX, VEX_W, VEX_LIG;
1449 defm VCVTTSD2SI : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
1450 "cvttsd2si\t{$src, $dst|$dst, $src}",
1453 defm VCVTTSD2SI64 : sse12_cvt_s<0x2C, FR64, GR64, fp_to_sint, f64mem, loadf64,
1454 "cvttsd2si\t{$src, $dst|$dst, $src}",
1456 XD, VEX, VEX_W, VEX_LIG;
1458 // The assembler can recognize rr 64-bit instructions by seeing a rxx
1459 // register, but the same isn't true when only using memory operands,
1460 // provide other assembly "l" and "q" forms to address this explicitly
1461 // where appropriate to do so.
1462 defm VCVTSI2SS : sse12_vcvt_avx<0x2A, GR32, FR32, i32mem, "cvtsi2ss">,
1463 XS, VEX_4V, VEX_LIG;
1464 defm VCVTSI2SS64 : sse12_vcvt_avx<0x2A, GR64, FR32, i64mem, "cvtsi2ss{q}">,
1465 XS, VEX_4V, VEX_W, VEX_LIG;
1466 defm VCVTSI2SD : sse12_vcvt_avx<0x2A, GR32, FR64, i32mem, "cvtsi2sd">,
1467 XD, VEX_4V, VEX_LIG;
1468 defm VCVTSI2SDL : sse12_vcvt_avx<0x2A, GR32, FR64, i32mem, "cvtsi2sd{l}">,
1469 XD, VEX_4V, VEX_LIG;
1470 defm VCVTSI2SD64 : sse12_vcvt_avx<0x2A, GR64, FR64, i64mem, "cvtsi2sd{q}">,
1471 XD, VEX_4V, VEX_W, VEX_LIG;
1473 let Predicates = [HasAVX], AddedComplexity = 1 in {
1474 def : Pat<(f32 (sint_to_fp (loadi32 addr:$src))),
1475 (VCVTSI2SSrm (f32 (IMPLICIT_DEF)), addr:$src)>;
1476 def : Pat<(f32 (sint_to_fp (loadi64 addr:$src))),
1477 (VCVTSI2SS64rm (f32 (IMPLICIT_DEF)), addr:$src)>;
1478 def : Pat<(f64 (sint_to_fp (loadi32 addr:$src))),
1479 (VCVTSI2SDrm (f64 (IMPLICIT_DEF)), addr:$src)>;
1480 def : Pat<(f64 (sint_to_fp (loadi64 addr:$src))),
1481 (VCVTSI2SD64rm (f64 (IMPLICIT_DEF)), addr:$src)>;
1483 def : Pat<(f32 (sint_to_fp GR32:$src)),
1484 (VCVTSI2SSrr (f32 (IMPLICIT_DEF)), GR32:$src)>;
1485 def : Pat<(f32 (sint_to_fp GR64:$src)),
1486 (VCVTSI2SS64rr (f32 (IMPLICIT_DEF)), GR64:$src)>;
1487 def : Pat<(f64 (sint_to_fp GR32:$src)),
1488 (VCVTSI2SDrr (f64 (IMPLICIT_DEF)), GR32:$src)>;
1489 def : Pat<(f64 (sint_to_fp GR64:$src)),
1490 (VCVTSI2SD64rr (f64 (IMPLICIT_DEF)), GR64:$src)>;
1493 defm CVTTSS2SI : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
1494 "cvttss2si\t{$src, $dst|$dst, $src}",
1495 SSE_CVT_SS2SI_32>, XS;
1496 defm CVTTSS2SI64 : sse12_cvt_s<0x2C, FR32, GR64, fp_to_sint, f32mem, loadf32,
1497 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1498 SSE_CVT_SS2SI_64>, XS, REX_W;
1499 defm CVTTSD2SI : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
1500 "cvttsd2si\t{$src, $dst|$dst, $src}",
1502 defm CVTTSD2SI64 : sse12_cvt_s<0x2C, FR64, GR64, fp_to_sint, f64mem, loadf64,
1503 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1504 SSE_CVT_SD2SI>, XD, REX_W;
1505 defm CVTSI2SS : sse12_cvt_s<0x2A, GR32, FR32, sint_to_fp, i32mem, loadi32,
1506 "cvtsi2ss\t{$src, $dst|$dst, $src}",
1507 SSE_CVT_Scalar>, XS;
1508 defm CVTSI2SS64 : sse12_cvt_s<0x2A, GR64, FR32, sint_to_fp, i64mem, loadi64,
1509 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1510 SSE_CVT_Scalar>, XS, REX_W;
1511 defm CVTSI2SD : sse12_cvt_s<0x2A, GR32, FR64, sint_to_fp, i32mem, loadi32,
1512 "cvtsi2sd\t{$src, $dst|$dst, $src}",
1513 SSE_CVT_Scalar>, XD;
1514 defm CVTSI2SD64 : sse12_cvt_s<0x2A, GR64, FR64, sint_to_fp, i64mem, loadi64,
1515 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1516 SSE_CVT_Scalar>, XD, REX_W;
1518 // Conversion Instructions Intrinsics - Match intrinsics which expect MM
1519 // and/or XMM operand(s).
1521 multiclass sse12_cvt_sint<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
1522 Intrinsic Int, X86MemOperand x86memop, PatFrag ld_frag,
1523 string asm, OpndItins itins> {
1524 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src),
1525 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
1526 [(set DstRC:$dst, (Int SrcRC:$src))], itins.rr>;
1527 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src),
1528 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
1529 [(set DstRC:$dst, (Int (ld_frag addr:$src)))], itins.rm>;
1532 multiclass sse12_cvt_sint_3addr<bits<8> opc, RegisterClass SrcRC,
1533 RegisterClass DstRC, Intrinsic Int, X86MemOperand x86memop,
1534 PatFrag ld_frag, string asm, OpndItins itins,
1536 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src2),
1538 !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
1539 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
1540 [(set DstRC:$dst, (Int DstRC:$src1, SrcRC:$src2))],
1542 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
1543 (ins DstRC:$src1, x86memop:$src2),
1545 !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
1546 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
1547 [(set DstRC:$dst, (Int DstRC:$src1, (ld_frag addr:$src2)))],
1551 defm VCVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse2_cvtsd2si,
1552 f128mem, load, "cvtsd2si", SSE_CVT_SD2SI>, XD, VEX, VEX_LIG;
1553 defm VCVTSD2SI64 : sse12_cvt_sint<0x2D, VR128, GR64,
1554 int_x86_sse2_cvtsd2si64, f128mem, load, "cvtsd2si",
1555 SSE_CVT_SD2SI>, XD, VEX, VEX_W, VEX_LIG;
1557 defm CVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse2_cvtsd2si,
1558 f128mem, load, "cvtsd2si{l}", SSE_CVT_SD2SI>, XD;
1559 defm CVTSD2SI64 : sse12_cvt_sint<0x2D, VR128, GR64, int_x86_sse2_cvtsd2si64,
1560 f128mem, load, "cvtsd2si{q}", SSE_CVT_SD2SI>, XD, REX_W;
1563 defm Int_VCVTSI2SS : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
1564 int_x86_sse_cvtsi2ss, i32mem, loadi32, "cvtsi2ss",
1565 SSE_CVT_Scalar, 0>, XS, VEX_4V;
1566 defm Int_VCVTSI2SS64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
1567 int_x86_sse_cvtsi642ss, i64mem, loadi64, "cvtsi2ss",
1568 SSE_CVT_Scalar, 0>, XS, VEX_4V,
1570 defm Int_VCVTSI2SD : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
1571 int_x86_sse2_cvtsi2sd, i32mem, loadi32, "cvtsi2sd",
1572 SSE_CVT_Scalar, 0>, XD, VEX_4V;
1573 defm Int_VCVTSI2SD64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
1574 int_x86_sse2_cvtsi642sd, i64mem, loadi64, "cvtsi2sd",
1575 SSE_CVT_Scalar, 0>, XD,
1578 let Constraints = "$src1 = $dst" in {
1579 defm Int_CVTSI2SS : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
1580 int_x86_sse_cvtsi2ss, i32mem, loadi32,
1581 "cvtsi2ss", SSE_CVT_Scalar>, XS;
1582 defm Int_CVTSI2SS64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
1583 int_x86_sse_cvtsi642ss, i64mem, loadi64,
1584 "cvtsi2ss{q}", SSE_CVT_Scalar>, XS, REX_W;
1585 defm Int_CVTSI2SD : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
1586 int_x86_sse2_cvtsi2sd, i32mem, loadi32,
1587 "cvtsi2sd", SSE_CVT_Scalar>, XD;
1588 defm Int_CVTSI2SD64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
1589 int_x86_sse2_cvtsi642sd, i64mem, loadi64,
1590 "cvtsi2sd", SSE_CVT_Scalar>, XD, REX_W;
1595 // Aliases for intrinsics
1596 defm Int_VCVTTSS2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse_cvttss2si,
1597 f32mem, load, "cvttss2si",
1598 SSE_CVT_SS2SI_32>, XS, VEX;
1599 defm Int_VCVTTSS2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
1600 int_x86_sse_cvttss2si64, f32mem, load,
1601 "cvttss2si", SSE_CVT_SS2SI_64>,
1603 defm Int_VCVTTSD2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse2_cvttsd2si,
1604 f128mem, load, "cvttsd2si", SSE_CVT_SD2SI>,
1606 defm Int_VCVTTSD2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
1607 int_x86_sse2_cvttsd2si64, f128mem, load,
1608 "cvttsd2si", SSE_CVT_SD2SI>,
1610 defm Int_CVTTSS2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse_cvttss2si,
1611 f32mem, load, "cvttss2si",
1612 SSE_CVT_SS2SI_32>, XS;
1613 defm Int_CVTTSS2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
1614 int_x86_sse_cvttss2si64, f32mem, load,
1615 "cvttss2si{q}", SSE_CVT_SS2SI_64>,
1617 defm Int_CVTTSD2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse2_cvttsd2si,
1618 f128mem, load, "cvttsd2si", SSE_CVT_SD2SI>,
1620 defm Int_CVTTSD2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
1621 int_x86_sse2_cvttsd2si64, f128mem, load,
1622 "cvttsd2si{q}", SSE_CVT_SD2SI>,
1625 let Pattern = []<dag>, neverHasSideEffects = 1 in {
1626 defm VCVTSS2SI : sse12_cvt_s<0x2D, FR32, GR32, undef, f32mem, load,
1627 "cvtss2si{l}\t{$src, $dst|$dst, $src}",
1628 SSE_CVT_SS2SI_32>, XS, VEX, VEX_LIG;
1629 defm VCVTSS2SI64 : sse12_cvt_s<0x2D, FR32, GR64, undef, f32mem, load,
1630 "cvtss2si\t{$src, $dst|$dst, $src}",
1631 SSE_CVT_SS2SI_64>, XS, VEX, VEX_W, VEX_LIG;
1632 defm VCVTDQ2PS : sse12_cvt_p<0x5B, VR128, VR128, undef, i128mem, load,
1633 "vcvtdq2ps\t{$src, $dst|$dst, $src}",
1634 SSEPackedSingle, SSE_CVT_PS>, TB, VEX,
1636 defm VCVTDQ2PSY : sse12_cvt_p<0x5B, VR256, VR256, undef, i256mem, load,
1637 "vcvtdq2ps\t{$src, $dst|$dst, $src}",
1638 SSEPackedSingle, SSE_CVT_PS>, TB, VEX,
1642 let Pattern = []<dag>, neverHasSideEffects = 1 in {
1643 defm CVTSS2SI : sse12_cvt_s<0x2D, FR32, GR32, undef, f32mem, load /*dummy*/,
1644 "cvtss2si{l}\t{$src, $dst|$dst, $src}",
1645 SSE_CVT_SS2SI_32>, XS;
1646 defm CVTSS2SI64 : sse12_cvt_s<0x2D, FR32, GR64, undef, f32mem, load /*dummy*/,
1647 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1648 SSE_CVT_SS2SI_64>, XS, REX_W;
1649 defm CVTDQ2PS : sse12_cvt_p<0x5B, VR128, VR128, undef, i128mem, load /*dummy*/,
1650 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1651 SSEPackedSingle, SSE_CVT_PS>, TB,
1652 Requires<[HasSSE2]>;
1655 let Predicates = [HasAVX] in {
1656 def : Pat<(int_x86_sse_cvtss2si VR128:$src),
1657 (VCVTSS2SIrr (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1658 def : Pat<(int_x86_sse_cvtss2si (load addr:$src)),
1659 (VCVTSS2SIrm addr:$src)>;
1660 def : Pat<(int_x86_sse_cvtss2si64 VR128:$src),
1661 (VCVTSS2SI64rr (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1662 def : Pat<(int_x86_sse_cvtss2si64 (load addr:$src)),
1663 (VCVTSS2SI64rm addr:$src)>;
1666 let Predicates = [HasSSE1] in {
1667 def : Pat<(int_x86_sse_cvtss2si VR128:$src),
1668 (CVTSS2SIrr (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1669 def : Pat<(int_x86_sse_cvtss2si (load addr:$src)),
1670 (CVTSS2SIrm addr:$src)>;
1671 def : Pat<(int_x86_sse_cvtss2si64 VR128:$src),
1672 (CVTSS2SI64rr (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1673 def : Pat<(int_x86_sse_cvtss2si64 (load addr:$src)),
1674 (CVTSS2SI64rm addr:$src)>;
1679 // Convert scalar double to scalar single
1680 def VCVTSD2SSrr : VSDI<0x5A, MRMSrcReg, (outs FR32:$dst),
1681 (ins FR64:$src1, FR64:$src2),
1682 "cvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}", [],
1683 IIC_SSE_CVT_Scalar_RR>, VEX_4V, VEX_LIG;
1685 def VCVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst),
1686 (ins FR64:$src1, f64mem:$src2),
1687 "vcvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1688 [], IIC_SSE_CVT_Scalar_RM>,
1689 XD, Requires<[HasAVX, OptForSize]>, VEX_4V, VEX_LIG;
1691 def : Pat<(f32 (fround FR64:$src)), (VCVTSD2SSrr FR64:$src, FR64:$src)>,
1694 def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
1695 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1696 [(set FR32:$dst, (fround FR64:$src))],
1697 IIC_SSE_CVT_Scalar_RR>;
1698 def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
1699 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1700 [(set FR32:$dst, (fround (loadf64 addr:$src)))],
1701 IIC_SSE_CVT_Scalar_RM>,
1703 Requires<[HasSSE2, OptForSize]>;
1705 defm Int_VCVTSD2SS: sse12_cvt_sint_3addr<0x5A, VR128, VR128,
1706 int_x86_sse2_cvtsd2ss, f64mem, load, "cvtsd2ss",
1709 let Constraints = "$src1 = $dst" in
1710 defm Int_CVTSD2SS: sse12_cvt_sint_3addr<0x5A, VR128, VR128,
1711 int_x86_sse2_cvtsd2ss, f64mem, load, "cvtsd2ss",
1712 SSE_CVT_Scalar>, XS;
1714 // Convert scalar single to scalar double
1715 // SSE2 instructions with XS prefix
1716 def VCVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst),
1717 (ins FR32:$src1, FR32:$src2),
1718 "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1719 [], IIC_SSE_CVT_Scalar_RR>,
1720 XS, Requires<[HasAVX]>, VEX_4V, VEX_LIG;
1722 def VCVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst),
1723 (ins FR32:$src1, f32mem:$src2),
1724 "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1725 [], IIC_SSE_CVT_Scalar_RM>,
1726 XS, VEX_4V, VEX_LIG, Requires<[HasAVX, OptForSize]>;
1728 let Predicates = [HasAVX] in {
1729 def : Pat<(f64 (fextend FR32:$src)),
1730 (VCVTSS2SDrr FR32:$src, FR32:$src)>;
1731 def : Pat<(fextend (loadf32 addr:$src)),
1732 (VCVTSS2SDrm (f32 (IMPLICIT_DEF)), addr:$src)>;
1733 def : Pat<(extloadf32 addr:$src),
1734 (VCVTSS2SDrm (f32 (IMPLICIT_DEF)), addr:$src)>;
1737 def : Pat<(extloadf32 addr:$src),
1738 (VCVTSS2SDrr (f32 (IMPLICIT_DEF)), (MOVSSrm addr:$src))>,
1739 Requires<[HasAVX, OptForSpeed]>;
1741 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
1742 "cvtss2sd\t{$src, $dst|$dst, $src}",
1743 [(set FR64:$dst, (fextend FR32:$src))],
1744 IIC_SSE_CVT_Scalar_RR>, XS,
1745 Requires<[HasSSE2]>;
1746 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
1747 "cvtss2sd\t{$src, $dst|$dst, $src}",
1748 [(set FR64:$dst, (extloadf32 addr:$src))],
1749 IIC_SSE_CVT_Scalar_RM>, XS,
1750 Requires<[HasSSE2, OptForSize]>;
1752 // extload f32 -> f64. This matches load+fextend because we have a hack in
1753 // the isel (PreprocessForFPConvert) that can introduce loads after dag
1755 // Since these loads aren't folded into the fextend, we have to match it
1757 def : Pat<(fextend (loadf32 addr:$src)),
1758 (CVTSS2SDrm addr:$src)>, Requires<[HasSSE2]>;
1759 def : Pat<(extloadf32 addr:$src),
1760 (CVTSS2SDrr (MOVSSrm addr:$src))>, Requires<[HasSSE2, OptForSpeed]>;
1762 def Int_VCVTSS2SDrr: I<0x5A, MRMSrcReg,
1763 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1764 "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1765 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1767 IIC_SSE_CVT_Scalar_RR>, XS, VEX_4V,
1769 def Int_VCVTSS2SDrm: I<0x5A, MRMSrcMem,
1770 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
1771 "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1772 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1773 (load addr:$src2)))],
1774 IIC_SSE_CVT_Scalar_RM>, XS, VEX_4V,
1776 let Constraints = "$src1 = $dst" in { // SSE2 instructions with XS prefix
1777 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
1778 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1779 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1780 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1782 IIC_SSE_CVT_Scalar_RR>, XS,
1783 Requires<[HasSSE2]>;
1784 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
1785 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
1786 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1787 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1788 (load addr:$src2)))],
1789 IIC_SSE_CVT_Scalar_RM>, XS,
1790 Requires<[HasSSE2]>;
1793 // Convert packed single/double fp to doubleword
1794 def VCVTPS2DQrr : VPDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1795 "cvtps2dq\t{$src, $dst|$dst, $src}", [],
1796 IIC_SSE_CVT_PS_RR>, VEX;
1797 def VCVTPS2DQrm : VPDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1798 "cvtps2dq\t{$src, $dst|$dst, $src}", [],
1799 IIC_SSE_CVT_PS_RM>, VEX;
1800 def VCVTPS2DQYrr : VPDI<0x5B, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
1801 "cvtps2dq\t{$src, $dst|$dst, $src}", [],
1802 IIC_SSE_CVT_PS_RR>, VEX;
1803 def VCVTPS2DQYrm : VPDI<0x5B, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
1804 "cvtps2dq\t{$src, $dst|$dst, $src}", [],
1805 IIC_SSE_CVT_PS_RM>, VEX;
1806 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1807 "cvtps2dq\t{$src, $dst|$dst, $src}", [],
1809 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1810 "cvtps2dq\t{$src, $dst|$dst, $src}", [],
1813 let Predicates = [HasAVX] in {
1814 def : Pat<(int_x86_sse2_cvtps2dq VR128:$src),
1815 (VCVTPS2DQrr VR128:$src)>;
1816 def : Pat<(int_x86_sse2_cvtps2dq (memopv4f32 addr:$src)),
1817 (VCVTPS2DQrm addr:$src)>;
1820 let Predicates = [HasSSE2] in {
1821 def : Pat<(int_x86_sse2_cvtps2dq VR128:$src),
1822 (CVTPS2DQrr VR128:$src)>;
1823 def : Pat<(int_x86_sse2_cvtps2dq (memopv4f32 addr:$src)),
1824 (CVTPS2DQrm addr:$src)>;
1827 // Convert Packed Double FP to Packed DW Integers
1828 let Predicates = [HasAVX] in {
1829 // The assembler can recognize rr 256-bit instructions by seeing a ymm
1830 // register, but the same isn't true when using memory operands instead.
1831 // Provide other assembly rr and rm forms to address this explicitly.
1832 def VCVTPD2DQrr : SDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1833 "vcvtpd2dq\t{$src, $dst|$dst, $src}", []>, VEX;
1836 def : InstAlias<"vcvtpd2dqx\t{$src, $dst|$dst, $src}",
1837 (VCVTPD2DQrr VR128:$dst, VR128:$src)>;
1838 def VCVTPD2DQXrm : SDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1839 "vcvtpd2dqx\t{$src, $dst|$dst, $src}", []>, VEX;
1842 def VCVTPD2DQYrr : SDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
1843 "vcvtpd2dq{y}\t{$src, $dst|$dst, $src}", []>, VEX;
1844 def VCVTPD2DQYrm : SDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
1845 "vcvtpd2dq{y}\t{$src, $dst|$dst, $src}", []>, VEX, VEX_L;
1846 def : InstAlias<"vcvtpd2dq\t{$src, $dst|$dst, $src}",
1847 (VCVTPD2DQYrr VR128:$dst, VR256:$src)>;
1850 def CVTPD2DQrm : SDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1851 "cvtpd2dq\t{$src, $dst|$dst, $src}", [],
1853 def CVTPD2DQrr : SDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1854 "cvtpd2dq\t{$src, $dst|$dst, $src}", [],
1857 let Predicates = [HasAVX] in {
1858 def : Pat<(int_x86_sse2_cvtpd2dq VR128:$src),
1859 (VCVTPD2DQrr VR128:$src)>;
1860 def : Pat<(int_x86_sse2_cvtpd2dq (memopv2f64 addr:$src)),
1861 (VCVTPD2DQXrm addr:$src)>;
1864 let Predicates = [HasSSE2] in {
1865 def : Pat<(int_x86_sse2_cvtpd2dq VR128:$src),
1866 (CVTPD2DQrr VR128:$src)>;
1867 def : Pat<(int_x86_sse2_cvtpd2dq (memopv2f64 addr:$src)),
1868 (CVTPD2DQrm addr:$src)>;
1871 // Convert with truncation packed single/double fp to doubleword
1872 // SSE2 packed instructions with XS prefix
1873 def VCVTTPS2DQrr : VSSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1874 "cvttps2dq\t{$src, $dst|$dst, $src}",
1876 (int_x86_sse2_cvttps2dq VR128:$src))],
1877 IIC_SSE_CVT_PS_RR>, VEX;
1878 def VCVTTPS2DQrm : VSSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1879 "cvttps2dq\t{$src, $dst|$dst, $src}",
1880 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1881 (memopv4f32 addr:$src)))],
1882 IIC_SSE_CVT_PS_RM>, VEX;
1883 def VCVTTPS2DQYrr : VSSI<0x5B, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
1884 "cvttps2dq\t{$src, $dst|$dst, $src}",
1886 (int_x86_avx_cvtt_ps2dq_256 VR256:$src))],
1887 IIC_SSE_CVT_PS_RR>, VEX;
1888 def VCVTTPS2DQYrm : VSSI<0x5B, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
1889 "cvttps2dq\t{$src, $dst|$dst, $src}",
1890 [(set VR256:$dst, (int_x86_avx_cvtt_ps2dq_256
1891 (memopv8f32 addr:$src)))],
1892 IIC_SSE_CVT_PS_RM>, VEX;
1894 def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1895 "cvttps2dq\t{$src, $dst|$dst, $src}",
1897 (int_x86_sse2_cvttps2dq VR128:$src))],
1899 def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1900 "cvttps2dq\t{$src, $dst|$dst, $src}",
1902 (int_x86_sse2_cvttps2dq (memopv4f32 addr:$src)))],
1905 let Predicates = [HasAVX] in {
1906 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
1907 (VCVTDQ2PSrr VR128:$src)>;
1908 def : Pat<(v4f32 (sint_to_fp (bc_v4i32 (memopv2i64 addr:$src)))),
1909 (VCVTDQ2PSrm addr:$src)>;
1911 def : Pat<(int_x86_sse2_cvtdq2ps VR128:$src),
1912 (VCVTDQ2PSrr VR128:$src)>;
1913 def : Pat<(int_x86_sse2_cvtdq2ps (bc_v4i32 (memopv2i64 addr:$src))),
1914 (VCVTDQ2PSrm addr:$src)>;
1916 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
1917 (VCVTTPS2DQrr VR128:$src)>;
1918 def : Pat<(v4i32 (fp_to_sint (memopv4f32 addr:$src))),
1919 (VCVTTPS2DQrm addr:$src)>;
1921 def : Pat<(v8f32 (sint_to_fp (v8i32 VR256:$src))),
1922 (VCVTDQ2PSYrr VR256:$src)>;
1923 def : Pat<(v8f32 (sint_to_fp (bc_v8i32 (memopv4i64 addr:$src)))),
1924 (VCVTDQ2PSYrm addr:$src)>;
1926 def : Pat<(v8i32 (fp_to_sint (v8f32 VR256:$src))),
1927 (VCVTTPS2DQYrr VR256:$src)>;
1928 def : Pat<(v8i32 (fp_to_sint (memopv8f32 addr:$src))),
1929 (VCVTTPS2DQYrm addr:$src)>;
1932 let Predicates = [HasSSE2] in {
1933 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
1934 (CVTDQ2PSrr VR128:$src)>;
1935 def : Pat<(v4f32 (sint_to_fp (bc_v4i32 (memopv2i64 addr:$src)))),
1936 (CVTDQ2PSrm addr:$src)>;
1938 def : Pat<(int_x86_sse2_cvtdq2ps VR128:$src),
1939 (CVTDQ2PSrr VR128:$src)>;
1940 def : Pat<(int_x86_sse2_cvtdq2ps (bc_v4i32 (memopv2i64 addr:$src))),
1941 (CVTDQ2PSrm addr:$src)>;
1943 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
1944 (CVTTPS2DQrr VR128:$src)>;
1945 def : Pat<(v4i32 (fp_to_sint (memopv4f32 addr:$src))),
1946 (CVTTPS2DQrm addr:$src)>;
1949 def VCVTTPD2DQrr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1950 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1952 (int_x86_sse2_cvttpd2dq VR128:$src))],
1953 IIC_SSE_CVT_PD_RR>, VEX;
1955 def CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1956 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1957 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))],
1959 def CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
1960 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1961 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1962 (memopv2f64 addr:$src)))],
1965 // The assembler can recognize rr 256-bit instructions by seeing a ymm
1966 // register, but the same isn't true when using memory operands instead.
1967 // Provide other assembly rr and rm forms to address this explicitly.
1970 def : InstAlias<"vcvttpd2dqx\t{$src, $dst|$dst, $src}",
1971 (VCVTTPD2DQrr VR128:$dst, VR128:$src)>;
1972 def VCVTTPD2DQXrm : VPDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1973 "cvttpd2dqx\t{$src, $dst|$dst, $src}",
1974 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1975 (memopv2f64 addr:$src)))],
1976 IIC_SSE_CVT_PD_RM>, VEX;
1979 def VCVTTPD2DQYrr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
1980 "cvttpd2dq{y}\t{$src, $dst|$dst, $src}", [],
1981 IIC_SSE_CVT_PD_RR>, VEX;
1982 def VCVTTPD2DQYrm : VPDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
1983 "cvttpd2dq{y}\t{$src, $dst|$dst, $src}", [],
1984 IIC_SSE_CVT_PD_RM>, VEX, VEX_L;
1985 def : InstAlias<"vcvttpd2dq\t{$src, $dst|$dst, $src}",
1986 (VCVTTPD2DQYrr VR128:$dst, VR256:$src)>;
1988 let Predicates = [HasAVX] in {
1989 def : Pat<(v4i32 (fp_to_sint (v4f64 VR256:$src))),
1990 (VCVTTPD2DQYrr VR256:$src)>;
1991 def : Pat<(v4i32 (fp_to_sint (memopv4f64 addr:$src))),
1992 (VCVTTPD2DQYrm addr:$src)>;
1993 } // Predicates = [HasAVX]
1995 // Convert packed single to packed double
1996 let Predicates = [HasAVX] in {
1997 // SSE2 instructions without OpSize prefix
1998 def VCVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1999 "vcvtps2pd\t{$src, $dst|$dst, $src}", [],
2000 IIC_SSE_CVT_PD_RR>, TB, VEX;
2001 def VCVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2002 "vcvtps2pd\t{$src, $dst|$dst, $src}", [],
2003 IIC_SSE_CVT_PD_RM>, TB, VEX;
2004 def VCVTPS2PDYrr : I<0x5A, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
2005 "vcvtps2pd\t{$src, $dst|$dst, $src}", [],
2006 IIC_SSE_CVT_PD_RR>, TB, VEX;
2007 def VCVTPS2PDYrm : I<0x5A, MRMSrcMem, (outs VR256:$dst), (ins f128mem:$src),
2008 "vcvtps2pd\t{$src, $dst|$dst, $src}", [],
2009 IIC_SSE_CVT_PD_RM>, TB, VEX;
2012 let Predicates = [HasSSE2] in {
2013 def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2014 "cvtps2pd\t{$src, $dst|$dst, $src}", [],
2015 IIC_SSE_CVT_PD_RR>, TB;
2016 def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2017 "cvtps2pd\t{$src, $dst|$dst, $src}", [],
2018 IIC_SSE_CVT_PD_RM>, TB;
2021 let Predicates = [HasAVX] in {
2022 def : Pat<(int_x86_sse2_cvtps2pd VR128:$src),
2023 (VCVTPS2PDrr VR128:$src)>;
2026 let Predicates = [HasSSE2] in {
2027 def : Pat<(int_x86_sse2_cvtps2pd VR128:$src),
2028 (CVTPS2PDrr VR128:$src)>;
2031 // Convert Packed DW Integers to Packed Double FP
2032 let Predicates = [HasAVX] in {
2033 def VCVTDQ2PDrm : SSDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2034 "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
2035 def VCVTDQ2PDrr : SSDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2036 "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
2037 def VCVTDQ2PDYrm : SSDI<0xE6, MRMSrcMem, (outs VR256:$dst), (ins i128mem:$src),
2038 "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
2039 def VCVTDQ2PDYrr : SSDI<0xE6, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
2040 "vcvtdq2pd\t{$src, $dst|$dst, $src}", []>, VEX;
2043 def CVTDQ2PDrm : SSDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2044 "cvtdq2pd\t{$src, $dst|$dst, $src}", [],
2046 def CVTDQ2PDrr : SSDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2047 "cvtdq2pd\t{$src, $dst|$dst, $src}", [],
2050 // 128 bit register conversion intrinsics
2051 let Predicates = [HasAVX] in
2052 def : Pat<(int_x86_sse2_cvtdq2pd VR128:$src),
2053 (VCVTDQ2PDrr VR128:$src)>;
2055 let Predicates = [HasSSE2] in
2056 def : Pat<(int_x86_sse2_cvtdq2pd VR128:$src),
2057 (CVTDQ2PDrr VR128:$src)>;
2059 // AVX 256-bit register conversion intrinsics
2060 let Predicates = [HasAVX] in {
2061 def : Pat<(int_x86_avx_cvtdq2_pd_256 VR128:$src),
2062 (VCVTDQ2PDYrr VR128:$src)>;
2063 def : Pat<(int_x86_avx_cvtdq2_pd_256 (bitconvert (memopv2i64 addr:$src))),
2064 (VCVTDQ2PDYrm addr:$src)>;
2066 def : Pat<(int_x86_avx_cvt_pd2dq_256 VR256:$src),
2067 (VCVTPD2DQYrr VR256:$src)>;
2068 def : Pat<(int_x86_avx_cvt_pd2dq_256 (memopv4f64 addr:$src)),
2069 (VCVTPD2DQYrm addr:$src)>;
2071 def : Pat<(v4f64 (sint_to_fp (v4i32 VR128:$src))),
2072 (VCVTDQ2PDYrr VR128:$src)>;
2073 def : Pat<(v4f64 (sint_to_fp (bc_v4i32 (memopv2i64 addr:$src)))),
2074 (VCVTDQ2PDYrm addr:$src)>;
2075 } // Predicates = [HasAVX]
2077 // Convert packed double to packed single
2078 // The assembler can recognize rr 256-bit instructions by seeing a ymm
2079 // register, but the same isn't true when using memory operands instead.
2080 // Provide other assembly rr and rm forms to address this explicitly.
2081 def VCVTPD2PSrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2082 "cvtpd2ps\t{$src, $dst|$dst, $src}", [],
2083 IIC_SSE_CVT_PD_RR>, VEX;
2086 def : InstAlias<"vcvtpd2psx\t{$src, $dst|$dst, $src}",
2087 (VCVTPD2PSrr VR128:$dst, VR128:$src)>;
2088 def VCVTPD2PSXrm : VPDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2089 "cvtpd2psx\t{$src, $dst|$dst, $src}", [],
2090 IIC_SSE_CVT_PD_RM>, VEX;
2093 def VCVTPD2PSYrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
2094 "cvtpd2ps{y}\t{$src, $dst|$dst, $src}", [],
2095 IIC_SSE_CVT_PD_RR>, VEX;
2096 def VCVTPD2PSYrm : VPDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
2097 "cvtpd2ps{y}\t{$src, $dst|$dst, $src}", [],
2098 IIC_SSE_CVT_PD_RM>, VEX, VEX_L;
2099 def : InstAlias<"vcvtpd2ps\t{$src, $dst|$dst, $src}",
2100 (VCVTPD2PSYrr VR128:$dst, VR256:$src)>;
2102 def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2103 "cvtpd2ps\t{$src, $dst|$dst, $src}", [],
2105 def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2106 "cvtpd2ps\t{$src, $dst|$dst, $src}", [],
2110 let Predicates = [HasAVX] in {
2111 def : Pat<(int_x86_sse2_cvtpd2ps VR128:$src),
2112 (VCVTPD2PSrr VR128:$src)>;
2113 def : Pat<(int_x86_sse2_cvtpd2ps (memopv2f64 addr:$src)),
2114 (VCVTPD2PSXrm addr:$src)>;
2117 let Predicates = [HasSSE2] in {
2118 def : Pat<(int_x86_sse2_cvtpd2ps VR128:$src),
2119 (CVTPD2PSrr VR128:$src)>;
2120 def : Pat<(int_x86_sse2_cvtpd2ps (memopv2f64 addr:$src)),
2121 (CVTPD2PSrm addr:$src)>;
2124 // AVX 256-bit register conversion intrinsics
2125 // FIXME: Migrate SSE conversion intrinsics matching to use patterns as below
2126 // whenever possible to avoid declaring two versions of each one.
2127 let Predicates = [HasAVX] in {
2128 def : Pat<(int_x86_avx_cvtdq2_ps_256 VR256:$src),
2129 (VCVTDQ2PSYrr VR256:$src)>;
2130 def : Pat<(int_x86_avx_cvtdq2_ps_256 (bitconvert (memopv4i64 addr:$src))),
2131 (VCVTDQ2PSYrm addr:$src)>;
2133 def : Pat<(int_x86_avx_cvt_pd2_ps_256 VR256:$src),
2134 (VCVTPD2PSYrr VR256:$src)>;
2135 def : Pat<(int_x86_avx_cvt_pd2_ps_256 (memopv4f64 addr:$src)),
2136 (VCVTPD2PSYrm addr:$src)>;
2138 def : Pat<(int_x86_avx_cvt_ps2dq_256 VR256:$src),
2139 (VCVTPS2DQYrr VR256:$src)>;
2140 def : Pat<(int_x86_avx_cvt_ps2dq_256 (memopv8f32 addr:$src)),
2141 (VCVTPS2DQYrm addr:$src)>;
2143 def : Pat<(int_x86_avx_cvt_ps2_pd_256 VR128:$src),
2144 (VCVTPS2PDYrr VR128:$src)>;
2145 def : Pat<(int_x86_avx_cvt_ps2_pd_256 (memopv4f32 addr:$src)),
2146 (VCVTPS2PDYrm addr:$src)>;
2148 def : Pat<(int_x86_avx_cvtt_pd2dq_256 VR256:$src),
2149 (VCVTTPD2DQYrr VR256:$src)>;
2150 def : Pat<(int_x86_avx_cvtt_pd2dq_256 (memopv4f64 addr:$src)),
2151 (VCVTTPD2DQYrm addr:$src)>;
2153 // Match fround and fextend for 128/256-bit conversions
2154 def : Pat<(v4f32 (fround (v4f64 VR256:$src))),
2155 (VCVTPD2PSYrr VR256:$src)>;
2156 def : Pat<(v4f32 (fround (loadv4f64 addr:$src))),
2157 (VCVTPD2PSYrm addr:$src)>;
2159 def : Pat<(v4f64 (fextend (v4f32 VR128:$src))),
2160 (VCVTPS2PDYrr VR128:$src)>;
2161 def : Pat<(v4f64 (fextend (loadv4f32 addr:$src))),
2162 (VCVTPS2PDYrm addr:$src)>;
2165 //===----------------------------------------------------------------------===//
2166 // SSE 1 & 2 - Compare Instructions
2167 //===----------------------------------------------------------------------===//
2169 // sse12_cmp_scalar - sse 1 & 2 compare scalar instructions
2170 multiclass sse12_cmp_scalar<RegisterClass RC, X86MemOperand x86memop,
2171 Operand CC, SDNode OpNode, ValueType VT,
2172 PatFrag ld_frag, string asm, string asm_alt,
2174 def rr : SIi8<0xC2, MRMSrcReg,
2175 (outs RC:$dst), (ins RC:$src1, RC:$src2, CC:$cc), asm,
2176 [(set RC:$dst, (OpNode (VT RC:$src1), RC:$src2, imm:$cc))],
2178 def rm : SIi8<0xC2, MRMSrcMem,
2179 (outs RC:$dst), (ins RC:$src1, x86memop:$src2, CC:$cc), asm,
2180 [(set RC:$dst, (OpNode (VT RC:$src1),
2181 (ld_frag addr:$src2), imm:$cc))],
2184 // Accept explicit immediate argument form instead of comparison code.
2185 let neverHasSideEffects = 1 in {
2186 def rr_alt : SIi8<0xC2, MRMSrcReg, (outs RC:$dst),
2187 (ins RC:$src1, RC:$src2, i8imm:$cc), asm_alt, [],
2188 IIC_SSE_ALU_F32S_RR>;
2190 def rm_alt : SIi8<0xC2, MRMSrcMem, (outs RC:$dst),
2191 (ins RC:$src1, x86memop:$src2, i8imm:$cc), asm_alt, [],
2192 IIC_SSE_ALU_F32S_RM>;
2196 defm VCMPSS : sse12_cmp_scalar<FR32, f32mem, AVXCC, X86cmpss, f32, loadf32,
2197 "cmp${cc}ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2198 "cmpss\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2200 XS, VEX_4V, VEX_LIG;
2201 defm VCMPSD : sse12_cmp_scalar<FR64, f64mem, AVXCC, X86cmpsd, f64, loadf64,
2202 "cmp${cc}sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2203 "cmpsd\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2204 SSE_ALU_F32S>, // same latency as 32 bit compare
2205 XD, VEX_4V, VEX_LIG;
2207 let Constraints = "$src1 = $dst" in {
2208 defm CMPSS : sse12_cmp_scalar<FR32, f32mem, SSECC, X86cmpss, f32, loadf32,
2209 "cmp${cc}ss\t{$src2, $dst|$dst, $src2}",
2210 "cmpss\t{$cc, $src2, $dst|$dst, $src2, $cc}", SSE_ALU_F32S>,
2212 defm CMPSD : sse12_cmp_scalar<FR64, f64mem, SSECC, X86cmpsd, f64, loadf64,
2213 "cmp${cc}sd\t{$src2, $dst|$dst, $src2}",
2214 "cmpsd\t{$cc, $src2, $dst|$dst, $src2, $cc}",
2215 SSE_ALU_F32S>, // same latency as 32 bit compare
2219 multiclass sse12_cmp_scalar_int<X86MemOperand x86memop, Operand CC,
2220 Intrinsic Int, string asm, OpndItins itins> {
2221 def rr : SIi8<0xC2, MRMSrcReg, (outs VR128:$dst),
2222 (ins VR128:$src1, VR128:$src, CC:$cc), asm,
2223 [(set VR128:$dst, (Int VR128:$src1,
2224 VR128:$src, imm:$cc))],
2226 def rm : SIi8<0xC2, MRMSrcMem, (outs VR128:$dst),
2227 (ins VR128:$src1, x86memop:$src, CC:$cc), asm,
2228 [(set VR128:$dst, (Int VR128:$src1,
2229 (load addr:$src), imm:$cc))],
2233 // Aliases to match intrinsics which expect XMM operand(s).
2234 defm Int_VCMPSS : sse12_cmp_scalar_int<f32mem, AVXCC, int_x86_sse_cmp_ss,
2235 "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}",
2238 defm Int_VCMPSD : sse12_cmp_scalar_int<f64mem, AVXCC, int_x86_sse2_cmp_sd,
2239 "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}",
2240 SSE_ALU_F32S>, // same latency as f32
2242 let Constraints = "$src1 = $dst" in {
2243 defm Int_CMPSS : sse12_cmp_scalar_int<f32mem, SSECC, int_x86_sse_cmp_ss,
2244 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
2246 defm Int_CMPSD : sse12_cmp_scalar_int<f64mem, SSECC, int_x86_sse2_cmp_sd,
2247 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
2248 SSE_ALU_F32S>, // same latency as f32
2253 // sse12_ord_cmp - Unordered/Ordered scalar fp compare and set EFLAGS
2254 multiclass sse12_ord_cmp<bits<8> opc, RegisterClass RC, SDNode OpNode,
2255 ValueType vt, X86MemOperand x86memop,
2256 PatFrag ld_frag, string OpcodeStr, Domain d> {
2257 def rr: PI<opc, MRMSrcReg, (outs), (ins RC:$src1, RC:$src2),
2258 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
2259 [(set EFLAGS, (OpNode (vt RC:$src1), RC:$src2))],
2260 IIC_SSE_COMIS_RR, d>;
2261 def rm: PI<opc, MRMSrcMem, (outs), (ins RC:$src1, x86memop:$src2),
2262 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
2263 [(set EFLAGS, (OpNode (vt RC:$src1),
2264 (ld_frag addr:$src2)))],
2265 IIC_SSE_COMIS_RM, d>;
2268 let Defs = [EFLAGS] in {
2269 defm VUCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
2270 "ucomiss", SSEPackedSingle>, TB, VEX, VEX_LIG;
2271 defm VUCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
2272 "ucomisd", SSEPackedDouble>, TB, OpSize, VEX,
2274 let Pattern = []<dag> in {
2275 defm VCOMISS : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
2276 "comiss", SSEPackedSingle>, TB, VEX,
2278 defm VCOMISD : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
2279 "comisd", SSEPackedDouble>, TB, OpSize, VEX,
2283 defm Int_VUCOMISS : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
2284 load, "ucomiss", SSEPackedSingle>, TB, VEX;
2285 defm Int_VUCOMISD : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
2286 load, "ucomisd", SSEPackedDouble>, TB, OpSize, VEX;
2288 defm Int_VCOMISS : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem,
2289 load, "comiss", SSEPackedSingle>, TB, VEX;
2290 defm Int_VCOMISD : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem,
2291 load, "comisd", SSEPackedDouble>, TB, OpSize, VEX;
2292 defm UCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
2293 "ucomiss", SSEPackedSingle>, TB;
2294 defm UCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
2295 "ucomisd", SSEPackedDouble>, TB, OpSize;
2297 let Pattern = []<dag> in {
2298 defm COMISS : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
2299 "comiss", SSEPackedSingle>, TB;
2300 defm COMISD : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
2301 "comisd", SSEPackedDouble>, TB, OpSize;
2304 defm Int_UCOMISS : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
2305 load, "ucomiss", SSEPackedSingle>, TB;
2306 defm Int_UCOMISD : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
2307 load, "ucomisd", SSEPackedDouble>, TB, OpSize;
2309 defm Int_COMISS : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem, load,
2310 "comiss", SSEPackedSingle>, TB;
2311 defm Int_COMISD : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem, load,
2312 "comisd", SSEPackedDouble>, TB, OpSize;
2313 } // Defs = [EFLAGS]
2315 // sse12_cmp_packed - sse 1 & 2 compare packed instructions
2316 multiclass sse12_cmp_packed<RegisterClass RC, X86MemOperand x86memop,
2317 Operand CC, Intrinsic Int, string asm,
2318 string asm_alt, Domain d> {
2319 def rri : PIi8<0xC2, MRMSrcReg,
2320 (outs RC:$dst), (ins RC:$src1, RC:$src2, CC:$cc), asm,
2321 [(set RC:$dst, (Int RC:$src1, RC:$src2, imm:$cc))],
2322 IIC_SSE_CMPP_RR, d>;
2323 def rmi : PIi8<0xC2, MRMSrcMem,
2324 (outs RC:$dst), (ins RC:$src1, x86memop:$src2, CC:$cc), asm,
2325 [(set RC:$dst, (Int RC:$src1, (memop addr:$src2), imm:$cc))],
2326 IIC_SSE_CMPP_RM, d>;
2328 // Accept explicit immediate argument form instead of comparison code.
2329 let neverHasSideEffects = 1 in {
2330 def rri_alt : PIi8<0xC2, MRMSrcReg,
2331 (outs RC:$dst), (ins RC:$src1, RC:$src2, i8imm:$cc),
2332 asm_alt, [], IIC_SSE_CMPP_RR, d>;
2333 def rmi_alt : PIi8<0xC2, MRMSrcMem,
2334 (outs RC:$dst), (ins RC:$src1, x86memop:$src2, i8imm:$cc),
2335 asm_alt, [], IIC_SSE_CMPP_RM, d>;
2339 defm VCMPPS : sse12_cmp_packed<VR128, f128mem, AVXCC, int_x86_sse_cmp_ps,
2340 "cmp${cc}ps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2341 "cmpps\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2342 SSEPackedSingle>, TB, VEX_4V;
2343 defm VCMPPD : sse12_cmp_packed<VR128, f128mem, AVXCC, int_x86_sse2_cmp_pd,
2344 "cmp${cc}pd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2345 "cmppd\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2346 SSEPackedDouble>, TB, OpSize, VEX_4V;
2347 defm VCMPPSY : sse12_cmp_packed<VR256, f256mem, AVXCC, int_x86_avx_cmp_ps_256,
2348 "cmp${cc}ps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2349 "cmpps\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2350 SSEPackedSingle>, TB, VEX_4V;
2351 defm VCMPPDY : sse12_cmp_packed<VR256, f256mem, AVXCC, int_x86_avx_cmp_pd_256,
2352 "cmp${cc}pd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2353 "cmppd\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2354 SSEPackedDouble>, TB, OpSize, VEX_4V;
2355 let Constraints = "$src1 = $dst" in {
2356 defm CMPPS : sse12_cmp_packed<VR128, f128mem, SSECC, int_x86_sse_cmp_ps,
2357 "cmp${cc}ps\t{$src2, $dst|$dst, $src2}",
2358 "cmpps\t{$cc, $src2, $dst|$dst, $src2, $cc}",
2359 SSEPackedSingle>, TB;
2360 defm CMPPD : sse12_cmp_packed<VR128, f128mem, SSECC, int_x86_sse2_cmp_pd,
2361 "cmp${cc}pd\t{$src2, $dst|$dst, $src2}",
2362 "cmppd\t{$cc, $src2, $dst|$dst, $src2, $cc}",
2363 SSEPackedDouble>, TB, OpSize;
2366 let Predicates = [HasAVX] in {
2367 def : Pat<(v4i32 (X86cmpp (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
2368 (VCMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
2369 def : Pat<(v4i32 (X86cmpp (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
2370 (VCMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
2371 def : Pat<(v2i64 (X86cmpp (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
2372 (VCMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
2373 def : Pat<(v2i64 (X86cmpp (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
2374 (VCMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
2376 def : Pat<(v8i32 (X86cmpp (v8f32 VR256:$src1), VR256:$src2, imm:$cc)),
2377 (VCMPPSYrri (v8f32 VR256:$src1), (v8f32 VR256:$src2), imm:$cc)>;
2378 def : Pat<(v8i32 (X86cmpp (v8f32 VR256:$src1), (memop addr:$src2), imm:$cc)),
2379 (VCMPPSYrmi (v8f32 VR256:$src1), addr:$src2, imm:$cc)>;
2380 def : Pat<(v4i64 (X86cmpp (v4f64 VR256:$src1), VR256:$src2, imm:$cc)),
2381 (VCMPPDYrri VR256:$src1, VR256:$src2, imm:$cc)>;
2382 def : Pat<(v4i64 (X86cmpp (v4f64 VR256:$src1), (memop addr:$src2), imm:$cc)),
2383 (VCMPPDYrmi VR256:$src1, addr:$src2, imm:$cc)>;
2386 let Predicates = [HasSSE1] in {
2387 def : Pat<(v4i32 (X86cmpp (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
2388 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
2389 def : Pat<(v4i32 (X86cmpp (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
2390 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
2393 let Predicates = [HasSSE2] in {
2394 def : Pat<(v2i64 (X86cmpp (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
2395 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
2396 def : Pat<(v2i64 (X86cmpp (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
2397 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
2400 //===----------------------------------------------------------------------===//
2401 // SSE 1 & 2 - Shuffle Instructions
2402 //===----------------------------------------------------------------------===//
2404 /// sse12_shuffle - sse 1 & 2 shuffle instructions
2405 multiclass sse12_shuffle<RegisterClass RC, X86MemOperand x86memop,
2406 ValueType vt, string asm, PatFrag mem_frag,
2407 Domain d, bit IsConvertibleToThreeAddress = 0> {
2408 def rmi : PIi8<0xC6, MRMSrcMem, (outs RC:$dst),
2409 (ins RC:$src1, x86memop:$src2, i8imm:$src3), asm,
2410 [(set RC:$dst, (vt (X86Shufp RC:$src1, (mem_frag addr:$src2),
2411 (i8 imm:$src3))))], IIC_SSE_SHUFP, d>;
2412 let isConvertibleToThreeAddress = IsConvertibleToThreeAddress in
2413 def rri : PIi8<0xC6, MRMSrcReg, (outs RC:$dst),
2414 (ins RC:$src1, RC:$src2, i8imm:$src3), asm,
2415 [(set RC:$dst, (vt (X86Shufp RC:$src1, RC:$src2,
2416 (i8 imm:$src3))))], IIC_SSE_SHUFP, d>;
2419 defm VSHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
2420 "shufps\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
2421 memopv4f32, SSEPackedSingle>, TB, VEX_4V;
2422 defm VSHUFPSY : sse12_shuffle<VR256, f256mem, v8f32,
2423 "shufps\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
2424 memopv8f32, SSEPackedSingle>, TB, VEX_4V;
2425 defm VSHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
2426 "shufpd\t{$src3, $src2, $src1, $dst|$dst, $src2, $src2, $src3}",
2427 memopv2f64, SSEPackedDouble>, TB, OpSize, VEX_4V;
2428 defm VSHUFPDY : sse12_shuffle<VR256, f256mem, v4f64,
2429 "shufpd\t{$src3, $src2, $src1, $dst|$dst, $src2, $src2, $src3}",
2430 memopv4f64, SSEPackedDouble>, TB, OpSize, VEX_4V;
2432 let Constraints = "$src1 = $dst" in {
2433 defm SHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
2434 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2435 memopv4f32, SSEPackedSingle, 1 /* cvt to pshufd */>,
2437 defm SHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
2438 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2439 memopv2f64, SSEPackedDouble, 1 /* cvt to pshufd */>,
2443 let Predicates = [HasAVX] in {
2444 def : Pat<(v4i32 (X86Shufp VR128:$src1,
2445 (bc_v4i32 (memopv2i64 addr:$src2)), (i8 imm:$imm))),
2446 (VSHUFPSrmi VR128:$src1, addr:$src2, imm:$imm)>;
2447 def : Pat<(v4i32 (X86Shufp VR128:$src1, VR128:$src2, (i8 imm:$imm))),
2448 (VSHUFPSrri VR128:$src1, VR128:$src2, imm:$imm)>;
2450 def : Pat<(v2i64 (X86Shufp VR128:$src1,
2451 (memopv2i64 addr:$src2), (i8 imm:$imm))),
2452 (VSHUFPDrmi VR128:$src1, addr:$src2, imm:$imm)>;
2453 def : Pat<(v2i64 (X86Shufp VR128:$src1, VR128:$src2, (i8 imm:$imm))),
2454 (VSHUFPDrri VR128:$src1, VR128:$src2, imm:$imm)>;
2457 def : Pat<(v8i32 (X86Shufp VR256:$src1, VR256:$src2, (i8 imm:$imm))),
2458 (VSHUFPSYrri VR256:$src1, VR256:$src2, imm:$imm)>;
2459 def : Pat<(v8i32 (X86Shufp VR256:$src1,
2460 (bc_v8i32 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
2461 (VSHUFPSYrmi VR256:$src1, addr:$src2, imm:$imm)>;
2463 def : Pat<(v4i64 (X86Shufp VR256:$src1, VR256:$src2, (i8 imm:$imm))),
2464 (VSHUFPDYrri VR256:$src1, VR256:$src2, imm:$imm)>;
2465 def : Pat<(v4i64 (X86Shufp VR256:$src1,
2466 (memopv4i64 addr:$src2), (i8 imm:$imm))),
2467 (VSHUFPDYrmi VR256:$src1, addr:$src2, imm:$imm)>;
2470 let Predicates = [HasSSE1] in {
2471 def : Pat<(v4i32 (X86Shufp VR128:$src1,
2472 (bc_v4i32 (memopv2i64 addr:$src2)), (i8 imm:$imm))),
2473 (SHUFPSrmi VR128:$src1, addr:$src2, imm:$imm)>;
2474 def : Pat<(v4i32 (X86Shufp VR128:$src1, VR128:$src2, (i8 imm:$imm))),
2475 (SHUFPSrri VR128:$src1, VR128:$src2, imm:$imm)>;
2478 let Predicates = [HasSSE2] in {
2479 // Generic SHUFPD patterns
2480 def : Pat<(v2i64 (X86Shufp VR128:$src1,
2481 (memopv2i64 addr:$src2), (i8 imm:$imm))),
2482 (SHUFPDrmi VR128:$src1, addr:$src2, imm:$imm)>;
2483 def : Pat<(v2i64 (X86Shufp VR128:$src1, VR128:$src2, (i8 imm:$imm))),
2484 (SHUFPDrri VR128:$src1, VR128:$src2, imm:$imm)>;
2487 //===----------------------------------------------------------------------===//
2488 // SSE 1 & 2 - Unpack Instructions
2489 //===----------------------------------------------------------------------===//
2491 /// sse12_unpack_interleave - sse 1 & 2 unpack and interleave
2492 multiclass sse12_unpack_interleave<bits<8> opc, SDNode OpNode, ValueType vt,
2493 PatFrag mem_frag, RegisterClass RC,
2494 X86MemOperand x86memop, string asm,
2496 def rr : PI<opc, MRMSrcReg,
2497 (outs RC:$dst), (ins RC:$src1, RC:$src2),
2499 (vt (OpNode RC:$src1, RC:$src2)))],
2501 def rm : PI<opc, MRMSrcMem,
2502 (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
2504 (vt (OpNode RC:$src1,
2505 (mem_frag addr:$src2))))],
2509 defm VUNPCKHPS: sse12_unpack_interleave<0x15, X86Unpckh, v4f32, memopv4f32,
2510 VR128, f128mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2511 SSEPackedSingle>, TB, VEX_4V;
2512 defm VUNPCKHPD: sse12_unpack_interleave<0x15, X86Unpckh, v2f64, memopv2f64,
2513 VR128, f128mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2514 SSEPackedDouble>, TB, OpSize, VEX_4V;
2515 defm VUNPCKLPS: sse12_unpack_interleave<0x14, X86Unpckl, v4f32, memopv4f32,
2516 VR128, f128mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2517 SSEPackedSingle>, TB, VEX_4V;
2518 defm VUNPCKLPD: sse12_unpack_interleave<0x14, X86Unpckl, v2f64, memopv2f64,
2519 VR128, f128mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2520 SSEPackedDouble>, TB, OpSize, VEX_4V;
2522 defm VUNPCKHPSY: sse12_unpack_interleave<0x15, X86Unpckh, v8f32, memopv8f32,
2523 VR256, f256mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2524 SSEPackedSingle>, TB, VEX_4V;
2525 defm VUNPCKHPDY: sse12_unpack_interleave<0x15, X86Unpckh, v4f64, memopv4f64,
2526 VR256, f256mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2527 SSEPackedDouble>, TB, OpSize, VEX_4V;
2528 defm VUNPCKLPSY: sse12_unpack_interleave<0x14, X86Unpckl, v8f32, memopv8f32,
2529 VR256, f256mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2530 SSEPackedSingle>, TB, VEX_4V;
2531 defm VUNPCKLPDY: sse12_unpack_interleave<0x14, X86Unpckl, v4f64, memopv4f64,
2532 VR256, f256mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2533 SSEPackedDouble>, TB, OpSize, VEX_4V;
2535 let Constraints = "$src1 = $dst" in {
2536 defm UNPCKHPS: sse12_unpack_interleave<0x15, X86Unpckh, v4f32, memopv4f32,
2537 VR128, f128mem, "unpckhps\t{$src2, $dst|$dst, $src2}",
2538 SSEPackedSingle>, TB;
2539 defm UNPCKHPD: sse12_unpack_interleave<0x15, X86Unpckh, v2f64, memopv2f64,
2540 VR128, f128mem, "unpckhpd\t{$src2, $dst|$dst, $src2}",
2541 SSEPackedDouble>, TB, OpSize;
2542 defm UNPCKLPS: sse12_unpack_interleave<0x14, X86Unpckl, v4f32, memopv4f32,
2543 VR128, f128mem, "unpcklps\t{$src2, $dst|$dst, $src2}",
2544 SSEPackedSingle>, TB;
2545 defm UNPCKLPD: sse12_unpack_interleave<0x14, X86Unpckl, v2f64, memopv2f64,
2546 VR128, f128mem, "unpcklpd\t{$src2, $dst|$dst, $src2}",
2547 SSEPackedDouble>, TB, OpSize;
2548 } // Constraints = "$src1 = $dst"
2550 let Predicates = [HasAVX], AddedComplexity = 1 in {
2551 // FIXME: Instead of X86Movddup, there should be a X86Unpckl here, the
2552 // problem is during lowering, where it's not possible to recognize the load
2553 // fold cause it has two uses through a bitcast. One use disappears at isel
2554 // time and the fold opportunity reappears.
2555 def : Pat<(v2f64 (X86Movddup VR128:$src)),
2556 (VUNPCKLPDrr VR128:$src, VR128:$src)>;
2559 let Predicates = [HasSSE2] in {
2560 // FIXME: Instead of X86Movddup, there should be a X86Unpckl here, the
2561 // problem is during lowering, where it's not possible to recognize the load
2562 // fold cause it has two uses through a bitcast. One use disappears at isel
2563 // time and the fold opportunity reappears.
2564 def : Pat<(v2f64 (X86Movddup VR128:$src)),
2565 (UNPCKLPDrr VR128:$src, VR128:$src)>;
2568 //===----------------------------------------------------------------------===//
2569 // SSE 1 & 2 - Extract Floating-Point Sign mask
2570 //===----------------------------------------------------------------------===//
2572 /// sse12_extr_sign_mask - sse 1 & 2 unpack and interleave
2573 multiclass sse12_extr_sign_mask<RegisterClass RC, Intrinsic Int, string asm,
2575 def rr32 : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins RC:$src),
2576 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
2577 [(set GR32:$dst, (Int RC:$src))], IIC_SSE_MOVMSK, d>;
2578 def rr64 : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins RC:$src),
2579 !strconcat(asm, "\t{$src, $dst|$dst, $src}"), [],
2580 IIC_SSE_MOVMSK, d>, REX_W;
2583 let Predicates = [HasAVX] in {
2584 defm VMOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps,
2585 "movmskps", SSEPackedSingle>, TB, VEX;
2586 defm VMOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd,
2587 "movmskpd", SSEPackedDouble>, TB,
2589 defm VMOVMSKPSY : sse12_extr_sign_mask<VR256, int_x86_avx_movmsk_ps_256,
2590 "movmskps", SSEPackedSingle>, TB, VEX;
2591 defm VMOVMSKPDY : sse12_extr_sign_mask<VR256, int_x86_avx_movmsk_pd_256,
2592 "movmskpd", SSEPackedDouble>, TB,
2595 def : Pat<(i32 (X86fgetsign FR32:$src)),
2596 (VMOVMSKPSrr32 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src,
2598 def : Pat<(i64 (X86fgetsign FR32:$src)),
2599 (VMOVMSKPSrr64 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src,
2601 def : Pat<(i32 (X86fgetsign FR64:$src)),
2602 (VMOVMSKPDrr32 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src,
2604 def : Pat<(i64 (X86fgetsign FR64:$src)),
2605 (VMOVMSKPDrr64 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src,
2609 def VMOVMSKPSr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
2610 "movmskps\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK,
2611 SSEPackedSingle>, TB, VEX;
2612 def VMOVMSKPDr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
2613 "movmskpd\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK,
2614 SSEPackedDouble>, TB,
2616 def VMOVMSKPSYr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR256:$src),
2617 "movmskps\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK,
2618 SSEPackedSingle>, TB, VEX;
2619 def VMOVMSKPDYr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR256:$src),
2620 "movmskpd\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK,
2621 SSEPackedDouble>, TB,
2625 defm MOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps, "movmskps",
2626 SSEPackedSingle>, TB;
2627 defm MOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd, "movmskpd",
2628 SSEPackedDouble>, TB, OpSize;
2630 def : Pat<(i32 (X86fgetsign FR32:$src)),
2631 (MOVMSKPSrr32 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src,
2632 sub_ss))>, Requires<[HasSSE1]>;
2633 def : Pat<(i64 (X86fgetsign FR32:$src)),
2634 (MOVMSKPSrr64 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src,
2635 sub_ss))>, Requires<[HasSSE1]>;
2636 def : Pat<(i32 (X86fgetsign FR64:$src)),
2637 (MOVMSKPDrr32 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src,
2638 sub_sd))>, Requires<[HasSSE2]>;
2639 def : Pat<(i64 (X86fgetsign FR64:$src)),
2640 (MOVMSKPDrr64 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src,
2641 sub_sd))>, Requires<[HasSSE2]>;
2643 //===---------------------------------------------------------------------===//
2644 // SSE2 - Packed Integer Logical Instructions
2645 //===---------------------------------------------------------------------===//
2647 let ExeDomain = SSEPackedInt in { // SSE integer instructions
2649 /// PDI_binop_rm - Simple SSE2 binary operator.
2650 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
2651 ValueType OpVT, RegisterClass RC, PatFrag memop_frag,
2652 X86MemOperand x86memop,
2654 bit IsCommutable = 0,
2656 let isCommutable = IsCommutable in
2657 def rr : PDI<opc, MRMSrcReg, (outs RC:$dst),
2658 (ins RC:$src1, RC:$src2),
2660 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2661 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2662 [(set RC:$dst, (OpVT (OpNode RC:$src1, RC:$src2)))], itins.rr>;
2663 def rm : PDI<opc, MRMSrcMem, (outs RC:$dst),
2664 (ins RC:$src1, x86memop:$src2),
2666 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2667 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2668 [(set RC:$dst, (OpVT (OpNode RC:$src1,
2669 (bitconvert (memop_frag addr:$src2)))))],
2672 } // ExeDomain = SSEPackedInt
2674 // These are ordered here for pattern ordering requirements with the fp versions
2676 let Predicates = [HasAVX] in {
2677 defm VPAND : PDI_binop_rm<0xDB, "vpand", and, v2i64, VR128, memopv2i64,
2678 i128mem, SSE_BIT_ITINS_P, 1, 0>, VEX_4V;
2679 defm VPOR : PDI_binop_rm<0xEB, "vpor" , or, v2i64, VR128, memopv2i64,
2680 i128mem, SSE_BIT_ITINS_P, 1, 0>, VEX_4V;
2681 defm VPXOR : PDI_binop_rm<0xEF, "vpxor", xor, v2i64, VR128, memopv2i64,
2682 i128mem, SSE_BIT_ITINS_P, 1, 0>, VEX_4V;
2683 defm VPANDN : PDI_binop_rm<0xDF, "vpandn", X86andnp, v2i64, VR128, memopv2i64,
2684 i128mem, SSE_BIT_ITINS_P, 0, 0>, VEX_4V;
2687 let Constraints = "$src1 = $dst" in {
2688 defm PAND : PDI_binop_rm<0xDB, "pand", and, v2i64, VR128, memopv2i64,
2689 i128mem, SSE_BIT_ITINS_P, 1>;
2690 defm POR : PDI_binop_rm<0xEB, "por" , or, v2i64, VR128, memopv2i64,
2691 i128mem, SSE_BIT_ITINS_P, 1>;
2692 defm PXOR : PDI_binop_rm<0xEF, "pxor", xor, v2i64, VR128, memopv2i64,
2693 i128mem, SSE_BIT_ITINS_P, 1>;
2694 defm PANDN : PDI_binop_rm<0xDF, "pandn", X86andnp, v2i64, VR128, memopv2i64,
2695 i128mem, SSE_BIT_ITINS_P, 0>;
2696 } // Constraints = "$src1 = $dst"
2698 let Predicates = [HasAVX2] in {
2699 defm VPANDY : PDI_binop_rm<0xDB, "vpand", and, v4i64, VR256, memopv4i64,
2700 i256mem, SSE_BIT_ITINS_P, 1, 0>, VEX_4V;
2701 defm VPORY : PDI_binop_rm<0xEB, "vpor", or, v4i64, VR256, memopv4i64,
2702 i256mem, SSE_BIT_ITINS_P, 1, 0>, VEX_4V;
2703 defm VPXORY : PDI_binop_rm<0xEF, "vpxor", xor, v4i64, VR256, memopv4i64,
2704 i256mem, SSE_BIT_ITINS_P, 1, 0>, VEX_4V;
2705 defm VPANDNY : PDI_binop_rm<0xDF, "vpandn", X86andnp, v4i64, VR256, memopv4i64,
2706 i256mem, SSE_BIT_ITINS_P, 0, 0>, VEX_4V;
2709 //===----------------------------------------------------------------------===//
2710 // SSE 1 & 2 - Logical Instructions
2711 //===----------------------------------------------------------------------===//
2713 /// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
2715 multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
2716 SDNode OpNode, OpndItins itins> {
2717 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode,
2718 FR32, f32, f128mem, memopfsf32, SSEPackedSingle, itins, 0>,
2721 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode,
2722 FR64, f64, f128mem, memopfsf64, SSEPackedDouble, itins, 0>,
2725 let Constraints = "$src1 = $dst" in {
2726 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, FR32,
2727 f32, f128mem, memopfsf32, SSEPackedSingle, itins>,
2730 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, FR64,
2731 f64, f128mem, memopfsf64, SSEPackedDouble, itins>,
2736 // Alias bitwise logical operations using SSE logical ops on packed FP values.
2737 let mayLoad = 0 in {
2738 defm FsAND : sse12_fp_alias_pack_logical<0x54, "and", X86fand,
2740 defm FsOR : sse12_fp_alias_pack_logical<0x56, "or", X86for,
2742 defm FsXOR : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor,
2746 let neverHasSideEffects = 1, Pattern = []<dag>, isCommutable = 0 in
2747 defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef,
2750 /// sse12_fp_packed_logical - SSE 1 & 2 packed FP logical ops
2752 multiclass sse12_fp_packed_logical<bits<8> opc, string OpcodeStr,
2754 // In AVX no need to add a pattern for 128-bit logical rr ps, because they
2755 // are all promoted to v2i64, and the patterns are covered by the int
2756 // version. This is needed in SSE only, because v2i64 isn't supported on
2757 // SSE1, but only on SSE2.
2758 defm V#NAME#PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
2759 !strconcat(OpcodeStr, "ps"), f128mem, [],
2760 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
2761 (memopv2i64 addr:$src2)))], 0, 1>, TB, VEX_4V;
2763 defm V#NAME#PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
2764 !strconcat(OpcodeStr, "pd"), f128mem,
2765 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
2766 (bc_v2i64 (v2f64 VR128:$src2))))],
2767 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
2768 (memopv2i64 addr:$src2)))], 0>,
2770 let Constraints = "$src1 = $dst" in {
2771 defm PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
2772 !strconcat(OpcodeStr, "ps"), f128mem,
2773 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))],
2774 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
2775 (memopv2i64 addr:$src2)))]>, TB;
2777 defm PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
2778 !strconcat(OpcodeStr, "pd"), f128mem,
2779 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
2780 (bc_v2i64 (v2f64 VR128:$src2))))],
2781 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
2782 (memopv2i64 addr:$src2)))]>, TB, OpSize;
2786 /// sse12_fp_packed_logical_y - AVX 256-bit SSE 1 & 2 logical ops forms
2788 multiclass sse12_fp_packed_logical_y<bits<8> opc, string OpcodeStr,
2790 defm PSY : sse12_fp_packed_logical_rm<opc, VR256, SSEPackedSingle,
2791 !strconcat(OpcodeStr, "ps"), f256mem,
2792 [(set VR256:$dst, (v4i64 (OpNode VR256:$src1, VR256:$src2)))],
2793 [(set VR256:$dst, (OpNode (bc_v4i64 (v8f32 VR256:$src1)),
2794 (memopv4i64 addr:$src2)))], 0>, TB, VEX_4V;
2796 defm PDY : sse12_fp_packed_logical_rm<opc, VR256, SSEPackedDouble,
2797 !strconcat(OpcodeStr, "pd"), f256mem,
2798 [(set VR256:$dst, (OpNode (bc_v4i64 (v4f64 VR256:$src1)),
2799 (bc_v4i64 (v4f64 VR256:$src2))))],
2800 [(set VR256:$dst, (OpNode (bc_v4i64 (v4f64 VR256:$src1)),
2801 (memopv4i64 addr:$src2)))], 0>,
2805 // AVX 256-bit packed logical ops forms
2806 defm VAND : sse12_fp_packed_logical_y<0x54, "and", and>;
2807 defm VOR : sse12_fp_packed_logical_y<0x56, "or", or>;
2808 defm VXOR : sse12_fp_packed_logical_y<0x57, "xor", xor>;
2809 defm VANDN : sse12_fp_packed_logical_y<0x55, "andn", X86andnp>;
2811 defm AND : sse12_fp_packed_logical<0x54, "and", and>;
2812 defm OR : sse12_fp_packed_logical<0x56, "or", or>;
2813 defm XOR : sse12_fp_packed_logical<0x57, "xor", xor>;
2814 let isCommutable = 0 in
2815 defm ANDN : sse12_fp_packed_logical<0x55, "andn", X86andnp>;
2817 //===----------------------------------------------------------------------===//
2818 // SSE 1 & 2 - Arithmetic Instructions
2819 //===----------------------------------------------------------------------===//
2821 /// basic_sse12_fp_binop_xxx - SSE 1 & 2 binops come in both scalar and
2824 /// In addition, we also have a special variant of the scalar form here to
2825 /// represent the associated intrinsic operation. This form is unlike the
2826 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
2827 /// and leaves the top elements unmodified (therefore these cannot be commuted).
2829 /// These three forms can each be reg+reg or reg+mem.
2832 /// FIXME: once all 256-bit intrinsics are matched, cleanup and refactor those
2834 multiclass basic_sse12_fp_binop_s<bits<8> opc, string OpcodeStr, SDNode OpNode,
2837 defm SS : sse12_fp_scalar<opc, !strconcat(OpcodeStr, "ss"),
2838 OpNode, FR32, f32mem,
2839 itins.s, Is2Addr>, XS;
2840 defm SD : sse12_fp_scalar<opc, !strconcat(OpcodeStr, "sd"),
2841 OpNode, FR64, f64mem,
2842 itins.d, Is2Addr>, XD;
2845 multiclass basic_sse12_fp_binop_p<bits<8> opc, string OpcodeStr, SDNode OpNode,
2848 let mayLoad = 0 in {
2849 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, VR128,
2850 v4f32, f128mem, memopv4f32, SSEPackedSingle, itins.s, Is2Addr>,
2852 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, VR128,
2853 v2f64, f128mem, memopv2f64, SSEPackedDouble, itins.d, Is2Addr>,
2858 multiclass basic_sse12_fp_binop_p_y<bits<8> opc, string OpcodeStr,
2861 let mayLoad = 0 in {
2862 defm PSY : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, VR256,
2863 v8f32, f256mem, memopv8f32, SSEPackedSingle, itins.s, 0>,
2865 defm PDY : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, VR256,
2866 v4f64, f256mem, memopv4f64, SSEPackedDouble, itins.d, 0>,
2871 multiclass basic_sse12_fp_binop_s_int<bits<8> opc, string OpcodeStr,
2874 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
2875 !strconcat(OpcodeStr, "ss"), "", "_ss", ssmem, sse_load_f32,
2876 itins.s, Is2Addr>, XS;
2877 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
2878 !strconcat(OpcodeStr, "sd"), "2", "_sd", sdmem, sse_load_f64,
2879 itins.d, Is2Addr>, XD;
2882 multiclass basic_sse12_fp_binop_p_int<bits<8> opc, string OpcodeStr,
2885 defm PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
2886 !strconcat(OpcodeStr, "ps"), "sse", "_ps", f128mem, memopv4f32,
2887 SSEPackedSingle, itins.s, Is2Addr>,
2890 defm PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
2891 !strconcat(OpcodeStr, "pd"), "sse2", "_pd", f128mem, memopv2f64,
2892 SSEPackedDouble, itins.d, Is2Addr>,
2896 multiclass basic_sse12_fp_binop_p_y_int<bits<8> opc, string OpcodeStr,
2898 defm PSY : sse12_fp_packed_int<opc, OpcodeStr, VR256,
2899 !strconcat(OpcodeStr, "ps"), "avx", "_ps_256", f256mem, memopv8f32,
2900 SSEPackedSingle, itins.s, 0>, TB;
2902 defm PDY : sse12_fp_packed_int<opc, OpcodeStr, VR256,
2903 !strconcat(OpcodeStr, "pd"), "avx", "_pd_256", f256mem, memopv4f64,
2904 SSEPackedDouble, itins.d, 0>, TB, OpSize;
2907 // Binary Arithmetic instructions
2908 defm VADD : basic_sse12_fp_binop_s<0x58, "add", fadd, SSE_ALU_ITINS_S, 0>,
2909 basic_sse12_fp_binop_s_int<0x58, "add", SSE_ALU_ITINS_S, 0>,
2911 defm VADD : basic_sse12_fp_binop_p<0x58, "add", fadd, SSE_ALU_ITINS_P, 0>,
2912 basic_sse12_fp_binop_p_y<0x58, "add", fadd, SSE_ALU_ITINS_P>,
2914 defm VMUL : basic_sse12_fp_binop_s<0x59, "mul", fmul, SSE_MUL_ITINS_S, 0>,
2915 basic_sse12_fp_binop_s_int<0x59, "mul", SSE_MUL_ITINS_S, 0>,
2917 defm VMUL : basic_sse12_fp_binop_p<0x59, "mul", fmul, SSE_MUL_ITINS_P, 0>,
2918 basic_sse12_fp_binop_p_y<0x59, "mul", fmul, SSE_MUL_ITINS_P>,
2921 let isCommutable = 0 in {
2922 defm VSUB : basic_sse12_fp_binop_s<0x5C, "sub", fsub, SSE_ALU_ITINS_S, 0>,
2923 basic_sse12_fp_binop_s_int<0x5C, "sub", SSE_ALU_ITINS_S, 0>,
2925 defm VSUB : basic_sse12_fp_binop_p<0x5C, "sub", fsub, SSE_ALU_ITINS_P, 0>,
2926 basic_sse12_fp_binop_p_y<0x5C, "sub", fsub, SSE_ALU_ITINS_P>, VEX_4V;
2927 defm VDIV : basic_sse12_fp_binop_s<0x5E, "div", fdiv, SSE_DIV_ITINS_S, 0>,
2928 basic_sse12_fp_binop_s_int<0x5E, "div", SSE_DIV_ITINS_S, 0>,
2930 defm VDIV : basic_sse12_fp_binop_p<0x5E, "div", fdiv, SSE_ALU_ITINS_P, 0>,
2931 basic_sse12_fp_binop_p_y<0x5E, "div", fdiv, SSE_DIV_ITINS_P>,
2933 defm VMAX : basic_sse12_fp_binop_s<0x5F, "max", X86fmax, SSE_ALU_ITINS_S, 0>,
2934 basic_sse12_fp_binop_s_int<0x5F, "max", SSE_ALU_ITINS_S, 0>,
2936 defm VMAX : basic_sse12_fp_binop_p<0x5F, "max", X86fmax, SSE_ALU_ITINS_P, 0>,
2937 basic_sse12_fp_binop_p_int<0x5F, "max", SSE_ALU_ITINS_P, 0>,
2938 basic_sse12_fp_binop_p_y<0x5F, "max", X86fmax, SSE_ALU_ITINS_P>,
2939 basic_sse12_fp_binop_p_y_int<0x5F, "max", SSE_ALU_ITINS_P>,
2941 defm VMIN : basic_sse12_fp_binop_s<0x5D, "min", X86fmin, SSE_ALU_ITINS_S, 0>,
2942 basic_sse12_fp_binop_s_int<0x5D, "min", SSE_ALU_ITINS_S, 0>,
2944 defm VMIN : basic_sse12_fp_binop_p<0x5D, "min", X86fmin, SSE_ALU_ITINS_P, 0>,
2945 basic_sse12_fp_binop_p_int<0x5D, "min", SSE_ALU_ITINS_P, 0>,
2946 basic_sse12_fp_binop_p_y_int<0x5D, "min", SSE_ALU_ITINS_P>,
2947 basic_sse12_fp_binop_p_y<0x5D, "min", X86fmin, SSE_ALU_ITINS_P>,
2951 let Constraints = "$src1 = $dst" in {
2952 defm ADD : basic_sse12_fp_binop_s<0x58, "add", fadd, SSE_ALU_ITINS_S>,
2953 basic_sse12_fp_binop_p<0x58, "add", fadd, SSE_ALU_ITINS_P>,
2954 basic_sse12_fp_binop_s_int<0x58, "add", SSE_ALU_ITINS_S>;
2955 defm MUL : basic_sse12_fp_binop_s<0x59, "mul", fmul, SSE_MUL_ITINS_S>,
2956 basic_sse12_fp_binop_p<0x59, "mul", fmul, SSE_MUL_ITINS_P>,
2957 basic_sse12_fp_binop_s_int<0x59, "mul", SSE_MUL_ITINS_S>;
2959 let isCommutable = 0 in {
2960 defm SUB : basic_sse12_fp_binop_s<0x5C, "sub", fsub, SSE_ALU_ITINS_S>,
2961 basic_sse12_fp_binop_p<0x5C, "sub", fsub, SSE_ALU_ITINS_P>,
2962 basic_sse12_fp_binop_s_int<0x5C, "sub", SSE_ALU_ITINS_S>;
2963 defm DIV : basic_sse12_fp_binop_s<0x5E, "div", fdiv, SSE_DIV_ITINS_S>,
2964 basic_sse12_fp_binop_p<0x5E, "div", fdiv, SSE_DIV_ITINS_P>,
2965 basic_sse12_fp_binop_s_int<0x5E, "div", SSE_DIV_ITINS_S>;
2966 defm MAX : basic_sse12_fp_binop_s<0x5F, "max", X86fmax, SSE_ALU_ITINS_S>,
2967 basic_sse12_fp_binop_p<0x5F, "max", X86fmax, SSE_ALU_ITINS_P>,
2968 basic_sse12_fp_binop_s_int<0x5F, "max", SSE_ALU_ITINS_S>,
2969 basic_sse12_fp_binop_p_int<0x5F, "max", SSE_ALU_ITINS_P>;
2970 defm MIN : basic_sse12_fp_binop_s<0x5D, "min", X86fmin, SSE_ALU_ITINS_S>,
2971 basic_sse12_fp_binop_p<0x5D, "min", X86fmin, SSE_ALU_ITINS_P>,
2972 basic_sse12_fp_binop_s_int<0x5D, "min", SSE_ALU_ITINS_S>,
2973 basic_sse12_fp_binop_p_int<0x5D, "min", SSE_ALU_ITINS_P>;
2978 /// In addition, we also have a special variant of the scalar form here to
2979 /// represent the associated intrinsic operation. This form is unlike the
2980 /// plain scalar form, in that it takes an entire vector (instead of a
2981 /// scalar) and leaves the top elements undefined.
2983 /// And, we have a special variant form for a full-vector intrinsic form.
2985 def SSE_SQRTP : OpndItins<
2986 IIC_SSE_SQRTP_RR, IIC_SSE_SQRTP_RM
2989 def SSE_SQRTS : OpndItins<
2990 IIC_SSE_SQRTS_RR, IIC_SSE_SQRTS_RM
2993 def SSE_RCPP : OpndItins<
2994 IIC_SSE_RCPP_RR, IIC_SSE_RCPP_RM
2997 def SSE_RCPS : OpndItins<
2998 IIC_SSE_RCPS_RR, IIC_SSE_RCPS_RM
3001 /// sse1_fp_unop_s - SSE1 unops in scalar form.
3002 multiclass sse1_fp_unop_s<bits<8> opc, string OpcodeStr,
3003 SDNode OpNode, Intrinsic F32Int, OpndItins itins> {
3004 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
3005 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3006 [(set FR32:$dst, (OpNode FR32:$src))]>;
3007 // For scalar unary operations, fold a load into the operation
3008 // only in OptForSize mode. It eliminates an instruction, but it also
3009 // eliminates a whole-register clobber (the load), so it introduces a
3010 // partial register update condition.
3011 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
3012 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3013 [(set FR32:$dst, (OpNode (load addr:$src)))], itins.rm>, XS,
3014 Requires<[HasSSE1, OptForSize]>;
3015 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3016 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3017 [(set VR128:$dst, (F32Int VR128:$src))], itins.rr>;
3018 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
3019 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3020 [(set VR128:$dst, (F32Int sse_load_f32:$src))], itins.rm>;
3023 /// sse1_fp_unop_s_avx - AVX SSE1 unops in scalar form.
3024 multiclass sse1_fp_unop_s_avx<bits<8> opc, string OpcodeStr> {
3025 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
3026 !strconcat(OpcodeStr,
3027 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
3029 def SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1,f32mem:$src2),
3030 !strconcat(OpcodeStr,
3031 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
3032 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
3033 (ins VR128:$src1, ssmem:$src2),
3034 !strconcat(OpcodeStr,
3035 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
3038 /// sse1_fp_unop_p - SSE1 unops in packed form.
3039 multiclass sse1_fp_unop_p<bits<8> opc, string OpcodeStr, SDNode OpNode,
3041 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3042 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3043 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))], itins.rr>;
3044 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3045 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3046 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))], itins.rm>;
3049 /// sse1_fp_unop_p_y - AVX 256-bit SSE1 unops in packed form.
3050 multiclass sse1_fp_unop_p_y<bits<8> opc, string OpcodeStr, SDNode OpNode,
3052 def PSYr : PSI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3053 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3054 [(set VR256:$dst, (v8f32 (OpNode VR256:$src)))],
3056 def PSYm : PSI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3057 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3058 [(set VR256:$dst, (OpNode (memopv8f32 addr:$src)))],
3062 /// sse1_fp_unop_p_int - SSE1 intrinsics unops in packed forms.
3063 multiclass sse1_fp_unop_p_int<bits<8> opc, string OpcodeStr,
3064 Intrinsic V4F32Int, OpndItins itins> {
3065 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3066 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3067 [(set VR128:$dst, (V4F32Int VR128:$src))],
3069 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3070 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3071 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))],
3075 /// sse1_fp_unop_p_y_int - AVX 256-bit intrinsics unops in packed forms.
3076 multiclass sse1_fp_unop_p_y_int<bits<8> opc, string OpcodeStr,
3077 Intrinsic V4F32Int, OpndItins itins> {
3078 def PSYr_Int : PSI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3079 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3080 [(set VR256:$dst, (V4F32Int VR256:$src))],
3082 def PSYm_Int : PSI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3083 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3084 [(set VR256:$dst, (V4F32Int (memopv8f32 addr:$src)))],
3088 /// sse2_fp_unop_s - SSE2 unops in scalar form.
3089 multiclass sse2_fp_unop_s<bits<8> opc, string OpcodeStr,
3090 SDNode OpNode, Intrinsic F64Int, OpndItins itins> {
3091 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
3092 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
3093 [(set FR64:$dst, (OpNode FR64:$src))], itins.rr>;
3094 // See the comments in sse1_fp_unop_s for why this is OptForSize.
3095 def SDm : I<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
3096 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
3097 [(set FR64:$dst, (OpNode (load addr:$src)))], itins.rm>, XD,
3098 Requires<[HasSSE2, OptForSize]>;
3099 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3100 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
3101 [(set VR128:$dst, (F64Int VR128:$src))], itins.rr>;
3102 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
3103 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
3104 [(set VR128:$dst, (F64Int sse_load_f64:$src))], itins.rm>;
3107 /// sse2_fp_unop_s_avx - AVX SSE2 unops in scalar form.
3108 multiclass sse2_fp_unop_s_avx<bits<8> opc, string OpcodeStr> {
3109 let neverHasSideEffects = 1 in {
3110 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
3111 !strconcat(OpcodeStr,
3112 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
3114 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1,f64mem:$src2),
3115 !strconcat(OpcodeStr,
3116 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
3118 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
3119 (ins VR128:$src1, sdmem:$src2),
3120 !strconcat(OpcodeStr,
3121 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>;
3124 /// sse2_fp_unop_p - SSE2 unops in vector forms.
3125 multiclass sse2_fp_unop_p<bits<8> opc, string OpcodeStr,
3126 SDNode OpNode, OpndItins itins> {
3127 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3128 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3129 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))], itins.rr>;
3130 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3131 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3132 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))], itins.rm>;
3135 /// sse2_fp_unop_p_y - AVX SSE2 256-bit unops in vector forms.
3136 multiclass sse2_fp_unop_p_y<bits<8> opc, string OpcodeStr, SDNode OpNode,
3138 def PDYr : PDI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3139 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3140 [(set VR256:$dst, (v4f64 (OpNode VR256:$src)))],
3142 def PDYm : PDI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3143 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3144 [(set VR256:$dst, (OpNode (memopv4f64 addr:$src)))],
3148 /// sse2_fp_unop_p_int - SSE2 intrinsic unops in vector forms.
3149 multiclass sse2_fp_unop_p_int<bits<8> opc, string OpcodeStr,
3150 Intrinsic V2F64Int, OpndItins itins> {
3151 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3152 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3153 [(set VR128:$dst, (V2F64Int VR128:$src))],
3155 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3156 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3157 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))],
3161 /// sse2_fp_unop_p_y_int - AVX 256-bit intrinsic unops in vector forms.
3162 multiclass sse2_fp_unop_p_y_int<bits<8> opc, string OpcodeStr,
3163 Intrinsic V2F64Int, OpndItins itins> {
3164 def PDYr_Int : PDI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3165 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3166 [(set VR256:$dst, (V2F64Int VR256:$src))],
3168 def PDYm_Int : PDI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3169 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3170 [(set VR256:$dst, (V2F64Int (memopv4f64 addr:$src)))],
3174 let Predicates = [HasAVX] in {
3176 defm VSQRT : sse1_fp_unop_s_avx<0x51, "vsqrt">,
3177 sse2_fp_unop_s_avx<0x51, "vsqrt">, VEX_4V, VEX_LIG;
3179 defm VSQRT : sse1_fp_unop_p<0x51, "vsqrt", fsqrt, SSE_SQRTP>,
3180 sse2_fp_unop_p<0x51, "vsqrt", fsqrt, SSE_SQRTP>,
3181 sse1_fp_unop_p_y<0x51, "vsqrt", fsqrt, SSE_SQRTP>,
3182 sse2_fp_unop_p_y<0x51, "vsqrt", fsqrt, SSE_SQRTP>,
3183 sse1_fp_unop_p_int<0x51, "vsqrt", int_x86_sse_sqrt_ps,
3185 sse2_fp_unop_p_int<0x51, "vsqrt", int_x86_sse2_sqrt_pd,
3187 sse1_fp_unop_p_y_int<0x51, "vsqrt", int_x86_avx_sqrt_ps_256,
3189 sse2_fp_unop_p_y_int<0x51, "vsqrt", int_x86_avx_sqrt_pd_256,
3193 // Reciprocal approximations. Note that these typically require refinement
3194 // in order to obtain suitable precision.
3195 defm VRSQRT : sse1_fp_unop_s_avx<0x52, "vrsqrt">, VEX_4V, VEX_LIG;
3196 defm VRSQRT : sse1_fp_unop_p<0x52, "vrsqrt", X86frsqrt, SSE_SQRTP>,
3197 sse1_fp_unop_p_y<0x52, "vrsqrt", X86frsqrt, SSE_SQRTP>,
3198 sse1_fp_unop_p_y_int<0x52, "vrsqrt", int_x86_avx_rsqrt_ps_256,
3200 sse1_fp_unop_p_int<0x52, "vrsqrt", int_x86_sse_rsqrt_ps,
3203 defm VRCP : sse1_fp_unop_s_avx<0x53, "vrcp">, VEX_4V, VEX_LIG;
3204 defm VRCP : sse1_fp_unop_p<0x53, "vrcp", X86frcp, SSE_RCPP>,
3205 sse1_fp_unop_p_y<0x53, "vrcp", X86frcp, SSE_RCPP>,
3206 sse1_fp_unop_p_y_int<0x53, "vrcp", int_x86_avx_rcp_ps_256,
3208 sse1_fp_unop_p_int<0x53, "vrcp", int_x86_sse_rcp_ps,
3212 let AddedComplexity = 1 in {
3213 def : Pat<(f32 (fsqrt FR32:$src)),
3214 (VSQRTSSr (f32 (IMPLICIT_DEF)), FR32:$src)>, Requires<[HasAVX]>;
3215 def : Pat<(f32 (fsqrt (load addr:$src))),
3216 (VSQRTSSm (f32 (IMPLICIT_DEF)), addr:$src)>,
3217 Requires<[HasAVX, OptForSize]>;
3218 def : Pat<(f64 (fsqrt FR64:$src)),
3219 (VSQRTSDr (f64 (IMPLICIT_DEF)), FR64:$src)>, Requires<[HasAVX]>;
3220 def : Pat<(f64 (fsqrt (load addr:$src))),
3221 (VSQRTSDm (f64 (IMPLICIT_DEF)), addr:$src)>,
3222 Requires<[HasAVX, OptForSize]>;
3224 def : Pat<(f32 (X86frsqrt FR32:$src)),
3225 (VRSQRTSSr (f32 (IMPLICIT_DEF)), FR32:$src)>, Requires<[HasAVX]>;
3226 def : Pat<(f32 (X86frsqrt (load addr:$src))),
3227 (VRSQRTSSm (f32 (IMPLICIT_DEF)), addr:$src)>,
3228 Requires<[HasAVX, OptForSize]>;
3230 def : Pat<(f32 (X86frcp FR32:$src)),
3231 (VRCPSSr (f32 (IMPLICIT_DEF)), FR32:$src)>, Requires<[HasAVX]>;
3232 def : Pat<(f32 (X86frcp (load addr:$src))),
3233 (VRCPSSm (f32 (IMPLICIT_DEF)), addr:$src)>,
3234 Requires<[HasAVX, OptForSize]>;
3237 let Predicates = [HasAVX], AddedComplexity = 1 in {
3238 def : Pat<(int_x86_sse_sqrt_ss VR128:$src),
3239 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)),
3240 (VSQRTSSr (f32 (IMPLICIT_DEF)),
3241 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)),
3243 def : Pat<(int_x86_sse_sqrt_ss sse_load_f32:$src),
3244 (VSQRTSSm_Int (v4f32 (IMPLICIT_DEF)), sse_load_f32:$src)>;
3246 def : Pat<(int_x86_sse2_sqrt_sd VR128:$src),
3247 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)),
3248 (VSQRTSDr (f64 (IMPLICIT_DEF)),
3249 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd)),
3251 def : Pat<(int_x86_sse2_sqrt_sd sse_load_f64:$src),
3252 (VSQRTSDm_Int (v2f64 (IMPLICIT_DEF)), sse_load_f64:$src)>;
3254 def : Pat<(int_x86_sse_rsqrt_ss VR128:$src),
3255 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)),
3256 (VRSQRTSSr (f32 (IMPLICIT_DEF)),
3257 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)),
3259 def : Pat<(int_x86_sse_rsqrt_ss sse_load_f32:$src),
3260 (VRSQRTSSm_Int (v4f32 (IMPLICIT_DEF)), sse_load_f32:$src)>;
3262 def : Pat<(int_x86_sse_rcp_ss VR128:$src),
3263 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)),
3264 (VRCPSSr (f32 (IMPLICIT_DEF)),
3265 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)),
3267 def : Pat<(int_x86_sse_rcp_ss sse_load_f32:$src),
3268 (VRCPSSm_Int (v4f32 (IMPLICIT_DEF)), sse_load_f32:$src)>;
3272 defm SQRT : sse1_fp_unop_s<0x51, "sqrt", fsqrt, int_x86_sse_sqrt_ss,
3274 sse1_fp_unop_p<0x51, "sqrt", fsqrt, SSE_SQRTS>,
3275 sse1_fp_unop_p_int<0x51, "sqrt", int_x86_sse_sqrt_ps, SSE_SQRTS>,
3276 sse2_fp_unop_s<0x51, "sqrt", fsqrt, int_x86_sse2_sqrt_sd,
3278 sse2_fp_unop_p<0x51, "sqrt", fsqrt, SSE_SQRTS>,
3279 sse2_fp_unop_p_int<0x51, "sqrt", int_x86_sse2_sqrt_pd, SSE_SQRTS>;
3281 // Reciprocal approximations. Note that these typically require refinement
3282 // in order to obtain suitable precision.
3283 defm RSQRT : sse1_fp_unop_s<0x52, "rsqrt", X86frsqrt, int_x86_sse_rsqrt_ss,
3285 sse1_fp_unop_p<0x52, "rsqrt", X86frsqrt, SSE_SQRTS>,
3286 sse1_fp_unop_p_int<0x52, "rsqrt", int_x86_sse_rsqrt_ps,
3288 defm RCP : sse1_fp_unop_s<0x53, "rcp", X86frcp, int_x86_sse_rcp_ss,
3290 sse1_fp_unop_p<0x53, "rcp", X86frcp, SSE_RCPS>,
3291 sse1_fp_unop_p_int<0x53, "rcp", int_x86_sse_rcp_ps, SSE_RCPS>;
3293 // There is no f64 version of the reciprocal approximation instructions.
3295 //===----------------------------------------------------------------------===//
3296 // SSE 1 & 2 - Non-temporal stores
3297 //===----------------------------------------------------------------------===//
3299 let AddedComplexity = 400 in { // Prefer non-temporal versions
3300 def VMOVNTPSmr : VPSI<0x2B, MRMDestMem, (outs),
3301 (ins f128mem:$dst, VR128:$src),
3302 "movntps\t{$src, $dst|$dst, $src}",
3303 [(alignednontemporalstore (v4f32 VR128:$src),
3305 IIC_SSE_MOVNT>, VEX;
3306 def VMOVNTPDmr : VPDI<0x2B, MRMDestMem, (outs),
3307 (ins f128mem:$dst, VR128:$src),
3308 "movntpd\t{$src, $dst|$dst, $src}",
3309 [(alignednontemporalstore (v2f64 VR128:$src),
3311 IIC_SSE_MOVNT>, VEX;
3313 let ExeDomain = SSEPackedInt in
3314 def VMOVNTDQmr : VPDI<0xE7, MRMDestMem, (outs),
3315 (ins f128mem:$dst, VR128:$src),
3316 "movntdq\t{$src, $dst|$dst, $src}",
3317 [(alignednontemporalstore (v2i64 VR128:$src),
3319 IIC_SSE_MOVNT>, VEX;
3321 def : Pat<(alignednontemporalstore (v2i64 VR128:$src), addr:$dst),
3322 (VMOVNTDQmr addr:$dst, VR128:$src)>, Requires<[HasAVX]>;
3324 def VMOVNTPSYmr : VPSI<0x2B, MRMDestMem, (outs),
3325 (ins f256mem:$dst, VR256:$src),
3326 "movntps\t{$src, $dst|$dst, $src}",
3327 [(alignednontemporalstore (v8f32 VR256:$src),
3329 IIC_SSE_MOVNT>, VEX;
3330 def VMOVNTPDYmr : VPDI<0x2B, MRMDestMem, (outs),
3331 (ins f256mem:$dst, VR256:$src),
3332 "movntpd\t{$src, $dst|$dst, $src}",
3333 [(alignednontemporalstore (v4f64 VR256:$src),
3335 IIC_SSE_MOVNT>, VEX;
3336 let ExeDomain = SSEPackedInt in
3337 def VMOVNTDQYmr : VPDI<0xE7, MRMDestMem, (outs),
3338 (ins f256mem:$dst, VR256:$src),
3339 "movntdq\t{$src, $dst|$dst, $src}",
3340 [(alignednontemporalstore (v4i64 VR256:$src),
3342 IIC_SSE_MOVNT>, VEX;
3345 let AddedComplexity = 400 in { // Prefer non-temporal versions
3346 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
3347 "movntps\t{$src, $dst|$dst, $src}",
3348 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)],
3350 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
3351 "movntpd\t{$src, $dst|$dst, $src}",
3352 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)],
3355 let ExeDomain = SSEPackedInt in
3356 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
3357 "movntdq\t{$src, $dst|$dst, $src}",
3358 [(alignednontemporalstore (v2i64 VR128:$src), addr:$dst)],
3361 def : Pat<(alignednontemporalstore (v2i64 VR128:$src), addr:$dst),
3362 (MOVNTDQmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3364 // There is no AVX form for instructions below this point
3365 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
3366 "movnti{l}\t{$src, $dst|$dst, $src}",
3367 [(nontemporalstore (i32 GR32:$src), addr:$dst)],
3369 TB, Requires<[HasSSE2]>;
3370 def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
3371 "movnti{q}\t{$src, $dst|$dst, $src}",
3372 [(nontemporalstore (i64 GR64:$src), addr:$dst)],
3374 TB, Requires<[HasSSE2]>;
3377 //===----------------------------------------------------------------------===//
3378 // SSE 1 & 2 - Prefetch and memory fence
3379 //===----------------------------------------------------------------------===//
3381 // Prefetch intrinsic.
3382 let Predicates = [HasSSE1] in {
3383 def PREFETCHT0 : I<0x18, MRM1m, (outs), (ins i8mem:$src),
3384 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3), (i32 1))],
3385 IIC_SSE_PREFETCH>, TB;
3386 def PREFETCHT1 : I<0x18, MRM2m, (outs), (ins i8mem:$src),
3387 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2), (i32 1))],
3388 IIC_SSE_PREFETCH>, TB;
3389 def PREFETCHT2 : I<0x18, MRM3m, (outs), (ins i8mem:$src),
3390 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1), (i32 1))],
3391 IIC_SSE_PREFETCH>, TB;
3392 def PREFETCHNTA : I<0x18, MRM0m, (outs), (ins i8mem:$src),
3393 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0), (i32 1))],
3394 IIC_SSE_PREFETCH>, TB;
3398 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
3399 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)],
3400 IIC_SSE_PREFETCH>, TB, Requires<[HasSSE2]>;
3402 // Pause. This "instruction" is encoded as "rep; nop", so even though it
3403 // was introduced with SSE2, it's backward compatible.
3404 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", [], IIC_SSE_PAUSE>, REP;
3406 // Load, store, and memory fence
3407 def SFENCE : I<0xAE, MRM_F8, (outs), (ins),
3408 "sfence", [(int_x86_sse_sfence)], IIC_SSE_SFENCE>,
3409 TB, Requires<[HasSSE1]>;
3410 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
3411 "lfence", [(int_x86_sse2_lfence)], IIC_SSE_LFENCE>,
3412 TB, Requires<[HasSSE2]>;
3413 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
3414 "mfence", [(int_x86_sse2_mfence)], IIC_SSE_MFENCE>,
3415 TB, Requires<[HasSSE2]>;
3417 def : Pat<(X86SFence), (SFENCE)>;
3418 def : Pat<(X86LFence), (LFENCE)>;
3419 def : Pat<(X86MFence), (MFENCE)>;
3421 //===----------------------------------------------------------------------===//
3422 // SSE 1 & 2 - Load/Store XCSR register
3423 //===----------------------------------------------------------------------===//
3425 def VLDMXCSR : VPSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
3426 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)],
3427 IIC_SSE_LDMXCSR>, VEX;
3428 def VSTMXCSR : VPSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
3429 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)],
3430 IIC_SSE_STMXCSR>, VEX;
3432 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
3433 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)],
3435 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
3436 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)],
3439 //===---------------------------------------------------------------------===//
3440 // SSE2 - Move Aligned/Unaligned Packed Integer Instructions
3441 //===---------------------------------------------------------------------===//
3443 let ExeDomain = SSEPackedInt in { // SSE integer instructions
3445 let neverHasSideEffects = 1 in {
3446 def VMOVDQArr : VPDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3447 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RR>,
3449 def VMOVDQAYrr : VPDI<0x6F, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3450 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RR>,
3453 def VMOVDQUrr : VSSI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3454 "movdqu\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVU_P_RR>,
3456 def VMOVDQUYrr : VSSI<0x6F, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3457 "movdqu\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVU_P_RR>,
3461 let isCodeGenOnly = 1 in {
3462 def VMOVDQArr_REV : VPDI<0x7F, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
3463 "movdqa\t{$src, $dst|$dst, $src}", [],
3466 def VMOVDQAYrr_REV : VPDI<0x7F, MRMDestReg, (outs VR256:$dst), (ins VR256:$src),
3467 "movdqa\t{$src, $dst|$dst, $src}", [],
3470 def VMOVDQUrr_REV : VSSI<0x7F, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
3471 "movdqu\t{$src, $dst|$dst, $src}", [],
3474 def VMOVDQUYrr_REV : VSSI<0x7F, MRMDestReg, (outs VR256:$dst), (ins VR256:$src),
3475 "movdqu\t{$src, $dst|$dst, $src}", [],
3480 let canFoldAsLoad = 1, mayLoad = 1 in {
3481 def VMOVDQArm : VPDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3482 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RM>,
3484 def VMOVDQAYrm : VPDI<0x6F, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
3485 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RM>,
3487 let Predicates = [HasAVX] in {
3488 def VMOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3489 "vmovdqu\t{$src, $dst|$dst, $src}",[], IIC_SSE_MOVU_P_RM>,
3491 def VMOVDQUYrm : I<0x6F, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
3492 "vmovdqu\t{$src, $dst|$dst, $src}",[], IIC_SSE_MOVU_P_RM>,
3497 let mayStore = 1 in {
3498 def VMOVDQAmr : VPDI<0x7F, MRMDestMem, (outs),
3499 (ins i128mem:$dst, VR128:$src),
3500 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_MR>,
3502 def VMOVDQAYmr : VPDI<0x7F, MRMDestMem, (outs),
3503 (ins i256mem:$dst, VR256:$src),
3504 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_MR>,
3506 let Predicates = [HasAVX] in {
3507 def VMOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
3508 "vmovdqu\t{$src, $dst|$dst, $src}",[], IIC_SSE_MOVU_P_MR>,
3510 def VMOVDQUYmr : I<0x7F, MRMDestMem, (outs), (ins i256mem:$dst, VR256:$src),
3511 "vmovdqu\t{$src, $dst|$dst, $src}",[], IIC_SSE_MOVU_P_MR>,
3516 let neverHasSideEffects = 1 in
3517 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3518 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RR>;
3520 def MOVDQUrr : I<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3521 "movdqu\t{$src, $dst|$dst, $src}",
3522 [], IIC_SSE_MOVU_P_RR>, XS, Requires<[HasSSE2]>;
3525 let isCodeGenOnly = 1 in {
3526 def MOVDQArr_REV : PDI<0x7F, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
3527 "movdqa\t{$src, $dst|$dst, $src}", [],
3530 def MOVDQUrr_REV : I<0x7F, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
3531 "movdqu\t{$src, $dst|$dst, $src}",
3532 [], IIC_SSE_MOVU_P_RR>, XS, Requires<[HasSSE2]>;
3535 let canFoldAsLoad = 1, mayLoad = 1 in {
3536 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3537 "movdqa\t{$src, $dst|$dst, $src}",
3538 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/],
3540 def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3541 "movdqu\t{$src, $dst|$dst, $src}",
3542 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/],
3544 XS, Requires<[HasSSE2]>;
3547 let mayStore = 1 in {
3548 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
3549 "movdqa\t{$src, $dst|$dst, $src}",
3550 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/],
3552 def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
3553 "movdqu\t{$src, $dst|$dst, $src}",
3554 [/*(store (v2i64 VR128:$src), addr:$dst)*/],
3556 XS, Requires<[HasSSE2]>;
3559 // Intrinsic forms of MOVDQU load and store
3560 def VMOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
3561 "vmovdqu\t{$src, $dst|$dst, $src}",
3562 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)],
3564 XS, VEX, Requires<[HasAVX]>;
3566 def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
3567 "movdqu\t{$src, $dst|$dst, $src}",
3568 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)],
3570 XS, Requires<[HasSSE2]>;
3572 } // ExeDomain = SSEPackedInt
3574 let Predicates = [HasAVX] in {
3575 def : Pat<(int_x86_avx_storeu_dq_256 addr:$dst, VR256:$src),
3576 (VMOVDQUYmr addr:$dst, VR256:$src)>;
3579 //===---------------------------------------------------------------------===//
3580 // SSE2 - Packed Integer Arithmetic Instructions
3581 //===---------------------------------------------------------------------===//
3583 def SSE_PMADD : OpndItins<
3584 IIC_SSE_PMADD, IIC_SSE_PMADD
3587 let ExeDomain = SSEPackedInt in { // SSE integer instructions
3589 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
3590 RegisterClass RC, PatFrag memop_frag,
3591 X86MemOperand x86memop,
3593 bit IsCommutable = 0,
3595 let isCommutable = IsCommutable in
3596 def rr : PDI<opc, MRMSrcReg, (outs RC:$dst),
3597 (ins RC:$src1, RC:$src2),
3599 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3600 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3601 [(set RC:$dst, (IntId RC:$src1, RC:$src2))], itins.rr>;
3602 def rm : PDI<opc, MRMSrcMem, (outs RC:$dst),
3603 (ins RC:$src1, x86memop:$src2),
3605 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3606 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3607 [(set RC:$dst, (IntId RC:$src1, (bitconvert (memop_frag addr:$src2))))],
3611 multiclass PDI_binop_rmi<bits<8> opc, bits<8> opc2, Format ImmForm,
3612 string OpcodeStr, SDNode OpNode,
3613 SDNode OpNode2, RegisterClass RC,
3614 ValueType DstVT, ValueType SrcVT, PatFrag bc_frag,
3615 ShiftOpndItins itins,
3617 // src2 is always 128-bit
3618 def rr : PDI<opc, MRMSrcReg, (outs RC:$dst),
3619 (ins RC:$src1, VR128:$src2),
3621 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3622 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3623 [(set RC:$dst, (DstVT (OpNode RC:$src1, (SrcVT VR128:$src2))))],
3625 def rm : PDI<opc, MRMSrcMem, (outs RC:$dst),
3626 (ins RC:$src1, i128mem:$src2),
3628 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3629 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3630 [(set RC:$dst, (DstVT (OpNode RC:$src1,
3631 (bc_frag (memopv2i64 addr:$src2)))))], itins.rm>;
3632 def ri : PDIi8<opc2, ImmForm, (outs RC:$dst),
3633 (ins RC:$src1, i32i8imm:$src2),
3635 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3636 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3637 [(set RC:$dst, (DstVT (OpNode2 RC:$src1, (i32 imm:$src2))))], itins.ri>;
3640 /// PDI_binop_rm - Simple SSE2 binary operator with different src and dst types
3641 multiclass PDI_binop_rm2<bits<8> opc, string OpcodeStr, SDNode OpNode,
3642 ValueType DstVT, ValueType SrcVT, RegisterClass RC,
3643 PatFrag memop_frag, X86MemOperand x86memop,
3645 bit IsCommutable = 0, bit Is2Addr = 1> {
3646 let isCommutable = IsCommutable in
3647 def rr : PDI<opc, MRMSrcReg, (outs RC:$dst),
3648 (ins RC:$src1, RC:$src2),
3650 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3651 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3652 [(set RC:$dst, (DstVT (OpNode (SrcVT RC:$src1), RC:$src2)))]>;
3653 def rm : PDI<opc, MRMSrcMem, (outs RC:$dst),
3654 (ins RC:$src1, x86memop:$src2),
3656 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3657 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3658 [(set RC:$dst, (DstVT (OpNode (SrcVT RC:$src1),
3659 (bitconvert (memop_frag addr:$src2)))))]>;
3661 } // ExeDomain = SSEPackedInt
3663 // 128-bit Integer Arithmetic
3665 let Predicates = [HasAVX] in {
3666 defm VPADDB : PDI_binop_rm<0xFC, "vpaddb", add, v16i8, VR128, memopv2i64,
3667 i128mem, SSE_INTALU_ITINS_P, 1, 0 /*3addr*/>,
3669 defm VPADDW : PDI_binop_rm<0xFD, "vpaddw", add, v8i16, VR128, memopv2i64,
3670 i128mem, SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3671 defm VPADDD : PDI_binop_rm<0xFE, "vpaddd", add, v4i32, VR128, memopv2i64,
3672 i128mem, SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3673 defm VPADDQ : PDI_binop_rm<0xD4, "vpaddq", add, v2i64, VR128, memopv2i64,
3674 i128mem, SSE_INTALUQ_ITINS_P, 1, 0>, VEX_4V;
3675 defm VPMULLW : PDI_binop_rm<0xD5, "vpmullw", mul, v8i16, VR128, memopv2i64,
3676 i128mem, SSE_INTMUL_ITINS_P, 1, 0>, VEX_4V;
3677 defm VPSUBB : PDI_binop_rm<0xF8, "vpsubb", sub, v16i8, VR128, memopv2i64,
3678 i128mem, SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3679 defm VPSUBW : PDI_binop_rm<0xF9, "vpsubw", sub, v8i16, VR128, memopv2i64,
3680 i128mem, SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3681 defm VPSUBD : PDI_binop_rm<0xFA, "vpsubd", sub, v4i32, VR128, memopv2i64,
3682 i128mem, SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3683 defm VPSUBQ : PDI_binop_rm<0xFB, "vpsubq", sub, v2i64, VR128, memopv2i64,
3684 i128mem, SSE_INTALUQ_ITINS_P, 0, 0>, VEX_4V;
3685 defm VPMULUDQ : PDI_binop_rm2<0xF4, "vpmuludq", X86pmuludq, v2i64, v4i32, VR128,
3686 memopv2i64, i128mem, SSE_INTMUL_ITINS_P, 1, 0>,
3690 defm VPSUBSB : PDI_binop_rm_int<0xE8, "vpsubsb" , int_x86_sse2_psubs_b,
3691 VR128, memopv2i64, i128mem,
3692 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3693 defm VPSUBSW : PDI_binop_rm_int<0xE9, "vpsubsw" , int_x86_sse2_psubs_w,
3694 VR128, memopv2i64, i128mem,
3695 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3696 defm VPSUBUSB : PDI_binop_rm_int<0xD8, "vpsubusb", int_x86_sse2_psubus_b,
3697 VR128, memopv2i64, i128mem,
3698 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3699 defm VPSUBUSW : PDI_binop_rm_int<0xD9, "vpsubusw", int_x86_sse2_psubus_w,
3700 VR128, memopv2i64, i128mem,
3701 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3702 defm VPADDSB : PDI_binop_rm_int<0xEC, "vpaddsb" , int_x86_sse2_padds_b,
3703 VR128, memopv2i64, i128mem,
3704 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3705 defm VPADDSW : PDI_binop_rm_int<0xED, "vpaddsw" , int_x86_sse2_padds_w,
3706 VR128, memopv2i64, i128mem,
3707 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3708 defm VPADDUSB : PDI_binop_rm_int<0xDC, "vpaddusb", int_x86_sse2_paddus_b,
3709 VR128, memopv2i64, i128mem,
3710 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3711 defm VPADDUSW : PDI_binop_rm_int<0xDD, "vpaddusw", int_x86_sse2_paddus_w,
3712 VR128, memopv2i64, i128mem,
3713 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3714 defm VPMULHUW : PDI_binop_rm_int<0xE4, "vpmulhuw", int_x86_sse2_pmulhu_w,
3715 VR128, memopv2i64, i128mem,
3716 SSE_INTMUL_ITINS_P, 1, 0>, VEX_4V;
3717 defm VPMULHW : PDI_binop_rm_int<0xE5, "vpmulhw" , int_x86_sse2_pmulh_w,
3718 VR128, memopv2i64, i128mem,
3719 SSE_INTMUL_ITINS_P, 1, 0>, VEX_4V;
3720 defm VPMADDWD : PDI_binop_rm_int<0xF5, "vpmaddwd", int_x86_sse2_pmadd_wd,
3721 VR128, memopv2i64, i128mem,
3722 SSE_PMADD, 1, 0>, VEX_4V;
3723 defm VPAVGB : PDI_binop_rm_int<0xE0, "vpavgb", int_x86_sse2_pavg_b,
3724 VR128, memopv2i64, i128mem,
3725 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3726 defm VPAVGW : PDI_binop_rm_int<0xE3, "vpavgw", int_x86_sse2_pavg_w,
3727 VR128, memopv2i64, i128mem,
3728 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3729 defm VPMINUB : PDI_binop_rm_int<0xDA, "vpminub", int_x86_sse2_pminu_b,
3730 VR128, memopv2i64, i128mem,
3731 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3732 defm VPMINSW : PDI_binop_rm_int<0xEA, "vpminsw", int_x86_sse2_pmins_w,
3733 VR128, memopv2i64, i128mem,
3734 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3735 defm VPMAXUB : PDI_binop_rm_int<0xDE, "vpmaxub", int_x86_sse2_pmaxu_b,
3736 VR128, memopv2i64, i128mem,
3737 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3738 defm VPMAXSW : PDI_binop_rm_int<0xEE, "vpmaxsw", int_x86_sse2_pmaxs_w,
3739 VR128, memopv2i64, i128mem,
3740 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3741 defm VPSADBW : PDI_binop_rm_int<0xF6, "vpsadbw", int_x86_sse2_psad_bw,
3742 VR128, memopv2i64, i128mem,
3743 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3746 let Predicates = [HasAVX2] in {
3747 defm VPADDBY : PDI_binop_rm<0xFC, "vpaddb", add, v32i8, VR256, memopv4i64,
3748 i256mem, SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3749 defm VPADDWY : PDI_binop_rm<0xFD, "vpaddw", add, v16i16, VR256, memopv4i64,
3750 i256mem, SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3751 defm VPADDDY : PDI_binop_rm<0xFE, "vpaddd", add, v8i32, VR256, memopv4i64,
3752 i256mem, SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3753 defm VPADDQY : PDI_binop_rm<0xD4, "vpaddq", add, v4i64, VR256, memopv4i64,
3754 i256mem, SSE_INTALUQ_ITINS_P, 1, 0>, VEX_4V;
3755 defm VPMULLWY : PDI_binop_rm<0xD5, "vpmullw", mul, v16i16, VR256, memopv4i64,
3756 i256mem, SSE_INTMUL_ITINS_P, 1, 0>, VEX_4V;
3757 defm VPSUBBY : PDI_binop_rm<0xF8, "vpsubb", sub, v32i8, VR256, memopv4i64,
3758 i256mem, SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3759 defm VPSUBWY : PDI_binop_rm<0xF9, "vpsubw", sub, v16i16,VR256, memopv4i64,
3760 i256mem, SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3761 defm VPSUBDY : PDI_binop_rm<0xFA, "vpsubd", sub, v8i32, VR256, memopv4i64,
3762 i256mem, SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3763 defm VPSUBQY : PDI_binop_rm<0xFB, "vpsubq", sub, v4i64, VR256, memopv4i64,
3764 i256mem, SSE_INTALUQ_ITINS_P, 0, 0>, VEX_4V;
3765 defm VPMULUDQY : PDI_binop_rm2<0xF4, "vpmuludq", X86pmuludq, v4i64, v8i32,
3766 VR256, memopv4i64, i256mem,
3767 SSE_INTMUL_ITINS_P, 1, 0>, VEX_4V;
3770 defm VPSUBSBY : PDI_binop_rm_int<0xE8, "vpsubsb" , int_x86_avx2_psubs_b,
3771 VR256, memopv4i64, i256mem,
3772 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3773 defm VPSUBSWY : PDI_binop_rm_int<0xE9, "vpsubsw" , int_x86_avx2_psubs_w,
3774 VR256, memopv4i64, i256mem,
3775 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3776 defm VPSUBUSBY : PDI_binop_rm_int<0xD8, "vpsubusb", int_x86_avx2_psubus_b,
3777 VR256, memopv4i64, i256mem,
3778 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3779 defm VPSUBUSWY : PDI_binop_rm_int<0xD9, "vpsubusw", int_x86_avx2_psubus_w,
3780 VR256, memopv4i64, i256mem,
3781 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
3782 defm VPADDSBY : PDI_binop_rm_int<0xEC, "vpaddsb" , int_x86_avx2_padds_b,
3783 VR256, memopv4i64, i256mem,
3784 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3785 defm VPADDSWY : PDI_binop_rm_int<0xED, "vpaddsw" , int_x86_avx2_padds_w,
3786 VR256, memopv4i64, i256mem,
3787 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3788 defm VPADDUSBY : PDI_binop_rm_int<0xDC, "vpaddusb", int_x86_avx2_paddus_b,
3789 VR256, memopv4i64, i256mem,
3790 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3791 defm VPADDUSWY : PDI_binop_rm_int<0xDD, "vpaddusw", int_x86_avx2_paddus_w,
3792 VR256, memopv4i64, i256mem,
3793 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3794 defm VPMULHUWY : PDI_binop_rm_int<0xE4, "vpmulhuw", int_x86_avx2_pmulhu_w,
3795 VR256, memopv4i64, i256mem,
3796 SSE_INTMUL_ITINS_P, 1, 0>, VEX_4V;
3797 defm VPMULHWY : PDI_binop_rm_int<0xE5, "vpmulhw" , int_x86_avx2_pmulh_w,
3798 VR256, memopv4i64, i256mem,
3799 SSE_INTMUL_ITINS_P, 1, 0>, VEX_4V;
3800 defm VPMADDWDY : PDI_binop_rm_int<0xF5, "vpmaddwd", int_x86_avx2_pmadd_wd,
3801 VR256, memopv4i64, i256mem,
3802 SSE_PMADD, 1, 0>, VEX_4V;
3803 defm VPAVGBY : PDI_binop_rm_int<0xE0, "vpavgb", int_x86_avx2_pavg_b,
3804 VR256, memopv4i64, i256mem,
3805 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3806 defm VPAVGWY : PDI_binop_rm_int<0xE3, "vpavgw", int_x86_avx2_pavg_w,
3807 VR256, memopv4i64, i256mem,
3808 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3809 defm VPMINUBY : PDI_binop_rm_int<0xDA, "vpminub", int_x86_avx2_pminu_b,
3810 VR256, memopv4i64, i256mem,
3811 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3812 defm VPMINSWY : PDI_binop_rm_int<0xEA, "vpminsw", int_x86_avx2_pmins_w,
3813 VR256, memopv4i64, i256mem,
3814 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3815 defm VPMAXUBY : PDI_binop_rm_int<0xDE, "vpmaxub", int_x86_avx2_pmaxu_b,
3816 VR256, memopv4i64, i256mem,
3817 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3818 defm VPMAXSWY : PDI_binop_rm_int<0xEE, "vpmaxsw", int_x86_avx2_pmaxs_w,
3819 VR256, memopv4i64, i256mem,
3820 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3821 defm VPSADBWY : PDI_binop_rm_int<0xF6, "vpsadbw", int_x86_avx2_psad_bw,
3822 VR256, memopv4i64, i256mem,
3823 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
3826 let Constraints = "$src1 = $dst" in {
3827 defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, VR128, memopv2i64,
3828 i128mem, SSE_INTALU_ITINS_P, 1>;
3829 defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, VR128, memopv2i64,
3830 i128mem, SSE_INTALU_ITINS_P, 1>;
3831 defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, VR128, memopv2i64,
3832 i128mem, SSE_INTALU_ITINS_P, 1>;
3833 defm PADDQ : PDI_binop_rm<0xD4, "paddq", add, v2i64, VR128, memopv2i64,
3834 i128mem, SSE_INTALUQ_ITINS_P, 1>;
3835 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, VR128, memopv2i64,
3836 i128mem, SSE_INTMUL_ITINS_P, 1>;
3837 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8, VR128, memopv2i64,
3838 i128mem, SSE_INTALU_ITINS_P>;
3839 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16, VR128, memopv2i64,
3840 i128mem, SSE_INTALU_ITINS_P>;
3841 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32, VR128, memopv2i64,
3842 i128mem, SSE_INTALU_ITINS_P>;
3843 defm PSUBQ : PDI_binop_rm<0xFB, "psubq", sub, v2i64, VR128, memopv2i64,
3844 i128mem, SSE_INTALUQ_ITINS_P>;
3845 defm PMULUDQ : PDI_binop_rm2<0xF4, "pmuludq", X86pmuludq, v2i64, v4i32, VR128,
3846 memopv2i64, i128mem, SSE_INTMUL_ITINS_P, 1>;
3849 defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b,
3850 VR128, memopv2i64, i128mem,
3851 SSE_INTALU_ITINS_P>;
3852 defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w,
3853 VR128, memopv2i64, i128mem,
3854 SSE_INTALU_ITINS_P>;
3855 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b,
3856 VR128, memopv2i64, i128mem,
3857 SSE_INTALU_ITINS_P>;
3858 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w,
3859 VR128, memopv2i64, i128mem,
3860 SSE_INTALU_ITINS_P>;
3861 defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b,
3862 VR128, memopv2i64, i128mem,
3863 SSE_INTALU_ITINS_P, 1>;
3864 defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w,
3865 VR128, memopv2i64, i128mem,
3866 SSE_INTALU_ITINS_P, 1>;
3867 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b,
3868 VR128, memopv2i64, i128mem,
3869 SSE_INTALU_ITINS_P, 1>;
3870 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w,
3871 VR128, memopv2i64, i128mem,
3872 SSE_INTALU_ITINS_P, 1>;
3873 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w,
3874 VR128, memopv2i64, i128mem,
3875 SSE_INTMUL_ITINS_P, 1>;
3876 defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w,
3877 VR128, memopv2i64, i128mem,
3878 SSE_INTMUL_ITINS_P, 1>;
3879 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd,
3880 VR128, memopv2i64, i128mem,
3882 defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b,
3883 VR128, memopv2i64, i128mem,
3884 SSE_INTALU_ITINS_P, 1>;
3885 defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w,
3886 VR128, memopv2i64, i128mem,
3887 SSE_INTALU_ITINS_P, 1>;
3888 defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b,
3889 VR128, memopv2i64, i128mem,
3890 SSE_INTALU_ITINS_P, 1>;
3891 defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w,
3892 VR128, memopv2i64, i128mem,
3893 SSE_INTALU_ITINS_P, 1>;
3894 defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b,
3895 VR128, memopv2i64, i128mem,
3896 SSE_INTALU_ITINS_P, 1>;
3897 defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w,
3898 VR128, memopv2i64, i128mem,
3899 SSE_INTALU_ITINS_P, 1>;
3900 defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw,
3901 VR128, memopv2i64, i128mem,
3902 SSE_INTALU_ITINS_P, 1>;
3904 } // Constraints = "$src1 = $dst"
3906 //===---------------------------------------------------------------------===//
3907 // SSE2 - Packed Integer Logical Instructions
3908 //===---------------------------------------------------------------------===//
3910 let Predicates = [HasAVX] in {
3911 defm VPSLLW : PDI_binop_rmi<0xF1, 0x71, MRM6r, "vpsllw", X86vshl, X86vshli,
3912 VR128, v8i16, v8i16, bc_v8i16,
3913 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3914 defm VPSLLD : PDI_binop_rmi<0xF2, 0x72, MRM6r, "vpslld", X86vshl, X86vshli,
3915 VR128, v4i32, v4i32, bc_v4i32,
3916 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3917 defm VPSLLQ : PDI_binop_rmi<0xF3, 0x73, MRM6r, "vpsllq", X86vshl, X86vshli,
3918 VR128, v2i64, v2i64, bc_v2i64,
3919 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3921 defm VPSRLW : PDI_binop_rmi<0xD1, 0x71, MRM2r, "vpsrlw", X86vsrl, X86vsrli,
3922 VR128, v8i16, v8i16, bc_v8i16,
3923 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3924 defm VPSRLD : PDI_binop_rmi<0xD2, 0x72, MRM2r, "vpsrld", X86vsrl, X86vsrli,
3925 VR128, v4i32, v4i32, bc_v4i32,
3926 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3927 defm VPSRLQ : PDI_binop_rmi<0xD3, 0x73, MRM2r, "vpsrlq", X86vsrl, X86vsrli,
3928 VR128, v2i64, v2i64, bc_v2i64,
3929 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3931 defm VPSRAW : PDI_binop_rmi<0xE1, 0x71, MRM4r, "vpsraw", X86vsra, X86vsrai,
3932 VR128, v8i16, v8i16, bc_v8i16,
3933 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3934 defm VPSRAD : PDI_binop_rmi<0xE2, 0x72, MRM4r, "vpsrad", X86vsra, X86vsrai,
3935 VR128, v4i32, v4i32, bc_v4i32,
3936 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3938 let ExeDomain = SSEPackedInt in {
3939 // 128-bit logical shifts.
3940 def VPSLLDQri : PDIi8<0x73, MRM7r,
3941 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3942 "vpslldq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3944 (int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2))]>,
3946 def VPSRLDQri : PDIi8<0x73, MRM3r,
3947 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3948 "vpsrldq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3950 (int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2))]>,
3952 // PSRADQri doesn't exist in SSE[1-3].
3954 } // Predicates = [HasAVX]
3956 let Predicates = [HasAVX2] in {
3957 defm VPSLLWY : PDI_binop_rmi<0xF1, 0x71, MRM6r, "vpsllw", X86vshl, X86vshli,
3958 VR256, v16i16, v8i16, bc_v8i16,
3959 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3960 defm VPSLLDY : PDI_binop_rmi<0xF2, 0x72, MRM6r, "vpslld", X86vshl, X86vshli,
3961 VR256, v8i32, v4i32, bc_v4i32,
3962 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3963 defm VPSLLQY : PDI_binop_rmi<0xF3, 0x73, MRM6r, "vpsllq", X86vshl, X86vshli,
3964 VR256, v4i64, v2i64, bc_v2i64,
3965 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3967 defm VPSRLWY : PDI_binop_rmi<0xD1, 0x71, MRM2r, "vpsrlw", X86vsrl, X86vsrli,
3968 VR256, v16i16, v8i16, bc_v8i16,
3969 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3970 defm VPSRLDY : PDI_binop_rmi<0xD2, 0x72, MRM2r, "vpsrld", X86vsrl, X86vsrli,
3971 VR256, v8i32, v4i32, bc_v4i32,
3972 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3973 defm VPSRLQY : PDI_binop_rmi<0xD3, 0x73, MRM2r, "vpsrlq", X86vsrl, X86vsrli,
3974 VR256, v4i64, v2i64, bc_v2i64,
3975 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3977 defm VPSRAWY : PDI_binop_rmi<0xE1, 0x71, MRM4r, "vpsraw", X86vsra, X86vsrai,
3978 VR256, v16i16, v8i16, bc_v8i16,
3979 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3980 defm VPSRADY : PDI_binop_rmi<0xE2, 0x72, MRM4r, "vpsrad", X86vsra, X86vsrai,
3981 VR256, v8i32, v4i32, bc_v4i32,
3982 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3984 let ExeDomain = SSEPackedInt in {
3985 // 256-bit logical shifts.
3986 def VPSLLDQYri : PDIi8<0x73, MRM7r,
3987 (outs VR256:$dst), (ins VR256:$src1, i32i8imm:$src2),
3988 "vpslldq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3990 (int_x86_avx2_psll_dq_bs VR256:$src1, imm:$src2))]>,
3992 def VPSRLDQYri : PDIi8<0x73, MRM3r,
3993 (outs VR256:$dst), (ins VR256:$src1, i32i8imm:$src2),
3994 "vpsrldq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3996 (int_x86_avx2_psrl_dq_bs VR256:$src1, imm:$src2))]>,
3998 // PSRADQYri doesn't exist in SSE[1-3].
4000 } // Predicates = [HasAVX2]
4002 let Constraints = "$src1 = $dst" in {
4003 defm PSLLW : PDI_binop_rmi<0xF1, 0x71, MRM6r, "psllw", X86vshl, X86vshli,
4004 VR128, v8i16, v8i16, bc_v8i16,
4005 SSE_INTSHIFT_ITINS_P>;
4006 defm PSLLD : PDI_binop_rmi<0xF2, 0x72, MRM6r, "pslld", X86vshl, X86vshli,
4007 VR128, v4i32, v4i32, bc_v4i32,
4008 SSE_INTSHIFT_ITINS_P>;
4009 defm PSLLQ : PDI_binop_rmi<0xF3, 0x73, MRM6r, "psllq", X86vshl, X86vshli,
4010 VR128, v2i64, v2i64, bc_v2i64,
4011 SSE_INTSHIFT_ITINS_P>;
4013 defm PSRLW : PDI_binop_rmi<0xD1, 0x71, MRM2r, "psrlw", X86vsrl, X86vsrli,
4014 VR128, v8i16, v8i16, bc_v8i16,
4015 SSE_INTSHIFT_ITINS_P>;
4016 defm PSRLD : PDI_binop_rmi<0xD2, 0x72, MRM2r, "psrld", X86vsrl, X86vsrli,
4017 VR128, v4i32, v4i32, bc_v4i32,
4018 SSE_INTSHIFT_ITINS_P>;
4019 defm PSRLQ : PDI_binop_rmi<0xD3, 0x73, MRM2r, "psrlq", X86vsrl, X86vsrli,
4020 VR128, v2i64, v2i64, bc_v2i64,
4021 SSE_INTSHIFT_ITINS_P>;
4023 defm PSRAW : PDI_binop_rmi<0xE1, 0x71, MRM4r, "psraw", X86vsra, X86vsrai,
4024 VR128, v8i16, v8i16, bc_v8i16,
4025 SSE_INTSHIFT_ITINS_P>;
4026 defm PSRAD : PDI_binop_rmi<0xE2, 0x72, MRM4r, "psrad", X86vsra, X86vsrai,
4027 VR128, v4i32, v4i32, bc_v4i32,
4028 SSE_INTSHIFT_ITINS_P>;
4030 let ExeDomain = SSEPackedInt in {
4031 // 128-bit logical shifts.
4032 def PSLLDQri : PDIi8<0x73, MRM7r,
4033 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
4034 "pslldq\t{$src2, $dst|$dst, $src2}",
4036 (int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2))]>;
4037 def PSRLDQri : PDIi8<0x73, MRM3r,
4038 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
4039 "psrldq\t{$src2, $dst|$dst, $src2}",
4041 (int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2))]>;
4042 // PSRADQri doesn't exist in SSE[1-3].
4044 } // Constraints = "$src1 = $dst"
4046 let Predicates = [HasAVX] in {
4047 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
4048 (VPSLLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
4049 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
4050 (VPSRLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
4051 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
4052 (VPSRLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
4054 // Shift up / down and insert zero's.
4055 def : Pat<(v2i64 (X86vshldq VR128:$src, (i8 imm:$amt))),
4056 (VPSLLDQri VR128:$src, (BYTE_imm imm:$amt))>;
4057 def : Pat<(v2i64 (X86vshrdq VR128:$src, (i8 imm:$amt))),
4058 (VPSRLDQri VR128:$src, (BYTE_imm imm:$amt))>;
4061 let Predicates = [HasAVX2] in {
4062 def : Pat<(int_x86_avx2_psll_dq VR256:$src1, imm:$src2),
4063 (VPSLLDQYri VR256:$src1, (BYTE_imm imm:$src2))>;
4064 def : Pat<(int_x86_avx2_psrl_dq VR256:$src1, imm:$src2),
4065 (VPSRLDQYri VR256:$src1, (BYTE_imm imm:$src2))>;
4068 let Predicates = [HasSSE2] in {
4069 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
4070 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
4071 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
4072 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
4073 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
4074 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
4076 // Shift up / down and insert zero's.
4077 def : Pat<(v2i64 (X86vshldq VR128:$src, (i8 imm:$amt))),
4078 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt))>;
4079 def : Pat<(v2i64 (X86vshrdq VR128:$src, (i8 imm:$amt))),
4080 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt))>;
4083 //===---------------------------------------------------------------------===//
4084 // SSE2 - Packed Integer Comparison Instructions
4085 //===---------------------------------------------------------------------===//
4087 let Predicates = [HasAVX] in {
4088 defm VPCMPEQB : PDI_binop_rm<0x74, "vpcmpeqb", X86pcmpeq, v16i8,
4089 VR128, memopv2i64, i128mem,
4090 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
4091 defm VPCMPEQW : PDI_binop_rm<0x75, "vpcmpeqw", X86pcmpeq, v8i16,
4092 VR128, memopv2i64, i128mem,
4093 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
4094 defm VPCMPEQD : PDI_binop_rm<0x76, "vpcmpeqd", X86pcmpeq, v4i32,
4095 VR128, memopv2i64, i128mem,
4096 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
4097 defm VPCMPGTB : PDI_binop_rm<0x64, "vpcmpgtb", X86pcmpgt, v16i8,
4098 VR128, memopv2i64, i128mem,
4099 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4100 defm VPCMPGTW : PDI_binop_rm<0x65, "vpcmpgtw", X86pcmpgt, v8i16,
4101 VR128, memopv2i64, i128mem,
4102 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4103 defm VPCMPGTD : PDI_binop_rm<0x66, "vpcmpgtd", X86pcmpgt, v4i32,
4104 VR128, memopv2i64, i128mem,
4105 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4108 let Predicates = [HasAVX2] in {
4109 defm VPCMPEQBY : PDI_binop_rm<0x74, "vpcmpeqb", X86pcmpeq, v32i8,
4110 VR256, memopv4i64, i256mem,
4111 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
4112 defm VPCMPEQWY : PDI_binop_rm<0x75, "vpcmpeqw", X86pcmpeq, v16i16,
4113 VR256, memopv4i64, i256mem,
4114 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
4115 defm VPCMPEQDY : PDI_binop_rm<0x76, "vpcmpeqd", X86pcmpeq, v8i32,
4116 VR256, memopv4i64, i256mem,
4117 SSE_INTALU_ITINS_P, 1, 0>, VEX_4V;
4118 defm VPCMPGTBY : PDI_binop_rm<0x64, "vpcmpgtb", X86pcmpgt, v32i8,
4119 VR256, memopv4i64, i256mem,
4120 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4121 defm VPCMPGTWY : PDI_binop_rm<0x65, "vpcmpgtw", X86pcmpgt, v16i16,
4122 VR256, memopv4i64, i256mem,
4123 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4124 defm VPCMPGTDY : PDI_binop_rm<0x66, "vpcmpgtd", X86pcmpgt, v8i32,
4125 VR256, memopv4i64, i256mem,
4126 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4129 let Constraints = "$src1 = $dst" in {
4130 defm PCMPEQB : PDI_binop_rm<0x74, "pcmpeqb", X86pcmpeq, v16i8,
4131 VR128, memopv2i64, i128mem,
4132 SSE_INTALU_ITINS_P, 1>;
4133 defm PCMPEQW : PDI_binop_rm<0x75, "pcmpeqw", X86pcmpeq, v8i16,
4134 VR128, memopv2i64, i128mem,
4135 SSE_INTALU_ITINS_P, 1>;
4136 defm PCMPEQD : PDI_binop_rm<0x76, "pcmpeqd", X86pcmpeq, v4i32,
4137 VR128, memopv2i64, i128mem,
4138 SSE_INTALU_ITINS_P, 1>;
4139 defm PCMPGTB : PDI_binop_rm<0x64, "pcmpgtb", X86pcmpgt, v16i8,
4140 VR128, memopv2i64, i128mem,
4141 SSE_INTALU_ITINS_P>;
4142 defm PCMPGTW : PDI_binop_rm<0x65, "pcmpgtw", X86pcmpgt, v8i16,
4143 VR128, memopv2i64, i128mem,
4144 SSE_INTALU_ITINS_P>;
4145 defm PCMPGTD : PDI_binop_rm<0x66, "pcmpgtd", X86pcmpgt, v4i32,
4146 VR128, memopv2i64, i128mem,
4147 SSE_INTALU_ITINS_P>;
4148 } // Constraints = "$src1 = $dst"
4150 //===---------------------------------------------------------------------===//
4151 // SSE2 - Packed Integer Pack Instructions
4152 //===---------------------------------------------------------------------===//
4154 let Predicates = [HasAVX] in {
4155 defm VPACKSSWB : PDI_binop_rm_int<0x63, "vpacksswb", int_x86_sse2_packsswb_128,
4156 VR128, memopv2i64, i128mem,
4157 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4158 defm VPACKSSDW : PDI_binop_rm_int<0x6B, "vpackssdw", int_x86_sse2_packssdw_128,
4159 VR128, memopv2i64, i128mem,
4160 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4161 defm VPACKUSWB : PDI_binop_rm_int<0x67, "vpackuswb", int_x86_sse2_packuswb_128,
4162 VR128, memopv2i64, i128mem,
4163 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4166 let Predicates = [HasAVX2] in {
4167 defm VPACKSSWBY : PDI_binop_rm_int<0x63, "vpacksswb", int_x86_avx2_packsswb,
4168 VR256, memopv4i64, i256mem,
4169 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4170 defm VPACKSSDWY : PDI_binop_rm_int<0x6B, "vpackssdw", int_x86_avx2_packssdw,
4171 VR256, memopv4i64, i256mem,
4172 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4173 defm VPACKUSWBY : PDI_binop_rm_int<0x67, "vpackuswb", int_x86_avx2_packuswb,
4174 VR256, memopv4i64, i256mem,
4175 SSE_INTALU_ITINS_P, 0, 0>, VEX_4V;
4178 let Constraints = "$src1 = $dst" in {
4179 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128,
4180 VR128, memopv2i64, i128mem,
4181 SSE_INTALU_ITINS_P>;
4182 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128,
4183 VR128, memopv2i64, i128mem,
4184 SSE_INTALU_ITINS_P>;
4185 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128,
4186 VR128, memopv2i64, i128mem,
4187 SSE_INTALU_ITINS_P>;
4188 } // Constraints = "$src1 = $dst"
4190 //===---------------------------------------------------------------------===//
4191 // SSE2 - Packed Integer Shuffle Instructions
4192 //===---------------------------------------------------------------------===//
4194 let ExeDomain = SSEPackedInt in {
4195 multiclass sse2_pshuffle<string OpcodeStr, ValueType vt, SDNode OpNode> {
4196 def ri : Ii8<0x70, MRMSrcReg,
4197 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
4198 !strconcat(OpcodeStr,
4199 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4200 [(set VR128:$dst, (vt (OpNode VR128:$src1, (i8 imm:$src2))))],
4202 def mi : Ii8<0x70, MRMSrcMem,
4203 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
4204 !strconcat(OpcodeStr,
4205 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4207 (vt (OpNode (bitconvert (memopv2i64 addr:$src1)),
4212 multiclass sse2_pshuffle_y<string OpcodeStr, ValueType vt, SDNode OpNode> {
4213 def Yri : Ii8<0x70, MRMSrcReg,
4214 (outs VR256:$dst), (ins VR256:$src1, i8imm:$src2),
4215 !strconcat(OpcodeStr,
4216 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4217 [(set VR256:$dst, (vt (OpNode VR256:$src1, (i8 imm:$src2))))]>;
4218 def Ymi : Ii8<0x70, MRMSrcMem,
4219 (outs VR256:$dst), (ins i256mem:$src1, i8imm:$src2),
4220 !strconcat(OpcodeStr,
4221 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4223 (vt (OpNode (bitconvert (memopv4i64 addr:$src1)),
4224 (i8 imm:$src2))))]>;
4226 } // ExeDomain = SSEPackedInt
4228 let Predicates = [HasAVX] in {
4229 let AddedComplexity = 5 in
4230 defm VPSHUFD : sse2_pshuffle<"vpshufd", v4i32, X86PShufd>, TB, OpSize, VEX;
4232 // SSE2 with ImmT == Imm8 and XS prefix.
4233 defm VPSHUFHW : sse2_pshuffle<"vpshufhw", v8i16, X86PShufhw>, XS, VEX;
4235 // SSE2 with ImmT == Imm8 and XD prefix.
4236 defm VPSHUFLW : sse2_pshuffle<"vpshuflw", v8i16, X86PShuflw>, XD, VEX;
4238 def : Pat<(v4f32 (X86PShufd (memopv4f32 addr:$src1), (i8 imm:$imm))),
4239 (VPSHUFDmi addr:$src1, imm:$imm)>;
4240 def : Pat<(v4f32 (X86PShufd VR128:$src1, (i8 imm:$imm))),
4241 (VPSHUFDri VR128:$src1, imm:$imm)>;
4244 let Predicates = [HasAVX2] in {
4245 defm VPSHUFD : sse2_pshuffle_y<"vpshufd", v8i32, X86PShufd>, TB, OpSize, VEX;
4246 defm VPSHUFHW : sse2_pshuffle_y<"vpshufhw", v16i16, X86PShufhw>, XS, VEX;
4247 defm VPSHUFLW : sse2_pshuffle_y<"vpshuflw", v16i16, X86PShuflw>, XD, VEX;
4250 let Predicates = [HasSSE2] in {
4251 let AddedComplexity = 5 in
4252 defm PSHUFD : sse2_pshuffle<"pshufd", v4i32, X86PShufd>, TB, OpSize;
4254 // SSE2 with ImmT == Imm8 and XS prefix.
4255 defm PSHUFHW : sse2_pshuffle<"pshufhw", v8i16, X86PShufhw>, XS;
4257 // SSE2 with ImmT == Imm8 and XD prefix.
4258 defm PSHUFLW : sse2_pshuffle<"pshuflw", v8i16, X86PShuflw>, XD;
4260 def : Pat<(v4f32 (X86PShufd (memopv4f32 addr:$src1), (i8 imm:$imm))),
4261 (PSHUFDmi addr:$src1, imm:$imm)>;
4262 def : Pat<(v4f32 (X86PShufd VR128:$src1, (i8 imm:$imm))),
4263 (PSHUFDri VR128:$src1, imm:$imm)>;
4266 //===---------------------------------------------------------------------===//
4267 // SSE2 - Packed Integer Unpack Instructions
4268 //===---------------------------------------------------------------------===//
4270 let ExeDomain = SSEPackedInt in {
4271 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
4272 SDNode OpNode, PatFrag bc_frag, bit Is2Addr = 1> {
4273 def rr : PDI<opc, MRMSrcReg,
4274 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
4276 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
4277 !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4278 [(set VR128:$dst, (vt (OpNode VR128:$src1, VR128:$src2)))],
4280 def rm : PDI<opc, MRMSrcMem,
4281 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
4283 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
4284 !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4285 [(set VR128:$dst, (OpNode VR128:$src1,
4286 (bc_frag (memopv2i64
4291 multiclass sse2_unpack_y<bits<8> opc, string OpcodeStr, ValueType vt,
4292 SDNode OpNode, PatFrag bc_frag> {
4293 def Yrr : PDI<opc, MRMSrcReg,
4294 (outs VR256:$dst), (ins VR256:$src1, VR256:$src2),
4295 !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4296 [(set VR256:$dst, (vt (OpNode VR256:$src1, VR256:$src2)))]>;
4297 def Yrm : PDI<opc, MRMSrcMem,
4298 (outs VR256:$dst), (ins VR256:$src1, i256mem:$src2),
4299 !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4300 [(set VR256:$dst, (OpNode VR256:$src1,
4301 (bc_frag (memopv4i64 addr:$src2))))]>;
4304 let Predicates = [HasAVX] in {
4305 defm VPUNPCKLBW : sse2_unpack<0x60, "vpunpcklbw", v16i8, X86Unpckl,
4306 bc_v16i8, 0>, VEX_4V;
4307 defm VPUNPCKLWD : sse2_unpack<0x61, "vpunpcklwd", v8i16, X86Unpckl,
4308 bc_v8i16, 0>, VEX_4V;
4309 defm VPUNPCKLDQ : sse2_unpack<0x62, "vpunpckldq", v4i32, X86Unpckl,
4310 bc_v4i32, 0>, VEX_4V;
4311 defm VPUNPCKLQDQ : sse2_unpack<0x6C, "vpunpcklqdq", v2i64, X86Unpckl,
4312 bc_v2i64, 0>, VEX_4V;
4314 defm VPUNPCKHBW : sse2_unpack<0x68, "vpunpckhbw", v16i8, X86Unpckh,
4315 bc_v16i8, 0>, VEX_4V;
4316 defm VPUNPCKHWD : sse2_unpack<0x69, "vpunpckhwd", v8i16, X86Unpckh,
4317 bc_v8i16, 0>, VEX_4V;
4318 defm VPUNPCKHDQ : sse2_unpack<0x6A, "vpunpckhdq", v4i32, X86Unpckh,
4319 bc_v4i32, 0>, VEX_4V;
4320 defm VPUNPCKHQDQ : sse2_unpack<0x6D, "vpunpckhqdq", v2i64, X86Unpckh,
4321 bc_v2i64, 0>, VEX_4V;
4324 let Predicates = [HasAVX2] in {
4325 defm VPUNPCKLBW : sse2_unpack_y<0x60, "vpunpcklbw", v32i8, X86Unpckl,
4327 defm VPUNPCKLWD : sse2_unpack_y<0x61, "vpunpcklwd", v16i16, X86Unpckl,
4329 defm VPUNPCKLDQ : sse2_unpack_y<0x62, "vpunpckldq", v8i32, X86Unpckl,
4331 defm VPUNPCKLQDQ : sse2_unpack_y<0x6C, "vpunpcklqdq", v4i64, X86Unpckl,
4334 defm VPUNPCKHBW : sse2_unpack_y<0x68, "vpunpckhbw", v32i8, X86Unpckh,
4336 defm VPUNPCKHWD : sse2_unpack_y<0x69, "vpunpckhwd", v16i16, X86Unpckh,
4338 defm VPUNPCKHDQ : sse2_unpack_y<0x6A, "vpunpckhdq", v8i32, X86Unpckh,
4340 defm VPUNPCKHQDQ : sse2_unpack_y<0x6D, "vpunpckhqdq", v4i64, X86Unpckh,
4344 let Constraints = "$src1 = $dst" in {
4345 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, X86Unpckl,
4347 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, X86Unpckl,
4349 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, X86Unpckl,
4351 defm PUNPCKLQDQ : sse2_unpack<0x6C, "punpcklqdq", v2i64, X86Unpckl,
4354 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, X86Unpckh,
4356 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, X86Unpckh,
4358 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, X86Unpckh,
4360 defm PUNPCKHQDQ : sse2_unpack<0x6D, "punpckhqdq", v2i64, X86Unpckh,
4363 } // ExeDomain = SSEPackedInt
4365 // Patterns for using AVX1 instructions with integer vectors
4366 // Here to give AVX2 priority
4367 let Predicates = [HasAVX] in {
4368 def : Pat<(v8i32 (X86Unpckl VR256:$src1, (bc_v8i32 (memopv4i64 addr:$src2)))),
4369 (VUNPCKLPSYrm VR256:$src1, addr:$src2)>;
4370 def : Pat<(v8i32 (X86Unpckl VR256:$src1, VR256:$src2)),
4371 (VUNPCKLPSYrr VR256:$src1, VR256:$src2)>;
4372 def : Pat<(v8i32 (X86Unpckh VR256:$src1, (bc_v8i32 (memopv4i64 addr:$src2)))),
4373 (VUNPCKHPSYrm VR256:$src1, addr:$src2)>;
4374 def : Pat<(v8i32 (X86Unpckh VR256:$src1, VR256:$src2)),
4375 (VUNPCKHPSYrr VR256:$src1, VR256:$src2)>;
4377 def : Pat<(v4i64 (X86Unpckl VR256:$src1, (memopv4i64 addr:$src2))),
4378 (VUNPCKLPDYrm VR256:$src1, addr:$src2)>;
4379 def : Pat<(v4i64 (X86Unpckl VR256:$src1, VR256:$src2)),
4380 (VUNPCKLPDYrr VR256:$src1, VR256:$src2)>;
4381 def : Pat<(v4i64 (X86Unpckh VR256:$src1, (memopv4i64 addr:$src2))),
4382 (VUNPCKHPDYrm VR256:$src1, addr:$src2)>;
4383 def : Pat<(v4i64 (X86Unpckh VR256:$src1, VR256:$src2)),
4384 (VUNPCKHPDYrr VR256:$src1, VR256:$src2)>;
4387 //===---------------------------------------------------------------------===//
4388 // SSE2 - Packed Integer Extract and Insert
4389 //===---------------------------------------------------------------------===//
4391 let ExeDomain = SSEPackedInt in {
4392 multiclass sse2_pinsrw<bit Is2Addr = 1> {
4393 def rri : Ii8<0xC4, MRMSrcReg,
4394 (outs VR128:$dst), (ins VR128:$src1,
4395 GR32:$src2, i32i8imm:$src3),
4397 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
4398 "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4400 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))], IIC_SSE_PINSRW>;
4401 def rmi : Ii8<0xC4, MRMSrcMem,
4402 (outs VR128:$dst), (ins VR128:$src1,
4403 i16mem:$src2, i32i8imm:$src3),
4405 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
4406 "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4408 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
4409 imm:$src3))], IIC_SSE_PINSRW>;
4413 let Predicates = [HasAVX] in
4414 def VPEXTRWri : Ii8<0xC5, MRMSrcReg,
4415 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
4416 "vpextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
4417 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
4418 imm:$src2))]>, TB, OpSize, VEX;
4419 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
4420 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
4421 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
4422 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
4423 imm:$src2))], IIC_SSE_PEXTRW>;
4426 let Predicates = [HasAVX] in {
4427 defm VPINSRW : sse2_pinsrw<0>, TB, OpSize, VEX_4V;
4428 def VPINSRWrr64i : Ii8<0xC4, MRMSrcReg, (outs VR128:$dst),
4429 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
4430 "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
4431 []>, TB, OpSize, VEX_4V;
4434 let Constraints = "$src1 = $dst" in
4435 defm PINSRW : sse2_pinsrw, TB, OpSize, Requires<[HasSSE2]>;
4437 } // ExeDomain = SSEPackedInt
4439 //===---------------------------------------------------------------------===//
4440 // SSE2 - Packed Mask Creation
4441 //===---------------------------------------------------------------------===//
4443 let ExeDomain = SSEPackedInt in {
4445 def VPMOVMSKBrr : VPDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
4446 "pmovmskb\t{$src, $dst|$dst, $src}",
4447 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))],
4448 IIC_SSE_MOVMSK>, VEX;
4449 def VPMOVMSKBr64r : VPDI<0xD7, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
4450 "pmovmskb\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK>, VEX;
4452 let Predicates = [HasAVX2] in {
4453 def VPMOVMSKBYrr : VPDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR256:$src),
4454 "pmovmskb\t{$src, $dst|$dst, $src}",
4455 [(set GR32:$dst, (int_x86_avx2_pmovmskb VR256:$src))]>, VEX;
4456 def VPMOVMSKBYr64r : VPDI<0xD7, MRMSrcReg, (outs GR64:$dst), (ins VR256:$src),
4457 "pmovmskb\t{$src, $dst|$dst, $src}", []>, VEX;
4460 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
4461 "pmovmskb\t{$src, $dst|$dst, $src}",
4462 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))],
4465 } // ExeDomain = SSEPackedInt
4467 //===---------------------------------------------------------------------===//
4468 // SSE2 - Conditional Store
4469 //===---------------------------------------------------------------------===//
4471 let ExeDomain = SSEPackedInt in {
4474 def VMASKMOVDQU : VPDI<0xF7, MRMSrcReg, (outs),
4475 (ins VR128:$src, VR128:$mask),
4476 "maskmovdqu\t{$mask, $src|$src, $mask}",
4477 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)],
4478 IIC_SSE_MASKMOV>, VEX;
4480 def VMASKMOVDQU64 : VPDI<0xF7, MRMSrcReg, (outs),
4481 (ins VR128:$src, VR128:$mask),
4482 "maskmovdqu\t{$mask, $src|$src, $mask}",
4483 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)],
4484 IIC_SSE_MASKMOV>, VEX;
4487 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
4488 "maskmovdqu\t{$mask, $src|$src, $mask}",
4489 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)],
4492 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
4493 "maskmovdqu\t{$mask, $src|$src, $mask}",
4494 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)],
4497 } // ExeDomain = SSEPackedInt
4499 //===---------------------------------------------------------------------===//
4500 // SSE2 - Move Doubleword
4501 //===---------------------------------------------------------------------===//
4503 //===---------------------------------------------------------------------===//
4504 // Move Int Doubleword to Packed Double Int
4506 def VMOVDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
4507 "movd\t{$src, $dst|$dst, $src}",
4509 (v4i32 (scalar_to_vector GR32:$src)))], IIC_SSE_MOVDQ>,
4511 def VMOVDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
4512 "movd\t{$src, $dst|$dst, $src}",
4514 (v4i32 (scalar_to_vector (loadi32 addr:$src))))],
4517 def VMOV64toPQIrr : VRPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4518 "mov{d|q}\t{$src, $dst|$dst, $src}",
4520 (v2i64 (scalar_to_vector GR64:$src)))],
4521 IIC_SSE_MOVDQ>, VEX;
4522 def VMOV64toSDrr : VRPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
4523 "mov{d|q}\t{$src, $dst|$dst, $src}",
4524 [(set FR64:$dst, (bitconvert GR64:$src))],
4525 IIC_SSE_MOVDQ>, VEX;
4527 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
4528 "movd\t{$src, $dst|$dst, $src}",
4530 (v4i32 (scalar_to_vector GR32:$src)))], IIC_SSE_MOVDQ>;
4531 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
4532 "movd\t{$src, $dst|$dst, $src}",
4534 (v4i32 (scalar_to_vector (loadi32 addr:$src))))],
4536 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4537 "mov{d|q}\t{$src, $dst|$dst, $src}",
4539 (v2i64 (scalar_to_vector GR64:$src)))],
4541 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
4542 "mov{d|q}\t{$src, $dst|$dst, $src}",
4543 [(set FR64:$dst, (bitconvert GR64:$src))],
4546 //===---------------------------------------------------------------------===//
4547 // Move Int Doubleword to Single Scalar
4549 def VMOVDI2SSrr : VPDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
4550 "movd\t{$src, $dst|$dst, $src}",
4551 [(set FR32:$dst, (bitconvert GR32:$src))],
4552 IIC_SSE_MOVDQ>, VEX;
4554 def VMOVDI2SSrm : VPDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
4555 "movd\t{$src, $dst|$dst, $src}",
4556 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))],
4559 def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
4560 "movd\t{$src, $dst|$dst, $src}",
4561 [(set FR32:$dst, (bitconvert GR32:$src))],
4564 def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
4565 "movd\t{$src, $dst|$dst, $src}",
4566 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))],
4569 //===---------------------------------------------------------------------===//
4570 // Move Packed Doubleword Int to Packed Double Int
4572 def VMOVPDI2DIrr : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
4573 "movd\t{$src, $dst|$dst, $src}",
4574 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
4575 (iPTR 0)))], IIC_SSE_MOVD_ToGP>, VEX;
4576 def VMOVPDI2DImr : VPDI<0x7E, MRMDestMem, (outs),
4577 (ins i32mem:$dst, VR128:$src),
4578 "movd\t{$src, $dst|$dst, $src}",
4579 [(store (i32 (vector_extract (v4i32 VR128:$src),
4580 (iPTR 0))), addr:$dst)], IIC_SSE_MOVDQ>,
4582 def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
4583 "movd\t{$src, $dst|$dst, $src}",
4584 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
4585 (iPTR 0)))], IIC_SSE_MOVD_ToGP>;
4586 def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
4587 "movd\t{$src, $dst|$dst, $src}",
4588 [(store (i32 (vector_extract (v4i32 VR128:$src),
4589 (iPTR 0))), addr:$dst)],
4592 //===---------------------------------------------------------------------===//
4593 // Move Packed Doubleword Int first element to Doubleword Int
4595 def VMOVPQIto64rr : I<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
4596 "mov{d|q}\t{$src, $dst|$dst, $src}",
4597 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
4600 TB, OpSize, VEX, VEX_W, Requires<[HasAVX, In64BitMode]>;
4602 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
4603 "mov{d|q}\t{$src, $dst|$dst, $src}",
4604 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
4608 //===---------------------------------------------------------------------===//
4609 // Bitcast FR64 <-> GR64
4611 let Predicates = [HasAVX] in
4612 def VMOV64toSDrm : SSDI<0x7E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
4613 "vmovq\t{$src, $dst|$dst, $src}",
4614 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>,
4616 def VMOVSDto64rr : VRPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
4617 "mov{d|q}\t{$src, $dst|$dst, $src}",
4618 [(set GR64:$dst, (bitconvert FR64:$src))],
4619 IIC_SSE_MOVDQ>, VEX;
4620 def VMOVSDto64mr : VRPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
4621 "movq\t{$src, $dst|$dst, $src}",
4622 [(store (i64 (bitconvert FR64:$src)), addr:$dst)],
4623 IIC_SSE_MOVDQ>, VEX;
4625 def MOV64toSDrm : SSDI<0x7E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
4626 "movq\t{$src, $dst|$dst, $src}",
4627 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))],
4629 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
4630 "mov{d|q}\t{$src, $dst|$dst, $src}",
4631 [(set GR64:$dst, (bitconvert FR64:$src))],
4633 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
4634 "movq\t{$src, $dst|$dst, $src}",
4635 [(store (i64 (bitconvert FR64:$src)), addr:$dst)],
4638 //===---------------------------------------------------------------------===//
4639 // Move Scalar Single to Double Int
4641 def VMOVSS2DIrr : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
4642 "movd\t{$src, $dst|$dst, $src}",
4643 [(set GR32:$dst, (bitconvert FR32:$src))],
4644 IIC_SSE_MOVD_ToGP>, VEX;
4645 def VMOVSS2DImr : VPDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
4646 "movd\t{$src, $dst|$dst, $src}",
4647 [(store (i32 (bitconvert FR32:$src)), addr:$dst)],
4648 IIC_SSE_MOVDQ>, VEX;
4649 def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
4650 "movd\t{$src, $dst|$dst, $src}",
4651 [(set GR32:$dst, (bitconvert FR32:$src))],
4653 def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
4654 "movd\t{$src, $dst|$dst, $src}",
4655 [(store (i32 (bitconvert FR32:$src)), addr:$dst)],
4658 //===---------------------------------------------------------------------===//
4659 // Patterns and instructions to describe movd/movq to XMM register zero-extends
4661 let AddedComplexity = 15 in {
4662 def VMOVZDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
4663 "movd\t{$src, $dst|$dst, $src}",
4664 [(set VR128:$dst, (v4i32 (X86vzmovl
4665 (v4i32 (scalar_to_vector GR32:$src)))))],
4666 IIC_SSE_MOVDQ>, VEX;
4667 def VMOVZQI2PQIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4668 "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
4669 [(set VR128:$dst, (v2i64 (X86vzmovl
4670 (v2i64 (scalar_to_vector GR64:$src)))))],
4674 let AddedComplexity = 15 in {
4675 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
4676 "movd\t{$src, $dst|$dst, $src}",
4677 [(set VR128:$dst, (v4i32 (X86vzmovl
4678 (v4i32 (scalar_to_vector GR32:$src)))))],
4680 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4681 "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
4682 [(set VR128:$dst, (v2i64 (X86vzmovl
4683 (v2i64 (scalar_to_vector GR64:$src)))))],
4687 let AddedComplexity = 20 in {
4688 def VMOVZDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
4689 "movd\t{$src, $dst|$dst, $src}",
4691 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
4692 (loadi32 addr:$src))))))],
4693 IIC_SSE_MOVDQ>, VEX;
4694 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
4695 "movd\t{$src, $dst|$dst, $src}",
4697 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
4698 (loadi32 addr:$src))))))],
4702 let Predicates = [HasAVX] in {
4703 // AVX 128-bit movd/movq instruction write zeros in the high 128-bit part.
4704 let AddedComplexity = 20 in {
4705 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
4706 (VMOVZDI2PDIrm addr:$src)>;
4707 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
4708 (VMOVZDI2PDIrm addr:$src)>;
4710 // Use regular 128-bit instructions to match 256-bit scalar_to_vec+zext.
4711 def : Pat<(v8i32 (X86vzmovl (insert_subvector undef,
4712 (v4i32 (scalar_to_vector GR32:$src)),(i32 0)))),
4713 (SUBREG_TO_REG (i32 0), (VMOVZDI2PDIrr GR32:$src), sub_xmm)>;
4714 def : Pat<(v4i64 (X86vzmovl (insert_subvector undef,
4715 (v2i64 (scalar_to_vector GR64:$src)),(i32 0)))),
4716 (SUBREG_TO_REG (i64 0), (VMOVZQI2PQIrr GR64:$src), sub_xmm)>;
4719 let Predicates = [HasSSE2], AddedComplexity = 20 in {
4720 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
4721 (MOVZDI2PDIrm addr:$src)>;
4722 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
4723 (MOVZDI2PDIrm addr:$src)>;
4726 // These are the correct encodings of the instructions so that we know how to
4727 // read correct assembly, even though we continue to emit the wrong ones for
4728 // compatibility with Darwin's buggy assembler.
4729 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4730 (MOV64toPQIrr VR128:$dst, GR64:$src), 0>;
4731 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4732 (MOV64toSDrr FR64:$dst, GR64:$src), 0>;
4733 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4734 (MOVPQIto64rr GR64:$dst, VR128:$src), 0>;
4735 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4736 (MOVSDto64rr GR64:$dst, FR64:$src), 0>;
4737 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4738 (VMOVZQI2PQIrr VR128:$dst, GR64:$src), 0>;
4739 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4740 (MOVZQI2PQIrr VR128:$dst, GR64:$src), 0>;
4742 //===---------------------------------------------------------------------===//
4743 // SSE2 - Move Quadword
4744 //===---------------------------------------------------------------------===//
4746 //===---------------------------------------------------------------------===//
4747 // Move Quadword Int to Packed Quadword Int
4749 def VMOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
4750 "vmovq\t{$src, $dst|$dst, $src}",
4752 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
4753 VEX, Requires<[HasAVX]>;
4754 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
4755 "movq\t{$src, $dst|$dst, $src}",
4757 (v2i64 (scalar_to_vector (loadi64 addr:$src))))],
4759 Requires<[HasSSE2]>; // SSE2 instruction with XS Prefix
4761 //===---------------------------------------------------------------------===//
4762 // Move Packed Quadword Int to Quadword Int
4764 def VMOVPQI2QImr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
4765 "movq\t{$src, $dst|$dst, $src}",
4766 [(store (i64 (vector_extract (v2i64 VR128:$src),
4767 (iPTR 0))), addr:$dst)],
4768 IIC_SSE_MOVDQ>, VEX;
4769 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
4770 "movq\t{$src, $dst|$dst, $src}",
4771 [(store (i64 (vector_extract (v2i64 VR128:$src),
4772 (iPTR 0))), addr:$dst)],
4775 //===---------------------------------------------------------------------===//
4776 // Store / copy lower 64-bits of a XMM register.
4778 def VMOVLQ128mr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
4779 "movq\t{$src, $dst|$dst, $src}",
4780 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>, VEX;
4781 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
4782 "movq\t{$src, $dst|$dst, $src}",
4783 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)],
4786 let AddedComplexity = 20 in
4787 def VMOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
4788 "vmovq\t{$src, $dst|$dst, $src}",
4790 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
4791 (loadi64 addr:$src))))))],
4793 XS, VEX, Requires<[HasAVX]>;
4795 let AddedComplexity = 20 in
4796 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
4797 "movq\t{$src, $dst|$dst, $src}",
4799 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
4800 (loadi64 addr:$src))))))],
4802 XS, Requires<[HasSSE2]>;
4804 let Predicates = [HasAVX], AddedComplexity = 20 in {
4805 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
4806 (VMOVZQI2PQIrm addr:$src)>;
4807 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
4808 (VMOVZQI2PQIrm addr:$src)>;
4809 def : Pat<(v2i64 (X86vzload addr:$src)),
4810 (VMOVZQI2PQIrm addr:$src)>;
4813 let Predicates = [HasSSE2], AddedComplexity = 20 in {
4814 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
4815 (MOVZQI2PQIrm addr:$src)>;
4816 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
4817 (MOVZQI2PQIrm addr:$src)>;
4818 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
4821 let Predicates = [HasAVX] in {
4822 def : Pat<(v4i64 (alignedX86vzload addr:$src)),
4823 (SUBREG_TO_REG (i32 0), (VMOVAPSrm addr:$src), sub_xmm)>;
4824 def : Pat<(v4i64 (X86vzload addr:$src)),
4825 (SUBREG_TO_REG (i32 0), (VMOVUPSrm addr:$src), sub_xmm)>;
4828 //===---------------------------------------------------------------------===//
4829 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
4830 // IA32 document. movq xmm1, xmm2 does clear the high bits.
4832 let AddedComplexity = 15 in
4833 def VMOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4834 "vmovq\t{$src, $dst|$dst, $src}",
4835 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))],
4837 XS, VEX, Requires<[HasAVX]>;
4838 let AddedComplexity = 15 in
4839 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4840 "movq\t{$src, $dst|$dst, $src}",
4841 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))],
4843 XS, Requires<[HasSSE2]>;
4845 let AddedComplexity = 20 in
4846 def VMOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4847 "vmovq\t{$src, $dst|$dst, $src}",
4848 [(set VR128:$dst, (v2i64 (X86vzmovl
4849 (loadv2i64 addr:$src))))],
4851 XS, VEX, Requires<[HasAVX]>;
4852 let AddedComplexity = 20 in {
4853 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4854 "movq\t{$src, $dst|$dst, $src}",
4855 [(set VR128:$dst, (v2i64 (X86vzmovl
4856 (loadv2i64 addr:$src))))],
4858 XS, Requires<[HasSSE2]>;
4861 let AddedComplexity = 20 in {
4862 let Predicates = [HasAVX] in {
4863 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
4864 (VMOVZPQILo2PQIrm addr:$src)>;
4865 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
4866 (VMOVZPQILo2PQIrr VR128:$src)>;
4868 let Predicates = [HasSSE2] in {
4869 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
4870 (MOVZPQILo2PQIrm addr:$src)>;
4871 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
4872 (MOVZPQILo2PQIrr VR128:$src)>;
4876 // Instructions to match in the assembler
4877 def VMOVQs64rr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4878 "movq\t{$src, $dst|$dst, $src}", [],
4879 IIC_SSE_MOVDQ>, VEX, VEX_W;
4880 def VMOVQd64rr : VPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
4881 "movq\t{$src, $dst|$dst, $src}", [],
4882 IIC_SSE_MOVDQ>, VEX, VEX_W;
4883 // Recognize "movd" with GR64 destination, but encode as a "movq"
4884 def VMOVQd64rr_alt : VPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
4885 "movd\t{$src, $dst|$dst, $src}", [],
4886 IIC_SSE_MOVDQ>, VEX, VEX_W;
4888 // Instructions for the disassembler
4889 // xr = XMM register
4892 let Predicates = [HasAVX] in
4893 def VMOVQxrxr: I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4894 "vmovq\t{$src, $dst|$dst, $src}", []>, VEX, XS;
4895 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4896 "movq\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVQ_RR>, XS;
4898 //===---------------------------------------------------------------------===//
4899 // SSE3 - Replicate Single FP - MOVSHDUP and MOVSLDUP
4900 //===---------------------------------------------------------------------===//
4901 multiclass sse3_replicate_sfp<bits<8> op, SDNode OpNode, string OpcodeStr,
4902 ValueType vt, RegisterClass RC, PatFrag mem_frag,
4903 X86MemOperand x86memop> {
4904 def rr : S3SI<op, MRMSrcReg, (outs RC:$dst), (ins RC:$src),
4905 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4906 [(set RC:$dst, (vt (OpNode RC:$src)))],
4908 def rm : S3SI<op, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
4909 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4910 [(set RC:$dst, (OpNode (mem_frag addr:$src)))],
4914 let Predicates = [HasAVX] in {
4915 defm VMOVSHDUP : sse3_replicate_sfp<0x16, X86Movshdup, "vmovshdup",
4916 v4f32, VR128, memopv4f32, f128mem>, VEX;
4917 defm VMOVSLDUP : sse3_replicate_sfp<0x12, X86Movsldup, "vmovsldup",
4918 v4f32, VR128, memopv4f32, f128mem>, VEX;
4919 defm VMOVSHDUPY : sse3_replicate_sfp<0x16, X86Movshdup, "vmovshdup",
4920 v8f32, VR256, memopv8f32, f256mem>, VEX;
4921 defm VMOVSLDUPY : sse3_replicate_sfp<0x12, X86Movsldup, "vmovsldup",
4922 v8f32, VR256, memopv8f32, f256mem>, VEX;
4924 defm MOVSHDUP : sse3_replicate_sfp<0x16, X86Movshdup, "movshdup", v4f32, VR128,
4925 memopv4f32, f128mem>;
4926 defm MOVSLDUP : sse3_replicate_sfp<0x12, X86Movsldup, "movsldup", v4f32, VR128,
4927 memopv4f32, f128mem>;
4929 let Predicates = [HasAVX] in {
4930 def : Pat<(v4i32 (X86Movshdup VR128:$src)),
4931 (VMOVSHDUPrr VR128:$src)>;
4932 def : Pat<(v4i32 (X86Movshdup (bc_v4i32 (memopv2i64 addr:$src)))),
4933 (VMOVSHDUPrm addr:$src)>;
4934 def : Pat<(v4i32 (X86Movsldup VR128:$src)),
4935 (VMOVSLDUPrr VR128:$src)>;
4936 def : Pat<(v4i32 (X86Movsldup (bc_v4i32 (memopv2i64 addr:$src)))),
4937 (VMOVSLDUPrm addr:$src)>;
4938 def : Pat<(v8i32 (X86Movshdup VR256:$src)),
4939 (VMOVSHDUPYrr VR256:$src)>;
4940 def : Pat<(v8i32 (X86Movshdup (bc_v8i32 (memopv4i64 addr:$src)))),
4941 (VMOVSHDUPYrm addr:$src)>;
4942 def : Pat<(v8i32 (X86Movsldup VR256:$src)),
4943 (VMOVSLDUPYrr VR256:$src)>;
4944 def : Pat<(v8i32 (X86Movsldup (bc_v8i32 (memopv4i64 addr:$src)))),
4945 (VMOVSLDUPYrm addr:$src)>;
4948 let Predicates = [HasSSE3] in {
4949 def : Pat<(v4i32 (X86Movshdup VR128:$src)),
4950 (MOVSHDUPrr VR128:$src)>;
4951 def : Pat<(v4i32 (X86Movshdup (bc_v4i32 (memopv2i64 addr:$src)))),
4952 (MOVSHDUPrm addr:$src)>;
4953 def : Pat<(v4i32 (X86Movsldup VR128:$src)),
4954 (MOVSLDUPrr VR128:$src)>;
4955 def : Pat<(v4i32 (X86Movsldup (bc_v4i32 (memopv2i64 addr:$src)))),
4956 (MOVSLDUPrm addr:$src)>;
4959 //===---------------------------------------------------------------------===//
4960 // SSE3 - Replicate Double FP - MOVDDUP
4961 //===---------------------------------------------------------------------===//
4963 multiclass sse3_replicate_dfp<string OpcodeStr> {
4964 let neverHasSideEffects = 1 in
4965 def rr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4966 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4967 [], IIC_SSE_MOV_LH>;
4968 def rm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
4969 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4972 (scalar_to_vector (loadf64 addr:$src)))))],
4976 // FIXME: Merge with above classe when there're patterns for the ymm version
4977 multiclass sse3_replicate_dfp_y<string OpcodeStr> {
4978 def rr : S3DI<0x12, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
4979 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4980 [(set VR256:$dst, (v4f64 (X86Movddup VR256:$src)))]>;
4981 def rm : S3DI<0x12, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
4982 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4985 (scalar_to_vector (loadf64 addr:$src)))))]>;
4988 let Predicates = [HasAVX] in {
4989 defm VMOVDDUP : sse3_replicate_dfp<"vmovddup">, VEX;
4990 defm VMOVDDUPY : sse3_replicate_dfp_y<"vmovddup">, VEX;
4993 defm MOVDDUP : sse3_replicate_dfp<"movddup">;
4995 let Predicates = [HasAVX] in {
4996 def : Pat<(X86Movddup (memopv2f64 addr:$src)),
4997 (VMOVDDUPrm addr:$src)>, Requires<[HasAVX]>;
4998 def : Pat<(X86Movddup (bc_v2f64 (memopv4f32 addr:$src))),
4999 (VMOVDDUPrm addr:$src)>, Requires<[HasAVX]>;
5000 def : Pat<(X86Movddup (bc_v2f64 (memopv2i64 addr:$src))),
5001 (VMOVDDUPrm addr:$src)>, Requires<[HasAVX]>;
5002 def : Pat<(X86Movddup (bc_v2f64
5003 (v2i64 (scalar_to_vector (loadi64 addr:$src))))),
5004 (VMOVDDUPrm addr:$src)>, Requires<[HasAVX]>;
5007 def : Pat<(X86Movddup (memopv4f64 addr:$src)),
5008 (VMOVDDUPYrm addr:$src)>;
5009 def : Pat<(X86Movddup (memopv4i64 addr:$src)),
5010 (VMOVDDUPYrm addr:$src)>;
5011 def : Pat<(X86Movddup (v4i64 (scalar_to_vector (loadi64 addr:$src)))),
5012 (VMOVDDUPYrm addr:$src)>;
5013 def : Pat<(X86Movddup (v4i64 VR256:$src)),
5014 (VMOVDDUPYrr VR256:$src)>;
5017 let Predicates = [HasSSE3] in {
5018 def : Pat<(X86Movddup (memopv2f64 addr:$src)),
5019 (MOVDDUPrm addr:$src)>;
5020 def : Pat<(X86Movddup (bc_v2f64 (memopv4f32 addr:$src))),
5021 (MOVDDUPrm addr:$src)>;
5022 def : Pat<(X86Movddup (bc_v2f64 (memopv2i64 addr:$src))),
5023 (MOVDDUPrm addr:$src)>;
5024 def : Pat<(X86Movddup (bc_v2f64
5025 (v2i64 (scalar_to_vector (loadi64 addr:$src))))),
5026 (MOVDDUPrm addr:$src)>;
5029 //===---------------------------------------------------------------------===//
5030 // SSE3 - Move Unaligned Integer
5031 //===---------------------------------------------------------------------===//
5033 let Predicates = [HasAVX] in {
5034 def VLDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
5035 "vlddqu\t{$src, $dst|$dst, $src}",
5036 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>, VEX;
5037 def VLDDQUYrm : S3DI<0xF0, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
5038 "vlddqu\t{$src, $dst|$dst, $src}",
5039 [(set VR256:$dst, (int_x86_avx_ldu_dq_256 addr:$src))]>, VEX;
5041 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
5042 "lddqu\t{$src, $dst|$dst, $src}",
5043 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))],
5046 //===---------------------------------------------------------------------===//
5047 // SSE3 - Arithmetic
5048 //===---------------------------------------------------------------------===//
5050 multiclass sse3_addsub<Intrinsic Int, string OpcodeStr, RegisterClass RC,
5051 X86MemOperand x86memop, OpndItins itins,
5053 def rr : I<0xD0, MRMSrcReg,
5054 (outs RC:$dst), (ins RC:$src1, RC:$src2),
5056 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5057 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5058 [(set RC:$dst, (Int RC:$src1, RC:$src2))], itins.rr>;
5059 def rm : I<0xD0, MRMSrcMem,
5060 (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
5062 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5063 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5064 [(set RC:$dst, (Int RC:$src1, (memop addr:$src2)))], itins.rr>;
5067 let Predicates = [HasAVX] in {
5068 let ExeDomain = SSEPackedSingle in {
5069 defm VADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "vaddsubps", VR128,
5070 f128mem, SSE_ALU_F32P, 0>, TB, XD, VEX_4V;
5071 defm VADDSUBPSY : sse3_addsub<int_x86_avx_addsub_ps_256, "vaddsubps", VR256,
5072 f256mem, SSE_ALU_F32P, 0>, TB, XD, VEX_4V;
5074 let ExeDomain = SSEPackedDouble in {
5075 defm VADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "vaddsubpd", VR128,
5076 f128mem, SSE_ALU_F64P, 0>, TB, OpSize, VEX_4V;
5077 defm VADDSUBPDY : sse3_addsub<int_x86_avx_addsub_pd_256, "vaddsubpd", VR256,
5078 f256mem, SSE_ALU_F64P, 0>, TB, OpSize, VEX_4V;
5081 let Constraints = "$src1 = $dst", Predicates = [HasSSE3] in {
5082 let ExeDomain = SSEPackedSingle in
5083 defm ADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "addsubps", VR128,
5084 f128mem, SSE_ALU_F32P>, TB, XD;
5085 let ExeDomain = SSEPackedDouble in
5086 defm ADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "addsubpd", VR128,
5087 f128mem, SSE_ALU_F64P>, TB, OpSize;
5090 //===---------------------------------------------------------------------===//
5091 // SSE3 Instructions
5092 //===---------------------------------------------------------------------===//
5095 multiclass S3D_Int<bits<8> o, string OpcodeStr, ValueType vt, RegisterClass RC,
5096 X86MemOperand x86memop, SDNode OpNode, bit Is2Addr = 1> {
5097 def rr : S3DI<o, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
5099 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5100 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5101 [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))], IIC_SSE_HADDSUB_RR>;
5103 def rm : S3DI<o, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
5105 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5106 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5107 [(set RC:$dst, (vt (OpNode RC:$src1, (memop addr:$src2))))],
5108 IIC_SSE_HADDSUB_RM>;
5110 multiclass S3_Int<bits<8> o, string OpcodeStr, ValueType vt, RegisterClass RC,
5111 X86MemOperand x86memop, SDNode OpNode, bit Is2Addr = 1> {
5112 def rr : S3I<o, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
5114 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5115 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5116 [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))], IIC_SSE_HADDSUB_RR>;
5118 def rm : S3I<o, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
5120 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5121 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5122 [(set RC:$dst, (vt (OpNode RC:$src1, (memop addr:$src2))))],
5123 IIC_SSE_HADDSUB_RM>;
5126 let Predicates = [HasAVX] in {
5127 let ExeDomain = SSEPackedSingle in {
5128 defm VHADDPS : S3D_Int<0x7C, "vhaddps", v4f32, VR128, f128mem,
5129 X86fhadd, 0>, VEX_4V;
5130 defm VHSUBPS : S3D_Int<0x7D, "vhsubps", v4f32, VR128, f128mem,
5131 X86fhsub, 0>, VEX_4V;
5132 defm VHADDPSY : S3D_Int<0x7C, "vhaddps", v8f32, VR256, f256mem,
5133 X86fhadd, 0>, VEX_4V;
5134 defm VHSUBPSY : S3D_Int<0x7D, "vhsubps", v8f32, VR256, f256mem,
5135 X86fhsub, 0>, VEX_4V;
5137 let ExeDomain = SSEPackedDouble in {
5138 defm VHADDPD : S3_Int <0x7C, "vhaddpd", v2f64, VR128, f128mem,
5139 X86fhadd, 0>, VEX_4V;
5140 defm VHSUBPD : S3_Int <0x7D, "vhsubpd", v2f64, VR128, f128mem,
5141 X86fhsub, 0>, VEX_4V;
5142 defm VHADDPDY : S3_Int <0x7C, "vhaddpd", v4f64, VR256, f256mem,
5143 X86fhadd, 0>, VEX_4V;
5144 defm VHSUBPDY : S3_Int <0x7D, "vhsubpd", v4f64, VR256, f256mem,
5145 X86fhsub, 0>, VEX_4V;
5149 let Constraints = "$src1 = $dst" in {
5150 let ExeDomain = SSEPackedSingle in {
5151 defm HADDPS : S3D_Int<0x7C, "haddps", v4f32, VR128, f128mem, X86fhadd>;
5152 defm HSUBPS : S3D_Int<0x7D, "hsubps", v4f32, VR128, f128mem, X86fhsub>;
5154 let ExeDomain = SSEPackedDouble in {
5155 defm HADDPD : S3_Int<0x7C, "haddpd", v2f64, VR128, f128mem, X86fhadd>;
5156 defm HSUBPD : S3_Int<0x7D, "hsubpd", v2f64, VR128, f128mem, X86fhsub>;
5160 //===---------------------------------------------------------------------===//
5161 // SSSE3 - Packed Absolute Instructions
5162 //===---------------------------------------------------------------------===//
5165 /// SS3I_unop_rm_int - Simple SSSE3 unary op whose type can be v*{i8,i16,i32}.
5166 multiclass SS3I_unop_rm_int<bits<8> opc, string OpcodeStr,
5167 Intrinsic IntId128> {
5168 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
5170 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5171 [(set VR128:$dst, (IntId128 VR128:$src))], IIC_SSE_PABS_RR>,
5174 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
5176 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5179 (bitconvert (memopv2i64 addr:$src))))], IIC_SSE_PABS_RM>,
5183 /// SS3I_unop_rm_int_y - Simple SSSE3 unary op whose type can be v*{i8,i16,i32}.
5184 multiclass SS3I_unop_rm_int_y<bits<8> opc, string OpcodeStr,
5185 Intrinsic IntId256> {
5186 def rr256 : SS38I<opc, MRMSrcReg, (outs VR256:$dst),
5188 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5189 [(set VR256:$dst, (IntId256 VR256:$src))]>,
5192 def rm256 : SS38I<opc, MRMSrcMem, (outs VR256:$dst),
5194 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5197 (bitconvert (memopv4i64 addr:$src))))]>, OpSize;
5200 let Predicates = [HasAVX] in {
5201 defm VPABSB : SS3I_unop_rm_int<0x1C, "vpabsb",
5202 int_x86_ssse3_pabs_b_128>, VEX;
5203 defm VPABSW : SS3I_unop_rm_int<0x1D, "vpabsw",
5204 int_x86_ssse3_pabs_w_128>, VEX;
5205 defm VPABSD : SS3I_unop_rm_int<0x1E, "vpabsd",
5206 int_x86_ssse3_pabs_d_128>, VEX;
5209 let Predicates = [HasAVX2] in {
5210 defm VPABSB : SS3I_unop_rm_int_y<0x1C, "vpabsb",
5211 int_x86_avx2_pabs_b>, VEX;
5212 defm VPABSW : SS3I_unop_rm_int_y<0x1D, "vpabsw",
5213 int_x86_avx2_pabs_w>, VEX;
5214 defm VPABSD : SS3I_unop_rm_int_y<0x1E, "vpabsd",
5215 int_x86_avx2_pabs_d>, VEX;
5218 defm PABSB : SS3I_unop_rm_int<0x1C, "pabsb",
5219 int_x86_ssse3_pabs_b_128>;
5220 defm PABSW : SS3I_unop_rm_int<0x1D, "pabsw",
5221 int_x86_ssse3_pabs_w_128>;
5222 defm PABSD : SS3I_unop_rm_int<0x1E, "pabsd",
5223 int_x86_ssse3_pabs_d_128>;
5225 //===---------------------------------------------------------------------===//
5226 // SSSE3 - Packed Binary Operator Instructions
5227 //===---------------------------------------------------------------------===//
5229 def SSE_PHADDSUBD : OpndItins<
5230 IIC_SSE_PHADDSUBD_RR, IIC_SSE_PHADDSUBD_RM
5232 def SSE_PHADDSUBSW : OpndItins<
5233 IIC_SSE_PHADDSUBSW_RR, IIC_SSE_PHADDSUBSW_RM
5235 def SSE_PHADDSUBW : OpndItins<
5236 IIC_SSE_PHADDSUBW_RR, IIC_SSE_PHADDSUBW_RM
5238 def SSE_PSHUFB : OpndItins<
5239 IIC_SSE_PSHUFB_RR, IIC_SSE_PSHUFB_RM
5241 def SSE_PSIGN : OpndItins<
5242 IIC_SSE_PSIGN_RR, IIC_SSE_PSIGN_RM
5244 def SSE_PMULHRSW : OpndItins<
5245 IIC_SSE_PMULHRSW, IIC_SSE_PMULHRSW
5248 /// SS3I_binop_rm - Simple SSSE3 bin op
5249 multiclass SS3I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
5250 ValueType OpVT, RegisterClass RC, PatFrag memop_frag,
5251 X86MemOperand x86memop, OpndItins itins,
5253 let isCommutable = 1 in
5254 def rr : SS38I<opc, MRMSrcReg, (outs RC:$dst),
5255 (ins RC:$src1, RC:$src2),
5257 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5258 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5259 [(set RC:$dst, (OpVT (OpNode RC:$src1, RC:$src2)))], itins.rr>,
5261 def rm : SS38I<opc, MRMSrcMem, (outs RC:$dst),
5262 (ins RC:$src1, x86memop:$src2),
5264 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5265 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5267 (OpVT (OpNode RC:$src1,
5268 (bitconvert (memop_frag addr:$src2)))))], itins.rm>, OpSize;
5271 /// SS3I_binop_rm_int - Simple SSSE3 bin op whose type can be v*{i8,i16,i32}.
5272 multiclass SS3I_binop_rm_int<bits<8> opc, string OpcodeStr,
5273 Intrinsic IntId128, OpndItins itins,
5275 let isCommutable = 1 in
5276 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
5277 (ins VR128:$src1, VR128:$src2),
5279 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5280 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5281 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
5283 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
5284 (ins VR128:$src1, i128mem:$src2),
5286 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5287 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5289 (IntId128 VR128:$src1,
5290 (bitconvert (memopv2i64 addr:$src2))))]>, OpSize;
5293 multiclass SS3I_binop_rm_int_y<bits<8> opc, string OpcodeStr,
5294 Intrinsic IntId256> {
5295 let isCommutable = 1 in
5296 def rr256 : SS38I<opc, MRMSrcReg, (outs VR256:$dst),
5297 (ins VR256:$src1, VR256:$src2),
5298 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5299 [(set VR256:$dst, (IntId256 VR256:$src1, VR256:$src2))]>,
5301 def rm256 : SS38I<opc, MRMSrcMem, (outs VR256:$dst),
5302 (ins VR256:$src1, i256mem:$src2),
5303 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5305 (IntId256 VR256:$src1,
5306 (bitconvert (memopv4i64 addr:$src2))))]>, OpSize;
5309 let ImmT = NoImm, Predicates = [HasAVX] in {
5310 let isCommutable = 0 in {
5311 defm VPHADDW : SS3I_binop_rm<0x01, "vphaddw", X86hadd, v8i16, VR128,
5312 memopv2i64, i128mem,
5313 SSE_PHADDSUBW, 0>, VEX_4V;
5314 defm VPHADDD : SS3I_binop_rm<0x02, "vphaddd", X86hadd, v4i32, VR128,
5315 memopv2i64, i128mem,
5316 SSE_PHADDSUBD, 0>, VEX_4V;
5317 defm VPHSUBW : SS3I_binop_rm<0x05, "vphsubw", X86hsub, v8i16, VR128,
5318 memopv2i64, i128mem,
5319 SSE_PHADDSUBW, 0>, VEX_4V;
5320 defm VPHSUBD : SS3I_binop_rm<0x06, "vphsubd", X86hsub, v4i32, VR128,
5321 memopv2i64, i128mem,
5322 SSE_PHADDSUBD, 0>, VEX_4V;
5323 defm VPSIGNB : SS3I_binop_rm<0x08, "vpsignb", X86psign, v16i8, VR128,
5324 memopv2i64, i128mem,
5325 SSE_PSIGN, 0>, VEX_4V;
5326 defm VPSIGNW : SS3I_binop_rm<0x09, "vpsignw", X86psign, v8i16, VR128,
5327 memopv2i64, i128mem,
5328 SSE_PSIGN, 0>, VEX_4V;
5329 defm VPSIGND : SS3I_binop_rm<0x0A, "vpsignd", X86psign, v4i32, VR128,
5330 memopv2i64, i128mem,
5331 SSE_PSIGN, 0>, VEX_4V;
5332 defm VPSHUFB : SS3I_binop_rm<0x00, "vpshufb", X86pshufb, v16i8, VR128,
5333 memopv2i64, i128mem,
5334 SSE_PSHUFB, 0>, VEX_4V;
5335 defm VPHADDSW : SS3I_binop_rm_int<0x03, "vphaddsw",
5336 int_x86_ssse3_phadd_sw_128,
5337 SSE_PHADDSUBSW, 0>, VEX_4V;
5338 defm VPHSUBSW : SS3I_binop_rm_int<0x07, "vphsubsw",
5339 int_x86_ssse3_phsub_sw_128,
5340 SSE_PHADDSUBSW, 0>, VEX_4V;
5341 defm VPMADDUBSW : SS3I_binop_rm_int<0x04, "vpmaddubsw",
5342 int_x86_ssse3_pmadd_ub_sw_128,
5343 SSE_PMADD, 0>, VEX_4V;
5345 defm VPMULHRSW : SS3I_binop_rm_int<0x0B, "vpmulhrsw",
5346 int_x86_ssse3_pmul_hr_sw_128,
5347 SSE_PMULHRSW, 0>, VEX_4V;
5350 let ImmT = NoImm, Predicates = [HasAVX2] in {
5351 let isCommutable = 0 in {
5352 defm VPHADDWY : SS3I_binop_rm<0x01, "vphaddw", X86hadd, v16i16, VR256,
5353 memopv4i64, i256mem,
5354 SSE_PHADDSUBW, 0>, VEX_4V;
5355 defm VPHADDDY : SS3I_binop_rm<0x02, "vphaddd", X86hadd, v8i32, VR256,
5356 memopv4i64, i256mem,
5357 SSE_PHADDSUBW, 0>, VEX_4V;
5358 defm VPHSUBWY : SS3I_binop_rm<0x05, "vphsubw", X86hsub, v16i16, VR256,
5359 memopv4i64, i256mem,
5360 SSE_PHADDSUBW, 0>, VEX_4V;
5361 defm VPHSUBDY : SS3I_binop_rm<0x06, "vphsubd", X86hsub, v8i32, VR256,
5362 memopv4i64, i256mem,
5363 SSE_PHADDSUBW, 0>, VEX_4V;
5364 defm VPSIGNBY : SS3I_binop_rm<0x08, "vpsignb", X86psign, v32i8, VR256,
5365 memopv4i64, i256mem,
5366 SSE_PHADDSUBW, 0>, VEX_4V;
5367 defm VPSIGNWY : SS3I_binop_rm<0x09, "vpsignw", X86psign, v16i16, VR256,
5368 memopv4i64, i256mem,
5369 SSE_PHADDSUBW, 0>, VEX_4V;
5370 defm VPSIGNDY : SS3I_binop_rm<0x0A, "vpsignd", X86psign, v8i32, VR256,
5371 memopv4i64, i256mem,
5372 SSE_PHADDSUBW, 0>, VEX_4V;
5373 defm VPSHUFBY : SS3I_binop_rm<0x00, "vpshufb", X86pshufb, v32i8, VR256,
5374 memopv4i64, i256mem,
5375 SSE_PHADDSUBW, 0>, VEX_4V;
5376 defm VPHADDSW : SS3I_binop_rm_int_y<0x03, "vphaddsw",
5377 int_x86_avx2_phadd_sw>, VEX_4V;
5378 defm VPHSUBSW : SS3I_binop_rm_int_y<0x07, "vphsubsw",
5379 int_x86_avx2_phsub_sw>, VEX_4V;
5380 defm VPMADDUBSW : SS3I_binop_rm_int_y<0x04, "vpmaddubsw",
5381 int_x86_avx2_pmadd_ub_sw>, VEX_4V;
5383 defm VPMULHRSW : SS3I_binop_rm_int_y<0x0B, "vpmulhrsw",
5384 int_x86_avx2_pmul_hr_sw>, VEX_4V;
5387 // None of these have i8 immediate fields.
5388 let ImmT = NoImm, Constraints = "$src1 = $dst" in {
5389 let isCommutable = 0 in {
5390 defm PHADDW : SS3I_binop_rm<0x01, "phaddw", X86hadd, v8i16, VR128,
5391 memopv2i64, i128mem, SSE_PHADDSUBW>;
5392 defm PHADDD : SS3I_binop_rm<0x02, "phaddd", X86hadd, v4i32, VR128,
5393 memopv2i64, i128mem, SSE_PHADDSUBD>;
5394 defm PHSUBW : SS3I_binop_rm<0x05, "phsubw", X86hsub, v8i16, VR128,
5395 memopv2i64, i128mem, SSE_PHADDSUBW>;
5396 defm PHSUBD : SS3I_binop_rm<0x06, "phsubd", X86hsub, v4i32, VR128,
5397 memopv2i64, i128mem, SSE_PHADDSUBD>;
5398 defm PSIGNB : SS3I_binop_rm<0x08, "psignb", X86psign, v16i8, VR128,
5399 memopv2i64, i128mem, SSE_PSIGN>;
5400 defm PSIGNW : SS3I_binop_rm<0x09, "psignw", X86psign, v8i16, VR128,
5401 memopv2i64, i128mem, SSE_PSIGN>;
5402 defm PSIGND : SS3I_binop_rm<0x0A, "psignd", X86psign, v4i32, VR128,
5403 memopv2i64, i128mem, SSE_PSIGN>;
5404 defm PSHUFB : SS3I_binop_rm<0x00, "pshufb", X86pshufb, v16i8, VR128,
5405 memopv2i64, i128mem, SSE_PSHUFB>;
5406 defm PHADDSW : SS3I_binop_rm_int<0x03, "phaddsw",
5407 int_x86_ssse3_phadd_sw_128,
5409 defm PHSUBSW : SS3I_binop_rm_int<0x07, "phsubsw",
5410 int_x86_ssse3_phsub_sw_128,
5412 defm PMADDUBSW : SS3I_binop_rm_int<0x04, "pmaddubsw",
5413 int_x86_ssse3_pmadd_ub_sw_128, SSE_PMADD>;
5415 defm PMULHRSW : SS3I_binop_rm_int<0x0B, "pmulhrsw",
5416 int_x86_ssse3_pmul_hr_sw_128,
5420 //===---------------------------------------------------------------------===//
5421 // SSSE3 - Packed Align Instruction Patterns
5422 //===---------------------------------------------------------------------===//
5424 multiclass ssse3_palign<string asm, bit Is2Addr = 1> {
5425 let neverHasSideEffects = 1 in {
5426 def R128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
5427 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
5429 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5431 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5432 [], IIC_SSE_PALIGNR>, OpSize;
5434 def R128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
5435 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
5437 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5439 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5440 [], IIC_SSE_PALIGNR>, OpSize;
5444 multiclass ssse3_palign_y<string asm, bit Is2Addr = 1> {
5445 let neverHasSideEffects = 1 in {
5446 def R256rr : SS3AI<0x0F, MRMSrcReg, (outs VR256:$dst),
5447 (ins VR256:$src1, VR256:$src2, i8imm:$src3),
5449 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
5452 def R256rm : SS3AI<0x0F, MRMSrcMem, (outs VR256:$dst),
5453 (ins VR256:$src1, i256mem:$src2, i8imm:$src3),
5455 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
5460 let Predicates = [HasAVX] in
5461 defm VPALIGN : ssse3_palign<"vpalignr", 0>, VEX_4V;
5462 let Predicates = [HasAVX2] in
5463 defm VPALIGN : ssse3_palign_y<"vpalignr", 0>, VEX_4V;
5464 let Constraints = "$src1 = $dst", Predicates = [HasSSSE3] in
5465 defm PALIGN : ssse3_palign<"palignr">;
5467 let Predicates = [HasAVX2] in {
5468 def : Pat<(v8i32 (X86PAlign VR256:$src1, VR256:$src2, (i8 imm:$imm))),
5469 (VPALIGNR256rr VR256:$src2, VR256:$src1, imm:$imm)>;
5470 def : Pat<(v8f32 (X86PAlign VR256:$src1, VR256:$src2, (i8 imm:$imm))),
5471 (VPALIGNR256rr VR256:$src2, VR256:$src1, imm:$imm)>;
5472 def : Pat<(v16i16 (X86PAlign VR256:$src1, VR256:$src2, (i8 imm:$imm))),
5473 (VPALIGNR256rr VR256:$src2, VR256:$src1, imm:$imm)>;
5474 def : Pat<(v32i8 (X86PAlign VR256:$src1, VR256:$src2, (i8 imm:$imm))),
5475 (VPALIGNR256rr VR256:$src2, VR256:$src1, imm:$imm)>;
5478 let Predicates = [HasAVX] in {
5479 def : Pat<(v4i32 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5480 (VPALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5481 def : Pat<(v4f32 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5482 (VPALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5483 def : Pat<(v8i16 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5484 (VPALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5485 def : Pat<(v16i8 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5486 (VPALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5489 let Predicates = [HasSSSE3] in {
5490 def : Pat<(v4i32 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5491 (PALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5492 def : Pat<(v4f32 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5493 (PALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5494 def : Pat<(v8i16 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5495 (PALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5496 def : Pat<(v16i8 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5497 (PALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5500 //===---------------------------------------------------------------------===//
5501 // SSSE3 - Thread synchronization
5502 //===---------------------------------------------------------------------===//
5504 let usesCustomInserter = 1 in {
5505 def MONITOR : PseudoI<(outs), (ins i32mem:$src1, GR32:$src2, GR32:$src3),
5506 [(int_x86_sse3_monitor addr:$src1, GR32:$src2, GR32:$src3)]>,
5507 Requires<[HasSSE3]>;
5508 def MWAIT : PseudoI<(outs), (ins GR32:$src1, GR32:$src2),
5509 [(int_x86_sse3_mwait GR32:$src1, GR32:$src2)]>,
5510 Requires<[HasSSE3]>;
5513 let Uses = [EAX, ECX, EDX] in
5514 def MONITORrrr : I<0x01, MRM_C8, (outs), (ins), "monitor", [], IIC_SSE_MONITOR>,
5515 TB, Requires<[HasSSE3]>;
5516 let Uses = [ECX, EAX] in
5517 def MWAITrr : I<0x01, MRM_C9, (outs), (ins), "mwait", [], IIC_SSE_MWAIT>,
5518 TB, Requires<[HasSSE3]>;
5520 def : InstAlias<"mwait %eax, %ecx", (MWAITrr)>, Requires<[In32BitMode]>;
5521 def : InstAlias<"mwait %rax, %rcx", (MWAITrr)>, Requires<[In64BitMode]>;
5523 def : InstAlias<"monitor %eax, %ecx, %edx", (MONITORrrr)>,
5524 Requires<[In32BitMode]>;
5525 def : InstAlias<"monitor %rax, %rcx, %rdx", (MONITORrrr)>,
5526 Requires<[In64BitMode]>;
5528 //===----------------------------------------------------------------------===//
5529 // SSE4.1 - Packed Move with Sign/Zero Extend
5530 //===----------------------------------------------------------------------===//
5532 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
5533 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
5534 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5535 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
5537 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
5538 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5540 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
5544 multiclass SS41I_binop_rm_int16_y<bits<8> opc, string OpcodeStr,
5546 def Yrr : SS48I<opc, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
5547 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5548 [(set VR256:$dst, (IntId VR128:$src))]>, OpSize;
5550 def Yrm : SS48I<opc, MRMSrcMem, (outs VR256:$dst), (ins i128mem:$src),
5551 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5552 [(set VR256:$dst, (IntId (load addr:$src)))]>, OpSize;
5555 let Predicates = [HasAVX] in {
5556 defm VPMOVSXBW : SS41I_binop_rm_int8<0x20, "vpmovsxbw", int_x86_sse41_pmovsxbw>,
5558 defm VPMOVSXWD : SS41I_binop_rm_int8<0x23, "vpmovsxwd", int_x86_sse41_pmovsxwd>,
5560 defm VPMOVSXDQ : SS41I_binop_rm_int8<0x25, "vpmovsxdq", int_x86_sse41_pmovsxdq>,
5562 defm VPMOVZXBW : SS41I_binop_rm_int8<0x30, "vpmovzxbw", int_x86_sse41_pmovzxbw>,
5564 defm VPMOVZXWD : SS41I_binop_rm_int8<0x33, "vpmovzxwd", int_x86_sse41_pmovzxwd>,
5566 defm VPMOVZXDQ : SS41I_binop_rm_int8<0x35, "vpmovzxdq", int_x86_sse41_pmovzxdq>,
5570 let Predicates = [HasAVX2] in {
5571 defm VPMOVSXBW : SS41I_binop_rm_int16_y<0x20, "vpmovsxbw",
5572 int_x86_avx2_pmovsxbw>, VEX;
5573 defm VPMOVSXWD : SS41I_binop_rm_int16_y<0x23, "vpmovsxwd",
5574 int_x86_avx2_pmovsxwd>, VEX;
5575 defm VPMOVSXDQ : SS41I_binop_rm_int16_y<0x25, "vpmovsxdq",
5576 int_x86_avx2_pmovsxdq>, VEX;
5577 defm VPMOVZXBW : SS41I_binop_rm_int16_y<0x30, "vpmovzxbw",
5578 int_x86_avx2_pmovzxbw>, VEX;
5579 defm VPMOVZXWD : SS41I_binop_rm_int16_y<0x33, "vpmovzxwd",
5580 int_x86_avx2_pmovzxwd>, VEX;
5581 defm VPMOVZXDQ : SS41I_binop_rm_int16_y<0x35, "vpmovzxdq",
5582 int_x86_avx2_pmovzxdq>, VEX;
5585 defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
5586 defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
5587 defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
5588 defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
5589 defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
5590 defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
5592 let Predicates = [HasAVX] in {
5593 // Common patterns involving scalar load.
5594 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
5595 (VPMOVSXBWrm addr:$src)>;
5596 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
5597 (VPMOVSXBWrm addr:$src)>;
5599 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
5600 (VPMOVSXWDrm addr:$src)>;
5601 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
5602 (VPMOVSXWDrm addr:$src)>;
5604 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
5605 (VPMOVSXDQrm addr:$src)>;
5606 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
5607 (VPMOVSXDQrm addr:$src)>;
5609 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
5610 (VPMOVZXBWrm addr:$src)>;
5611 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
5612 (VPMOVZXBWrm addr:$src)>;
5614 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
5615 (VPMOVZXWDrm addr:$src)>;
5616 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
5617 (VPMOVZXWDrm addr:$src)>;
5619 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
5620 (VPMOVZXDQrm addr:$src)>;
5621 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
5622 (VPMOVZXDQrm addr:$src)>;
5625 let Predicates = [HasSSE41] in {
5626 // Common patterns involving scalar load.
5627 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
5628 (PMOVSXBWrm addr:$src)>;
5629 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
5630 (PMOVSXBWrm addr:$src)>;
5632 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
5633 (PMOVSXWDrm addr:$src)>;
5634 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
5635 (PMOVSXWDrm addr:$src)>;
5637 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
5638 (PMOVSXDQrm addr:$src)>;
5639 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
5640 (PMOVSXDQrm addr:$src)>;
5642 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
5643 (PMOVZXBWrm addr:$src)>;
5644 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
5645 (PMOVZXBWrm addr:$src)>;
5647 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
5648 (PMOVZXWDrm addr:$src)>;
5649 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
5650 (PMOVZXWDrm addr:$src)>;
5652 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
5653 (PMOVZXDQrm addr:$src)>;
5654 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
5655 (PMOVZXDQrm addr:$src)>;
5658 let Predicates = [HasAVX2] in {
5659 let AddedComplexity = 15 in {
5660 def : Pat<(v4i64 (X86vzmovly (v4i32 VR128:$src))),
5661 (VPMOVZXDQYrr VR128:$src)>;
5662 def : Pat<(v8i32 (X86vzmovly (v8i16 VR128:$src))),
5663 (VPMOVZXWDYrr VR128:$src)>;
5666 def : Pat<(v4i64 (X86vsmovl (v4i32 VR128:$src))), (VPMOVSXDQYrr VR128:$src)>;
5667 def : Pat<(v8i32 (X86vsmovl (v8i16 VR128:$src))), (VPMOVSXWDYrr VR128:$src)>;
5670 let Predicates = [HasAVX] in {
5671 def : Pat<(v2i64 (X86vsmovl (v4i32 VR128:$src))), (VPMOVSXDQrr VR128:$src)>;
5672 def : Pat<(v4i32 (X86vsmovl (v8i16 VR128:$src))), (VPMOVSXWDrr VR128:$src)>;
5675 let Predicates = [HasSSE41] in {
5676 def : Pat<(v2i64 (X86vsmovl (v4i32 VR128:$src))), (PMOVSXDQrr VR128:$src)>;
5677 def : Pat<(v4i32 (X86vsmovl (v8i16 VR128:$src))), (PMOVSXWDrr VR128:$src)>;
5681 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
5682 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
5683 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5684 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
5686 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
5687 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5689 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
5693 multiclass SS41I_binop_rm_int8_y<bits<8> opc, string OpcodeStr,
5695 def Yrr : SS48I<opc, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
5696 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5697 [(set VR256:$dst, (IntId VR128:$src))]>, OpSize;
5699 def Yrm : SS48I<opc, MRMSrcMem, (outs VR256:$dst), (ins i32mem:$src),
5700 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5702 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
5706 let Predicates = [HasAVX] in {
5707 defm VPMOVSXBD : SS41I_binop_rm_int4<0x21, "vpmovsxbd", int_x86_sse41_pmovsxbd>,
5709 defm VPMOVSXWQ : SS41I_binop_rm_int4<0x24, "vpmovsxwq", int_x86_sse41_pmovsxwq>,
5711 defm VPMOVZXBD : SS41I_binop_rm_int4<0x31, "vpmovzxbd", int_x86_sse41_pmovzxbd>,
5713 defm VPMOVZXWQ : SS41I_binop_rm_int4<0x34, "vpmovzxwq", int_x86_sse41_pmovzxwq>,
5717 let Predicates = [HasAVX2] in {
5718 defm VPMOVSXBD : SS41I_binop_rm_int8_y<0x21, "vpmovsxbd",
5719 int_x86_avx2_pmovsxbd>, VEX;
5720 defm VPMOVSXWQ : SS41I_binop_rm_int8_y<0x24, "vpmovsxwq",
5721 int_x86_avx2_pmovsxwq>, VEX;
5722 defm VPMOVZXBD : SS41I_binop_rm_int8_y<0x31, "vpmovzxbd",
5723 int_x86_avx2_pmovzxbd>, VEX;
5724 defm VPMOVZXWQ : SS41I_binop_rm_int8_y<0x34, "vpmovzxwq",
5725 int_x86_avx2_pmovzxwq>, VEX;
5728 defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
5729 defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
5730 defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
5731 defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
5733 let Predicates = [HasAVX] in {
5734 // Common patterns involving scalar load
5735 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
5736 (VPMOVSXBDrm addr:$src)>;
5737 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
5738 (VPMOVSXWQrm addr:$src)>;
5740 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
5741 (VPMOVZXBDrm addr:$src)>;
5742 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
5743 (VPMOVZXWQrm addr:$src)>;
5746 let Predicates = [HasSSE41] in {
5747 // Common patterns involving scalar load
5748 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
5749 (PMOVSXBDrm addr:$src)>;
5750 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
5751 (PMOVSXWQrm addr:$src)>;
5753 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
5754 (PMOVZXBDrm addr:$src)>;
5755 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
5756 (PMOVZXWQrm addr:$src)>;
5759 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
5760 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
5761 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5762 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
5764 // Expecting a i16 load any extended to i32 value.
5765 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
5766 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5767 [(set VR128:$dst, (IntId (bitconvert
5768 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
5772 multiclass SS41I_binop_rm_int4_y<bits<8> opc, string OpcodeStr,
5774 def Yrr : SS48I<opc, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
5775 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5776 [(set VR256:$dst, (IntId VR128:$src))]>, OpSize;
5778 // Expecting a i16 load any extended to i32 value.
5779 def Yrm : SS48I<opc, MRMSrcMem, (outs VR256:$dst), (ins i16mem:$src),
5780 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5781 [(set VR256:$dst, (IntId (bitconvert
5782 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
5786 let Predicates = [HasAVX] in {
5787 defm VPMOVSXBQ : SS41I_binop_rm_int2<0x22, "vpmovsxbq", int_x86_sse41_pmovsxbq>,
5789 defm VPMOVZXBQ : SS41I_binop_rm_int2<0x32, "vpmovzxbq", int_x86_sse41_pmovzxbq>,
5792 let Predicates = [HasAVX2] in {
5793 defm VPMOVSXBQ : SS41I_binop_rm_int4_y<0x22, "vpmovsxbq",
5794 int_x86_avx2_pmovsxbq>, VEX;
5795 defm VPMOVZXBQ : SS41I_binop_rm_int4_y<0x32, "vpmovzxbq",
5796 int_x86_avx2_pmovzxbq>, VEX;
5798 defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
5799 defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
5801 let Predicates = [HasAVX] in {
5802 // Common patterns involving scalar load
5803 def : Pat<(int_x86_sse41_pmovsxbq
5804 (bitconvert (v4i32 (X86vzmovl
5805 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5806 (VPMOVSXBQrm addr:$src)>;
5808 def : Pat<(int_x86_sse41_pmovzxbq
5809 (bitconvert (v4i32 (X86vzmovl
5810 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5811 (VPMOVZXBQrm addr:$src)>;
5814 let Predicates = [HasSSE41] in {
5815 // Common patterns involving scalar load
5816 def : Pat<(int_x86_sse41_pmovsxbq
5817 (bitconvert (v4i32 (X86vzmovl
5818 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5819 (PMOVSXBQrm addr:$src)>;
5821 def : Pat<(int_x86_sse41_pmovzxbq
5822 (bitconvert (v4i32 (X86vzmovl
5823 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5824 (PMOVZXBQrm addr:$src)>;
5827 //===----------------------------------------------------------------------===//
5828 // SSE4.1 - Extract Instructions
5829 //===----------------------------------------------------------------------===//
5831 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
5832 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
5833 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
5834 (ins VR128:$src1, i32i8imm:$src2),
5835 !strconcat(OpcodeStr,
5836 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5837 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
5839 let neverHasSideEffects = 1, mayStore = 1 in
5840 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5841 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
5842 !strconcat(OpcodeStr,
5843 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5846 // There's an AssertZext in the way of writing the store pattern
5847 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
5850 let Predicates = [HasAVX] in {
5851 defm VPEXTRB : SS41I_extract8<0x14, "vpextrb">, VEX;
5852 def VPEXTRBrr64 : SS4AIi8<0x14, MRMDestReg, (outs GR64:$dst),
5853 (ins VR128:$src1, i32i8imm:$src2),
5854 "vpextrb\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>, OpSize, VEX;
5857 defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
5860 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
5861 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
5862 let neverHasSideEffects = 1, mayStore = 1 in
5863 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5864 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
5865 !strconcat(OpcodeStr,
5866 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5869 // There's an AssertZext in the way of writing the store pattern
5870 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
5873 let Predicates = [HasAVX] in
5874 defm VPEXTRW : SS41I_extract16<0x15, "vpextrw">, VEX;
5876 defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
5879 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
5880 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
5881 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
5882 (ins VR128:$src1, i32i8imm:$src2),
5883 !strconcat(OpcodeStr,
5884 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5886 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
5887 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5888 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
5889 !strconcat(OpcodeStr,
5890 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5891 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
5892 addr:$dst)]>, OpSize;
5895 let Predicates = [HasAVX] in
5896 defm VPEXTRD : SS41I_extract32<0x16, "vpextrd">, VEX;
5898 defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
5900 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
5901 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
5902 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
5903 (ins VR128:$src1, i32i8imm:$src2),
5904 !strconcat(OpcodeStr,
5905 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5907 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
5908 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5909 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
5910 !strconcat(OpcodeStr,
5911 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5912 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
5913 addr:$dst)]>, OpSize, REX_W;
5916 let Predicates = [HasAVX] in
5917 defm VPEXTRQ : SS41I_extract64<0x16, "vpextrq">, VEX, VEX_W;
5919 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
5921 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
5923 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
5924 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
5925 (ins VR128:$src1, i32i8imm:$src2),
5926 !strconcat(OpcodeStr,
5927 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5929 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
5931 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5932 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
5933 !strconcat(OpcodeStr,
5934 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5935 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
5936 addr:$dst)]>, OpSize;
5939 let ExeDomain = SSEPackedSingle in {
5940 let Predicates = [HasAVX] in {
5941 defm VEXTRACTPS : SS41I_extractf32<0x17, "vextractps">, VEX;
5942 def VEXTRACTPSrr64 : SS4AIi8<0x17, MRMDestReg, (outs GR64:$dst),
5943 (ins VR128:$src1, i32i8imm:$src2),
5944 "vextractps \t{$src2, $src1, $dst|$dst, $src1, $src2}",
5947 defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
5950 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
5951 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
5954 (VEXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
5956 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
5959 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
5960 Requires<[HasSSE41]>;
5962 //===----------------------------------------------------------------------===//
5963 // SSE4.1 - Insert Instructions
5964 //===----------------------------------------------------------------------===//
5966 multiclass SS41I_insert8<bits<8> opc, string asm, bit Is2Addr = 1> {
5967 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
5968 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
5970 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5972 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5974 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
5975 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
5976 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
5978 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5980 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5982 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
5983 imm:$src3))]>, OpSize;
5986 let Predicates = [HasAVX] in
5987 defm VPINSRB : SS41I_insert8<0x20, "vpinsrb", 0>, VEX_4V;
5988 let Constraints = "$src1 = $dst" in
5989 defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
5991 multiclass SS41I_insert32<bits<8> opc, string asm, bit Is2Addr = 1> {
5992 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
5993 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
5995 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5997 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5999 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
6001 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
6002 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
6004 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6006 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6008 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
6009 imm:$src3)))]>, OpSize;
6012 let Predicates = [HasAVX] in
6013 defm VPINSRD : SS41I_insert32<0x22, "vpinsrd", 0>, VEX_4V;
6014 let Constraints = "$src1 = $dst" in
6015 defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
6017 multiclass SS41I_insert64<bits<8> opc, string asm, bit Is2Addr = 1> {
6018 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
6019 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
6021 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6023 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6025 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
6027 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
6028 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
6030 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6032 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6034 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
6035 imm:$src3)))]>, OpSize;
6038 let Predicates = [HasAVX] in
6039 defm VPINSRQ : SS41I_insert64<0x22, "vpinsrq", 0>, VEX_4V, VEX_W;
6040 let Constraints = "$src1 = $dst" in
6041 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">, REX_W;
6043 // insertps has a few different modes, there's the first two here below which
6044 // are optimized inserts that won't zero arbitrary elements in the destination
6045 // vector. The next one matches the intrinsic and could zero arbitrary elements
6046 // in the target vector.
6047 multiclass SS41I_insertf32<bits<8> opc, string asm, bit Is2Addr = 1> {
6048 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
6049 (ins VR128:$src1, VR128:$src2, u32u8imm:$src3),
6051 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6053 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6055 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
6057 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
6058 (ins VR128:$src1, f32mem:$src2, u32u8imm:$src3),
6060 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6062 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6064 (X86insrtps VR128:$src1,
6065 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
6066 imm:$src3))]>, OpSize;
6069 let ExeDomain = SSEPackedSingle in {
6070 let Predicates = [HasAVX] in
6071 defm VINSERTPS : SS41I_insertf32<0x21, "vinsertps", 0>, VEX_4V;
6072 let Constraints = "$src1 = $dst" in
6073 defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
6076 //===----------------------------------------------------------------------===//
6077 // SSE4.1 - Round Instructions
6078 //===----------------------------------------------------------------------===//
6080 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd, string OpcodeStr,
6081 X86MemOperand x86memop, RegisterClass RC,
6082 PatFrag mem_frag32, PatFrag mem_frag64,
6083 Intrinsic V4F32Int, Intrinsic V2F64Int> {
6084 let ExeDomain = SSEPackedSingle in {
6085 // Intrinsic operation, reg.
6086 // Vector intrinsic operation, reg
6087 def PSr : SS4AIi8<opcps, MRMSrcReg,
6088 (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
6089 !strconcat(OpcodeStr,
6090 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6091 [(set RC:$dst, (V4F32Int RC:$src1, imm:$src2))]>,
6094 // Vector intrinsic operation, mem
6095 def PSm : SS4AIi8<opcps, MRMSrcMem,
6096 (outs RC:$dst), (ins x86memop:$src1, i32i8imm:$src2),
6097 !strconcat(OpcodeStr,
6098 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6100 (V4F32Int (mem_frag32 addr:$src1),imm:$src2))]>,
6102 } // ExeDomain = SSEPackedSingle
6104 let ExeDomain = SSEPackedDouble in {
6105 // Vector intrinsic operation, reg
6106 def PDr : SS4AIi8<opcpd, MRMSrcReg,
6107 (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
6108 !strconcat(OpcodeStr,
6109 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6110 [(set RC:$dst, (V2F64Int RC:$src1, imm:$src2))]>,
6113 // Vector intrinsic operation, mem
6114 def PDm : SS4AIi8<opcpd, MRMSrcMem,
6115 (outs RC:$dst), (ins x86memop:$src1, i32i8imm:$src2),
6116 !strconcat(OpcodeStr,
6117 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6119 (V2F64Int (mem_frag64 addr:$src1),imm:$src2))]>,
6121 } // ExeDomain = SSEPackedDouble
6124 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
6127 Intrinsic F64Int, bit Is2Addr = 1> {
6128 let ExeDomain = GenericDomain in {
6130 def SSr : SS4AIi8<opcss, MRMSrcReg,
6131 (outs FR32:$dst), (ins FR32:$src1, FR32:$src2, i32i8imm:$src3),
6133 !strconcat(OpcodeStr,
6134 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6135 !strconcat(OpcodeStr,
6136 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6139 // Intrinsic operation, reg.
6140 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
6141 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
6143 !strconcat(OpcodeStr,
6144 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6145 !strconcat(OpcodeStr,
6146 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6147 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
6150 // Intrinsic operation, mem.
6151 def SSm : SS4AIi8<opcss, MRMSrcMem,
6152 (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
6154 !strconcat(OpcodeStr,
6155 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6156 !strconcat(OpcodeStr,
6157 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6159 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
6163 def SDr : SS4AIi8<opcsd, MRMSrcReg,
6164 (outs FR64:$dst), (ins FR64:$src1, FR64:$src2, i32i8imm:$src3),
6166 !strconcat(OpcodeStr,
6167 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6168 !strconcat(OpcodeStr,
6169 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6172 // Intrinsic operation, reg.
6173 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
6174 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
6176 !strconcat(OpcodeStr,
6177 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6178 !strconcat(OpcodeStr,
6179 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6180 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
6183 // Intrinsic operation, mem.
6184 def SDm : SS4AIi8<opcsd, MRMSrcMem,
6185 (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
6187 !strconcat(OpcodeStr,
6188 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6189 !strconcat(OpcodeStr,
6190 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6192 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
6194 } // ExeDomain = GenericDomain
6197 // FP round - roundss, roundps, roundsd, roundpd
6198 let Predicates = [HasAVX] in {
6200 defm VROUND : sse41_fp_unop_rm<0x08, 0x09, "vround", f128mem, VR128,
6201 memopv4f32, memopv2f64,
6202 int_x86_sse41_round_ps,
6203 int_x86_sse41_round_pd>, VEX;
6204 defm VROUNDY : sse41_fp_unop_rm<0x08, 0x09, "vround", f256mem, VR256,
6205 memopv8f32, memopv4f64,
6206 int_x86_avx_round_ps_256,
6207 int_x86_avx_round_pd_256>, VEX;
6208 defm VROUND : sse41_fp_binop_rm<0x0A, 0x0B, "vround",
6209 int_x86_sse41_round_ss,
6210 int_x86_sse41_round_sd, 0>, VEX_4V, VEX_LIG;
6212 def : Pat<(ffloor FR32:$src),
6213 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x1))>;
6214 def : Pat<(f64 (ffloor FR64:$src)),
6215 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x1))>;
6216 def : Pat<(f32 (fnearbyint FR32:$src)),
6217 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0xC))>;
6218 def : Pat<(f64 (fnearbyint FR64:$src)),
6219 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0xC))>;
6220 def : Pat<(f32 (fceil FR32:$src)),
6221 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x2))>;
6222 def : Pat<(f64 (fceil FR64:$src)),
6223 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x2))>;
6224 def : Pat<(f32 (frint FR32:$src)),
6225 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x4))>;
6226 def : Pat<(f64 (frint FR64:$src)),
6227 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x4))>;
6228 def : Pat<(f32 (ftrunc FR32:$src)),
6229 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x3))>;
6230 def : Pat<(f64 (ftrunc FR64:$src)),
6231 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x3))>;
6234 defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round", f128mem, VR128,
6235 memopv4f32, memopv2f64,
6236 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
6237 let Constraints = "$src1 = $dst" in
6238 defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
6239 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
6241 def : Pat<(ffloor FR32:$src),
6242 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x1))>;
6243 def : Pat<(f64 (ffloor FR64:$src)),
6244 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x1))>;
6245 def : Pat<(f32 (fnearbyint FR32:$src)),
6246 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0xC))>;
6247 def : Pat<(f64 (fnearbyint FR64:$src)),
6248 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0xC))>;
6249 def : Pat<(f32 (fceil FR32:$src)),
6250 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x2))>;
6251 def : Pat<(f64 (fceil FR64:$src)),
6252 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x2))>;
6253 def : Pat<(f32 (frint FR32:$src)),
6254 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x4))>;
6255 def : Pat<(f64 (frint FR64:$src)),
6256 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x4))>;
6257 def : Pat<(f32 (ftrunc FR32:$src)),
6258 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x3))>;
6259 def : Pat<(f64 (ftrunc FR64:$src)),
6260 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x3))>;
6262 //===----------------------------------------------------------------------===//
6263 // SSE4.1 - Packed Bit Test
6264 //===----------------------------------------------------------------------===//
6266 // ptest instruction we'll lower to this in X86ISelLowering primarily from
6267 // the intel intrinsic that corresponds to this.
6268 let Defs = [EFLAGS], Predicates = [HasAVX] in {
6269 def VPTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
6270 "vptest\t{$src2, $src1|$src1, $src2}",
6271 [(set EFLAGS, (X86ptest VR128:$src1, (v2i64 VR128:$src2)))]>,
6273 def VPTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
6274 "vptest\t{$src2, $src1|$src1, $src2}",
6275 [(set EFLAGS,(X86ptest VR128:$src1, (memopv2i64 addr:$src2)))]>,
6278 def VPTESTYrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR256:$src1, VR256:$src2),
6279 "vptest\t{$src2, $src1|$src1, $src2}",
6280 [(set EFLAGS, (X86ptest VR256:$src1, (v4i64 VR256:$src2)))]>,
6282 def VPTESTYrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR256:$src1, i256mem:$src2),
6283 "vptest\t{$src2, $src1|$src1, $src2}",
6284 [(set EFLAGS,(X86ptest VR256:$src1, (memopv4i64 addr:$src2)))]>,
6288 let Defs = [EFLAGS] in {
6289 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
6290 "ptest\t{$src2, $src1|$src1, $src2}",
6291 [(set EFLAGS, (X86ptest VR128:$src1, (v2i64 VR128:$src2)))]>,
6293 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
6294 "ptest\t{$src2, $src1|$src1, $src2}",
6295 [(set EFLAGS, (X86ptest VR128:$src1, (memopv2i64 addr:$src2)))]>,
6299 // The bit test instructions below are AVX only
6300 multiclass avx_bittest<bits<8> opc, string OpcodeStr, RegisterClass RC,
6301 X86MemOperand x86memop, PatFrag mem_frag, ValueType vt> {
6302 def rr : SS48I<opc, MRMSrcReg, (outs), (ins RC:$src1, RC:$src2),
6303 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
6304 [(set EFLAGS, (X86testp RC:$src1, (vt RC:$src2)))]>, OpSize, VEX;
6305 def rm : SS48I<opc, MRMSrcMem, (outs), (ins RC:$src1, x86memop:$src2),
6306 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
6307 [(set EFLAGS, (X86testp RC:$src1, (mem_frag addr:$src2)))]>,
6311 let Defs = [EFLAGS], Predicates = [HasAVX] in {
6312 let ExeDomain = SSEPackedSingle in {
6313 defm VTESTPS : avx_bittest<0x0E, "vtestps", VR128, f128mem, memopv4f32, v4f32>;
6314 defm VTESTPSY : avx_bittest<0x0E, "vtestps", VR256, f256mem, memopv8f32, v8f32>;
6316 let ExeDomain = SSEPackedDouble in {
6317 defm VTESTPD : avx_bittest<0x0F, "vtestpd", VR128, f128mem, memopv2f64, v2f64>;
6318 defm VTESTPDY : avx_bittest<0x0F, "vtestpd", VR256, f256mem, memopv4f64, v4f64>;
6322 //===----------------------------------------------------------------------===//
6323 // SSE4.1 - Misc Instructions
6324 //===----------------------------------------------------------------------===//
6326 let Defs = [EFLAGS], Predicates = [HasPOPCNT] in {
6327 def POPCNT16rr : I<0xB8, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
6328 "popcnt{w}\t{$src, $dst|$dst, $src}",
6329 [(set GR16:$dst, (ctpop GR16:$src)), (implicit EFLAGS)]>,
6331 def POPCNT16rm : I<0xB8, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
6332 "popcnt{w}\t{$src, $dst|$dst, $src}",
6333 [(set GR16:$dst, (ctpop (loadi16 addr:$src))),
6334 (implicit EFLAGS)]>, OpSize, XS;
6336 def POPCNT32rr : I<0xB8, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
6337 "popcnt{l}\t{$src, $dst|$dst, $src}",
6338 [(set GR32:$dst, (ctpop GR32:$src)), (implicit EFLAGS)]>,
6340 def POPCNT32rm : I<0xB8, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
6341 "popcnt{l}\t{$src, $dst|$dst, $src}",
6342 [(set GR32:$dst, (ctpop (loadi32 addr:$src))),
6343 (implicit EFLAGS)]>, XS;
6345 def POPCNT64rr : RI<0xB8, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
6346 "popcnt{q}\t{$src, $dst|$dst, $src}",
6347 [(set GR64:$dst, (ctpop GR64:$src)), (implicit EFLAGS)]>,
6349 def POPCNT64rm : RI<0xB8, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
6350 "popcnt{q}\t{$src, $dst|$dst, $src}",
6351 [(set GR64:$dst, (ctpop (loadi64 addr:$src))),
6352 (implicit EFLAGS)]>, XS;
6357 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
6358 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
6359 Intrinsic IntId128> {
6360 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
6362 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
6363 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
6364 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
6366 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
6369 (bitconvert (memopv2i64 addr:$src))))]>, OpSize;
6372 let Predicates = [HasAVX] in
6373 defm VPHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "vphminposuw",
6374 int_x86_sse41_phminposuw>, VEX;
6375 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
6376 int_x86_sse41_phminposuw>;
6378 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
6379 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
6380 Intrinsic IntId128, bit Is2Addr = 1> {
6381 let isCommutable = 1 in
6382 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
6383 (ins VR128:$src1, VR128:$src2),
6385 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6386 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6387 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>, OpSize;
6388 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
6389 (ins VR128:$src1, i128mem:$src2),
6391 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6392 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6394 (IntId128 VR128:$src1,
6395 (bitconvert (memopv2i64 addr:$src2))))]>, OpSize;
6398 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
6399 multiclass SS41I_binop_rm_int_y<bits<8> opc, string OpcodeStr,
6400 Intrinsic IntId256> {
6401 let isCommutable = 1 in
6402 def Yrr : SS48I<opc, MRMSrcReg, (outs VR256:$dst),
6403 (ins VR256:$src1, VR256:$src2),
6404 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6405 [(set VR256:$dst, (IntId256 VR256:$src1, VR256:$src2))]>, OpSize;
6406 def Yrm : SS48I<opc, MRMSrcMem, (outs VR256:$dst),
6407 (ins VR256:$src1, i256mem:$src2),
6408 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6410 (IntId256 VR256:$src1,
6411 (bitconvert (memopv4i64 addr:$src2))))]>, OpSize;
6414 let Predicates = [HasAVX] in {
6415 let isCommutable = 0 in
6416 defm VPACKUSDW : SS41I_binop_rm_int<0x2B, "vpackusdw", int_x86_sse41_packusdw,
6418 defm VPMINSB : SS41I_binop_rm_int<0x38, "vpminsb", int_x86_sse41_pminsb,
6420 defm VPMINSD : SS41I_binop_rm_int<0x39, "vpminsd", int_x86_sse41_pminsd,
6422 defm VPMINUD : SS41I_binop_rm_int<0x3B, "vpminud", int_x86_sse41_pminud,
6424 defm VPMINUW : SS41I_binop_rm_int<0x3A, "vpminuw", int_x86_sse41_pminuw,
6426 defm VPMAXSB : SS41I_binop_rm_int<0x3C, "vpmaxsb", int_x86_sse41_pmaxsb,
6428 defm VPMAXSD : SS41I_binop_rm_int<0x3D, "vpmaxsd", int_x86_sse41_pmaxsd,
6430 defm VPMAXUD : SS41I_binop_rm_int<0x3F, "vpmaxud", int_x86_sse41_pmaxud,
6432 defm VPMAXUW : SS41I_binop_rm_int<0x3E, "vpmaxuw", int_x86_sse41_pmaxuw,
6434 defm VPMULDQ : SS41I_binop_rm_int<0x28, "vpmuldq", int_x86_sse41_pmuldq,
6438 let Predicates = [HasAVX2] in {
6439 let isCommutable = 0 in
6440 defm VPACKUSDW : SS41I_binop_rm_int_y<0x2B, "vpackusdw",
6441 int_x86_avx2_packusdw>, VEX_4V;
6442 defm VPMINSB : SS41I_binop_rm_int_y<0x38, "vpminsb",
6443 int_x86_avx2_pmins_b>, VEX_4V;
6444 defm VPMINSD : SS41I_binop_rm_int_y<0x39, "vpminsd",
6445 int_x86_avx2_pmins_d>, VEX_4V;
6446 defm VPMINUD : SS41I_binop_rm_int_y<0x3B, "vpminud",
6447 int_x86_avx2_pminu_d>, VEX_4V;
6448 defm VPMINUW : SS41I_binop_rm_int_y<0x3A, "vpminuw",
6449 int_x86_avx2_pminu_w>, VEX_4V;
6450 defm VPMAXSB : SS41I_binop_rm_int_y<0x3C, "vpmaxsb",
6451 int_x86_avx2_pmaxs_b>, VEX_4V;
6452 defm VPMAXSD : SS41I_binop_rm_int_y<0x3D, "vpmaxsd",
6453 int_x86_avx2_pmaxs_d>, VEX_4V;
6454 defm VPMAXUD : SS41I_binop_rm_int_y<0x3F, "vpmaxud",
6455 int_x86_avx2_pmaxu_d>, VEX_4V;
6456 defm VPMAXUW : SS41I_binop_rm_int_y<0x3E, "vpmaxuw",
6457 int_x86_avx2_pmaxu_w>, VEX_4V;
6458 defm VPMULDQ : SS41I_binop_rm_int_y<0x28, "vpmuldq",
6459 int_x86_avx2_pmul_dq>, VEX_4V;
6462 let Constraints = "$src1 = $dst" in {
6463 let isCommutable = 0 in
6464 defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw", int_x86_sse41_packusdw>;
6465 defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb", int_x86_sse41_pminsb>;
6466 defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd", int_x86_sse41_pminsd>;
6467 defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud", int_x86_sse41_pminud>;
6468 defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw", int_x86_sse41_pminuw>;
6469 defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb", int_x86_sse41_pmaxsb>;
6470 defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd", int_x86_sse41_pmaxsd>;
6471 defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud", int_x86_sse41_pmaxud>;
6472 defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw", int_x86_sse41_pmaxuw>;
6473 defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq>;
6476 /// SS48I_binop_rm - Simple SSE41 binary operator.
6477 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
6478 ValueType OpVT, RegisterClass RC, PatFrag memop_frag,
6479 X86MemOperand x86memop, bit Is2Addr = 1> {
6480 let isCommutable = 1 in
6481 def rr : SS48I<opc, MRMSrcReg, (outs RC:$dst),
6482 (ins RC:$src1, RC:$src2),
6484 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6485 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6486 [(set RC:$dst, (OpVT (OpNode RC:$src1, RC:$src2)))]>, OpSize;
6487 def rm : SS48I<opc, MRMSrcMem, (outs RC:$dst),
6488 (ins RC:$src1, x86memop:$src2),
6490 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6491 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6493 (OpVT (OpNode RC:$src1,
6494 (bitconvert (memop_frag addr:$src2)))))]>, OpSize;
6497 let Predicates = [HasAVX] in {
6498 defm VPMULLD : SS48I_binop_rm<0x40, "vpmulld", mul, v4i32, VR128,
6499 memopv2i64, i128mem, 0>, VEX_4V;
6500 defm VPCMPEQQ : SS48I_binop_rm<0x29, "vpcmpeqq", X86pcmpeq, v2i64, VR128,
6501 memopv2i64, i128mem, 0>, VEX_4V;
6503 let Predicates = [HasAVX2] in {
6504 defm VPMULLDY : SS48I_binop_rm<0x40, "vpmulld", mul, v8i32, VR256,
6505 memopv4i64, i256mem, 0>, VEX_4V;
6506 defm VPCMPEQQY : SS48I_binop_rm<0x29, "vpcmpeqq", X86pcmpeq, v4i64, VR256,
6507 memopv4i64, i256mem, 0>, VEX_4V;
6510 let Constraints = "$src1 = $dst" in {
6511 defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, VR128,
6512 memopv2i64, i128mem>;
6513 defm PCMPEQQ : SS48I_binop_rm<0x29, "pcmpeqq", X86pcmpeq, v2i64, VR128,
6514 memopv2i64, i128mem>;
6517 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
6518 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
6519 Intrinsic IntId, RegisterClass RC, PatFrag memop_frag,
6520 X86MemOperand x86memop, bit Is2Addr = 1> {
6521 let isCommutable = 1 in
6522 def rri : SS4AIi8<opc, MRMSrcReg, (outs RC:$dst),
6523 (ins RC:$src1, RC:$src2, u32u8imm:$src3),
6525 !strconcat(OpcodeStr,
6526 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6527 !strconcat(OpcodeStr,
6528 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6529 [(set RC:$dst, (IntId RC:$src1, RC:$src2, imm:$src3))]>,
6531 def rmi : SS4AIi8<opc, MRMSrcMem, (outs RC:$dst),
6532 (ins RC:$src1, x86memop:$src2, u32u8imm:$src3),
6534 !strconcat(OpcodeStr,
6535 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6536 !strconcat(OpcodeStr,
6537 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6540 (bitconvert (memop_frag addr:$src2)), imm:$src3))]>,
6544 let Predicates = [HasAVX] in {
6545 let isCommutable = 0 in {
6546 let ExeDomain = SSEPackedSingle in {
6547 defm VBLENDPS : SS41I_binop_rmi_int<0x0C, "vblendps", int_x86_sse41_blendps,
6548 VR128, memopv4f32, f128mem, 0>, VEX_4V;
6549 defm VBLENDPSY : SS41I_binop_rmi_int<0x0C, "vblendps",
6550 int_x86_avx_blend_ps_256, VR256, memopv8f32, f256mem, 0>, VEX_4V;
6552 let ExeDomain = SSEPackedDouble in {
6553 defm VBLENDPD : SS41I_binop_rmi_int<0x0D, "vblendpd", int_x86_sse41_blendpd,
6554 VR128, memopv2f64, f128mem, 0>, VEX_4V;
6555 defm VBLENDPDY : SS41I_binop_rmi_int<0x0D, "vblendpd",
6556 int_x86_avx_blend_pd_256, VR256, memopv4f64, f256mem, 0>, VEX_4V;
6558 defm VPBLENDW : SS41I_binop_rmi_int<0x0E, "vpblendw", int_x86_sse41_pblendw,
6559 VR128, memopv2i64, i128mem, 0>, VEX_4V;
6560 defm VMPSADBW : SS41I_binop_rmi_int<0x42, "vmpsadbw", int_x86_sse41_mpsadbw,
6561 VR128, memopv2i64, i128mem, 0>, VEX_4V;
6563 let ExeDomain = SSEPackedSingle in
6564 defm VDPPS : SS41I_binop_rmi_int<0x40, "vdpps", int_x86_sse41_dpps,
6565 VR128, memopv4f32, f128mem, 0>, VEX_4V;
6566 let ExeDomain = SSEPackedDouble in
6567 defm VDPPD : SS41I_binop_rmi_int<0x41, "vdppd", int_x86_sse41_dppd,
6568 VR128, memopv2f64, f128mem, 0>, VEX_4V;
6569 let ExeDomain = SSEPackedSingle in
6570 defm VDPPSY : SS41I_binop_rmi_int<0x40, "vdpps", int_x86_avx_dp_ps_256,
6571 VR256, memopv8f32, i256mem, 0>, VEX_4V;
6574 let Predicates = [HasAVX2] in {
6575 let isCommutable = 0 in {
6576 defm VPBLENDWY : SS41I_binop_rmi_int<0x0E, "vpblendw", int_x86_avx2_pblendw,
6577 VR256, memopv4i64, i256mem, 0>, VEX_4V;
6578 defm VMPSADBWY : SS41I_binop_rmi_int<0x42, "vmpsadbw", int_x86_avx2_mpsadbw,
6579 VR256, memopv4i64, i256mem, 0>, VEX_4V;
6583 let Constraints = "$src1 = $dst" in {
6584 let isCommutable = 0 in {
6585 let ExeDomain = SSEPackedSingle in
6586 defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps", int_x86_sse41_blendps,
6587 VR128, memopv4f32, f128mem>;
6588 let ExeDomain = SSEPackedDouble in
6589 defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd", int_x86_sse41_blendpd,
6590 VR128, memopv2f64, f128mem>;
6591 defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw", int_x86_sse41_pblendw,
6592 VR128, memopv2i64, i128mem>;
6593 defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw", int_x86_sse41_mpsadbw,
6594 VR128, memopv2i64, i128mem>;
6596 let ExeDomain = SSEPackedSingle in
6597 defm DPPS : SS41I_binop_rmi_int<0x40, "dpps", int_x86_sse41_dpps,
6598 VR128, memopv4f32, f128mem>;
6599 let ExeDomain = SSEPackedDouble in
6600 defm DPPD : SS41I_binop_rmi_int<0x41, "dppd", int_x86_sse41_dppd,
6601 VR128, memopv2f64, f128mem>;
6604 /// SS41I_quaternary_int_avx - AVX SSE 4.1 with 4 operators
6605 multiclass SS41I_quaternary_int_avx<bits<8> opc, string OpcodeStr,
6606 RegisterClass RC, X86MemOperand x86memop,
6607 PatFrag mem_frag, Intrinsic IntId> {
6608 def rr : Ii8<opc, MRMSrcReg, (outs RC:$dst),
6609 (ins RC:$src1, RC:$src2, RC:$src3),
6610 !strconcat(OpcodeStr,
6611 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
6612 [(set RC:$dst, (IntId RC:$src1, RC:$src2, RC:$src3))],
6613 IIC_DEFAULT, SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
6615 def rm : Ii8<opc, MRMSrcMem, (outs RC:$dst),
6616 (ins RC:$src1, x86memop:$src2, RC:$src3),
6617 !strconcat(OpcodeStr,
6618 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
6620 (IntId RC:$src1, (bitconvert (mem_frag addr:$src2)),
6622 IIC_DEFAULT, SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
6625 let Predicates = [HasAVX] in {
6626 let ExeDomain = SSEPackedDouble in {
6627 defm VBLENDVPD : SS41I_quaternary_int_avx<0x4B, "vblendvpd", VR128, f128mem,
6628 memopv2f64, int_x86_sse41_blendvpd>;
6629 defm VBLENDVPDY : SS41I_quaternary_int_avx<0x4B, "vblendvpd", VR256, f256mem,
6630 memopv4f64, int_x86_avx_blendv_pd_256>;
6631 } // ExeDomain = SSEPackedDouble
6632 let ExeDomain = SSEPackedSingle in {
6633 defm VBLENDVPS : SS41I_quaternary_int_avx<0x4A, "vblendvps", VR128, f128mem,
6634 memopv4f32, int_x86_sse41_blendvps>;
6635 defm VBLENDVPSY : SS41I_quaternary_int_avx<0x4A, "vblendvps", VR256, f256mem,
6636 memopv8f32, int_x86_avx_blendv_ps_256>;
6637 } // ExeDomain = SSEPackedSingle
6638 defm VPBLENDVB : SS41I_quaternary_int_avx<0x4C, "vpblendvb", VR128, i128mem,
6639 memopv2i64, int_x86_sse41_pblendvb>;
6642 let Predicates = [HasAVX2] in {
6643 defm VPBLENDVBY : SS41I_quaternary_int_avx<0x4C, "vpblendvb", VR256, i256mem,
6644 memopv4i64, int_x86_avx2_pblendvb>;
6647 let Predicates = [HasAVX] in {
6648 def : Pat<(v16i8 (vselect (v16i8 VR128:$mask), (v16i8 VR128:$src1),
6649 (v16i8 VR128:$src2))),
6650 (VPBLENDVBrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6651 def : Pat<(v4i32 (vselect (v4i32 VR128:$mask), (v4i32 VR128:$src1),
6652 (v4i32 VR128:$src2))),
6653 (VBLENDVPSrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6654 def : Pat<(v4f32 (vselect (v4i32 VR128:$mask), (v4f32 VR128:$src1),
6655 (v4f32 VR128:$src2))),
6656 (VBLENDVPSrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6657 def : Pat<(v2i64 (vselect (v2i64 VR128:$mask), (v2i64 VR128:$src1),
6658 (v2i64 VR128:$src2))),
6659 (VBLENDVPDrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6660 def : Pat<(v2f64 (vselect (v2i64 VR128:$mask), (v2f64 VR128:$src1),
6661 (v2f64 VR128:$src2))),
6662 (VBLENDVPDrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6663 def : Pat<(v8i32 (vselect (v8i32 VR256:$mask), (v8i32 VR256:$src1),
6664 (v8i32 VR256:$src2))),
6665 (VBLENDVPSYrr VR256:$src2, VR256:$src1, VR256:$mask)>;
6666 def : Pat<(v8f32 (vselect (v8i32 VR256:$mask), (v8f32 VR256:$src1),
6667 (v8f32 VR256:$src2))),
6668 (VBLENDVPSYrr VR256:$src2, VR256:$src1, VR256:$mask)>;
6669 def : Pat<(v4i64 (vselect (v4i64 VR256:$mask), (v4i64 VR256:$src1),
6670 (v4i64 VR256:$src2))),
6671 (VBLENDVPDYrr VR256:$src2, VR256:$src1, VR256:$mask)>;
6672 def : Pat<(v4f64 (vselect (v4i64 VR256:$mask), (v4f64 VR256:$src1),
6673 (v4f64 VR256:$src2))),
6674 (VBLENDVPDYrr VR256:$src2, VR256:$src1, VR256:$mask)>;
6676 def : Pat<(v8f32 (X86Blendps (v8f32 VR256:$src1), (v8f32 VR256:$src2),
6678 (VBLENDPSYrri VR256:$src2, VR256:$src1, imm:$mask)>;
6679 def : Pat<(v4f64 (X86Blendpd (v4f64 VR256:$src1), (v4f64 VR256:$src2),
6681 (VBLENDPDYrri VR256:$src2, VR256:$src1, imm:$mask)>;
6683 def : Pat<(v8i16 (X86Blendpw (v8i16 VR128:$src1), (v8i16 VR128:$src2),
6685 (VPBLENDWrri VR128:$src2, VR128:$src1, imm:$mask)>;
6686 def : Pat<(v4f32 (X86Blendps (v4f32 VR128:$src1), (v4f32 VR128:$src2),
6688 (VBLENDPSrri VR128:$src2, VR128:$src1, imm:$mask)>;
6689 def : Pat<(v2f64 (X86Blendpd (v2f64 VR128:$src1), (v2f64 VR128:$src2),
6691 (VBLENDPDrri VR128:$src2, VR128:$src1, imm:$mask)>;
6694 let Predicates = [HasAVX2] in {
6695 def : Pat<(v32i8 (vselect (v32i8 VR256:$mask), (v32i8 VR256:$src1),
6696 (v32i8 VR256:$src2))),
6697 (VPBLENDVBYrr VR256:$src2, VR256:$src1, VR256:$mask)>;
6698 def : Pat<(v16i16 (X86Blendpw (v16i16 VR256:$src1), (v16i16 VR256:$src2),
6700 (VPBLENDWYrri VR256:$src2, VR256:$src1, imm:$mask)>;
6703 /// SS41I_ternary_int - SSE 4.1 ternary operator
6704 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
6705 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, PatFrag mem_frag,
6706 X86MemOperand x86memop, Intrinsic IntId> {
6707 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
6708 (ins VR128:$src1, VR128:$src2),
6709 !strconcat(OpcodeStr,
6710 "\t{$src2, $dst|$dst, $src2}"),
6711 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
6714 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
6715 (ins VR128:$src1, x86memop:$src2),
6716 !strconcat(OpcodeStr,
6717 "\t{$src2, $dst|$dst, $src2}"),
6720 (bitconvert (mem_frag addr:$src2)), XMM0))]>, OpSize;
6724 let ExeDomain = SSEPackedDouble in
6725 defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", memopv2f64, f128mem,
6726 int_x86_sse41_blendvpd>;
6727 let ExeDomain = SSEPackedSingle in
6728 defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", memopv4f32, f128mem,
6729 int_x86_sse41_blendvps>;
6730 defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", memopv2i64, i128mem,
6731 int_x86_sse41_pblendvb>;
6733 // Aliases with the implicit xmm0 argument
6734 def : InstAlias<"blendvpd\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6735 (BLENDVPDrr0 VR128:$dst, VR128:$src2)>;
6736 def : InstAlias<"blendvpd\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6737 (BLENDVPDrm0 VR128:$dst, f128mem:$src2)>;
6738 def : InstAlias<"blendvps\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6739 (BLENDVPSrr0 VR128:$dst, VR128:$src2)>;
6740 def : InstAlias<"blendvps\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6741 (BLENDVPSrm0 VR128:$dst, f128mem:$src2)>;
6742 def : InstAlias<"pblendvb\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6743 (PBLENDVBrr0 VR128:$dst, VR128:$src2)>;
6744 def : InstAlias<"pblendvb\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6745 (PBLENDVBrm0 VR128:$dst, i128mem:$src2)>;
6747 let Predicates = [HasSSE41] in {
6748 def : Pat<(v16i8 (vselect (v16i8 XMM0), (v16i8 VR128:$src1),
6749 (v16i8 VR128:$src2))),
6750 (PBLENDVBrr0 VR128:$src2, VR128:$src1)>;
6751 def : Pat<(v4i32 (vselect (v4i32 XMM0), (v4i32 VR128:$src1),
6752 (v4i32 VR128:$src2))),
6753 (BLENDVPSrr0 VR128:$src2, VR128:$src1)>;
6754 def : Pat<(v4f32 (vselect (v4i32 XMM0), (v4f32 VR128:$src1),
6755 (v4f32 VR128:$src2))),
6756 (BLENDVPSrr0 VR128:$src2, VR128:$src1)>;
6757 def : Pat<(v2i64 (vselect (v2i64 XMM0), (v2i64 VR128:$src1),
6758 (v2i64 VR128:$src2))),
6759 (BLENDVPDrr0 VR128:$src2, VR128:$src1)>;
6760 def : Pat<(v2f64 (vselect (v2i64 XMM0), (v2f64 VR128:$src1),
6761 (v2f64 VR128:$src2))),
6762 (BLENDVPDrr0 VR128:$src2, VR128:$src1)>;
6764 def : Pat<(v8i16 (X86Blendpw (v8i16 VR128:$src1), (v8i16 VR128:$src2),
6766 (PBLENDWrri VR128:$src2, VR128:$src1, imm:$mask)>;
6767 def : Pat<(v4f32 (X86Blendps (v4f32 VR128:$src1), (v4f32 VR128:$src2),
6769 (BLENDPSrri VR128:$src2, VR128:$src1, imm:$mask)>;
6770 def : Pat<(v2f64 (X86Blendpd (v2f64 VR128:$src1), (v2f64 VR128:$src2),
6772 (BLENDPDrri VR128:$src2, VR128:$src1, imm:$mask)>;
6776 let Predicates = [HasAVX] in
6777 def VMOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
6778 "vmovntdqa\t{$src, $dst|$dst, $src}",
6779 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
6781 let Predicates = [HasAVX2] in
6782 def VMOVNTDQAYrm : SS48I<0x2A, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
6783 "vmovntdqa\t{$src, $dst|$dst, $src}",
6784 [(set VR256:$dst, (int_x86_avx2_movntdqa addr:$src))]>,
6786 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
6787 "movntdqa\t{$src, $dst|$dst, $src}",
6788 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
6791 //===----------------------------------------------------------------------===//
6792 // SSE4.2 - Compare Instructions
6793 //===----------------------------------------------------------------------===//
6795 /// SS42I_binop_rm - Simple SSE 4.2 binary operator
6796 multiclass SS42I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
6797 ValueType OpVT, RegisterClass RC, PatFrag memop_frag,
6798 X86MemOperand x86memop, bit Is2Addr = 1> {
6799 def rr : SS428I<opc, MRMSrcReg, (outs RC:$dst),
6800 (ins RC:$src1, RC:$src2),
6802 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6803 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6804 [(set RC:$dst, (OpVT (OpNode RC:$src1, RC:$src2)))]>,
6806 def rm : SS428I<opc, MRMSrcMem, (outs RC:$dst),
6807 (ins RC:$src1, x86memop:$src2),
6809 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6810 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6812 (OpVT (OpNode RC:$src1, (memop_frag addr:$src2))))]>, OpSize;
6815 let Predicates = [HasAVX] in
6816 defm VPCMPGTQ : SS42I_binop_rm<0x37, "vpcmpgtq", X86pcmpgt, v2i64, VR128,
6817 memopv2i64, i128mem, 0>, VEX_4V;
6819 let Predicates = [HasAVX2] in
6820 defm VPCMPGTQY : SS42I_binop_rm<0x37, "vpcmpgtq", X86pcmpgt, v4i64, VR256,
6821 memopv4i64, i256mem, 0>, VEX_4V;
6823 let Constraints = "$src1 = $dst" in
6824 defm PCMPGTQ : SS42I_binop_rm<0x37, "pcmpgtq", X86pcmpgt, v2i64, VR128,
6825 memopv2i64, i128mem>;
6827 //===----------------------------------------------------------------------===//
6828 // SSE4.2 - String/text Processing Instructions
6829 //===----------------------------------------------------------------------===//
6831 // Packed Compare Implicit Length Strings, Return Mask
6832 multiclass pseudo_pcmpistrm<string asm> {
6833 def REG : PseudoI<(outs VR128:$dst),
6834 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
6835 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
6837 def MEM : PseudoI<(outs VR128:$dst),
6838 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
6839 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128
6840 VR128:$src1, (load addr:$src2), imm:$src3))]>;
6843 let Defs = [EFLAGS], usesCustomInserter = 1 in {
6844 let AddedComplexity = 1 in
6845 defm VPCMPISTRM128 : pseudo_pcmpistrm<"#VPCMPISTRM128">, Requires<[HasAVX]>;
6846 defm PCMPISTRM128 : pseudo_pcmpistrm<"#PCMPISTRM128">, Requires<[HasSSE42]>;
6849 let Defs = [XMM0, EFLAGS], neverHasSideEffects = 1, Predicates = [HasAVX] in {
6850 def VPCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
6851 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
6852 "vpcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize, VEX;
6854 def VPCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
6855 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
6856 "vpcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize, VEX;
6859 let Defs = [XMM0, EFLAGS], neverHasSideEffects = 1 in {
6860 def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
6861 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
6862 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
6864 def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
6865 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
6866 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
6869 // Packed Compare Explicit Length Strings, Return Mask
6870 multiclass pseudo_pcmpestrm<string asm> {
6871 def REG : PseudoI<(outs VR128:$dst),
6872 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
6873 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
6874 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>;
6875 def MEM : PseudoI<(outs VR128:$dst),
6876 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
6877 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
6878 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>;
6881 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
6882 let AddedComplexity = 1 in
6883 defm VPCMPESTRM128 : pseudo_pcmpestrm<"#VPCMPESTRM128">, Requires<[HasAVX]>;
6884 defm PCMPESTRM128 : pseudo_pcmpestrm<"#PCMPESTRM128">, Requires<[HasSSE42]>;
6887 let Predicates = [HasAVX],
6888 Defs = [XMM0, EFLAGS], Uses = [EAX, EDX], neverHasSideEffects = 1 in {
6889 def VPCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
6890 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
6891 "vpcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize, VEX;
6893 def VPCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
6894 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
6895 "vpcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize, VEX;
6898 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX], neverHasSideEffects = 1 in {
6899 def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
6900 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
6901 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
6903 def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
6904 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
6905 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
6908 // Packed Compare Implicit Length Strings, Return Index
6909 let Defs = [ECX, EFLAGS] in {
6910 multiclass SS42AI_pcmpistri<Intrinsic IntId128, string asm = "pcmpistri"> {
6911 def rr : SS42AI<0x63, MRMSrcReg, (outs),
6912 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
6913 !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
6914 [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
6915 (implicit EFLAGS)]>, OpSize;
6916 def rm : SS42AI<0x63, MRMSrcMem, (outs),
6917 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
6918 !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
6919 [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
6920 (implicit EFLAGS)]>, OpSize;
6924 let Predicates = [HasAVX] in {
6925 defm VPCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128, "vpcmpistri">,
6927 defm VPCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128, "vpcmpistri">,
6929 defm VPCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128, "vpcmpistri">,
6931 defm VPCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128, "vpcmpistri">,
6933 defm VPCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128, "vpcmpistri">,
6935 defm VPCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128, "vpcmpistri">,
6939 defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
6940 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
6941 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
6942 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
6943 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
6944 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
6946 // Packed Compare Explicit Length Strings, Return Index
6947 let Defs = [ECX, EFLAGS], Uses = [EAX, EDX] in {
6948 multiclass SS42AI_pcmpestri<Intrinsic IntId128, string asm = "pcmpestri"> {
6949 def rr : SS42AI<0x61, MRMSrcReg, (outs),
6950 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
6951 !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
6952 [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
6953 (implicit EFLAGS)]>, OpSize;
6954 def rm : SS42AI<0x61, MRMSrcMem, (outs),
6955 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
6956 !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
6958 (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
6959 (implicit EFLAGS)]>, OpSize;
6963 let Predicates = [HasAVX] in {
6964 defm VPCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128, "vpcmpestri">,
6966 defm VPCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128, "vpcmpestri">,
6968 defm VPCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128, "vpcmpestri">,
6970 defm VPCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128, "vpcmpestri">,
6972 defm VPCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128, "vpcmpestri">,
6974 defm VPCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128, "vpcmpestri">,
6978 defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
6979 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
6980 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
6981 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
6982 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
6983 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
6985 //===----------------------------------------------------------------------===//
6986 // SSE4.2 - CRC Instructions
6987 //===----------------------------------------------------------------------===//
6989 // No CRC instructions have AVX equivalents
6991 // crc intrinsic instruction
6992 // This set of instructions are only rm, the only difference is the size
6994 let Constraints = "$src1 = $dst" in {
6995 def CRC32r32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
6996 (ins GR32:$src1, i8mem:$src2),
6997 "crc32{b} \t{$src2, $src1|$src1, $src2}",
6999 (int_x86_sse42_crc32_32_8 GR32:$src1,
7000 (load addr:$src2)))]>;
7001 def CRC32r32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
7002 (ins GR32:$src1, GR8:$src2),
7003 "crc32{b} \t{$src2, $src1|$src1, $src2}",
7005 (int_x86_sse42_crc32_32_8 GR32:$src1, GR8:$src2))]>;
7006 def CRC32r32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
7007 (ins GR32:$src1, i16mem:$src2),
7008 "crc32{w} \t{$src2, $src1|$src1, $src2}",
7010 (int_x86_sse42_crc32_32_16 GR32:$src1,
7011 (load addr:$src2)))]>,
7013 def CRC32r32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
7014 (ins GR32:$src1, GR16:$src2),
7015 "crc32{w} \t{$src2, $src1|$src1, $src2}",
7017 (int_x86_sse42_crc32_32_16 GR32:$src1, GR16:$src2))]>,
7019 def CRC32r32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
7020 (ins GR32:$src1, i32mem:$src2),
7021 "crc32{l} \t{$src2, $src1|$src1, $src2}",
7023 (int_x86_sse42_crc32_32_32 GR32:$src1,
7024 (load addr:$src2)))]>;
7025 def CRC32r32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
7026 (ins GR32:$src1, GR32:$src2),
7027 "crc32{l} \t{$src2, $src1|$src1, $src2}",
7029 (int_x86_sse42_crc32_32_32 GR32:$src1, GR32:$src2))]>;
7030 def CRC32r64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
7031 (ins GR64:$src1, i8mem:$src2),
7032 "crc32{b} \t{$src2, $src1|$src1, $src2}",
7034 (int_x86_sse42_crc32_64_8 GR64:$src1,
7035 (load addr:$src2)))]>,
7037 def CRC32r64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
7038 (ins GR64:$src1, GR8:$src2),
7039 "crc32{b} \t{$src2, $src1|$src1, $src2}",
7041 (int_x86_sse42_crc32_64_8 GR64:$src1, GR8:$src2))]>,
7043 def CRC32r64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
7044 (ins GR64:$src1, i64mem:$src2),
7045 "crc32{q} \t{$src2, $src1|$src1, $src2}",
7047 (int_x86_sse42_crc32_64_64 GR64:$src1,
7048 (load addr:$src2)))]>,
7050 def CRC32r64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
7051 (ins GR64:$src1, GR64:$src2),
7052 "crc32{q} \t{$src2, $src1|$src1, $src2}",
7054 (int_x86_sse42_crc32_64_64 GR64:$src1, GR64:$src2))]>,
7058 //===----------------------------------------------------------------------===//
7059 // AES-NI Instructions
7060 //===----------------------------------------------------------------------===//
7062 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
7063 Intrinsic IntId128, bit Is2Addr = 1> {
7064 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
7065 (ins VR128:$src1, VR128:$src2),
7067 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
7068 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
7069 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
7071 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
7072 (ins VR128:$src1, i128mem:$src2),
7074 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
7075 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
7077 (IntId128 VR128:$src1, (memopv2i64 addr:$src2)))]>, OpSize;
7080 // Perform One Round of an AES Encryption/Decryption Flow
7081 let Predicates = [HasAVX, HasAES] in {
7082 defm VAESENC : AESI_binop_rm_int<0xDC, "vaesenc",
7083 int_x86_aesni_aesenc, 0>, VEX_4V;
7084 defm VAESENCLAST : AESI_binop_rm_int<0xDD, "vaesenclast",
7085 int_x86_aesni_aesenclast, 0>, VEX_4V;
7086 defm VAESDEC : AESI_binop_rm_int<0xDE, "vaesdec",
7087 int_x86_aesni_aesdec, 0>, VEX_4V;
7088 defm VAESDECLAST : AESI_binop_rm_int<0xDF, "vaesdeclast",
7089 int_x86_aesni_aesdeclast, 0>, VEX_4V;
7092 let Constraints = "$src1 = $dst" in {
7093 defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
7094 int_x86_aesni_aesenc>;
7095 defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
7096 int_x86_aesni_aesenclast>;
7097 defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
7098 int_x86_aesni_aesdec>;
7099 defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
7100 int_x86_aesni_aesdeclast>;
7103 // Perform the AES InvMixColumn Transformation
7104 let Predicates = [HasAVX, HasAES] in {
7105 def VAESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
7107 "vaesimc\t{$src1, $dst|$dst, $src1}",
7109 (int_x86_aesni_aesimc VR128:$src1))]>,
7111 def VAESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
7112 (ins i128mem:$src1),
7113 "vaesimc\t{$src1, $dst|$dst, $src1}",
7114 [(set VR128:$dst, (int_x86_aesni_aesimc (memopv2i64 addr:$src1)))]>,
7117 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
7119 "aesimc\t{$src1, $dst|$dst, $src1}",
7121 (int_x86_aesni_aesimc VR128:$src1))]>,
7123 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
7124 (ins i128mem:$src1),
7125 "aesimc\t{$src1, $dst|$dst, $src1}",
7126 [(set VR128:$dst, (int_x86_aesni_aesimc (memopv2i64 addr:$src1)))]>,
7129 // AES Round Key Generation Assist
7130 let Predicates = [HasAVX, HasAES] in {
7131 def VAESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
7132 (ins VR128:$src1, i8imm:$src2),
7133 "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7135 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
7137 def VAESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
7138 (ins i128mem:$src1, i8imm:$src2),
7139 "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7141 (int_x86_aesni_aeskeygenassist (memopv2i64 addr:$src1), imm:$src2))]>,
7144 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
7145 (ins VR128:$src1, i8imm:$src2),
7146 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7148 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
7150 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
7151 (ins i128mem:$src1, i8imm:$src2),
7152 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7154 (int_x86_aesni_aeskeygenassist (memopv2i64 addr:$src1), imm:$src2))]>,
7157 //===----------------------------------------------------------------------===//
7158 // PCLMUL Instructions
7159 //===----------------------------------------------------------------------===//
7161 // AVX carry-less Multiplication instructions
7162 def VPCLMULQDQrr : AVXPCLMULIi8<0x44, MRMSrcReg, (outs VR128:$dst),
7163 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
7164 "vpclmulqdq\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7166 (int_x86_pclmulqdq VR128:$src1, VR128:$src2, imm:$src3))]>;
7168 def VPCLMULQDQrm : AVXPCLMULIi8<0x44, MRMSrcMem, (outs VR128:$dst),
7169 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
7170 "vpclmulqdq\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7171 [(set VR128:$dst, (int_x86_pclmulqdq VR128:$src1,
7172 (memopv2i64 addr:$src2), imm:$src3))]>;
7174 // Carry-less Multiplication instructions
7175 let Constraints = "$src1 = $dst" in {
7176 def PCLMULQDQrr : PCLMULIi8<0x44, MRMSrcReg, (outs VR128:$dst),
7177 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
7178 "pclmulqdq\t{$src3, $src2, $dst|$dst, $src2, $src3}",
7180 (int_x86_pclmulqdq VR128:$src1, VR128:$src2, imm:$src3))]>;
7182 def PCLMULQDQrm : PCLMULIi8<0x44, MRMSrcMem, (outs VR128:$dst),
7183 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
7184 "pclmulqdq\t{$src3, $src2, $dst|$dst, $src2, $src3}",
7185 [(set VR128:$dst, (int_x86_pclmulqdq VR128:$src1,
7186 (memopv2i64 addr:$src2), imm:$src3))]>;
7187 } // Constraints = "$src1 = $dst"
7190 multiclass pclmul_alias<string asm, int immop> {
7191 def : InstAlias<!strconcat("pclmul", asm, "dq {$src, $dst|$dst, $src}"),
7192 (PCLMULQDQrr VR128:$dst, VR128:$src, immop)>;
7194 def : InstAlias<!strconcat("pclmul", asm, "dq {$src, $dst|$dst, $src}"),
7195 (PCLMULQDQrm VR128:$dst, i128mem:$src, immop)>;
7197 def : InstAlias<!strconcat("vpclmul", asm,
7198 "dq {$src2, $src1, $dst|$dst, $src1, $src2}"),
7199 (VPCLMULQDQrr VR128:$dst, VR128:$src1, VR128:$src2, immop)>;
7201 def : InstAlias<!strconcat("vpclmul", asm,
7202 "dq {$src2, $src1, $dst|$dst, $src1, $src2}"),
7203 (VPCLMULQDQrm VR128:$dst, VR128:$src1, i128mem:$src2, immop)>;
7205 defm : pclmul_alias<"hqhq", 0x11>;
7206 defm : pclmul_alias<"hqlq", 0x01>;
7207 defm : pclmul_alias<"lqhq", 0x10>;
7208 defm : pclmul_alias<"lqlq", 0x00>;
7210 //===----------------------------------------------------------------------===//
7211 // SSE4A Instructions
7212 //===----------------------------------------------------------------------===//
7214 let Predicates = [HasSSE4A] in {
7216 let Constraints = "$src = $dst" in {
7217 def EXTRQI : Ii8<0x78, MRM0r, (outs VR128:$dst),
7218 (ins VR128:$src, i8imm:$len, i8imm:$idx),
7219 "extrq\t{$idx, $len, $src|$src, $len, $idx}",
7220 [(set VR128:$dst, (int_x86_sse4a_extrqi VR128:$src, imm:$len,
7221 imm:$idx))]>, TB, OpSize;
7222 def EXTRQ : I<0x79, MRMSrcReg, (outs VR128:$dst),
7223 (ins VR128:$src, VR128:$mask),
7224 "extrq\t{$mask, $src|$src, $mask}",
7225 [(set VR128:$dst, (int_x86_sse4a_extrq VR128:$src,
7226 VR128:$mask))]>, TB, OpSize;
7228 def INSERTQI : Ii8<0x78, MRMSrcReg, (outs VR128:$dst),
7229 (ins VR128:$src, VR128:$src2, i8imm:$len, i8imm:$idx),
7230 "insertq\t{$idx, $len, $src2, $src|$src, $src2, $len, $idx}",
7231 [(set VR128:$dst, (int_x86_sse4a_insertqi VR128:$src,
7232 VR128:$src2, imm:$len, imm:$idx))]>, XD;
7233 def INSERTQ : I<0x79, MRMSrcReg, (outs VR128:$dst),
7234 (ins VR128:$src, VR128:$mask),
7235 "insertq\t{$mask, $src|$src, $mask}",
7236 [(set VR128:$dst, (int_x86_sse4a_insertq VR128:$src,
7237 VR128:$mask))]>, XD;
7240 def MOVNTSS : I<0x2B, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
7241 "movntss\t{$src, $dst|$dst, $src}",
7242 [(int_x86_sse4a_movnt_ss addr:$dst, VR128:$src)]>, XS;
7244 def MOVNTSD : I<0x2B, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
7245 "movntsd\t{$src, $dst|$dst, $src}",
7246 [(int_x86_sse4a_movnt_sd addr:$dst, VR128:$src)]>, XD;
7249 //===----------------------------------------------------------------------===//
7251 //===----------------------------------------------------------------------===//
7253 //===----------------------------------------------------------------------===//
7254 // VBROADCAST - Load from memory and broadcast to all elements of the
7255 // destination operand
7257 class avx_broadcast<bits<8> opc, string OpcodeStr, RegisterClass RC,
7258 X86MemOperand x86memop, Intrinsic Int> :
7259 AVX8I<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
7260 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7261 [(set RC:$dst, (Int addr:$src))]>, VEX;
7263 // AVX2 adds register forms
7264 class avx2_broadcast_reg<bits<8> opc, string OpcodeStr, RegisterClass RC,
7266 AVX28I<opc, MRMSrcReg, (outs RC:$dst), (ins VR128:$src),
7267 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7268 [(set RC:$dst, (Int VR128:$src))]>, VEX;
7270 let ExeDomain = SSEPackedSingle in {
7271 def VBROADCASTSSrm : avx_broadcast<0x18, "vbroadcastss", VR128, f32mem,
7272 int_x86_avx_vbroadcast_ss>;
7273 def VBROADCASTSSYrm : avx_broadcast<0x18, "vbroadcastss", VR256, f32mem,
7274 int_x86_avx_vbroadcast_ss_256>;
7276 let ExeDomain = SSEPackedDouble in
7277 def VBROADCASTSDrm : avx_broadcast<0x19, "vbroadcastsd", VR256, f64mem,
7278 int_x86_avx_vbroadcast_sd_256>;
7279 def VBROADCASTF128 : avx_broadcast<0x1A, "vbroadcastf128", VR256, f128mem,
7280 int_x86_avx_vbroadcastf128_pd_256>;
7282 let ExeDomain = SSEPackedSingle in {
7283 def VBROADCASTSSrr : avx2_broadcast_reg<0x18, "vbroadcastss", VR128,
7284 int_x86_avx2_vbroadcast_ss_ps>;
7285 def VBROADCASTSSYrr : avx2_broadcast_reg<0x18, "vbroadcastss", VR256,
7286 int_x86_avx2_vbroadcast_ss_ps_256>;
7288 let ExeDomain = SSEPackedDouble in
7289 def VBROADCASTSDYrr : avx2_broadcast_reg<0x19, "vbroadcastsd", VR256,
7290 int_x86_avx2_vbroadcast_sd_pd_256>;
7292 let Predicates = [HasAVX2] in
7293 def VBROADCASTI128 : avx_broadcast<0x5A, "vbroadcasti128", VR256, i128mem,
7294 int_x86_avx2_vbroadcasti128>;
7296 let Predicates = [HasAVX] in
7297 def : Pat<(int_x86_avx_vbroadcastf128_ps_256 addr:$src),
7298 (VBROADCASTF128 addr:$src)>;
7301 //===----------------------------------------------------------------------===//
7302 // VINSERTF128 - Insert packed floating-point values
7304 let neverHasSideEffects = 1, ExeDomain = SSEPackedSingle in {
7305 def VINSERTF128rr : AVXAIi8<0x18, MRMSrcReg, (outs VR256:$dst),
7306 (ins VR256:$src1, VR128:$src2, i8imm:$src3),
7307 "vinsertf128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7310 def VINSERTF128rm : AVXAIi8<0x18, MRMSrcMem, (outs VR256:$dst),
7311 (ins VR256:$src1, f128mem:$src2, i8imm:$src3),
7312 "vinsertf128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7316 let Predicates = [HasAVX] in {
7317 def : Pat<(vinsertf128_insert:$ins (v8f32 VR256:$src1), (v4f32 VR128:$src2),
7319 (VINSERTF128rr VR256:$src1, VR128:$src2,
7320 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7321 def : Pat<(vinsertf128_insert:$ins (v4f64 VR256:$src1), (v2f64 VR128:$src2),
7323 (VINSERTF128rr VR256:$src1, VR128:$src2,
7324 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7325 def : Pat<(vinsertf128_insert:$ins (v4i64 VR256:$src1), (v2i64 VR128:$src2),
7327 (VINSERTF128rr VR256:$src1, VR128:$src2,
7328 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7329 def : Pat<(vinsertf128_insert:$ins (v8i32 VR256:$src1), (v4i32 VR128:$src2),
7331 (VINSERTF128rr VR256:$src1, VR128:$src2,
7332 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7333 def : Pat<(vinsertf128_insert:$ins (v32i8 VR256:$src1), (v16i8 VR128:$src2),
7335 (VINSERTF128rr VR256:$src1, VR128:$src2,
7336 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7337 def : Pat<(vinsertf128_insert:$ins (v16i16 VR256:$src1), (v8i16 VR128:$src2),
7339 (VINSERTF128rr VR256:$src1, VR128:$src2,
7340 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7342 def : Pat<(vinsertf128_insert:$ins (v8f32 VR256:$src1), (loadv4f32 addr:$src2),
7344 (VINSERTF128rm VR256:$src1, addr:$src2,
7345 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7346 def : Pat<(vinsertf128_insert:$ins (v4f64 VR256:$src1), (loadv2f64 addr:$src2),
7348 (VINSERTF128rm VR256:$src1, addr:$src2,
7349 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7350 def : Pat<(vinsertf128_insert:$ins (v4i64 VR256:$src1), (loadv2i64 addr:$src2),
7352 (VINSERTF128rm VR256:$src1, addr:$src2,
7353 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7356 //===----------------------------------------------------------------------===//
7357 // VEXTRACTF128 - Extract packed floating-point values
7359 let neverHasSideEffects = 1, ExeDomain = SSEPackedSingle in {
7360 def VEXTRACTF128rr : AVXAIi8<0x19, MRMDestReg, (outs VR128:$dst),
7361 (ins VR256:$src1, i8imm:$src2),
7362 "vextractf128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7365 def VEXTRACTF128mr : AVXAIi8<0x19, MRMDestMem, (outs),
7366 (ins f128mem:$dst, VR256:$src1, i8imm:$src2),
7367 "vextractf128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7371 // Extract and store.
7372 let Predicates = [HasAVX] in {
7373 def : Pat<(alignedstore (int_x86_avx_vextractf128_ps_256 VR256:$src1, imm:$src2), addr:$dst),
7374 (VEXTRACTF128mr addr:$dst, VR256:$src1, imm:$src2)>;
7375 def : Pat<(alignedstore (int_x86_avx_vextractf128_pd_256 VR256:$src1, imm:$src2), addr:$dst),
7376 (VEXTRACTF128mr addr:$dst, VR256:$src1, imm:$src2)>;
7377 def : Pat<(alignedstore (int_x86_avx_vextractf128_si_256 VR256:$src1, imm:$src2), addr:$dst),
7378 (VEXTRACTF128mr addr:$dst, VR256:$src1, imm:$src2)>;
7380 def : Pat<(int_x86_sse_storeu_ps addr:$dst, (int_x86_avx_vextractf128_ps_256 VR256:$src1, imm:$src2)),
7381 (VEXTRACTF128mr addr:$dst, VR256:$src1, imm:$src2)>;
7382 def : Pat<(int_x86_sse2_storeu_pd addr:$dst, (int_x86_avx_vextractf128_pd_256 VR256:$src1, imm:$src2)),
7383 (VEXTRACTF128mr addr:$dst, VR256:$src1, imm:$src2)>;
7384 def : Pat<(int_x86_sse2_storeu_dq addr:$dst, (bc_v16i8 (int_x86_avx_vextractf128_si_256 VR256:$src1, imm:$src2))),
7385 (VEXTRACTF128mr addr:$dst, VR256:$src1, imm:$src2)>;
7389 let Predicates = [HasAVX] in {
7390 def : Pat<(int_x86_avx_vextractf128_pd_256 VR256:$src1, imm:$src2),
7391 (VEXTRACTF128rr VR256:$src1, imm:$src2)>;
7392 def : Pat<(int_x86_avx_vextractf128_ps_256 VR256:$src1, imm:$src2),
7393 (VEXTRACTF128rr VR256:$src1, imm:$src2)>;
7394 def : Pat<(int_x86_avx_vextractf128_si_256 VR256:$src1, imm:$src2),
7395 (VEXTRACTF128rr VR256:$src1, imm:$src2)>;
7397 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7398 (v4f32 (VEXTRACTF128rr
7399 (v8f32 VR256:$src1),
7400 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7401 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7402 (v2f64 (VEXTRACTF128rr
7403 (v4f64 VR256:$src1),
7404 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7405 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7406 (v2i64 (VEXTRACTF128rr
7407 (v4i64 VR256:$src1),
7408 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7409 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7410 (v4i32 (VEXTRACTF128rr
7411 (v8i32 VR256:$src1),
7412 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7413 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7414 (v8i16 (VEXTRACTF128rr
7415 (v16i16 VR256:$src1),
7416 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7417 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7418 (v16i8 (VEXTRACTF128rr
7419 (v32i8 VR256:$src1),
7420 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7423 //===----------------------------------------------------------------------===//
7424 // VMASKMOV - Conditional SIMD Packed Loads and Stores
7426 multiclass avx_movmask_rm<bits<8> opc_rm, bits<8> opc_mr, string OpcodeStr,
7427 Intrinsic IntLd, Intrinsic IntLd256,
7428 Intrinsic IntSt, Intrinsic IntSt256> {
7429 def rm : AVX8I<opc_rm, MRMSrcMem, (outs VR128:$dst),
7430 (ins VR128:$src1, f128mem:$src2),
7431 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7432 [(set VR128:$dst, (IntLd addr:$src2, VR128:$src1))]>,
7434 def Yrm : AVX8I<opc_rm, MRMSrcMem, (outs VR256:$dst),
7435 (ins VR256:$src1, f256mem:$src2),
7436 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7437 [(set VR256:$dst, (IntLd256 addr:$src2, VR256:$src1))]>,
7439 def mr : AVX8I<opc_mr, MRMDestMem, (outs),
7440 (ins f128mem:$dst, VR128:$src1, VR128:$src2),
7441 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7442 [(IntSt addr:$dst, VR128:$src1, VR128:$src2)]>, VEX_4V;
7443 def Ymr : AVX8I<opc_mr, MRMDestMem, (outs),
7444 (ins f256mem:$dst, VR256:$src1, VR256:$src2),
7445 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7446 [(IntSt256 addr:$dst, VR256:$src1, VR256:$src2)]>, VEX_4V;
7449 let ExeDomain = SSEPackedSingle in
7450 defm VMASKMOVPS : avx_movmask_rm<0x2C, 0x2E, "vmaskmovps",
7451 int_x86_avx_maskload_ps,
7452 int_x86_avx_maskload_ps_256,
7453 int_x86_avx_maskstore_ps,
7454 int_x86_avx_maskstore_ps_256>;
7455 let ExeDomain = SSEPackedDouble in
7456 defm VMASKMOVPD : avx_movmask_rm<0x2D, 0x2F, "vmaskmovpd",
7457 int_x86_avx_maskload_pd,
7458 int_x86_avx_maskload_pd_256,
7459 int_x86_avx_maskstore_pd,
7460 int_x86_avx_maskstore_pd_256>;
7462 //===----------------------------------------------------------------------===//
7463 // VPERMIL - Permute Single and Double Floating-Point Values
7465 multiclass avx_permil<bits<8> opc_rm, bits<8> opc_rmi, string OpcodeStr,
7466 RegisterClass RC, X86MemOperand x86memop_f,
7467 X86MemOperand x86memop_i, PatFrag i_frag,
7468 Intrinsic IntVar, ValueType vt> {
7469 def rr : AVX8I<opc_rm, MRMSrcReg, (outs RC:$dst),
7470 (ins RC:$src1, RC:$src2),
7471 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7472 [(set RC:$dst, (IntVar RC:$src1, RC:$src2))]>, VEX_4V;
7473 def rm : AVX8I<opc_rm, MRMSrcMem, (outs RC:$dst),
7474 (ins RC:$src1, x86memop_i:$src2),
7475 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7476 [(set RC:$dst, (IntVar RC:$src1,
7477 (bitconvert (i_frag addr:$src2))))]>, VEX_4V;
7479 def ri : AVXAIi8<opc_rmi, MRMSrcReg, (outs RC:$dst),
7480 (ins RC:$src1, i8imm:$src2),
7481 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7482 [(set RC:$dst, (vt (X86VPermilp RC:$src1, (i8 imm:$src2))))]>, VEX;
7483 def mi : AVXAIi8<opc_rmi, MRMSrcMem, (outs RC:$dst),
7484 (ins x86memop_f:$src1, i8imm:$src2),
7485 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7487 (vt (X86VPermilp (memop addr:$src1), (i8 imm:$src2))))]>, VEX;
7490 let ExeDomain = SSEPackedSingle in {
7491 defm VPERMILPS : avx_permil<0x0C, 0x04, "vpermilps", VR128, f128mem, i128mem,
7492 memopv2i64, int_x86_avx_vpermilvar_ps, v4f32>;
7493 defm VPERMILPSY : avx_permil<0x0C, 0x04, "vpermilps", VR256, f256mem, i256mem,
7494 memopv4i64, int_x86_avx_vpermilvar_ps_256, v8f32>;
7496 let ExeDomain = SSEPackedDouble in {
7497 defm VPERMILPD : avx_permil<0x0D, 0x05, "vpermilpd", VR128, f128mem, i128mem,
7498 memopv2i64, int_x86_avx_vpermilvar_pd, v2f64>;
7499 defm VPERMILPDY : avx_permil<0x0D, 0x05, "vpermilpd", VR256, f256mem, i256mem,
7500 memopv4i64, int_x86_avx_vpermilvar_pd_256, v4f64>;
7503 let Predicates = [HasAVX] in {
7504 def : Pat<(v8i32 (X86VPermilp VR256:$src1, (i8 imm:$imm))),
7505 (VPERMILPSYri VR256:$src1, imm:$imm)>;
7506 def : Pat<(v4i64 (X86VPermilp VR256:$src1, (i8 imm:$imm))),
7507 (VPERMILPDYri VR256:$src1, imm:$imm)>;
7508 def : Pat<(v8i32 (X86VPermilp (bc_v8i32 (memopv4i64 addr:$src1)),
7510 (VPERMILPSYmi addr:$src1, imm:$imm)>;
7511 def : Pat<(v4i64 (X86VPermilp (memopv4i64 addr:$src1), (i8 imm:$imm))),
7512 (VPERMILPDYmi addr:$src1, imm:$imm)>;
7514 def : Pat<(v2i64 (X86VPermilp VR128:$src1, (i8 imm:$imm))),
7515 (VPERMILPDri VR128:$src1, imm:$imm)>;
7516 def : Pat<(v2i64 (X86VPermilp (memopv2i64 addr:$src1), (i8 imm:$imm))),
7517 (VPERMILPDmi addr:$src1, imm:$imm)>;
7520 //===----------------------------------------------------------------------===//
7521 // VPERM2F128 - Permute Floating-Point Values in 128-bit chunks
7523 let ExeDomain = SSEPackedSingle in {
7524 def VPERM2F128rr : AVXAIi8<0x06, MRMSrcReg, (outs VR256:$dst),
7525 (ins VR256:$src1, VR256:$src2, i8imm:$src3),
7526 "vperm2f128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7527 [(set VR256:$dst, (v8f32 (X86VPerm2x128 VR256:$src1, VR256:$src2,
7528 (i8 imm:$src3))))]>, VEX_4V;
7529 def VPERM2F128rm : AVXAIi8<0x06, MRMSrcMem, (outs VR256:$dst),
7530 (ins VR256:$src1, f256mem:$src2, i8imm:$src3),
7531 "vperm2f128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7532 [(set VR256:$dst, (X86VPerm2x128 VR256:$src1, (memopv8f32 addr:$src2),
7533 (i8 imm:$src3)))]>, VEX_4V;
7536 let Predicates = [HasAVX] in {
7537 def : Pat<(v8i32 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7538 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7539 def : Pat<(v4i64 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7540 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7541 def : Pat<(v4f64 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7542 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7543 def : Pat<(v32i8 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7544 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7545 def : Pat<(v16i16 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7546 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7548 def : Pat<(v8f32 (X86VPerm2x128 VR256:$src1,
7549 (memopv8f32 addr:$src2), (i8 imm:$imm))),
7550 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7551 def : Pat<(v8i32 (X86VPerm2x128 VR256:$src1,
7552 (bc_v8i32 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
7553 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7554 def : Pat<(v4i64 (X86VPerm2x128 VR256:$src1,
7555 (memopv4i64 addr:$src2), (i8 imm:$imm))),
7556 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7557 def : Pat<(v4f64 (X86VPerm2x128 VR256:$src1,
7558 (memopv4f64 addr:$src2), (i8 imm:$imm))),
7559 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7560 def : Pat<(v32i8 (X86VPerm2x128 VR256:$src1,
7561 (bc_v32i8 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
7562 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7563 def : Pat<(v16i16 (X86VPerm2x128 VR256:$src1,
7564 (bc_v16i16 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
7565 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7568 //===----------------------------------------------------------------------===//
7569 // VZERO - Zero YMM registers
7571 let Defs = [YMM0, YMM1, YMM2, YMM3, YMM4, YMM5, YMM6, YMM7,
7572 YMM8, YMM9, YMM10, YMM11, YMM12, YMM13, YMM14, YMM15] in {
7573 // Zero All YMM registers
7574 def VZEROALL : I<0x77, RawFrm, (outs), (ins), "vzeroall",
7575 [(int_x86_avx_vzeroall)]>, TB, VEX, VEX_L, Requires<[HasAVX]>;
7577 // Zero Upper bits of YMM registers
7578 def VZEROUPPER : I<0x77, RawFrm, (outs), (ins), "vzeroupper",
7579 [(int_x86_avx_vzeroupper)]>, TB, VEX, Requires<[HasAVX]>;
7582 //===----------------------------------------------------------------------===//
7583 // Half precision conversion instructions
7584 //===----------------------------------------------------------------------===//
7585 multiclass f16c_ph2ps<RegisterClass RC, X86MemOperand x86memop, Intrinsic Int> {
7586 def rr : I<0x13, MRMSrcReg, (outs RC:$dst), (ins VR128:$src),
7587 "vcvtph2ps\t{$src, $dst|$dst, $src}",
7588 [(set RC:$dst, (Int VR128:$src))]>,
7590 let neverHasSideEffects = 1, mayLoad = 1 in
7591 def rm : I<0x13, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
7592 "vcvtph2ps\t{$src, $dst|$dst, $src}", []>, T8, OpSize, VEX;
7595 multiclass f16c_ps2ph<RegisterClass RC, X86MemOperand x86memop, Intrinsic Int> {
7596 def rr : Ii8<0x1D, MRMDestReg, (outs VR128:$dst),
7597 (ins RC:$src1, i32i8imm:$src2),
7598 "vcvtps2ph\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7599 [(set VR128:$dst, (Int RC:$src1, imm:$src2))]>,
7601 let neverHasSideEffects = 1, mayStore = 1 in
7602 def mr : Ii8<0x1D, MRMDestMem, (outs),
7603 (ins x86memop:$dst, RC:$src1, i32i8imm:$src2),
7604 "vcvtps2ph\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
7608 let Predicates = [HasAVX, HasF16C] in {
7609 defm VCVTPH2PS : f16c_ph2ps<VR128, f64mem, int_x86_vcvtph2ps_128>;
7610 defm VCVTPH2PSY : f16c_ph2ps<VR256, f128mem, int_x86_vcvtph2ps_256>;
7611 defm VCVTPS2PH : f16c_ps2ph<VR128, f64mem, int_x86_vcvtps2ph_128>;
7612 defm VCVTPS2PHY : f16c_ps2ph<VR256, f128mem, int_x86_vcvtps2ph_256>;
7615 //===----------------------------------------------------------------------===//
7616 // AVX2 Instructions
7617 //===----------------------------------------------------------------------===//
7619 /// AVX2_binop_rmi_int - AVX2 binary operator with 8-bit immediate
7620 multiclass AVX2_binop_rmi_int<bits<8> opc, string OpcodeStr,
7621 Intrinsic IntId, RegisterClass RC, PatFrag memop_frag,
7622 X86MemOperand x86memop> {
7623 let isCommutable = 1 in
7624 def rri : AVX2AIi8<opc, MRMSrcReg, (outs RC:$dst),
7625 (ins RC:$src1, RC:$src2, u32u8imm:$src3),
7626 !strconcat(OpcodeStr,
7627 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
7628 [(set RC:$dst, (IntId RC:$src1, RC:$src2, imm:$src3))]>,
7630 def rmi : AVX2AIi8<opc, MRMSrcMem, (outs RC:$dst),
7631 (ins RC:$src1, x86memop:$src2, u32u8imm:$src3),
7632 !strconcat(OpcodeStr,
7633 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
7636 (bitconvert (memop_frag addr:$src2)), imm:$src3))]>,
7640 let isCommutable = 0 in {
7641 defm VPBLENDD : AVX2_binop_rmi_int<0x02, "vpblendd", int_x86_avx2_pblendd_128,
7642 VR128, memopv2i64, i128mem>;
7643 defm VPBLENDDY : AVX2_binop_rmi_int<0x02, "vpblendd", int_x86_avx2_pblendd_256,
7644 VR256, memopv4i64, i256mem>;
7647 //===----------------------------------------------------------------------===//
7648 // VPBROADCAST - Load from memory and broadcast to all elements of the
7649 // destination operand
7651 multiclass avx2_broadcast<bits<8> opc, string OpcodeStr,
7652 X86MemOperand x86memop, PatFrag ld_frag,
7653 Intrinsic Int128, Intrinsic Int256> {
7654 def rr : AVX28I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
7655 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7656 [(set VR128:$dst, (Int128 VR128:$src))]>, VEX;
7657 def rm : AVX28I<opc, MRMSrcMem, (outs VR128:$dst), (ins x86memop:$src),
7658 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7660 (Int128 (scalar_to_vector (ld_frag addr:$src))))]>, VEX;
7661 def Yrr : AVX28I<opc, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
7662 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7663 [(set VR256:$dst, (Int256 VR128:$src))]>, VEX;
7664 def Yrm : AVX28I<opc, MRMSrcMem, (outs VR256:$dst), (ins x86memop:$src),
7665 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7667 (Int256 (scalar_to_vector (ld_frag addr:$src))))]>, VEX;
7670 defm VPBROADCASTB : avx2_broadcast<0x78, "vpbroadcastb", i8mem, loadi8,
7671 int_x86_avx2_pbroadcastb_128,
7672 int_x86_avx2_pbroadcastb_256>;
7673 defm VPBROADCASTW : avx2_broadcast<0x79, "vpbroadcastw", i16mem, loadi16,
7674 int_x86_avx2_pbroadcastw_128,
7675 int_x86_avx2_pbroadcastw_256>;
7676 defm VPBROADCASTD : avx2_broadcast<0x58, "vpbroadcastd", i32mem, loadi32,
7677 int_x86_avx2_pbroadcastd_128,
7678 int_x86_avx2_pbroadcastd_256>;
7679 defm VPBROADCASTQ : avx2_broadcast<0x59, "vpbroadcastq", i64mem, loadi64,
7680 int_x86_avx2_pbroadcastq_128,
7681 int_x86_avx2_pbroadcastq_256>;
7683 let Predicates = [HasAVX2] in {
7684 def : Pat<(v16i8 (X86VBroadcast (loadi8 addr:$src))),
7685 (VPBROADCASTBrm addr:$src)>;
7686 def : Pat<(v32i8 (X86VBroadcast (loadi8 addr:$src))),
7687 (VPBROADCASTBYrm addr:$src)>;
7688 def : Pat<(v8i16 (X86VBroadcast (loadi16 addr:$src))),
7689 (VPBROADCASTWrm addr:$src)>;
7690 def : Pat<(v16i16 (X86VBroadcast (loadi16 addr:$src))),
7691 (VPBROADCASTWYrm addr:$src)>;
7692 def : Pat<(v4i32 (X86VBroadcast (loadi32 addr:$src))),
7693 (VPBROADCASTDrm addr:$src)>;
7694 def : Pat<(v8i32 (X86VBroadcast (loadi32 addr:$src))),
7695 (VPBROADCASTDYrm addr:$src)>;
7696 def : Pat<(v2i64 (X86VBroadcast (loadi64 addr:$src))),
7697 (VPBROADCASTQrm addr:$src)>;
7698 def : Pat<(v4i64 (X86VBroadcast (loadi64 addr:$src))),
7699 (VPBROADCASTQYrm addr:$src)>;
7701 def : Pat<(v16i8 (X86VBroadcast (v16i8 VR128:$src))),
7702 (VPBROADCASTBrr VR128:$src)>;
7703 def : Pat<(v32i8 (X86VBroadcast (v16i8 VR128:$src))),
7704 (VPBROADCASTBYrr VR128:$src)>;
7705 def : Pat<(v8i16 (X86VBroadcast (v8i16 VR128:$src))),
7706 (VPBROADCASTWrr VR128:$src)>;
7707 def : Pat<(v16i16 (X86VBroadcast (v8i16 VR128:$src))),
7708 (VPBROADCASTWYrr VR128:$src)>;
7709 def : Pat<(v4i32 (X86VBroadcast (v4i32 VR128:$src))),
7710 (VPBROADCASTDrr VR128:$src)>;
7711 def : Pat<(v8i32 (X86VBroadcast (v4i32 VR128:$src))),
7712 (VPBROADCASTDYrr VR128:$src)>;
7713 def : Pat<(v2i64 (X86VBroadcast (v2i64 VR128:$src))),
7714 (VPBROADCASTQrr VR128:$src)>;
7715 def : Pat<(v4i64 (X86VBroadcast (v2i64 VR128:$src))),
7716 (VPBROADCASTQYrr VR128:$src)>;
7717 def : Pat<(v4f32 (X86VBroadcast (v4f32 VR128:$src))),
7718 (VBROADCASTSSrr VR128:$src)>;
7719 def : Pat<(v8f32 (X86VBroadcast (v4f32 VR128:$src))),
7720 (VBROADCASTSSYrr VR128:$src)>;
7721 def : Pat<(v2f64 (X86VBroadcast (v2f64 VR128:$src))),
7722 (VPBROADCASTQrr VR128:$src)>;
7723 def : Pat<(v4f64 (X86VBroadcast (v2f64 VR128:$src))),
7724 (VBROADCASTSDYrr VR128:$src)>;
7726 // Provide fallback in case the load node that is used in the patterns above
7727 // is used by additional users, which prevents the pattern selection.
7728 let AddedComplexity = 20 in {
7729 def : Pat<(v4f32 (X86VBroadcast FR32:$src)),
7731 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss))>;
7732 def : Pat<(v8f32 (X86VBroadcast FR32:$src)),
7734 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss))>;
7735 def : Pat<(v4f64 (X86VBroadcast FR64:$src)),
7737 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd))>;
7739 def : Pat<(v4i32 (X86VBroadcast GR32:$src)),
7741 (INSERT_SUBREG (v4i32 (IMPLICIT_DEF)), GR32:$src, sub_ss))>;
7742 def : Pat<(v8i32 (X86VBroadcast GR32:$src)),
7744 (INSERT_SUBREG (v4i32 (IMPLICIT_DEF)), GR32:$src, sub_ss))>;
7745 def : Pat<(v4i64 (X86VBroadcast GR64:$src)),
7747 (INSERT_SUBREG (v2i64 (IMPLICIT_DEF)), GR64:$src, sub_sd))>;
7751 // AVX1 broadcast patterns
7752 let Predicates = [HasAVX] in {
7753 def : Pat<(v8i32 (X86VBroadcast (loadi32 addr:$src))),
7754 (VBROADCASTSSYrm addr:$src)>;
7755 def : Pat<(v4i64 (X86VBroadcast (loadi64 addr:$src))),
7756 (VBROADCASTSDrm addr:$src)>;
7757 def : Pat<(v8f32 (X86VBroadcast (loadf32 addr:$src))),
7758 (VBROADCASTSSYrm addr:$src)>;
7759 def : Pat<(v4f64 (X86VBroadcast (loadf64 addr:$src))),
7760 (VBROADCASTSDrm addr:$src)>;
7761 def : Pat<(v4f32 (X86VBroadcast (loadf32 addr:$src))),
7762 (VBROADCASTSSrm addr:$src)>;
7763 def : Pat<(v4i32 (X86VBroadcast (loadi32 addr:$src))),
7764 (VBROADCASTSSrm addr:$src)>;
7766 // Provide fallback in case the load node that is used in the patterns above
7767 // is used by additional users, which prevents the pattern selection.
7768 let AddedComplexity = 20 in {
7769 // 128bit broadcasts:
7770 def : Pat<(v4f32 (X86VBroadcast FR32:$src)),
7772 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss), 0)>;
7773 def : Pat<(v8f32 (X86VBroadcast FR32:$src)),
7774 (VINSERTF128rr (INSERT_SUBREG (v8f32 (IMPLICIT_DEF)),
7776 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss), 0),
7779 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss),
7781 def : Pat<(v4f64 (X86VBroadcast FR64:$src)),
7782 (VINSERTF128rr (INSERT_SUBREG (v4f64 (IMPLICIT_DEF)),
7784 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd), 0),
7787 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd),
7790 def : Pat<(v4i32 (X86VBroadcast GR32:$src)),
7792 (INSERT_SUBREG (v4i32 (IMPLICIT_DEF)), GR32:$src, sub_ss), 0)>;
7793 def : Pat<(v8i32 (X86VBroadcast GR32:$src)),
7794 (VINSERTF128rr (INSERT_SUBREG (v8i32 (IMPLICIT_DEF)),
7796 (INSERT_SUBREG (v4i32 (IMPLICIT_DEF)), GR32:$src, sub_ss), 0),
7799 (INSERT_SUBREG (v4i32 (IMPLICIT_DEF)), GR32:$src, sub_ss),
7801 def : Pat<(v4i64 (X86VBroadcast GR64:$src)),
7802 (VINSERTF128rr (INSERT_SUBREG (v4i64 (IMPLICIT_DEF)),
7804 (INSERT_SUBREG (v2i64 (IMPLICIT_DEF)), GR64:$src, sub_sd), 0),
7807 (INSERT_SUBREG (v2i64 (IMPLICIT_DEF)), GR64:$src, sub_sd),
7812 //===----------------------------------------------------------------------===//
7813 // VPERM - Permute instructions
7816 multiclass avx2_perm<bits<8> opc, string OpcodeStr, PatFrag mem_frag,
7818 def Yrr : AVX28I<opc, MRMSrcReg, (outs VR256:$dst),
7819 (ins VR256:$src1, VR256:$src2),
7820 !strconcat(OpcodeStr,
7821 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7823 (OpVT (X86VPermv VR256:$src1, VR256:$src2)))]>, VEX_4V;
7824 def Yrm : AVX28I<opc, MRMSrcMem, (outs VR256:$dst),
7825 (ins VR256:$src1, i256mem:$src2),
7826 !strconcat(OpcodeStr,
7827 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7829 (OpVT (X86VPermv VR256:$src1,
7830 (bitconvert (mem_frag addr:$src2)))))]>,
7834 defm VPERMD : avx2_perm<0x36, "vpermd", memopv4i64, v8i32>;
7835 let ExeDomain = SSEPackedSingle in
7836 defm VPERMPS : avx2_perm<0x16, "vpermps", memopv8f32, v8f32>;
7838 multiclass avx2_perm_imm<bits<8> opc, string OpcodeStr, PatFrag mem_frag,
7840 def Yri : AVX2AIi8<opc, MRMSrcReg, (outs VR256:$dst),
7841 (ins VR256:$src1, i8imm:$src2),
7842 !strconcat(OpcodeStr,
7843 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7845 (OpVT (X86VPermi VR256:$src1, (i8 imm:$src2))))]>, VEX;
7846 def Ymi : AVX2AIi8<opc, MRMSrcMem, (outs VR256:$dst),
7847 (ins i256mem:$src1, i8imm:$src2),
7848 !strconcat(OpcodeStr,
7849 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7851 (OpVT (X86VPermi (mem_frag addr:$src1),
7852 (i8 imm:$src2))))]>, VEX;
7855 defm VPERMQ : avx2_perm_imm<0x00, "vpermq", memopv4i64, v4i64>, VEX_W;
7856 let ExeDomain = SSEPackedDouble in
7857 defm VPERMPD : avx2_perm_imm<0x01, "vpermpd", memopv4f64, v4f64>, VEX_W;
7859 //===----------------------------------------------------------------------===//
7860 // VPERM2I128 - Permute Floating-Point Values in 128-bit chunks
7862 let AddedComplexity = 1 in {
7863 def VPERM2I128rr : AVX2AIi8<0x46, MRMSrcReg, (outs VR256:$dst),
7864 (ins VR256:$src1, VR256:$src2, i8imm:$src3),
7865 "vperm2i128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7866 [(set VR256:$dst, (v4i64 (X86VPerm2x128 VR256:$src1, VR256:$src2,
7867 (i8 imm:$src3))))]>, VEX_4V;
7868 def VPERM2I128rm : AVX2AIi8<0x46, MRMSrcMem, (outs VR256:$dst),
7869 (ins VR256:$src1, f256mem:$src2, i8imm:$src3),
7870 "vperm2i128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7871 [(set VR256:$dst, (X86VPerm2x128 VR256:$src1, (memopv4i64 addr:$src2),
7872 (i8 imm:$src3)))]>, VEX_4V;
7875 let Predicates = [HasAVX2], AddedComplexity = 1 in {
7876 def : Pat<(v8i32 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7877 (VPERM2I128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7878 def : Pat<(v32i8 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7879 (VPERM2I128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7880 def : Pat<(v16i16 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7881 (VPERM2I128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7883 def : Pat<(v32i8 (X86VPerm2x128 VR256:$src1, (bc_v32i8 (memopv4i64 addr:$src2)),
7885 (VPERM2I128rm VR256:$src1, addr:$src2, imm:$imm)>;
7886 def : Pat<(v16i16 (X86VPerm2x128 VR256:$src1,
7887 (bc_v16i16 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
7888 (VPERM2I128rm VR256:$src1, addr:$src2, imm:$imm)>;
7889 def : Pat<(v8i32 (X86VPerm2x128 VR256:$src1, (bc_v8i32 (memopv4i64 addr:$src2)),
7891 (VPERM2I128rm VR256:$src1, addr:$src2, imm:$imm)>;
7895 //===----------------------------------------------------------------------===//
7896 // VINSERTI128 - Insert packed integer values
7898 let neverHasSideEffects = 1 in {
7899 def VINSERTI128rr : AVX2AIi8<0x38, MRMSrcReg, (outs VR256:$dst),
7900 (ins VR256:$src1, VR128:$src2, i8imm:$src3),
7901 "vinserti128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7904 def VINSERTI128rm : AVX2AIi8<0x38, MRMSrcMem, (outs VR256:$dst),
7905 (ins VR256:$src1, i128mem:$src2, i8imm:$src3),
7906 "vinserti128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7910 let Predicates = [HasAVX2], AddedComplexity = 1 in {
7911 def : Pat<(vinsertf128_insert:$ins (v4i64 VR256:$src1), (v2i64 VR128:$src2),
7913 (VINSERTI128rr VR256:$src1, VR128:$src2,
7914 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7915 def : Pat<(vinsertf128_insert:$ins (v8i32 VR256:$src1), (v4i32 VR128:$src2),
7917 (VINSERTI128rr VR256:$src1, VR128:$src2,
7918 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7919 def : Pat<(vinsertf128_insert:$ins (v32i8 VR256:$src1), (v16i8 VR128:$src2),
7921 (VINSERTI128rr VR256:$src1, VR128:$src2,
7922 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7923 def : Pat<(vinsertf128_insert:$ins (v16i16 VR256:$src1), (v8i16 VR128:$src2),
7925 (VINSERTI128rr VR256:$src1, VR128:$src2,
7926 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7929 //===----------------------------------------------------------------------===//
7930 // VEXTRACTI128 - Extract packed integer values
7932 def VEXTRACTI128rr : AVX2AIi8<0x39, MRMDestReg, (outs VR128:$dst),
7933 (ins VR256:$src1, i8imm:$src2),
7934 "vextracti128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7936 (int_x86_avx2_vextracti128 VR256:$src1, imm:$src2))]>,
7938 let neverHasSideEffects = 1, mayStore = 1 in
7939 def VEXTRACTI128mr : AVX2AIi8<0x39, MRMDestMem, (outs),
7940 (ins i128mem:$dst, VR256:$src1, i8imm:$src2),
7941 "vextracti128\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>, VEX;
7943 let Predicates = [HasAVX2], AddedComplexity = 1 in {
7944 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7945 (v2i64 (VEXTRACTI128rr
7946 (v4i64 VR256:$src1),
7947 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7948 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7949 (v4i32 (VEXTRACTI128rr
7950 (v8i32 VR256:$src1),
7951 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7952 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7953 (v8i16 (VEXTRACTI128rr
7954 (v16i16 VR256:$src1),
7955 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7956 def : Pat<(vextractf128_extract:$ext VR256:$src1, (i32 imm)),
7957 (v16i8 (VEXTRACTI128rr
7958 (v32i8 VR256:$src1),
7959 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7962 //===----------------------------------------------------------------------===//
7963 // VPMASKMOV - Conditional SIMD Integer Packed Loads and Stores
7965 multiclass avx2_pmovmask<string OpcodeStr,
7966 Intrinsic IntLd128, Intrinsic IntLd256,
7967 Intrinsic IntSt128, Intrinsic IntSt256> {
7968 def rm : AVX28I<0x8c, MRMSrcMem, (outs VR128:$dst),
7969 (ins VR128:$src1, i128mem:$src2),
7970 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7971 [(set VR128:$dst, (IntLd128 addr:$src2, VR128:$src1))]>, VEX_4V;
7972 def Yrm : AVX28I<0x8c, MRMSrcMem, (outs VR256:$dst),
7973 (ins VR256:$src1, i256mem:$src2),
7974 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7975 [(set VR256:$dst, (IntLd256 addr:$src2, VR256:$src1))]>, VEX_4V;
7976 def mr : AVX28I<0x8e, MRMDestMem, (outs),
7977 (ins i128mem:$dst, VR128:$src1, VR128:$src2),
7978 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7979 [(IntSt128 addr:$dst, VR128:$src1, VR128:$src2)]>, VEX_4V;
7980 def Ymr : AVX28I<0x8e, MRMDestMem, (outs),
7981 (ins i256mem:$dst, VR256:$src1, VR256:$src2),
7982 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7983 [(IntSt256 addr:$dst, VR256:$src1, VR256:$src2)]>, VEX_4V;
7986 defm VPMASKMOVD : avx2_pmovmask<"vpmaskmovd",
7987 int_x86_avx2_maskload_d,
7988 int_x86_avx2_maskload_d_256,
7989 int_x86_avx2_maskstore_d,
7990 int_x86_avx2_maskstore_d_256>;
7991 defm VPMASKMOVQ : avx2_pmovmask<"vpmaskmovq",
7992 int_x86_avx2_maskload_q,
7993 int_x86_avx2_maskload_q_256,
7994 int_x86_avx2_maskstore_q,
7995 int_x86_avx2_maskstore_q_256>, VEX_W;
7998 //===----------------------------------------------------------------------===//
7999 // Variable Bit Shifts
8001 multiclass avx2_var_shift<bits<8> opc, string OpcodeStr, SDNode OpNode,
8002 ValueType vt128, ValueType vt256> {
8003 def rr : AVX28I<opc, MRMSrcReg, (outs VR128:$dst),
8004 (ins VR128:$src1, VR128:$src2),
8005 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8007 (vt128 (OpNode VR128:$src1, (vt128 VR128:$src2))))]>,
8009 def rm : AVX28I<opc, MRMSrcMem, (outs VR128:$dst),
8010 (ins VR128:$src1, i128mem:$src2),
8011 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8013 (vt128 (OpNode VR128:$src1,
8014 (vt128 (bitconvert (memopv2i64 addr:$src2))))))]>,
8016 def Yrr : AVX28I<opc, MRMSrcReg, (outs VR256:$dst),
8017 (ins VR256:$src1, VR256:$src2),
8018 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8020 (vt256 (OpNode VR256:$src1, (vt256 VR256:$src2))))]>,
8022 def Yrm : AVX28I<opc, MRMSrcMem, (outs VR256:$dst),
8023 (ins VR256:$src1, i256mem:$src2),
8024 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8026 (vt256 (OpNode VR256:$src1,
8027 (vt256 (bitconvert (memopv4i64 addr:$src2))))))]>,
8031 defm VPSLLVD : avx2_var_shift<0x47, "vpsllvd", shl, v4i32, v8i32>;
8032 defm VPSLLVQ : avx2_var_shift<0x47, "vpsllvq", shl, v2i64, v4i64>, VEX_W;
8033 defm VPSRLVD : avx2_var_shift<0x45, "vpsrlvd", srl, v4i32, v8i32>;
8034 defm VPSRLVQ : avx2_var_shift<0x45, "vpsrlvq", srl, v2i64, v4i64>, VEX_W;
8035 defm VPSRAVD : avx2_var_shift<0x46, "vpsravd", sra, v4i32, v8i32>;
8037 //===----------------------------------------------------------------------===//
8038 // VGATHER - GATHER Operations
8039 multiclass avx2_gather<bits<8> opc, string OpcodeStr,
8040 RegisterClass RC256, X86MemOperand memop256,
8041 Intrinsic IntGather128, Intrinsic IntGather256> {
8042 def rm : AVX28I<opc, MRMSrcMem, (outs VR128:$dst),
8043 (ins VR128:$src1, v128mem:$src2, VR128:$mask),
8044 !strconcat(OpcodeStr,
8045 "\t{$src1, $src2, $mask|$mask, $src2, $src1}"),
8047 def Yrm : AVX28I<opc, MRMSrcMem, (outs RC256:$dst),
8048 (ins RC256:$src1, memop256:$src2, RC256:$mask),
8049 !strconcat(OpcodeStr,
8050 "\t{$src1, $src2, $mask|$mask, $src2, $src1}"),
8051 []>, VEX_4VOp3, VEX_L;
8054 let Constraints = "$src1 = $dst" in {
8055 defm VGATHERDPD : avx2_gather<0x92, "vgatherdpd",
8057 int_x86_avx2_gather_d_pd,
8058 int_x86_avx2_gather_d_pd_256>, VEX_W;
8059 defm VGATHERQPD : avx2_gather<0x93, "vgatherqpd",
8061 int_x86_avx2_gather_q_pd,
8062 int_x86_avx2_gather_q_pd_256>, VEX_W;
8063 defm VGATHERDPS : avx2_gather<0x92, "vgatherdps",
8065 int_x86_avx2_gather_d_ps,
8066 int_x86_avx2_gather_d_ps_256>;
8067 defm VGATHERQPS : avx2_gather<0x93, "vgatherqps",
8069 int_x86_avx2_gather_q_ps,
8070 int_x86_avx2_gather_q_ps_256>;
8071 defm VPGATHERDQ : avx2_gather<0x90, "vpgatherdq",
8073 int_x86_avx2_gather_d_q,
8074 int_x86_avx2_gather_d_q_256>, VEX_W;
8075 defm VPGATHERQQ : avx2_gather<0x91, "vpgatherqq",
8077 int_x86_avx2_gather_q_q,
8078 int_x86_avx2_gather_q_q_256>, VEX_W;
8079 defm VPGATHERDD : avx2_gather<0x90, "vpgatherdd",
8081 int_x86_avx2_gather_d_d,
8082 int_x86_avx2_gather_d_d_256>;
8083 defm VPGATHERQD : avx2_gather<0x91, "vpgatherqd",
8085 int_x86_avx2_gather_q_d,
8086 int_x86_avx2_gather_q_d_256>;