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 let isCommutable = 1, hasSideEffects = 0 in
208 def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
210 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
211 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
212 pat_rr, IIC_DEFAULT, d>;
213 def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
215 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
216 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
217 pat_rm, IIC_DEFAULT, d>;
220 //===----------------------------------------------------------------------===//
221 // Non-instruction patterns
222 //===----------------------------------------------------------------------===//
224 // A vector extract of the first f32/f64 position is a subregister copy
225 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
226 (COPY_TO_REGCLASS (v4f32 VR128:$src), FR32)>;
227 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
228 (COPY_TO_REGCLASS (v2f64 VR128:$src), FR64)>;
230 // A 128-bit subvector extract from the first 256-bit vector position
231 // is a subregister copy that needs no instruction.
232 def : Pat<(v4i32 (extract_subvector (v8i32 VR256:$src), (iPTR 0))),
233 (v4i32 (EXTRACT_SUBREG (v8i32 VR256:$src), sub_xmm))>;
234 def : Pat<(v4f32 (extract_subvector (v8f32 VR256:$src), (iPTR 0))),
235 (v4f32 (EXTRACT_SUBREG (v8f32 VR256:$src), sub_xmm))>;
237 def : Pat<(v2i64 (extract_subvector (v4i64 VR256:$src), (iPTR 0))),
238 (v2i64 (EXTRACT_SUBREG (v4i64 VR256:$src), sub_xmm))>;
239 def : Pat<(v2f64 (extract_subvector (v4f64 VR256:$src), (iPTR 0))),
240 (v2f64 (EXTRACT_SUBREG (v4f64 VR256:$src), sub_xmm))>;
242 def : Pat<(v8i16 (extract_subvector (v16i16 VR256:$src), (iPTR 0))),
243 (v8i16 (EXTRACT_SUBREG (v16i16 VR256:$src), sub_xmm))>;
244 def : Pat<(v16i8 (extract_subvector (v32i8 VR256:$src), (iPTR 0))),
245 (v16i8 (EXTRACT_SUBREG (v32i8 VR256:$src), sub_xmm))>;
247 // A 128-bit subvector insert to the first 256-bit vector position
248 // is a subregister copy that needs no instruction.
249 let AddedComplexity = 25 in { // to give priority over vinsertf128rm
250 def : Pat<(insert_subvector undef, (v2i64 VR128:$src), (iPTR 0)),
251 (INSERT_SUBREG (v4i64 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
252 def : Pat<(insert_subvector undef, (v2f64 VR128:$src), (iPTR 0)),
253 (INSERT_SUBREG (v4f64 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
254 def : Pat<(insert_subvector undef, (v4i32 VR128:$src), (iPTR 0)),
255 (INSERT_SUBREG (v8i32 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
256 def : Pat<(insert_subvector undef, (v4f32 VR128:$src), (iPTR 0)),
257 (INSERT_SUBREG (v8f32 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
258 def : Pat<(insert_subvector undef, (v8i16 VR128:$src), (iPTR 0)),
259 (INSERT_SUBREG (v16i16 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
260 def : Pat<(insert_subvector undef, (v16i8 VR128:$src), (iPTR 0)),
261 (INSERT_SUBREG (v32i8 (IMPLICIT_DEF)), VR128:$src, sub_xmm)>;
264 // Implicitly promote a 32-bit scalar to a vector.
265 def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
266 (COPY_TO_REGCLASS FR32:$src, VR128)>;
267 def : Pat<(v8f32 (scalar_to_vector FR32:$src)),
268 (COPY_TO_REGCLASS FR32:$src, VR128)>;
269 // Implicitly promote a 64-bit scalar to a vector.
270 def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
271 (COPY_TO_REGCLASS FR64:$src, VR128)>;
272 def : Pat<(v4f64 (scalar_to_vector FR64:$src)),
273 (COPY_TO_REGCLASS FR64:$src, VR128)>;
275 // Bitcasts between 128-bit vector types. Return the original type since
276 // no instruction is needed for the conversion
277 let Predicates = [HasSSE2] in {
278 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
279 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
280 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
281 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
282 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
283 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
284 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
285 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
286 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
287 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
288 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
289 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
290 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
291 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
292 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
293 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
294 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
295 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
296 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
297 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
298 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
299 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
300 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
301 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
302 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
303 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
304 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
305 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
306 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
307 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
310 // Bitcasts between 256-bit vector types. Return the original type since
311 // no instruction is needed for the conversion
312 let Predicates = [HasAVX] in {
313 def : Pat<(v4f64 (bitconvert (v8f32 VR256:$src))), (v4f64 VR256:$src)>;
314 def : Pat<(v4f64 (bitconvert (v8i32 VR256:$src))), (v4f64 VR256:$src)>;
315 def : Pat<(v4f64 (bitconvert (v4i64 VR256:$src))), (v4f64 VR256:$src)>;
316 def : Pat<(v4f64 (bitconvert (v16i16 VR256:$src))), (v4f64 VR256:$src)>;
317 def : Pat<(v4f64 (bitconvert (v32i8 VR256:$src))), (v4f64 VR256:$src)>;
318 def : Pat<(v8f32 (bitconvert (v8i32 VR256:$src))), (v8f32 VR256:$src)>;
319 def : Pat<(v8f32 (bitconvert (v4i64 VR256:$src))), (v8f32 VR256:$src)>;
320 def : Pat<(v8f32 (bitconvert (v4f64 VR256:$src))), (v8f32 VR256:$src)>;
321 def : Pat<(v8f32 (bitconvert (v32i8 VR256:$src))), (v8f32 VR256:$src)>;
322 def : Pat<(v8f32 (bitconvert (v16i16 VR256:$src))), (v8f32 VR256:$src)>;
323 def : Pat<(v4i64 (bitconvert (v8f32 VR256:$src))), (v4i64 VR256:$src)>;
324 def : Pat<(v4i64 (bitconvert (v8i32 VR256:$src))), (v4i64 VR256:$src)>;
325 def : Pat<(v4i64 (bitconvert (v4f64 VR256:$src))), (v4i64 VR256:$src)>;
326 def : Pat<(v4i64 (bitconvert (v32i8 VR256:$src))), (v4i64 VR256:$src)>;
327 def : Pat<(v4i64 (bitconvert (v16i16 VR256:$src))), (v4i64 VR256:$src)>;
328 def : Pat<(v32i8 (bitconvert (v4f64 VR256:$src))), (v32i8 VR256:$src)>;
329 def : Pat<(v32i8 (bitconvert (v4i64 VR256:$src))), (v32i8 VR256:$src)>;
330 def : Pat<(v32i8 (bitconvert (v8f32 VR256:$src))), (v32i8 VR256:$src)>;
331 def : Pat<(v32i8 (bitconvert (v8i32 VR256:$src))), (v32i8 VR256:$src)>;
332 def : Pat<(v32i8 (bitconvert (v16i16 VR256:$src))), (v32i8 VR256:$src)>;
333 def : Pat<(v8i32 (bitconvert (v32i8 VR256:$src))), (v8i32 VR256:$src)>;
334 def : Pat<(v8i32 (bitconvert (v16i16 VR256:$src))), (v8i32 VR256:$src)>;
335 def : Pat<(v8i32 (bitconvert (v8f32 VR256:$src))), (v8i32 VR256:$src)>;
336 def : Pat<(v8i32 (bitconvert (v4i64 VR256:$src))), (v8i32 VR256:$src)>;
337 def : Pat<(v8i32 (bitconvert (v4f64 VR256:$src))), (v8i32 VR256:$src)>;
338 def : Pat<(v16i16 (bitconvert (v8f32 VR256:$src))), (v16i16 VR256:$src)>;
339 def : Pat<(v16i16 (bitconvert (v8i32 VR256:$src))), (v16i16 VR256:$src)>;
340 def : Pat<(v16i16 (bitconvert (v4i64 VR256:$src))), (v16i16 VR256:$src)>;
341 def : Pat<(v16i16 (bitconvert (v4f64 VR256:$src))), (v16i16 VR256:$src)>;
342 def : Pat<(v16i16 (bitconvert (v32i8 VR256:$src))), (v16i16 VR256:$src)>;
345 // Alias instructions that map fld0 to xorps for sse or vxorps for avx.
346 // This is expanded by ExpandPostRAPseudos.
347 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
349 def FsFLD0SS : I<0, Pseudo, (outs FR32:$dst), (ins), "",
350 [(set FR32:$dst, fp32imm0)]>, Requires<[HasSSE1]>;
351 def FsFLD0SD : I<0, Pseudo, (outs FR64:$dst), (ins), "",
352 [(set FR64:$dst, fpimm0)]>, Requires<[HasSSE2]>;
355 //===----------------------------------------------------------------------===//
356 // AVX & SSE - Zero/One Vectors
357 //===----------------------------------------------------------------------===//
359 // Alias instruction that maps zero vector to pxor / xorp* for sse.
360 // This is expanded by ExpandPostRAPseudos to an xorps / vxorps, and then
361 // swizzled by ExecutionDepsFix to pxor.
362 // We set canFoldAsLoad because this can be converted to a constant-pool
363 // load of an all-zeros value if folding it would be beneficial.
364 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
366 def V_SET0 : I<0, Pseudo, (outs VR128:$dst), (ins), "",
367 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
370 def : Pat<(v2f64 immAllZerosV), (V_SET0)>;
371 def : Pat<(v4i32 immAllZerosV), (V_SET0)>;
372 def : Pat<(v2i64 immAllZerosV), (V_SET0)>;
373 def : Pat<(v8i16 immAllZerosV), (V_SET0)>;
374 def : Pat<(v16i8 immAllZerosV), (V_SET0)>;
377 // The same as done above but for AVX. The 256-bit AVX1 ISA doesn't support PI,
378 // and doesn't need it because on sandy bridge the register is set to zero
379 // at the rename stage without using any execution unit, so SET0PSY
380 // and SET0PDY can be used for vector int instructions without penalty
381 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
382 isPseudo = 1, Predicates = [HasAVX] in {
383 def AVX_SET0 : I<0, Pseudo, (outs VR256:$dst), (ins), "",
384 [(set VR256:$dst, (v8f32 immAllZerosV))]>;
387 let Predicates = [HasAVX] in
388 def : Pat<(v4f64 immAllZerosV), (AVX_SET0)>;
390 let Predicates = [HasAVX2] in {
391 def : Pat<(v4i64 immAllZerosV), (AVX_SET0)>;
392 def : Pat<(v8i32 immAllZerosV), (AVX_SET0)>;
393 def : Pat<(v16i16 immAllZerosV), (AVX_SET0)>;
394 def : Pat<(v32i8 immAllZerosV), (AVX_SET0)>;
397 // AVX1 has no support for 256-bit integer instructions, but since the 128-bit
398 // VPXOR instruction writes zero to its upper part, it's safe build zeros.
399 let Predicates = [HasAVX1Only] in {
400 def : Pat<(v32i8 immAllZerosV), (SUBREG_TO_REG (i8 0), (V_SET0), sub_xmm)>;
401 def : Pat<(bc_v32i8 (v8f32 immAllZerosV)),
402 (SUBREG_TO_REG (i8 0), (V_SET0), sub_xmm)>;
404 def : Pat<(v16i16 immAllZerosV), (SUBREG_TO_REG (i16 0), (V_SET0), sub_xmm)>;
405 def : Pat<(bc_v16i16 (v8f32 immAllZerosV)),
406 (SUBREG_TO_REG (i16 0), (V_SET0), sub_xmm)>;
408 def : Pat<(v8i32 immAllZerosV), (SUBREG_TO_REG (i32 0), (V_SET0), sub_xmm)>;
409 def : Pat<(bc_v8i32 (v8f32 immAllZerosV)),
410 (SUBREG_TO_REG (i32 0), (V_SET0), sub_xmm)>;
412 def : Pat<(v4i64 immAllZerosV), (SUBREG_TO_REG (i64 0), (V_SET0), sub_xmm)>;
413 def : Pat<(bc_v4i64 (v8f32 immAllZerosV)),
414 (SUBREG_TO_REG (i64 0), (V_SET0), sub_xmm)>;
417 // We set canFoldAsLoad because this can be converted to a constant-pool
418 // load of an all-ones value if folding it would be beneficial.
419 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
421 def V_SETALLONES : I<0, Pseudo, (outs VR128:$dst), (ins), "",
422 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
423 let Predicates = [HasAVX2] in
424 def AVX2_SETALLONES : I<0, Pseudo, (outs VR256:$dst), (ins), "",
425 [(set VR256:$dst, (v8i32 immAllOnesV))]>;
429 //===----------------------------------------------------------------------===//
430 // SSE 1 & 2 - Move FP Scalar Instructions
432 // Move Instructions. Register-to-register movss/movsd is not used for FR32/64
433 // register copies because it's a partial register update; FsMOVAPSrr/FsMOVAPDrr
434 // is used instead. Register-to-register movss/movsd is not modeled as an
435 // INSERT_SUBREG because INSERT_SUBREG requires that the insert be implementable
436 // in terms of a copy, and just mentioned, we don't use movss/movsd for copies.
437 //===----------------------------------------------------------------------===//
439 class sse12_move_rr<RegisterClass RC, SDNode OpNode, ValueType vt, string asm> :
440 SI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, RC:$src2), asm,
441 [(set VR128:$dst, (vt (OpNode VR128:$src1,
442 (scalar_to_vector RC:$src2))))],
445 // Loading from memory automatically zeroing upper bits.
446 class sse12_move_rm<RegisterClass RC, X86MemOperand x86memop,
447 PatFrag mem_pat, string OpcodeStr> :
448 SI<0x10, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
449 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
450 [(set RC:$dst, (mem_pat addr:$src))],
454 def VMOVSSrr : sse12_move_rr<FR32, X86Movss, v4f32,
455 "movss\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XS, VEX_4V,
457 def VMOVSDrr : sse12_move_rr<FR64, X86Movsd, v2f64,
458 "movsd\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XD, VEX_4V,
461 // For the disassembler
462 let isCodeGenOnly = 1, hasSideEffects = 0 in {
463 def VMOVSSrr_REV : SI<0x11, MRMDestReg, (outs VR128:$dst),
464 (ins VR128:$src1, FR32:$src2),
465 "movss\t{$src2, $src1, $dst|$dst, $src1, $src2}", [],
468 def VMOVSDrr_REV : SI<0x11, MRMDestReg, (outs VR128:$dst),
469 (ins VR128:$src1, FR64:$src2),
470 "movsd\t{$src2, $src1, $dst|$dst, $src1, $src2}", [],
475 let canFoldAsLoad = 1, isReMaterializable = 1 in {
476 def VMOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS, VEX,
478 let AddedComplexity = 20 in
479 def VMOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD, VEX,
483 def VMOVSSmr : SI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
484 "movss\t{$src, $dst|$dst, $src}",
485 [(store FR32:$src, addr:$dst)], IIC_SSE_MOV_S_MR>,
487 def VMOVSDmr : SI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
488 "movsd\t{$src, $dst|$dst, $src}",
489 [(store FR64:$src, addr:$dst)], IIC_SSE_MOV_S_MR>,
493 let Constraints = "$src1 = $dst" in {
494 def MOVSSrr : sse12_move_rr<FR32, X86Movss, v4f32,
495 "movss\t{$src2, $dst|$dst, $src2}">, XS;
496 def MOVSDrr : sse12_move_rr<FR64, X86Movsd, v2f64,
497 "movsd\t{$src2, $dst|$dst, $src2}">, XD;
499 // For the disassembler
500 let isCodeGenOnly = 1, hasSideEffects = 0 in {
501 def MOVSSrr_REV : SI<0x11, MRMDestReg, (outs VR128:$dst),
502 (ins VR128:$src1, FR32:$src2),
503 "movss\t{$src2, $dst|$dst, $src2}", [],
504 IIC_SSE_MOV_S_RR>, XS;
505 def MOVSDrr_REV : SI<0x11, MRMDestReg, (outs VR128:$dst),
506 (ins VR128:$src1, FR64:$src2),
507 "movsd\t{$src2, $dst|$dst, $src2}", [],
508 IIC_SSE_MOV_S_RR>, XD;
512 let canFoldAsLoad = 1, isReMaterializable = 1 in {
513 def MOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS;
515 let AddedComplexity = 20 in
516 def MOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD;
519 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
520 "movss\t{$src, $dst|$dst, $src}",
521 [(store FR32:$src, addr:$dst)], IIC_SSE_MOV_S_MR>;
522 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
523 "movsd\t{$src, $dst|$dst, $src}",
524 [(store FR64:$src, addr:$dst)], IIC_SSE_MOV_S_MR>;
527 let Predicates = [HasAVX] in {
528 let AddedComplexity = 15 in {
529 // Move scalar to XMM zero-extended, zeroing a VR128 then do a
530 // MOVS{S,D} to the lower bits.
531 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
532 (VMOVSSrr (v4f32 (V_SET0)), FR32:$src)>;
533 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
534 (VMOVSSrr (v4f32 (V_SET0)), (COPY_TO_REGCLASS VR128:$src, FR32))>;
535 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
536 (VMOVSSrr (v4i32 (V_SET0)), (COPY_TO_REGCLASS VR128:$src, FR32))>;
537 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
538 (VMOVSDrr (v2f64 (V_SET0)), FR64:$src)>;
540 // Move low f32 and clear high bits.
541 def : Pat<(v8f32 (X86vzmovl (v8f32 VR256:$src))),
542 (SUBREG_TO_REG (i32 0),
543 (VMOVSSrr (v4f32 (V_SET0)),
544 (EXTRACT_SUBREG (v8f32 VR256:$src), sub_xmm)), sub_xmm)>;
545 def : Pat<(v8i32 (X86vzmovl (v8i32 VR256:$src))),
546 (SUBREG_TO_REG (i32 0),
547 (VMOVSSrr (v4i32 (V_SET0)),
548 (EXTRACT_SUBREG (v8i32 VR256:$src), sub_xmm)), sub_xmm)>;
551 let AddedComplexity = 20 in {
552 // MOVSSrm zeros the high parts of the register; represent this
553 // with SUBREG_TO_REG. The AVX versions also write: DST[255:128] <- 0
554 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
555 (COPY_TO_REGCLASS (VMOVSSrm addr:$src), VR128)>;
556 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
557 (COPY_TO_REGCLASS (VMOVSSrm addr:$src), VR128)>;
558 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
559 (COPY_TO_REGCLASS (VMOVSSrm addr:$src), VR128)>;
561 // MOVSDrm zeros the high parts of the register; represent this
562 // with SUBREG_TO_REG. The AVX versions also write: DST[255:128] <- 0
563 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
564 (COPY_TO_REGCLASS (VMOVSDrm addr:$src), VR128)>;
565 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
566 (COPY_TO_REGCLASS (VMOVSDrm addr:$src), VR128)>;
567 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
568 (COPY_TO_REGCLASS (VMOVSDrm addr:$src), VR128)>;
569 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
570 (COPY_TO_REGCLASS (VMOVSDrm addr:$src), VR128)>;
571 def : Pat<(v2f64 (X86vzload addr:$src)),
572 (COPY_TO_REGCLASS (VMOVSDrm addr:$src), VR128)>;
574 // Represent the same patterns above but in the form they appear for
576 def : Pat<(v8i32 (X86vzmovl (insert_subvector undef,
577 (v4i32 (scalar_to_vector (loadi32 addr:$src))), (iPTR 0)))),
578 (SUBREG_TO_REG (i32 0), (VMOVSSrm addr:$src), sub_xmm)>;
579 def : Pat<(v8f32 (X86vzmovl (insert_subvector undef,
580 (v4f32 (scalar_to_vector (loadf32 addr:$src))), (iPTR 0)))),
581 (SUBREG_TO_REG (i32 0), (VMOVSSrm addr:$src), sub_xmm)>;
582 def : Pat<(v4f64 (X86vzmovl (insert_subvector undef,
583 (v2f64 (scalar_to_vector (loadf64 addr:$src))), (iPTR 0)))),
584 (SUBREG_TO_REG (i32 0), (VMOVSDrm addr:$src), sub_xmm)>;
586 def : Pat<(v8f32 (X86vzmovl (insert_subvector undef,
587 (v4f32 (scalar_to_vector FR32:$src)), (iPTR 0)))),
588 (SUBREG_TO_REG (i32 0),
589 (v4f32 (VMOVSSrr (v4f32 (V_SET0)), FR32:$src)),
591 def : Pat<(v4f64 (X86vzmovl (insert_subvector undef,
592 (v2f64 (scalar_to_vector FR64:$src)), (iPTR 0)))),
593 (SUBREG_TO_REG (i64 0),
594 (v2f64 (VMOVSDrr (v2f64 (V_SET0)), FR64:$src)),
596 def : Pat<(v4i64 (X86vzmovl (insert_subvector undef,
597 (v2i64 (scalar_to_vector (loadi64 addr:$src))), (iPTR 0)))),
598 (SUBREG_TO_REG (i64 0), (VMOVSDrm addr:$src), sub_xmm)>;
600 // Move low f64 and clear high bits.
601 def : Pat<(v4f64 (X86vzmovl (v4f64 VR256:$src))),
602 (SUBREG_TO_REG (i32 0),
603 (VMOVSDrr (v2f64 (V_SET0)),
604 (EXTRACT_SUBREG (v4f64 VR256:$src), sub_xmm)), sub_xmm)>;
606 def : Pat<(v4i64 (X86vzmovl (v4i64 VR256:$src))),
607 (SUBREG_TO_REG (i32 0),
608 (VMOVSDrr (v2i64 (V_SET0)),
609 (EXTRACT_SUBREG (v4i64 VR256:$src), sub_xmm)), sub_xmm)>;
611 // Extract and store.
612 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
614 (VMOVSSmr addr:$dst, (COPY_TO_REGCLASS (v4f32 VR128:$src), FR32))>;
615 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
617 (VMOVSDmr addr:$dst, (COPY_TO_REGCLASS (v2f64 VR128:$src), FR64))>;
619 // Shuffle with VMOVSS
620 def : Pat<(v4i32 (X86Movss VR128:$src1, VR128:$src2)),
621 (VMOVSSrr (v4i32 VR128:$src1),
622 (COPY_TO_REGCLASS (v4i32 VR128:$src2), FR32))>;
623 def : Pat<(v4f32 (X86Movss VR128:$src1, VR128:$src2)),
624 (VMOVSSrr (v4f32 VR128:$src1),
625 (COPY_TO_REGCLASS (v4f32 VR128:$src2), FR32))>;
628 def : Pat<(v8i32 (X86Movss VR256:$src1, VR256:$src2)),
629 (SUBREG_TO_REG (i32 0),
630 (VMOVSSrr (EXTRACT_SUBREG (v8i32 VR256:$src1), sub_xmm),
631 (EXTRACT_SUBREG (v8i32 VR256:$src2), sub_xmm)),
633 def : Pat<(v8f32 (X86Movss VR256:$src1, VR256:$src2)),
634 (SUBREG_TO_REG (i32 0),
635 (VMOVSSrr (EXTRACT_SUBREG (v8f32 VR256:$src1), sub_xmm),
636 (EXTRACT_SUBREG (v8f32 VR256:$src2), sub_xmm)),
639 // Shuffle with VMOVSD
640 def : Pat<(v2i64 (X86Movsd VR128:$src1, VR128:$src2)),
641 (VMOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
642 def : Pat<(v2f64 (X86Movsd VR128:$src1, VR128:$src2)),
643 (VMOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
644 def : Pat<(v4f32 (X86Movsd VR128:$src1, VR128:$src2)),
645 (VMOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
646 def : Pat<(v4i32 (X86Movsd VR128:$src1, VR128:$src2)),
647 (VMOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
650 def : Pat<(v4i64 (X86Movsd VR256:$src1, VR256:$src2)),
651 (SUBREG_TO_REG (i32 0),
652 (VMOVSDrr (EXTRACT_SUBREG (v4i64 VR256:$src1), sub_xmm),
653 (EXTRACT_SUBREG (v4i64 VR256:$src2), sub_xmm)),
655 def : Pat<(v4f64 (X86Movsd VR256:$src1, VR256:$src2)),
656 (SUBREG_TO_REG (i32 0),
657 (VMOVSDrr (EXTRACT_SUBREG (v4f64 VR256:$src1), sub_xmm),
658 (EXTRACT_SUBREG (v4f64 VR256:$src2), sub_xmm)),
662 // FIXME: Instead of a X86Movlps there should be a X86Movsd here, the problem
663 // is during lowering, where it's not possible to recognize the fold cause
664 // it has two uses through a bitcast. One use disappears at isel time and the
665 // fold opportunity reappears.
666 def : Pat<(v2f64 (X86Movlpd VR128:$src1, VR128:$src2)),
667 (VMOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
668 def : Pat<(v2i64 (X86Movlpd VR128:$src1, VR128:$src2)),
669 (VMOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
670 def : Pat<(v4f32 (X86Movlps VR128:$src1, VR128:$src2)),
671 (VMOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
672 def : Pat<(v4i32 (X86Movlps VR128:$src1, VR128:$src2)),
673 (VMOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
676 let Predicates = [UseSSE1] in {
677 let AddedComplexity = 15 in {
678 // Move scalar to XMM zero-extended, zeroing a VR128 then do a
679 // MOVSS to the lower bits.
680 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
681 (MOVSSrr (v4f32 (V_SET0)), FR32:$src)>;
682 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
683 (MOVSSrr (v4f32 (V_SET0)), (COPY_TO_REGCLASS VR128:$src, FR32))>;
684 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
685 (MOVSSrr (v4i32 (V_SET0)), (COPY_TO_REGCLASS VR128:$src, FR32))>;
688 let AddedComplexity = 20 in {
689 // MOVSSrm already zeros the high parts of the register.
690 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
691 (COPY_TO_REGCLASS (MOVSSrm addr:$src), VR128)>;
692 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
693 (COPY_TO_REGCLASS (MOVSSrm addr:$src), VR128)>;
694 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
695 (COPY_TO_REGCLASS (MOVSSrm addr:$src), VR128)>;
698 // Extract and store.
699 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
701 (MOVSSmr addr:$dst, (COPY_TO_REGCLASS VR128:$src, FR32))>;
703 // Shuffle with MOVSS
704 def : Pat<(v4i32 (X86Movss VR128:$src1, VR128:$src2)),
705 (MOVSSrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR32))>;
706 def : Pat<(v4f32 (X86Movss VR128:$src1, VR128:$src2)),
707 (MOVSSrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR32))>;
710 let Predicates = [UseSSE2] in {
711 let AddedComplexity = 15 in {
712 // Move scalar to XMM zero-extended, zeroing a VR128 then do a
713 // MOVSD to the lower bits.
714 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
715 (MOVSDrr (v2f64 (V_SET0)), FR64:$src)>;
718 let AddedComplexity = 20 in {
719 // MOVSDrm already zeros the high parts of the register.
720 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
721 (COPY_TO_REGCLASS (MOVSDrm addr:$src), VR128)>;
722 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
723 (COPY_TO_REGCLASS (MOVSDrm addr:$src), VR128)>;
724 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
725 (COPY_TO_REGCLASS (MOVSDrm addr:$src), VR128)>;
726 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
727 (COPY_TO_REGCLASS (MOVSDrm addr:$src), VR128)>;
728 def : Pat<(v2f64 (X86vzload addr:$src)),
729 (COPY_TO_REGCLASS (MOVSDrm addr:$src), VR128)>;
732 // Extract and store.
733 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
735 (MOVSDmr addr:$dst, (COPY_TO_REGCLASS VR128:$src, FR64))>;
737 // Shuffle with MOVSD
738 def : Pat<(v2i64 (X86Movsd VR128:$src1, VR128:$src2)),
739 (MOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
740 def : Pat<(v2f64 (X86Movsd VR128:$src1, VR128:$src2)),
741 (MOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
742 def : Pat<(v4f32 (X86Movsd VR128:$src1, VR128:$src2)),
743 (MOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
744 def : Pat<(v4i32 (X86Movsd VR128:$src1, VR128:$src2)),
745 (MOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
747 // FIXME: Instead of a X86Movlps there should be a X86Movsd here, the problem
748 // is during lowering, where it's not possible to recognize the fold cause
749 // it has two uses through a bitcast. One use disappears at isel time and the
750 // fold opportunity reappears.
751 def : Pat<(v2f64 (X86Movlpd VR128:$src1, VR128:$src2)),
752 (MOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
753 def : Pat<(v2i64 (X86Movlpd VR128:$src1, VR128:$src2)),
754 (MOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
755 def : Pat<(v4f32 (X86Movlps VR128:$src1, VR128:$src2)),
756 (MOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
757 def : Pat<(v4i32 (X86Movlps VR128:$src1, VR128:$src2)),
758 (MOVSDrr VR128:$src1, (COPY_TO_REGCLASS VR128:$src2, FR64))>;
761 //===----------------------------------------------------------------------===//
762 // SSE 1 & 2 - Move Aligned/Unaligned FP Instructions
763 //===----------------------------------------------------------------------===//
765 multiclass sse12_mov_packed<bits<8> opc, RegisterClass RC,
766 X86MemOperand x86memop, PatFrag ld_frag,
767 string asm, Domain d,
769 bit IsReMaterializable = 1> {
770 let neverHasSideEffects = 1 in
771 def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src),
772 !strconcat(asm, "\t{$src, $dst|$dst, $src}"), [], itins.rr, d>;
773 let canFoldAsLoad = 1, isReMaterializable = IsReMaterializable in
774 def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
775 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
776 [(set RC:$dst, (ld_frag addr:$src))], itins.rm, d>;
779 defm VMOVAPS : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv4f32,
780 "movaps", SSEPackedSingle, SSE_MOVA_ITINS>,
782 defm VMOVAPD : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv2f64,
783 "movapd", SSEPackedDouble, SSE_MOVA_ITINS>,
785 defm VMOVUPS : sse12_mov_packed<0x10, VR128, f128mem, loadv4f32,
786 "movups", SSEPackedSingle, SSE_MOVU_ITINS>,
788 defm VMOVUPD : sse12_mov_packed<0x10, VR128, f128mem, loadv2f64,
789 "movupd", SSEPackedDouble, SSE_MOVU_ITINS, 0>,
792 defm VMOVAPSY : sse12_mov_packed<0x28, VR256, f256mem, alignedloadv8f32,
793 "movaps", SSEPackedSingle, SSE_MOVA_ITINS>,
795 defm VMOVAPDY : sse12_mov_packed<0x28, VR256, f256mem, alignedloadv4f64,
796 "movapd", SSEPackedDouble, SSE_MOVA_ITINS>,
797 TB, OpSize, VEX, VEX_L;
798 defm VMOVUPSY : sse12_mov_packed<0x10, VR256, f256mem, loadv8f32,
799 "movups", SSEPackedSingle, SSE_MOVU_ITINS>,
801 defm VMOVUPDY : sse12_mov_packed<0x10, VR256, f256mem, loadv4f64,
802 "movupd", SSEPackedDouble, SSE_MOVU_ITINS, 0>,
803 TB, OpSize, VEX, VEX_L;
804 defm MOVAPS : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv4f32,
805 "movaps", SSEPackedSingle, SSE_MOVA_ITINS>,
807 defm MOVAPD : sse12_mov_packed<0x28, VR128, f128mem, alignedloadv2f64,
808 "movapd", SSEPackedDouble, SSE_MOVA_ITINS>,
810 defm MOVUPS : sse12_mov_packed<0x10, VR128, f128mem, loadv4f32,
811 "movups", SSEPackedSingle, SSE_MOVU_ITINS>,
813 defm MOVUPD : sse12_mov_packed<0x10, VR128, f128mem, loadv2f64,
814 "movupd", SSEPackedDouble, SSE_MOVU_ITINS, 0>,
817 def VMOVAPSmr : VPSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
818 "movaps\t{$src, $dst|$dst, $src}",
819 [(alignedstore (v4f32 VR128:$src), addr:$dst)],
820 IIC_SSE_MOVA_P_MR>, VEX;
821 def VMOVAPDmr : VPDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
822 "movapd\t{$src, $dst|$dst, $src}",
823 [(alignedstore (v2f64 VR128:$src), addr:$dst)],
824 IIC_SSE_MOVA_P_MR>, VEX;
825 def VMOVUPSmr : VPSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
826 "movups\t{$src, $dst|$dst, $src}",
827 [(store (v4f32 VR128:$src), addr:$dst)],
828 IIC_SSE_MOVU_P_MR>, VEX;
829 def VMOVUPDmr : VPDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
830 "movupd\t{$src, $dst|$dst, $src}",
831 [(store (v2f64 VR128:$src), addr:$dst)],
832 IIC_SSE_MOVU_P_MR>, VEX;
833 def VMOVAPSYmr : VPSI<0x29, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
834 "movaps\t{$src, $dst|$dst, $src}",
835 [(alignedstore256 (v8f32 VR256:$src), addr:$dst)],
836 IIC_SSE_MOVA_P_MR>, VEX, VEX_L;
837 def VMOVAPDYmr : VPDI<0x29, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
838 "movapd\t{$src, $dst|$dst, $src}",
839 [(alignedstore256 (v4f64 VR256:$src), addr:$dst)],
840 IIC_SSE_MOVA_P_MR>, VEX, VEX_L;
841 def VMOVUPSYmr : VPSI<0x11, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
842 "movups\t{$src, $dst|$dst, $src}",
843 [(store (v8f32 VR256:$src), addr:$dst)],
844 IIC_SSE_MOVU_P_MR>, VEX, VEX_L;
845 def VMOVUPDYmr : VPDI<0x11, MRMDestMem, (outs), (ins f256mem:$dst, VR256:$src),
846 "movupd\t{$src, $dst|$dst, $src}",
847 [(store (v4f64 VR256:$src), addr:$dst)],
848 IIC_SSE_MOVU_P_MR>, VEX, VEX_L;
851 let isCodeGenOnly = 1, hasSideEffects = 0 in {
852 def VMOVAPSrr_REV : VPSI<0x29, MRMDestReg, (outs VR128:$dst),
854 "movaps\t{$src, $dst|$dst, $src}", [],
855 IIC_SSE_MOVA_P_RR>, VEX;
856 def VMOVAPDrr_REV : VPDI<0x29, MRMDestReg, (outs VR128:$dst),
858 "movapd\t{$src, $dst|$dst, $src}", [],
859 IIC_SSE_MOVA_P_RR>, VEX;
860 def VMOVUPSrr_REV : VPSI<0x11, MRMDestReg, (outs VR128:$dst),
862 "movups\t{$src, $dst|$dst, $src}", [],
863 IIC_SSE_MOVU_P_RR>, VEX;
864 def VMOVUPDrr_REV : VPDI<0x11, MRMDestReg, (outs VR128:$dst),
866 "movupd\t{$src, $dst|$dst, $src}", [],
867 IIC_SSE_MOVU_P_RR>, VEX;
868 def VMOVAPSYrr_REV : VPSI<0x29, MRMDestReg, (outs VR256:$dst),
870 "movaps\t{$src, $dst|$dst, $src}", [],
871 IIC_SSE_MOVA_P_RR>, VEX, VEX_L;
872 def VMOVAPDYrr_REV : VPDI<0x29, MRMDestReg, (outs VR256:$dst),
874 "movapd\t{$src, $dst|$dst, $src}", [],
875 IIC_SSE_MOVA_P_RR>, VEX, VEX_L;
876 def VMOVUPSYrr_REV : VPSI<0x11, MRMDestReg, (outs VR256:$dst),
878 "movups\t{$src, $dst|$dst, $src}", [],
879 IIC_SSE_MOVU_P_RR>, VEX, VEX_L;
880 def VMOVUPDYrr_REV : VPDI<0x11, MRMDestReg, (outs VR256:$dst),
882 "movupd\t{$src, $dst|$dst, $src}", [],
883 IIC_SSE_MOVU_P_RR>, VEX, VEX_L;
886 let Predicates = [HasAVX] in {
887 def : Pat<(v8i32 (X86vzmovl
888 (insert_subvector undef, (v4i32 VR128:$src), (iPTR 0)))),
889 (SUBREG_TO_REG (i32 0), (VMOVAPSrr VR128:$src), sub_xmm)>;
890 def : Pat<(v4i64 (X86vzmovl
891 (insert_subvector undef, (v2i64 VR128:$src), (iPTR 0)))),
892 (SUBREG_TO_REG (i32 0), (VMOVAPSrr VR128:$src), sub_xmm)>;
893 def : Pat<(v8f32 (X86vzmovl
894 (insert_subvector undef, (v4f32 VR128:$src), (iPTR 0)))),
895 (SUBREG_TO_REG (i32 0), (VMOVAPSrr VR128:$src), sub_xmm)>;
896 def : Pat<(v4f64 (X86vzmovl
897 (insert_subvector undef, (v2f64 VR128:$src), (iPTR 0)))),
898 (SUBREG_TO_REG (i32 0), (VMOVAPSrr VR128:$src), sub_xmm)>;
902 def : Pat<(int_x86_avx_storeu_ps_256 addr:$dst, VR256:$src),
903 (VMOVUPSYmr addr:$dst, VR256:$src)>;
904 def : Pat<(int_x86_avx_storeu_pd_256 addr:$dst, VR256:$src),
905 (VMOVUPDYmr addr:$dst, VR256:$src)>;
907 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
908 "movaps\t{$src, $dst|$dst, $src}",
909 [(alignedstore (v4f32 VR128:$src), addr:$dst)],
911 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
912 "movapd\t{$src, $dst|$dst, $src}",
913 [(alignedstore (v2f64 VR128:$src), addr:$dst)],
915 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
916 "movups\t{$src, $dst|$dst, $src}",
917 [(store (v4f32 VR128:$src), addr:$dst)],
919 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
920 "movupd\t{$src, $dst|$dst, $src}",
921 [(store (v2f64 VR128:$src), addr:$dst)],
925 let isCodeGenOnly = 1, hasSideEffects = 0 in {
926 def MOVAPSrr_REV : PSI<0x29, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
927 "movaps\t{$src, $dst|$dst, $src}", [],
929 def MOVAPDrr_REV : PDI<0x29, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
930 "movapd\t{$src, $dst|$dst, $src}", [],
932 def MOVUPSrr_REV : PSI<0x11, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
933 "movups\t{$src, $dst|$dst, $src}", [],
935 def MOVUPDrr_REV : PDI<0x11, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
936 "movupd\t{$src, $dst|$dst, $src}", [],
940 let Predicates = [HasAVX] in {
941 def : Pat<(int_x86_sse_storeu_ps addr:$dst, VR128:$src),
942 (VMOVUPSmr addr:$dst, VR128:$src)>;
943 def : Pat<(int_x86_sse2_storeu_pd addr:$dst, VR128:$src),
944 (VMOVUPDmr addr:$dst, VR128:$src)>;
947 let Predicates = [UseSSE1] in
948 def : Pat<(int_x86_sse_storeu_ps addr:$dst, VR128:$src),
949 (MOVUPSmr addr:$dst, VR128:$src)>;
950 let Predicates = [UseSSE2] in
951 def : Pat<(int_x86_sse2_storeu_pd addr:$dst, VR128:$src),
952 (MOVUPDmr addr:$dst, VR128:$src)>;
954 // Use vmovaps/vmovups for AVX integer load/store.
955 let Predicates = [HasAVX] in {
956 // 128-bit load/store
957 def : Pat<(alignedloadv2i64 addr:$src),
958 (VMOVAPSrm addr:$src)>;
959 def : Pat<(loadv2i64 addr:$src),
960 (VMOVUPSrm addr:$src)>;
962 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
963 (VMOVAPSmr addr:$dst, VR128:$src)>;
964 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
965 (VMOVAPSmr addr:$dst, VR128:$src)>;
966 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
967 (VMOVAPSmr addr:$dst, VR128:$src)>;
968 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
969 (VMOVAPSmr addr:$dst, VR128:$src)>;
970 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
971 (VMOVUPSmr addr:$dst, VR128:$src)>;
972 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
973 (VMOVUPSmr addr:$dst, VR128:$src)>;
974 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
975 (VMOVUPSmr addr:$dst, VR128:$src)>;
976 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
977 (VMOVUPSmr addr:$dst, VR128:$src)>;
979 // 256-bit load/store
980 def : Pat<(alignedloadv4i64 addr:$src),
981 (VMOVAPSYrm addr:$src)>;
982 def : Pat<(loadv4i64 addr:$src),
983 (VMOVUPSYrm addr:$src)>;
984 def : Pat<(alignedstore256 (v4i64 VR256:$src), addr:$dst),
985 (VMOVAPSYmr addr:$dst, VR256:$src)>;
986 def : Pat<(alignedstore256 (v8i32 VR256:$src), addr:$dst),
987 (VMOVAPSYmr addr:$dst, VR256:$src)>;
988 def : Pat<(alignedstore256 (v16i16 VR256:$src), addr:$dst),
989 (VMOVAPSYmr addr:$dst, VR256:$src)>;
990 def : Pat<(alignedstore256 (v32i8 VR256:$src), addr:$dst),
991 (VMOVAPSYmr addr:$dst, VR256:$src)>;
992 def : Pat<(store (v4i64 VR256:$src), addr:$dst),
993 (VMOVUPSYmr addr:$dst, VR256:$src)>;
994 def : Pat<(store (v8i32 VR256:$src), addr:$dst),
995 (VMOVUPSYmr addr:$dst, VR256:$src)>;
996 def : Pat<(store (v16i16 VR256:$src), addr:$dst),
997 (VMOVUPSYmr addr:$dst, VR256:$src)>;
998 def : Pat<(store (v32i8 VR256:$src), addr:$dst),
999 (VMOVUPSYmr addr:$dst, VR256:$src)>;
1001 // Special patterns for storing subvector extracts of lower 128-bits
1002 // Its cheaper to just use VMOVAPS/VMOVUPS instead of VEXTRACTF128mr
1003 def : Pat<(alignedstore (v2f64 (extract_subvector
1004 (v4f64 VR256:$src), (iPTR 0))), addr:$dst),
1005 (VMOVAPDmr addr:$dst, (v2f64 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1006 def : Pat<(alignedstore (v4f32 (extract_subvector
1007 (v8f32 VR256:$src), (iPTR 0))), addr:$dst),
1008 (VMOVAPSmr addr:$dst, (v4f32 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1009 def : Pat<(alignedstore (v2i64 (extract_subvector
1010 (v4i64 VR256:$src), (iPTR 0))), addr:$dst),
1011 (VMOVAPDmr addr:$dst, (v2i64 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1012 def : Pat<(alignedstore (v4i32 (extract_subvector
1013 (v8i32 VR256:$src), (iPTR 0))), addr:$dst),
1014 (VMOVAPSmr addr:$dst, (v4i32 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1015 def : Pat<(alignedstore (v8i16 (extract_subvector
1016 (v16i16 VR256:$src), (iPTR 0))), addr:$dst),
1017 (VMOVAPSmr addr:$dst, (v8i16 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1018 def : Pat<(alignedstore (v16i8 (extract_subvector
1019 (v32i8 VR256:$src), (iPTR 0))), addr:$dst),
1020 (VMOVAPSmr addr:$dst, (v16i8 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1022 def : Pat<(store (v2f64 (extract_subvector
1023 (v4f64 VR256:$src), (iPTR 0))), addr:$dst),
1024 (VMOVUPDmr addr:$dst, (v2f64 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1025 def : Pat<(store (v4f32 (extract_subvector
1026 (v8f32 VR256:$src), (iPTR 0))), addr:$dst),
1027 (VMOVUPSmr addr:$dst, (v4f32 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1028 def : Pat<(store (v2i64 (extract_subvector
1029 (v4i64 VR256:$src), (iPTR 0))), addr:$dst),
1030 (VMOVUPDmr addr:$dst, (v2i64 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1031 def : Pat<(store (v4i32 (extract_subvector
1032 (v8i32 VR256:$src), (iPTR 0))), addr:$dst),
1033 (VMOVUPSmr addr:$dst, (v4i32 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1034 def : Pat<(store (v8i16 (extract_subvector
1035 (v16i16 VR256:$src), (iPTR 0))), addr:$dst),
1036 (VMOVAPSmr addr:$dst, (v8i16 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1037 def : Pat<(store (v16i8 (extract_subvector
1038 (v32i8 VR256:$src), (iPTR 0))), addr:$dst),
1039 (VMOVUPSmr addr:$dst, (v16i8 (EXTRACT_SUBREG VR256:$src,sub_xmm)))>;
1042 // Use movaps / movups for SSE integer load / store (one byte shorter).
1043 // The instructions selected below are then converted to MOVDQA/MOVDQU
1044 // during the SSE domain pass.
1045 let Predicates = [UseSSE1] in {
1046 def : Pat<(alignedloadv2i64 addr:$src),
1047 (MOVAPSrm addr:$src)>;
1048 def : Pat<(loadv2i64 addr:$src),
1049 (MOVUPSrm addr:$src)>;
1051 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
1052 (MOVAPSmr addr:$dst, VR128:$src)>;
1053 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
1054 (MOVAPSmr addr:$dst, VR128:$src)>;
1055 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
1056 (MOVAPSmr addr:$dst, VR128:$src)>;
1057 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
1058 (MOVAPSmr addr:$dst, VR128:$src)>;
1059 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
1060 (MOVUPSmr addr:$dst, VR128:$src)>;
1061 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
1062 (MOVUPSmr addr:$dst, VR128:$src)>;
1063 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
1064 (MOVUPSmr addr:$dst, VR128:$src)>;
1065 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
1066 (MOVUPSmr addr:$dst, VR128:$src)>;
1069 // Alias instruction to do FR32 or FR64 reg-to-reg copy using movaps. Upper
1070 // bits are disregarded. FIXME: Set encoding to pseudo!
1071 let neverHasSideEffects = 1 in {
1072 def FsVMOVAPSrr : VPSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1073 "movaps\t{$src, $dst|$dst, $src}", [],
1074 IIC_SSE_MOVA_P_RR>, VEX;
1075 def FsVMOVAPDrr : VPDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1076 "movapd\t{$src, $dst|$dst, $src}", [],
1077 IIC_SSE_MOVA_P_RR>, VEX;
1078 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1079 "movaps\t{$src, $dst|$dst, $src}", [],
1081 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1082 "movapd\t{$src, $dst|$dst, $src}", [],
1086 // Alias instruction to load FR32 or FR64 from f128mem using movaps. Upper
1087 // bits are disregarded. FIXME: Set encoding to pseudo!
1088 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1089 let isCodeGenOnly = 1 in {
1090 def FsVMOVAPSrm : VPSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
1091 "movaps\t{$src, $dst|$dst, $src}",
1092 [(set FR32:$dst, (alignedloadfsf32 addr:$src))],
1093 IIC_SSE_MOVA_P_RM>, VEX;
1094 def FsVMOVAPDrm : VPDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1095 "movapd\t{$src, $dst|$dst, $src}",
1096 [(set FR64:$dst, (alignedloadfsf64 addr:$src))],
1097 IIC_SSE_MOVA_P_RM>, VEX;
1099 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
1100 "movaps\t{$src, $dst|$dst, $src}",
1101 [(set FR32:$dst, (alignedloadfsf32 addr:$src))],
1103 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1104 "movapd\t{$src, $dst|$dst, $src}",
1105 [(set FR64:$dst, (alignedloadfsf64 addr:$src))],
1109 //===----------------------------------------------------------------------===//
1110 // SSE 1 & 2 - Move Low packed FP Instructions
1111 //===----------------------------------------------------------------------===//
1113 multiclass sse12_mov_hilo_packed<bits<8>opc, RegisterClass RC,
1114 SDNode psnode, SDNode pdnode, string base_opc,
1115 string asm_opr, InstrItinClass itin> {
1116 def PSrm : PI<opc, MRMSrcMem,
1117 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1118 !strconcat(base_opc, "s", asm_opr),
1121 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))],
1122 itin, SSEPackedSingle>, TB;
1124 def PDrm : PI<opc, MRMSrcMem,
1125 (outs RC:$dst), (ins RC:$src1, f64mem:$src2),
1126 !strconcat(base_opc, "d", asm_opr),
1127 [(set RC:$dst, (v2f64 (pdnode RC:$src1,
1128 (scalar_to_vector (loadf64 addr:$src2)))))],
1129 itin, SSEPackedDouble>, TB, OpSize;
1132 let AddedComplexity = 20 in {
1133 defm VMOVL : sse12_mov_hilo_packed<0x12, VR128, X86Movlps, X86Movlpd, "movlp",
1134 "\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1135 IIC_SSE_MOV_LH>, VEX_4V;
1137 let Constraints = "$src1 = $dst", AddedComplexity = 20 in {
1138 defm MOVL : sse12_mov_hilo_packed<0x12, VR128, X86Movlps, X86Movlpd, "movlp",
1139 "\t{$src2, $dst|$dst, $src2}",
1143 def VMOVLPSmr : VPSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1144 "movlps\t{$src, $dst|$dst, $src}",
1145 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
1146 (iPTR 0))), addr:$dst)],
1147 IIC_SSE_MOV_LH>, VEX;
1148 def VMOVLPDmr : VPDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1149 "movlpd\t{$src, $dst|$dst, $src}",
1150 [(store (f64 (vector_extract (v2f64 VR128:$src),
1151 (iPTR 0))), addr:$dst)],
1152 IIC_SSE_MOV_LH>, VEX;
1153 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1154 "movlps\t{$src, $dst|$dst, $src}",
1155 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
1156 (iPTR 0))), addr:$dst)],
1158 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1159 "movlpd\t{$src, $dst|$dst, $src}",
1160 [(store (f64 (vector_extract (v2f64 VR128:$src),
1161 (iPTR 0))), addr:$dst)],
1164 let Predicates = [HasAVX] in {
1165 // Shuffle with VMOVLPS
1166 def : Pat<(v4f32 (X86Movlps VR128:$src1, (load addr:$src2))),
1167 (VMOVLPSrm VR128:$src1, addr:$src2)>;
1168 def : Pat<(v4i32 (X86Movlps VR128:$src1, (load addr:$src2))),
1169 (VMOVLPSrm VR128:$src1, addr:$src2)>;
1171 // Shuffle with VMOVLPD
1172 def : Pat<(v2f64 (X86Movlpd VR128:$src1, (load addr:$src2))),
1173 (VMOVLPDrm VR128:$src1, addr:$src2)>;
1174 def : Pat<(v2i64 (X86Movlpd VR128:$src1, (load addr:$src2))),
1175 (VMOVLPDrm VR128:$src1, addr:$src2)>;
1178 def : Pat<(store (v4f32 (X86Movlps (load addr:$src1), VR128:$src2)),
1180 (VMOVLPSmr addr:$src1, VR128:$src2)>;
1181 def : Pat<(store (v4i32 (X86Movlps
1182 (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)), addr:$src1),
1183 (VMOVLPSmr addr:$src1, VR128:$src2)>;
1184 def : Pat<(store (v2f64 (X86Movlpd (load addr:$src1), VR128:$src2)),
1186 (VMOVLPDmr addr:$src1, VR128:$src2)>;
1187 def : Pat<(store (v2i64 (X86Movlpd (load addr:$src1), VR128:$src2)),
1189 (VMOVLPDmr addr:$src1, VR128:$src2)>;
1192 let Predicates = [UseSSE1] in {
1193 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
1194 def : Pat<(store (i64 (vector_extract (bc_v2i64 (v4f32 VR128:$src2)),
1195 (iPTR 0))), addr:$src1),
1196 (MOVLPSmr addr:$src1, VR128:$src2)>;
1198 // Shuffle with MOVLPS
1199 def : Pat<(v4f32 (X86Movlps VR128:$src1, (load addr:$src2))),
1200 (MOVLPSrm VR128:$src1, addr:$src2)>;
1201 def : Pat<(v4i32 (X86Movlps VR128:$src1, (load addr:$src2))),
1202 (MOVLPSrm VR128:$src1, addr:$src2)>;
1203 def : Pat<(X86Movlps VR128:$src1,
1204 (bc_v4f32 (v2i64 (scalar_to_vector (loadi64 addr:$src2))))),
1205 (MOVLPSrm VR128:$src1, addr:$src2)>;
1208 def : Pat<(store (v4f32 (X86Movlps (load addr:$src1), VR128:$src2)),
1210 (MOVLPSmr addr:$src1, VR128:$src2)>;
1211 def : Pat<(store (v4i32 (X86Movlps
1212 (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
1214 (MOVLPSmr addr:$src1, VR128:$src2)>;
1217 let Predicates = [UseSSE2] in {
1218 // Shuffle with MOVLPD
1219 def : Pat<(v2f64 (X86Movlpd VR128:$src1, (load addr:$src2))),
1220 (MOVLPDrm VR128:$src1, addr:$src2)>;
1221 def : Pat<(v2i64 (X86Movlpd VR128:$src1, (load addr:$src2))),
1222 (MOVLPDrm VR128:$src1, addr:$src2)>;
1225 def : Pat<(store (v2f64 (X86Movlpd (load addr:$src1), VR128:$src2)),
1227 (MOVLPDmr addr:$src1, VR128:$src2)>;
1228 def : Pat<(store (v2i64 (X86Movlpd (load addr:$src1), VR128:$src2)),
1230 (MOVLPDmr addr:$src1, VR128:$src2)>;
1233 //===----------------------------------------------------------------------===//
1234 // SSE 1 & 2 - Move Hi packed FP Instructions
1235 //===----------------------------------------------------------------------===//
1237 let AddedComplexity = 20 in {
1238 defm VMOVH : sse12_mov_hilo_packed<0x16, VR128, X86Movlhps, X86Movlhpd, "movhp",
1239 "\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1240 IIC_SSE_MOV_LH>, VEX_4V;
1242 let Constraints = "$src1 = $dst", AddedComplexity = 20 in {
1243 defm MOVH : sse12_mov_hilo_packed<0x16, VR128, X86Movlhps, X86Movlhpd, "movhp",
1244 "\t{$src2, $dst|$dst, $src2}",
1248 // v2f64 extract element 1 is always custom lowered to unpack high to low
1249 // and extract element 0 so the non-store version isn't too horrible.
1250 def VMOVHPSmr : VPSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1251 "movhps\t{$src, $dst|$dst, $src}",
1252 [(store (f64 (vector_extract
1253 (X86Unpckh (bc_v2f64 (v4f32 VR128:$src)),
1254 (bc_v2f64 (v4f32 VR128:$src))),
1255 (iPTR 0))), addr:$dst)], IIC_SSE_MOV_LH>, VEX;
1256 def VMOVHPDmr : VPDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1257 "movhpd\t{$src, $dst|$dst, $src}",
1258 [(store (f64 (vector_extract
1259 (v2f64 (X86Unpckh VR128:$src, VR128:$src)),
1260 (iPTR 0))), addr:$dst)], IIC_SSE_MOV_LH>, VEX;
1261 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1262 "movhps\t{$src, $dst|$dst, $src}",
1263 [(store (f64 (vector_extract
1264 (X86Unpckh (bc_v2f64 (v4f32 VR128:$src)),
1265 (bc_v2f64 (v4f32 VR128:$src))),
1266 (iPTR 0))), addr:$dst)], IIC_SSE_MOV_LH>;
1267 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1268 "movhpd\t{$src, $dst|$dst, $src}",
1269 [(store (f64 (vector_extract
1270 (v2f64 (X86Unpckh VR128:$src, VR128:$src)),
1271 (iPTR 0))), addr:$dst)], IIC_SSE_MOV_LH>;
1273 let Predicates = [HasAVX] in {
1275 def : Pat<(X86Movlhps VR128:$src1,
1276 (bc_v4f32 (v2i64 (scalar_to_vector (loadi64 addr:$src2))))),
1277 (VMOVHPSrm VR128:$src1, addr:$src2)>;
1278 def : Pat<(X86Movlhps VR128:$src1,
1279 (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
1280 (VMOVHPSrm VR128:$src1, addr:$src2)>;
1282 // FIXME: Instead of X86Unpckl, there should be a X86Movlhpd here, the problem
1283 // is during lowering, where it's not possible to recognize the load fold
1284 // cause it has two uses through a bitcast. One use disappears at isel time
1285 // and the fold opportunity reappears.
1286 def : Pat<(v2f64 (X86Unpckl VR128:$src1,
1287 (scalar_to_vector (loadf64 addr:$src2)))),
1288 (VMOVHPDrm VR128:$src1, addr:$src2)>;
1291 let Predicates = [UseSSE1] in {
1293 def : Pat<(X86Movlhps VR128:$src1,
1294 (bc_v4f32 (v2i64 (scalar_to_vector (loadi64 addr:$src2))))),
1295 (MOVHPSrm VR128:$src1, addr:$src2)>;
1296 def : Pat<(X86Movlhps VR128:$src1,
1297 (bc_v4f32 (v2i64 (X86vzload addr:$src2)))),
1298 (MOVHPSrm VR128:$src1, addr:$src2)>;
1301 let Predicates = [UseSSE2] in {
1302 // FIXME: Instead of X86Unpckl, there should be a X86Movlhpd here, the problem
1303 // is during lowering, where it's not possible to recognize the load fold
1304 // cause it has two uses through a bitcast. One use disappears at isel time
1305 // and the fold opportunity reappears.
1306 def : Pat<(v2f64 (X86Unpckl VR128:$src1,
1307 (scalar_to_vector (loadf64 addr:$src2)))),
1308 (MOVHPDrm VR128:$src1, addr:$src2)>;
1311 //===----------------------------------------------------------------------===//
1312 // SSE 1 & 2 - Move Low to High and High to Low packed FP Instructions
1313 //===----------------------------------------------------------------------===//
1315 let AddedComplexity = 20 in {
1316 def VMOVLHPSrr : VPSI<0x16, MRMSrcReg, (outs VR128:$dst),
1317 (ins VR128:$src1, VR128:$src2),
1318 "movlhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1320 (v4f32 (X86Movlhps VR128:$src1, VR128:$src2)))],
1323 def VMOVHLPSrr : VPSI<0x12, MRMSrcReg, (outs VR128:$dst),
1324 (ins VR128:$src1, VR128:$src2),
1325 "movhlps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1327 (v4f32 (X86Movhlps VR128:$src1, VR128:$src2)))],
1331 let Constraints = "$src1 = $dst", AddedComplexity = 20 in {
1332 def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
1333 (ins VR128:$src1, VR128:$src2),
1334 "movlhps\t{$src2, $dst|$dst, $src2}",
1336 (v4f32 (X86Movlhps VR128:$src1, VR128:$src2)))],
1338 def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
1339 (ins VR128:$src1, VR128:$src2),
1340 "movhlps\t{$src2, $dst|$dst, $src2}",
1342 (v4f32 (X86Movhlps VR128:$src1, VR128:$src2)))],
1346 let Predicates = [HasAVX] in {
1348 def : Pat<(v4i32 (X86Movlhps VR128:$src1, VR128:$src2)),
1349 (VMOVLHPSrr VR128:$src1, VR128:$src2)>;
1350 def : Pat<(v2i64 (X86Movlhps VR128:$src1, VR128:$src2)),
1351 (VMOVLHPSrr (v2i64 VR128:$src1), VR128:$src2)>;
1354 def : Pat<(v4i32 (X86Movhlps VR128:$src1, VR128:$src2)),
1355 (VMOVHLPSrr VR128:$src1, VR128:$src2)>;
1358 let Predicates = [UseSSE1] in {
1360 def : Pat<(v4i32 (X86Movlhps VR128:$src1, VR128:$src2)),
1361 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
1362 def : Pat<(v2i64 (X86Movlhps VR128:$src1, VR128:$src2)),
1363 (MOVLHPSrr (v2i64 VR128:$src1), VR128:$src2)>;
1366 def : Pat<(v4i32 (X86Movhlps VR128:$src1, VR128:$src2)),
1367 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
1370 //===----------------------------------------------------------------------===//
1371 // SSE 1 & 2 - Conversion Instructions
1372 //===----------------------------------------------------------------------===//
1374 def SSE_CVT_PD : OpndItins<
1375 IIC_SSE_CVT_PD_RR, IIC_SSE_CVT_PD_RM
1378 def SSE_CVT_PS : OpndItins<
1379 IIC_SSE_CVT_PS_RR, IIC_SSE_CVT_PS_RM
1382 def SSE_CVT_Scalar : OpndItins<
1383 IIC_SSE_CVT_Scalar_RR, IIC_SSE_CVT_Scalar_RM
1386 def SSE_CVT_SS2SI_32 : OpndItins<
1387 IIC_SSE_CVT_SS2SI32_RR, IIC_SSE_CVT_SS2SI32_RM
1390 def SSE_CVT_SS2SI_64 : OpndItins<
1391 IIC_SSE_CVT_SS2SI64_RR, IIC_SSE_CVT_SS2SI64_RM
1394 def SSE_CVT_SD2SI : OpndItins<
1395 IIC_SSE_CVT_SD2SI_RR, IIC_SSE_CVT_SD2SI_RM
1398 multiclass sse12_cvt_s<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
1399 SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
1400 string asm, OpndItins itins> {
1401 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
1402 [(set DstRC:$dst, (OpNode SrcRC:$src))],
1404 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
1405 [(set DstRC:$dst, (OpNode (ld_frag addr:$src)))],
1409 multiclass sse12_cvt_p<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
1410 X86MemOperand x86memop, string asm, Domain d,
1412 let neverHasSideEffects = 1 in {
1413 def rr : I<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
1416 def rm : I<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
1421 multiclass sse12_vcvt_avx<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
1422 X86MemOperand x86memop, string asm> {
1423 let neverHasSideEffects = 1 in {
1424 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src),
1425 !strconcat(asm,"\t{$src, $src1, $dst|$dst, $src1, $src}"), []>;
1427 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
1428 (ins DstRC:$src1, x86memop:$src),
1429 !strconcat(asm,"\t{$src, $src1, $dst|$dst, $src1, $src}"), []>;
1430 } // neverHasSideEffects = 1
1433 defm VCVTTSS2SI : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
1434 "cvttss2si\t{$src, $dst|$dst, $src}",
1437 defm VCVTTSS2SI64 : sse12_cvt_s<0x2C, FR32, GR64, fp_to_sint, f32mem, loadf32,
1438 "cvttss2si\t{$src, $dst|$dst, $src}",
1440 XS, VEX, VEX_W, VEX_LIG;
1441 defm VCVTTSD2SI : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
1442 "cvttsd2si\t{$src, $dst|$dst, $src}",
1445 defm VCVTTSD2SI64 : sse12_cvt_s<0x2C, FR64, GR64, fp_to_sint, f64mem, loadf64,
1446 "cvttsd2si\t{$src, $dst|$dst, $src}",
1448 XD, VEX, VEX_W, VEX_LIG;
1450 def : InstAlias<"vcvttss2si{l}\t{$src, $dst|$dst, $src}",
1451 (VCVTTSS2SIrr GR32:$dst, FR32:$src), 0>;
1452 def : InstAlias<"vcvttss2si{l}\t{$src, $dst|$dst, $src}",
1453 (VCVTTSS2SIrm GR32:$dst, f32mem:$src), 0>;
1454 def : InstAlias<"vcvttsd2si{l}\t{$src, $dst|$dst, $src}",
1455 (VCVTTSD2SIrr GR32:$dst, FR64:$src), 0>;
1456 def : InstAlias<"vcvttsd2si{l}\t{$src, $dst|$dst, $src}",
1457 (VCVTTSD2SIrm GR32:$dst, f64mem:$src), 0>;
1458 def : InstAlias<"vcvttss2si{q}\t{$src, $dst|$dst, $src}",
1459 (VCVTTSS2SI64rr GR64:$dst, FR32:$src), 0>;
1460 def : InstAlias<"vcvttss2si{q}\t{$src, $dst|$dst, $src}",
1461 (VCVTTSS2SI64rm GR64:$dst, f32mem:$src), 0>;
1462 def : InstAlias<"vcvttsd2si{q}\t{$src, $dst|$dst, $src}",
1463 (VCVTTSD2SI64rr GR64:$dst, FR64:$src), 0>;
1464 def : InstAlias<"vcvttsd2si{q}\t{$src, $dst|$dst, $src}",
1465 (VCVTTSD2SI64rm GR64:$dst, f64mem:$src), 0>;
1467 // The assembler can recognize rr 64-bit instructions by seeing a rxx
1468 // register, but the same isn't true when only using memory operands,
1469 // provide other assembly "l" and "q" forms to address this explicitly
1470 // where appropriate to do so.
1471 defm VCVTSI2SS : sse12_vcvt_avx<0x2A, GR32, FR32, i32mem, "cvtsi2ss{l}">,
1472 XS, VEX_4V, VEX_LIG;
1473 defm VCVTSI2SS64 : sse12_vcvt_avx<0x2A, GR64, FR32, i64mem, "cvtsi2ss{q}">,
1474 XS, VEX_4V, VEX_W, VEX_LIG;
1475 defm VCVTSI2SD : sse12_vcvt_avx<0x2A, GR32, FR64, i32mem, "cvtsi2sd{l}">,
1476 XD, VEX_4V, VEX_LIG;
1477 defm VCVTSI2SD64 : sse12_vcvt_avx<0x2A, GR64, FR64, i64mem, "cvtsi2sd{q}">,
1478 XD, VEX_4V, VEX_W, VEX_LIG;
1480 def : InstAlias<"vcvtsi2ss\t{$src, $src1, $dst|$dst, $src1, $src}",
1481 (VCVTSI2SSrm FR64:$dst, FR64:$src1, i32mem:$src)>;
1482 def : InstAlias<"vcvtsi2sd\t{$src, $src1, $dst|$dst, $src1, $src}",
1483 (VCVTSI2SDrm FR64:$dst, FR64:$src1, i32mem:$src)>;
1485 let Predicates = [HasAVX] in {
1486 def : Pat<(f32 (sint_to_fp (loadi32 addr:$src))),
1487 (VCVTSI2SSrm (f32 (IMPLICIT_DEF)), addr:$src)>;
1488 def : Pat<(f32 (sint_to_fp (loadi64 addr:$src))),
1489 (VCVTSI2SS64rm (f32 (IMPLICIT_DEF)), addr:$src)>;
1490 def : Pat<(f64 (sint_to_fp (loadi32 addr:$src))),
1491 (VCVTSI2SDrm (f64 (IMPLICIT_DEF)), addr:$src)>;
1492 def : Pat<(f64 (sint_to_fp (loadi64 addr:$src))),
1493 (VCVTSI2SD64rm (f64 (IMPLICIT_DEF)), addr:$src)>;
1495 def : Pat<(f32 (sint_to_fp GR32:$src)),
1496 (VCVTSI2SSrr (f32 (IMPLICIT_DEF)), GR32:$src)>;
1497 def : Pat<(f32 (sint_to_fp GR64:$src)),
1498 (VCVTSI2SS64rr (f32 (IMPLICIT_DEF)), GR64:$src)>;
1499 def : Pat<(f64 (sint_to_fp GR32:$src)),
1500 (VCVTSI2SDrr (f64 (IMPLICIT_DEF)), GR32:$src)>;
1501 def : Pat<(f64 (sint_to_fp GR64:$src)),
1502 (VCVTSI2SD64rr (f64 (IMPLICIT_DEF)), GR64:$src)>;
1505 defm CVTTSS2SI : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
1506 "cvttss2si\t{$src, $dst|$dst, $src}",
1507 SSE_CVT_SS2SI_32>, XS;
1508 defm CVTTSS2SI64 : sse12_cvt_s<0x2C, FR32, GR64, fp_to_sint, f32mem, loadf32,
1509 "cvttss2si\t{$src, $dst|$dst, $src}",
1510 SSE_CVT_SS2SI_64>, XS, REX_W;
1511 defm CVTTSD2SI : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
1512 "cvttsd2si\t{$src, $dst|$dst, $src}",
1514 defm CVTTSD2SI64 : sse12_cvt_s<0x2C, FR64, GR64, fp_to_sint, f64mem, loadf64,
1515 "cvttsd2si\t{$src, $dst|$dst, $src}",
1516 SSE_CVT_SD2SI>, XD, REX_W;
1517 defm CVTSI2SS : sse12_cvt_s<0x2A, GR32, FR32, sint_to_fp, i32mem, loadi32,
1518 "cvtsi2ss{l}\t{$src, $dst|$dst, $src}",
1519 SSE_CVT_Scalar>, XS;
1520 defm CVTSI2SS64 : sse12_cvt_s<0x2A, GR64, FR32, sint_to_fp, i64mem, loadi64,
1521 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1522 SSE_CVT_Scalar>, XS, REX_W;
1523 defm CVTSI2SD : sse12_cvt_s<0x2A, GR32, FR64, sint_to_fp, i32mem, loadi32,
1524 "cvtsi2sd{l}\t{$src, $dst|$dst, $src}",
1525 SSE_CVT_Scalar>, XD;
1526 defm CVTSI2SD64 : sse12_cvt_s<0x2A, GR64, FR64, sint_to_fp, i64mem, loadi64,
1527 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1528 SSE_CVT_Scalar>, XD, REX_W;
1530 def : InstAlias<"cvttss2si{l}\t{$src, $dst|$dst, $src}",
1531 (CVTTSS2SIrr GR32:$dst, FR32:$src), 0>;
1532 def : InstAlias<"cvttss2si{l}\t{$src, $dst|$dst, $src}",
1533 (CVTTSS2SIrm GR32:$dst, f32mem:$src), 0>;
1534 def : InstAlias<"cvttsd2si{l}\t{$src, $dst|$dst, $src}",
1535 (CVTTSD2SIrr GR32:$dst, FR64:$src), 0>;
1536 def : InstAlias<"cvttsd2si{l}\t{$src, $dst|$dst, $src}",
1537 (CVTTSD2SIrm GR32:$dst, f64mem:$src), 0>;
1538 def : InstAlias<"cvttss2si{q}\t{$src, $dst|$dst, $src}",
1539 (CVTTSS2SI64rr GR64:$dst, FR32:$src), 0>;
1540 def : InstAlias<"cvttss2si{q}\t{$src, $dst|$dst, $src}",
1541 (CVTTSS2SI64rm GR64:$dst, f32mem:$src), 0>;
1542 def : InstAlias<"cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1543 (CVTTSD2SI64rr GR64:$dst, FR64:$src), 0>;
1544 def : InstAlias<"cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1545 (CVTTSD2SI64rm GR64:$dst, f64mem:$src), 0>;
1547 def : InstAlias<"cvtsi2ss\t{$src, $dst|$dst, $src}",
1548 (CVTSI2SSrm FR64:$dst, i32mem:$src)>;
1549 def : InstAlias<"cvtsi2sd\t{$src, $dst|$dst, $src}",
1550 (CVTSI2SDrm FR64:$dst, i32mem:$src)>;
1552 // Conversion Instructions Intrinsics - Match intrinsics which expect MM
1553 // and/or XMM operand(s).
1555 multiclass sse12_cvt_sint<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
1556 Intrinsic Int, Operand memop, ComplexPattern mem_cpat,
1557 string asm, OpndItins itins> {
1558 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src),
1559 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
1560 [(set DstRC:$dst, (Int SrcRC:$src))], itins.rr>;
1561 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins memop:$src),
1562 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
1563 [(set DstRC:$dst, (Int mem_cpat:$src))], itins.rm>;
1566 multiclass sse12_cvt_sint_3addr<bits<8> opc, RegisterClass SrcRC,
1567 RegisterClass DstRC, Intrinsic Int, X86MemOperand x86memop,
1568 PatFrag ld_frag, string asm, OpndItins itins,
1570 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src2),
1572 !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
1573 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
1574 [(set DstRC:$dst, (Int DstRC:$src1, SrcRC:$src2))],
1576 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
1577 (ins DstRC:$src1, x86memop:$src2),
1579 !strconcat(asm, "\t{$src2, $dst|$dst, $src2}"),
1580 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
1581 [(set DstRC:$dst, (Int DstRC:$src1, (ld_frag addr:$src2)))],
1585 defm VCVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32,
1586 int_x86_sse2_cvtsd2si, sdmem, sse_load_f64, "cvtsd2si",
1587 SSE_CVT_SD2SI>, XD, VEX, VEX_LIG;
1588 defm VCVTSD2SI64 : sse12_cvt_sint<0x2D, VR128, GR64,
1589 int_x86_sse2_cvtsd2si64, sdmem, sse_load_f64, "cvtsd2si",
1590 SSE_CVT_SD2SI>, XD, VEX, VEX_W, VEX_LIG;
1592 defm CVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse2_cvtsd2si,
1593 sdmem, sse_load_f64, "cvtsd2si", SSE_CVT_SD2SI>, XD;
1594 defm CVTSD2SI64 : sse12_cvt_sint<0x2D, VR128, GR64, int_x86_sse2_cvtsd2si64,
1595 sdmem, sse_load_f64, "cvtsd2si", SSE_CVT_SD2SI>, XD, REX_W;
1598 defm Int_VCVTSI2SS : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
1599 int_x86_sse_cvtsi2ss, i32mem, loadi32, "cvtsi2ss{l}",
1600 SSE_CVT_Scalar, 0>, XS, VEX_4V;
1601 defm Int_VCVTSI2SS64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
1602 int_x86_sse_cvtsi642ss, i64mem, loadi64, "cvtsi2ss{q}",
1603 SSE_CVT_Scalar, 0>, XS, VEX_4V,
1605 defm Int_VCVTSI2SD : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
1606 int_x86_sse2_cvtsi2sd, i32mem, loadi32, "cvtsi2sd{l}",
1607 SSE_CVT_Scalar, 0>, XD, VEX_4V;
1608 defm Int_VCVTSI2SD64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
1609 int_x86_sse2_cvtsi642sd, i64mem, loadi64, "cvtsi2sd{q}",
1610 SSE_CVT_Scalar, 0>, XD,
1613 let Constraints = "$src1 = $dst" in {
1614 defm Int_CVTSI2SS : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
1615 int_x86_sse_cvtsi2ss, i32mem, loadi32,
1616 "cvtsi2ss{l}", SSE_CVT_Scalar>, XS;
1617 defm Int_CVTSI2SS64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
1618 int_x86_sse_cvtsi642ss, i64mem, loadi64,
1619 "cvtsi2ss{q}", SSE_CVT_Scalar>, XS, REX_W;
1620 defm Int_CVTSI2SD : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
1621 int_x86_sse2_cvtsi2sd, i32mem, loadi32,
1622 "cvtsi2sd{l}", SSE_CVT_Scalar>, XD;
1623 defm Int_CVTSI2SD64 : sse12_cvt_sint_3addr<0x2A, GR64, VR128,
1624 int_x86_sse2_cvtsi642sd, i64mem, loadi64,
1625 "cvtsi2sd{q}", SSE_CVT_Scalar>, XD, REX_W;
1630 // Aliases for intrinsics
1631 defm Int_VCVTTSS2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse_cvttss2si,
1632 ssmem, sse_load_f32, "cvttss2si",
1633 SSE_CVT_SS2SI_32>, XS, VEX;
1634 defm Int_VCVTTSS2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
1635 int_x86_sse_cvttss2si64, ssmem, sse_load_f32,
1636 "cvttss2si", SSE_CVT_SS2SI_64>,
1638 defm Int_VCVTTSD2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse2_cvttsd2si,
1639 sdmem, sse_load_f64, "cvttsd2si",
1640 SSE_CVT_SD2SI>, XD, VEX;
1641 defm Int_VCVTTSD2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
1642 int_x86_sse2_cvttsd2si64, sdmem, sse_load_f64,
1643 "cvttsd2si", SSE_CVT_SD2SI>,
1645 defm Int_CVTTSS2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse_cvttss2si,
1646 ssmem, sse_load_f32, "cvttss2si",
1647 SSE_CVT_SS2SI_32>, XS;
1648 defm Int_CVTTSS2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
1649 int_x86_sse_cvttss2si64, ssmem, sse_load_f32,
1650 "cvttss2si", SSE_CVT_SS2SI_64>, XS, REX_W;
1651 defm Int_CVTTSD2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse2_cvttsd2si,
1652 sdmem, sse_load_f64, "cvttsd2si",
1654 defm Int_CVTTSD2SI64 : sse12_cvt_sint<0x2C, VR128, GR64,
1655 int_x86_sse2_cvttsd2si64, sdmem, sse_load_f64,
1656 "cvttsd2si", SSE_CVT_SD2SI>, XD, REX_W;
1658 defm VCVTSS2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse_cvtss2si,
1659 ssmem, sse_load_f32, "cvtss2si",
1660 SSE_CVT_SS2SI_32>, XS, VEX, VEX_LIG;
1661 defm VCVTSS2SI64 : sse12_cvt_sint<0x2D, VR128, GR64, int_x86_sse_cvtss2si64,
1662 ssmem, sse_load_f32, "cvtss2si",
1663 SSE_CVT_SS2SI_64>, XS, VEX, VEX_W, VEX_LIG;
1665 defm CVTSS2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse_cvtss2si,
1666 ssmem, sse_load_f32, "cvtss2si",
1667 SSE_CVT_SS2SI_32>, XS;
1668 defm CVTSS2SI64 : sse12_cvt_sint<0x2D, VR128, GR64, int_x86_sse_cvtss2si64,
1669 ssmem, sse_load_f32, "cvtss2si",
1670 SSE_CVT_SS2SI_64>, XS, REX_W;
1672 defm VCVTDQ2PS : sse12_cvt_p<0x5B, VR128, VR128, i128mem,
1673 "vcvtdq2ps\t{$src, $dst|$dst, $src}",
1674 SSEPackedSingle, SSE_CVT_PS>,
1675 TB, VEX, Requires<[HasAVX]>;
1676 defm VCVTDQ2PSY : sse12_cvt_p<0x5B, VR256, VR256, i256mem,
1677 "vcvtdq2ps\t{$src, $dst|$dst, $src}",
1678 SSEPackedSingle, SSE_CVT_PS>,
1679 TB, VEX, VEX_L, Requires<[HasAVX]>;
1681 defm CVTDQ2PS : sse12_cvt_p<0x5B, VR128, VR128, i128mem,
1682 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1683 SSEPackedSingle, SSE_CVT_PS>,
1684 TB, Requires<[UseSSE2]>;
1686 def : InstAlias<"vcvtss2si{l}\t{$src, $dst|$dst, $src}",
1687 (VCVTSS2SIrr GR32:$dst, VR128:$src), 0>;
1688 def : InstAlias<"vcvtss2si{l}\t{$src, $dst|$dst, $src}",
1689 (VCVTSS2SIrm GR32:$dst, ssmem:$src), 0>;
1690 def : InstAlias<"vcvtsd2si{l}\t{$src, $dst|$dst, $src}",
1691 (VCVTSD2SIrr GR32:$dst, VR128:$src), 0>;
1692 def : InstAlias<"vcvtsd2si{l}\t{$src, $dst|$dst, $src}",
1693 (VCVTSD2SIrm GR32:$dst, sdmem:$src), 0>;
1694 def : InstAlias<"vcvtss2si{q}\t{$src, $dst|$dst, $src}",
1695 (VCVTSS2SI64rr GR64:$dst, VR128:$src), 0>;
1696 def : InstAlias<"vcvtss2si{q}\t{$src, $dst|$dst, $src}",
1697 (VCVTSS2SI64rm GR64:$dst, ssmem:$src), 0>;
1698 def : InstAlias<"vcvtsd2si{q}\t{$src, $dst|$dst, $src}",
1699 (VCVTSD2SI64rr GR64:$dst, VR128:$src), 0>;
1700 def : InstAlias<"vcvtsd2si{q}\t{$src, $dst|$dst, $src}",
1701 (VCVTSD2SI64rm GR64:$dst, sdmem:$src), 0>;
1703 def : InstAlias<"cvtss2si{l}\t{$src, $dst|$dst, $src}",
1704 (CVTSS2SIrr GR32:$dst, VR128:$src), 0>;
1705 def : InstAlias<"cvtss2si{l}\t{$src, $dst|$dst, $src}",
1706 (CVTSS2SIrm GR32:$dst, ssmem:$src), 0>;
1707 def : InstAlias<"cvtsd2si{l}\t{$src, $dst|$dst, $src}",
1708 (CVTSD2SIrr GR32:$dst, VR128:$src), 0>;
1709 def : InstAlias<"cvtsd2si{l}\t{$src, $dst|$dst, $src}",
1710 (CVTSD2SIrm GR32:$dst, sdmem:$src), 0>;
1711 def : InstAlias<"cvtss2si{q}\t{$src, $dst|$dst, $src}",
1712 (CVTSS2SI64rr GR64:$dst, VR128:$src), 0>;
1713 def : InstAlias<"cvtss2si{q}\t{$src, $dst|$dst, $src}",
1714 (CVTSS2SI64rm GR64:$dst, ssmem:$src), 0>;
1715 def : InstAlias<"cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1716 (CVTSD2SI64rr GR64:$dst, VR128:$src), 0>;
1717 def : InstAlias<"cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1718 (CVTSD2SI64rm GR64:$dst, sdmem:$src)>;
1722 // Convert scalar double to scalar single
1723 let neverHasSideEffects = 1 in {
1724 def VCVTSD2SSrr : VSDI<0x5A, MRMSrcReg, (outs FR32:$dst),
1725 (ins FR64:$src1, FR64:$src2),
1726 "cvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}", [],
1727 IIC_SSE_CVT_Scalar_RR>, VEX_4V, VEX_LIG;
1729 def VCVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst),
1730 (ins FR64:$src1, f64mem:$src2),
1731 "vcvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1732 [], IIC_SSE_CVT_Scalar_RM>,
1733 XD, Requires<[HasAVX, OptForSize]>, VEX_4V, VEX_LIG;
1736 def : Pat<(f32 (fround FR64:$src)), (VCVTSD2SSrr FR64:$src, FR64:$src)>,
1739 def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
1740 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1741 [(set FR32:$dst, (fround FR64:$src))],
1742 IIC_SSE_CVT_Scalar_RR>;
1743 def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
1744 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1745 [(set FR32:$dst, (fround (loadf64 addr:$src)))],
1746 IIC_SSE_CVT_Scalar_RM>,
1748 Requires<[UseSSE2, OptForSize]>;
1750 def Int_VCVTSD2SSrr: I<0x5A, MRMSrcReg,
1751 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1752 "vcvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1754 (int_x86_sse2_cvtsd2ss VR128:$src1, VR128:$src2))],
1755 IIC_SSE_CVT_Scalar_RR>, XD, VEX_4V, Requires<[HasAVX]>;
1756 def Int_VCVTSD2SSrm: I<0x5A, MRMSrcReg,
1757 (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
1758 "vcvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1759 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss
1760 VR128:$src1, sse_load_f64:$src2))],
1761 IIC_SSE_CVT_Scalar_RM>, XD, VEX_4V, Requires<[HasAVX]>;
1763 let Constraints = "$src1 = $dst" in {
1764 def Int_CVTSD2SSrr: I<0x5A, MRMSrcReg,
1765 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1766 "cvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1768 (int_x86_sse2_cvtsd2ss VR128:$src1, VR128:$src2))],
1769 IIC_SSE_CVT_Scalar_RR>, XD, Requires<[UseSSE2]>;
1770 def Int_CVTSD2SSrm: I<0x5A, MRMSrcReg,
1771 (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
1772 "cvtsd2ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1773 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss
1774 VR128:$src1, sse_load_f64:$src2))],
1775 IIC_SSE_CVT_Scalar_RM>, XD, Requires<[UseSSE2]>;
1778 // Convert scalar single to scalar double
1779 // SSE2 instructions with XS prefix
1780 let neverHasSideEffects = 1 in {
1781 def VCVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst),
1782 (ins FR32:$src1, FR32:$src2),
1783 "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1784 [], IIC_SSE_CVT_Scalar_RR>,
1785 XS, Requires<[HasAVX]>, VEX_4V, VEX_LIG;
1787 def VCVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst),
1788 (ins FR32:$src1, f32mem:$src2),
1789 "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1790 [], IIC_SSE_CVT_Scalar_RM>,
1791 XS, VEX_4V, VEX_LIG, Requires<[HasAVX, OptForSize]>;
1794 def : Pat<(f64 (fextend FR32:$src)),
1795 (VCVTSS2SDrr FR32:$src, FR32:$src)>, Requires<[HasAVX]>;
1796 def : Pat<(fextend (loadf32 addr:$src)),
1797 (VCVTSS2SDrm (f32 (IMPLICIT_DEF)), addr:$src)>, Requires<[HasAVX]>;
1799 def : Pat<(extloadf32 addr:$src),
1800 (VCVTSS2SDrm (f32 (IMPLICIT_DEF)), addr:$src)>,
1801 Requires<[HasAVX, OptForSize]>;
1802 def : Pat<(extloadf32 addr:$src),
1803 (VCVTSS2SDrr (f32 (IMPLICIT_DEF)), (VMOVSSrm addr:$src))>,
1804 Requires<[HasAVX, OptForSpeed]>;
1806 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
1807 "cvtss2sd\t{$src, $dst|$dst, $src}",
1808 [(set FR64:$dst, (fextend FR32:$src))],
1809 IIC_SSE_CVT_Scalar_RR>, XS,
1810 Requires<[UseSSE2]>;
1811 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
1812 "cvtss2sd\t{$src, $dst|$dst, $src}",
1813 [(set FR64:$dst, (extloadf32 addr:$src))],
1814 IIC_SSE_CVT_Scalar_RM>, XS,
1815 Requires<[UseSSE2, OptForSize]>;
1817 // extload f32 -> f64. This matches load+fextend because we have a hack in
1818 // the isel (PreprocessForFPConvert) that can introduce loads after dag
1820 // Since these loads aren't folded into the fextend, we have to match it
1822 def : Pat<(fextend (loadf32 addr:$src)),
1823 (CVTSS2SDrm addr:$src)>, Requires<[UseSSE2]>;
1824 def : Pat<(extloadf32 addr:$src),
1825 (CVTSS2SDrr (MOVSSrm addr:$src))>, Requires<[UseSSE2, OptForSpeed]>;
1827 def Int_VCVTSS2SDrr: I<0x5A, MRMSrcReg,
1828 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1829 "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1831 (int_x86_sse2_cvtss2sd VR128:$src1, VR128:$src2))],
1832 IIC_SSE_CVT_Scalar_RR>, XS, VEX_4V, Requires<[HasAVX]>;
1833 def Int_VCVTSS2SDrm: I<0x5A, MRMSrcMem,
1834 (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
1835 "vcvtss2sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1837 (int_x86_sse2_cvtss2sd VR128:$src1, sse_load_f32:$src2))],
1838 IIC_SSE_CVT_Scalar_RM>, XS, VEX_4V, Requires<[HasAVX]>;
1839 let Constraints = "$src1 = $dst" in { // SSE2 instructions with XS prefix
1840 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
1841 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1842 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1844 (int_x86_sse2_cvtss2sd VR128:$src1, VR128:$src2))],
1845 IIC_SSE_CVT_Scalar_RR>, XS, Requires<[UseSSE2]>;
1846 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
1847 (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
1848 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1850 (int_x86_sse2_cvtss2sd VR128:$src1, sse_load_f32:$src2))],
1851 IIC_SSE_CVT_Scalar_RM>, XS, Requires<[UseSSE2]>;
1854 // Convert packed single/double fp to doubleword
1855 def VCVTPS2DQrr : VPDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1856 "cvtps2dq\t{$src, $dst|$dst, $src}",
1857 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))],
1858 IIC_SSE_CVT_PS_RR>, VEX;
1859 def VCVTPS2DQrm : VPDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1860 "cvtps2dq\t{$src, $dst|$dst, $src}",
1862 (int_x86_sse2_cvtps2dq (memopv4f32 addr:$src)))],
1863 IIC_SSE_CVT_PS_RM>, VEX;
1864 def VCVTPS2DQYrr : VPDI<0x5B, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
1865 "cvtps2dq\t{$src, $dst|$dst, $src}",
1867 (int_x86_avx_cvt_ps2dq_256 VR256:$src))],
1868 IIC_SSE_CVT_PS_RR>, VEX, VEX_L;
1869 def VCVTPS2DQYrm : VPDI<0x5B, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
1870 "cvtps2dq\t{$src, $dst|$dst, $src}",
1872 (int_x86_avx_cvt_ps2dq_256 (memopv8f32 addr:$src)))],
1873 IIC_SSE_CVT_PS_RM>, VEX, VEX_L;
1874 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1875 "cvtps2dq\t{$src, $dst|$dst, $src}",
1876 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))],
1878 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1879 "cvtps2dq\t{$src, $dst|$dst, $src}",
1881 (int_x86_sse2_cvtps2dq (memopv4f32 addr:$src)))],
1885 // Convert Packed Double FP to Packed DW Integers
1886 let Predicates = [HasAVX] in {
1887 // The assembler can recognize rr 256-bit instructions by seeing a ymm
1888 // register, but the same isn't true when using memory operands instead.
1889 // Provide other assembly rr and rm forms to address this explicitly.
1890 def VCVTPD2DQrr : SDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1891 "vcvtpd2dq\t{$src, $dst|$dst, $src}",
1892 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1896 def : InstAlias<"vcvtpd2dqx\t{$src, $dst|$dst, $src}",
1897 (VCVTPD2DQrr VR128:$dst, VR128:$src)>;
1898 def VCVTPD2DQXrm : SDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1899 "vcvtpd2dqx\t{$src, $dst|$dst, $src}",
1901 (int_x86_sse2_cvtpd2dq (memopv2f64 addr:$src)))]>, VEX;
1904 def VCVTPD2DQYrr : SDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
1905 "vcvtpd2dq{y}\t{$src, $dst|$dst, $src}",
1907 (int_x86_avx_cvt_pd2dq_256 VR256:$src))]>, VEX, VEX_L;
1908 def VCVTPD2DQYrm : SDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
1909 "vcvtpd2dq{y}\t{$src, $dst|$dst, $src}",
1911 (int_x86_avx_cvt_pd2dq_256 (memopv4f64 addr:$src)))]>,
1913 def : InstAlias<"vcvtpd2dq\t{$src, $dst|$dst, $src}",
1914 (VCVTPD2DQYrr VR128:$dst, VR256:$src)>;
1917 def CVTPD2DQrm : SDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1918 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1920 (int_x86_sse2_cvtpd2dq (memopv2f64 addr:$src)))],
1922 def CVTPD2DQrr : SDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1923 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1924 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))],
1927 // Convert with truncation packed single/double fp to doubleword
1928 // SSE2 packed instructions with XS prefix
1929 def VCVTTPS2DQrr : VS2SI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1930 "cvttps2dq\t{$src, $dst|$dst, $src}",
1932 (int_x86_sse2_cvttps2dq VR128:$src))],
1933 IIC_SSE_CVT_PS_RR>, VEX;
1934 def VCVTTPS2DQrm : VS2SI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1935 "cvttps2dq\t{$src, $dst|$dst, $src}",
1936 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1937 (memopv4f32 addr:$src)))],
1938 IIC_SSE_CVT_PS_RM>, VEX;
1939 def VCVTTPS2DQYrr : VS2SI<0x5B, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
1940 "cvttps2dq\t{$src, $dst|$dst, $src}",
1942 (int_x86_avx_cvtt_ps2dq_256 VR256:$src))],
1943 IIC_SSE_CVT_PS_RR>, VEX, VEX_L;
1944 def VCVTTPS2DQYrm : VS2SI<0x5B, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
1945 "cvttps2dq\t{$src, $dst|$dst, $src}",
1946 [(set VR256:$dst, (int_x86_avx_cvtt_ps2dq_256
1947 (memopv8f32 addr:$src)))],
1948 IIC_SSE_CVT_PS_RM>, VEX, VEX_L;
1950 def CVTTPS2DQrr : S2SI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1951 "cvttps2dq\t{$src, $dst|$dst, $src}",
1952 [(set VR128:$dst, (int_x86_sse2_cvttps2dq VR128:$src))],
1954 def CVTTPS2DQrm : S2SI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1955 "cvttps2dq\t{$src, $dst|$dst, $src}",
1957 (int_x86_sse2_cvttps2dq (memopv4f32 addr:$src)))],
1960 let Predicates = [HasAVX] in {
1961 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
1962 (VCVTDQ2PSrr VR128:$src)>;
1963 def : Pat<(v4f32 (sint_to_fp (bc_v4i32 (memopv2i64 addr:$src)))),
1964 (VCVTDQ2PSrm addr:$src)>;
1966 def : Pat<(int_x86_sse2_cvtdq2ps VR128:$src),
1967 (VCVTDQ2PSrr VR128:$src)>;
1968 def : Pat<(int_x86_sse2_cvtdq2ps (bc_v4i32 (memopv2i64 addr:$src))),
1969 (VCVTDQ2PSrm addr:$src)>;
1971 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
1972 (VCVTTPS2DQrr VR128:$src)>;
1973 def : Pat<(v4i32 (fp_to_sint (memopv4f32 addr:$src))),
1974 (VCVTTPS2DQrm addr:$src)>;
1976 def : Pat<(v8f32 (sint_to_fp (v8i32 VR256:$src))),
1977 (VCVTDQ2PSYrr VR256:$src)>;
1978 def : Pat<(v8f32 (sint_to_fp (bc_v8i32 (memopv4i64 addr:$src)))),
1979 (VCVTDQ2PSYrm addr:$src)>;
1981 def : Pat<(v8i32 (fp_to_sint (v8f32 VR256:$src))),
1982 (VCVTTPS2DQYrr VR256:$src)>;
1983 def : Pat<(v8i32 (fp_to_sint (memopv8f32 addr:$src))),
1984 (VCVTTPS2DQYrm addr:$src)>;
1987 let Predicates = [UseSSE2] in {
1988 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
1989 (CVTDQ2PSrr VR128:$src)>;
1990 def : Pat<(v4f32 (sint_to_fp (bc_v4i32 (memopv2i64 addr:$src)))),
1991 (CVTDQ2PSrm addr:$src)>;
1993 def : Pat<(int_x86_sse2_cvtdq2ps VR128:$src),
1994 (CVTDQ2PSrr VR128:$src)>;
1995 def : Pat<(int_x86_sse2_cvtdq2ps (bc_v4i32 (memopv2i64 addr:$src))),
1996 (CVTDQ2PSrm addr:$src)>;
1998 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
1999 (CVTTPS2DQrr VR128:$src)>;
2000 def : Pat<(v4i32 (fp_to_sint (memopv4f32 addr:$src))),
2001 (CVTTPS2DQrm addr:$src)>;
2004 def VCVTTPD2DQrr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2005 "cvttpd2dq\t{$src, $dst|$dst, $src}",
2007 (int_x86_sse2_cvttpd2dq VR128:$src))],
2008 IIC_SSE_CVT_PD_RR>, VEX;
2010 // The assembler can recognize rr 256-bit instructions by seeing a ymm
2011 // register, but the same isn't true when using memory operands instead.
2012 // Provide other assembly rr and rm forms to address this explicitly.
2015 def : InstAlias<"vcvttpd2dqx\t{$src, $dst|$dst, $src}",
2016 (VCVTTPD2DQrr VR128:$dst, VR128:$src)>;
2017 def VCVTTPD2DQXrm : VPDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2018 "cvttpd2dqx\t{$src, $dst|$dst, $src}",
2019 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
2020 (memopv2f64 addr:$src)))],
2021 IIC_SSE_CVT_PD_RM>, VEX;
2024 def VCVTTPD2DQYrr : VPDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
2025 "cvttpd2dq{y}\t{$src, $dst|$dst, $src}",
2027 (int_x86_avx_cvtt_pd2dq_256 VR256:$src))],
2028 IIC_SSE_CVT_PD_RR>, VEX, VEX_L;
2029 def VCVTTPD2DQYrm : VPDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
2030 "cvttpd2dq{y}\t{$src, $dst|$dst, $src}",
2032 (int_x86_avx_cvtt_pd2dq_256 (memopv4f64 addr:$src)))],
2033 IIC_SSE_CVT_PD_RM>, VEX, VEX_L;
2034 def : InstAlias<"vcvttpd2dq\t{$src, $dst|$dst, $src}",
2035 (VCVTTPD2DQYrr VR128:$dst, VR256:$src)>;
2037 let Predicates = [HasAVX] in {
2038 def : Pat<(v4i32 (fp_to_sint (v4f64 VR256:$src))),
2039 (VCVTTPD2DQYrr VR256:$src)>;
2040 def : Pat<(v4i32 (fp_to_sint (memopv4f64 addr:$src))),
2041 (VCVTTPD2DQYrm addr:$src)>;
2042 } // Predicates = [HasAVX]
2044 def CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2045 "cvttpd2dq\t{$src, $dst|$dst, $src}",
2046 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))],
2048 def CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
2049 "cvttpd2dq\t{$src, $dst|$dst, $src}",
2050 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
2051 (memopv2f64 addr:$src)))],
2054 // Convert packed single to packed double
2055 let Predicates = [HasAVX] in {
2056 // SSE2 instructions without OpSize prefix
2057 def VCVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2058 "vcvtps2pd\t{$src, $dst|$dst, $src}",
2059 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))],
2060 IIC_SSE_CVT_PD_RR>, TB, VEX;
2061 def VCVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2062 "vcvtps2pd\t{$src, $dst|$dst, $src}",
2063 [(set VR128:$dst, (v2f64 (extloadv2f32 addr:$src)))],
2064 IIC_SSE_CVT_PD_RM>, TB, VEX;
2065 def VCVTPS2PDYrr : I<0x5A, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
2066 "vcvtps2pd\t{$src, $dst|$dst, $src}",
2068 (int_x86_avx_cvt_ps2_pd_256 VR128:$src))],
2069 IIC_SSE_CVT_PD_RR>, TB, VEX, VEX_L;
2070 def VCVTPS2PDYrm : I<0x5A, MRMSrcMem, (outs VR256:$dst), (ins f128mem:$src),
2071 "vcvtps2pd\t{$src, $dst|$dst, $src}",
2073 (int_x86_avx_cvt_ps2_pd_256 (memopv4f32 addr:$src)))],
2074 IIC_SSE_CVT_PD_RM>, TB, VEX, VEX_L;
2077 let Predicates = [UseSSE2] in {
2078 def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2079 "cvtps2pd\t{$src, $dst|$dst, $src}",
2080 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))],
2081 IIC_SSE_CVT_PD_RR>, TB;
2082 def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2083 "cvtps2pd\t{$src, $dst|$dst, $src}",
2084 [(set VR128:$dst, (v2f64 (extloadv2f32 addr:$src)))],
2085 IIC_SSE_CVT_PD_RM>, TB;
2088 // Convert Packed DW Integers to Packed Double FP
2089 let Predicates = [HasAVX] in {
2090 let neverHasSideEffects = 1, mayLoad = 1 in
2091 def VCVTDQ2PDrm : S2SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2092 "vcvtdq2pd\t{$src, $dst|$dst, $src}",
2094 def VCVTDQ2PDrr : S2SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2095 "vcvtdq2pd\t{$src, $dst|$dst, $src}",
2097 (int_x86_sse2_cvtdq2pd VR128:$src))]>, VEX;
2098 def VCVTDQ2PDYrm : S2SI<0xE6, MRMSrcMem, (outs VR256:$dst), (ins i128mem:$src),
2099 "vcvtdq2pd\t{$src, $dst|$dst, $src}",
2101 (int_x86_avx_cvtdq2_pd_256
2102 (bitconvert (memopv2i64 addr:$src))))]>, VEX, VEX_L;
2103 def VCVTDQ2PDYrr : S2SI<0xE6, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
2104 "vcvtdq2pd\t{$src, $dst|$dst, $src}",
2106 (int_x86_avx_cvtdq2_pd_256 VR128:$src))]>, VEX, VEX_L;
2109 let neverHasSideEffects = 1, mayLoad = 1 in
2110 def CVTDQ2PDrm : S2SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2111 "cvtdq2pd\t{$src, $dst|$dst, $src}", [],
2113 def CVTDQ2PDrr : S2SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2114 "cvtdq2pd\t{$src, $dst|$dst, $src}",
2115 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))],
2118 // AVX 256-bit register conversion intrinsics
2119 let Predicates = [HasAVX] in {
2120 def : Pat<(v4f64 (sint_to_fp (v4i32 VR128:$src))),
2121 (VCVTDQ2PDYrr VR128:$src)>;
2122 def : Pat<(v4f64 (sint_to_fp (bc_v4i32 (memopv2i64 addr:$src)))),
2123 (VCVTDQ2PDYrm addr:$src)>;
2124 } // Predicates = [HasAVX]
2126 // Convert packed double to packed single
2127 // The assembler can recognize rr 256-bit instructions by seeing a ymm
2128 // register, but the same isn't true when using memory operands instead.
2129 // Provide other assembly rr and rm forms to address this explicitly.
2130 def VCVTPD2PSrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2131 "cvtpd2ps\t{$src, $dst|$dst, $src}",
2132 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))],
2133 IIC_SSE_CVT_PD_RR>, VEX;
2136 def : InstAlias<"vcvtpd2psx\t{$src, $dst|$dst, $src}",
2137 (VCVTPD2PSrr VR128:$dst, VR128:$src)>;
2138 def VCVTPD2PSXrm : VPDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2139 "cvtpd2psx\t{$src, $dst|$dst, $src}",
2141 (int_x86_sse2_cvtpd2ps (memopv2f64 addr:$src)))],
2142 IIC_SSE_CVT_PD_RM>, VEX;
2145 def VCVTPD2PSYrr : VPDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR256:$src),
2146 "cvtpd2ps{y}\t{$src, $dst|$dst, $src}",
2148 (int_x86_avx_cvt_pd2_ps_256 VR256:$src))],
2149 IIC_SSE_CVT_PD_RR>, VEX, VEX_L;
2150 def VCVTPD2PSYrm : VPDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f256mem:$src),
2151 "cvtpd2ps{y}\t{$src, $dst|$dst, $src}",
2153 (int_x86_avx_cvt_pd2_ps_256 (memopv4f64 addr:$src)))],
2154 IIC_SSE_CVT_PD_RM>, VEX, VEX_L;
2155 def : InstAlias<"vcvtpd2ps\t{$src, $dst|$dst, $src}",
2156 (VCVTPD2PSYrr VR128:$dst, VR256:$src)>;
2158 def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2159 "cvtpd2ps\t{$src, $dst|$dst, $src}",
2160 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))],
2162 def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2163 "cvtpd2ps\t{$src, $dst|$dst, $src}",
2165 (int_x86_sse2_cvtpd2ps (memopv2f64 addr:$src)))],
2169 // AVX 256-bit register conversion intrinsics
2170 // FIXME: Migrate SSE conversion intrinsics matching to use patterns as below
2171 // whenever possible to avoid declaring two versions of each one.
2172 let Predicates = [HasAVX] in {
2173 def : Pat<(int_x86_avx_cvtdq2_ps_256 VR256:$src),
2174 (VCVTDQ2PSYrr VR256:$src)>;
2175 def : Pat<(int_x86_avx_cvtdq2_ps_256 (bitconvert (memopv4i64 addr:$src))),
2176 (VCVTDQ2PSYrm addr:$src)>;
2178 // Match fround and fextend for 128/256-bit conversions
2179 def : Pat<(v4f32 (X86vfpround (v2f64 VR128:$src))),
2180 (VCVTPD2PSrr VR128:$src)>;
2181 def : Pat<(v4f32 (X86vfpround (memopv2f64 addr:$src))),
2182 (VCVTPD2PSXrm addr:$src)>;
2183 def : Pat<(v4f32 (fround (v4f64 VR256:$src))),
2184 (VCVTPD2PSYrr VR256:$src)>;
2185 def : Pat<(v4f32 (fround (loadv4f64 addr:$src))),
2186 (VCVTPD2PSYrm addr:$src)>;
2188 def : Pat<(v2f64 (X86vfpext (v4f32 VR128:$src))),
2189 (VCVTPS2PDrr VR128:$src)>;
2190 def : Pat<(v4f64 (fextend (v4f32 VR128:$src))),
2191 (VCVTPS2PDYrr VR128:$src)>;
2192 def : Pat<(v4f64 (extloadv4f32 addr:$src)),
2193 (VCVTPS2PDYrm addr:$src)>;
2196 let Predicates = [UseSSE2] in {
2197 // Match fround and fextend for 128 conversions
2198 def : Pat<(v4f32 (X86vfpround (v2f64 VR128:$src))),
2199 (CVTPD2PSrr VR128:$src)>;
2200 def : Pat<(v4f32 (X86vfpround (memopv2f64 addr:$src))),
2201 (CVTPD2PSrm addr:$src)>;
2203 def : Pat<(v2f64 (X86vfpext (v4f32 VR128:$src))),
2204 (CVTPS2PDrr VR128:$src)>;
2207 //===----------------------------------------------------------------------===//
2208 // SSE 1 & 2 - Compare Instructions
2209 //===----------------------------------------------------------------------===//
2211 // sse12_cmp_scalar - sse 1 & 2 compare scalar instructions
2212 multiclass sse12_cmp_scalar<RegisterClass RC, X86MemOperand x86memop,
2213 Operand CC, SDNode OpNode, ValueType VT,
2214 PatFrag ld_frag, string asm, string asm_alt,
2216 def rr : SIi8<0xC2, MRMSrcReg,
2217 (outs RC:$dst), (ins RC:$src1, RC:$src2, CC:$cc), asm,
2218 [(set RC:$dst, (OpNode (VT RC:$src1), RC:$src2, imm:$cc))],
2220 def rm : SIi8<0xC2, MRMSrcMem,
2221 (outs RC:$dst), (ins RC:$src1, x86memop:$src2, CC:$cc), asm,
2222 [(set RC:$dst, (OpNode (VT RC:$src1),
2223 (ld_frag addr:$src2), imm:$cc))],
2226 // Accept explicit immediate argument form instead of comparison code.
2227 let neverHasSideEffects = 1 in {
2228 def rr_alt : SIi8<0xC2, MRMSrcReg, (outs RC:$dst),
2229 (ins RC:$src1, RC:$src2, i8imm:$cc), asm_alt, [],
2230 IIC_SSE_ALU_F32S_RR>;
2232 def rm_alt : SIi8<0xC2, MRMSrcMem, (outs RC:$dst),
2233 (ins RC:$src1, x86memop:$src2, i8imm:$cc), asm_alt, [],
2234 IIC_SSE_ALU_F32S_RM>;
2238 defm VCMPSS : sse12_cmp_scalar<FR32, f32mem, AVXCC, X86cmpss, f32, loadf32,
2239 "cmp${cc}ss\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2240 "cmpss\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2242 XS, VEX_4V, VEX_LIG;
2243 defm VCMPSD : sse12_cmp_scalar<FR64, f64mem, AVXCC, X86cmpsd, f64, loadf64,
2244 "cmp${cc}sd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2245 "cmpsd\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2246 SSE_ALU_F32S>, // same latency as 32 bit compare
2247 XD, VEX_4V, VEX_LIG;
2249 let Constraints = "$src1 = $dst" in {
2250 defm CMPSS : sse12_cmp_scalar<FR32, f32mem, SSECC, X86cmpss, f32, loadf32,
2251 "cmp${cc}ss\t{$src2, $dst|$dst, $src2}",
2252 "cmpss\t{$cc, $src2, $dst|$dst, $src2, $cc}", SSE_ALU_F32S>,
2254 defm CMPSD : sse12_cmp_scalar<FR64, f64mem, SSECC, X86cmpsd, f64, loadf64,
2255 "cmp${cc}sd\t{$src2, $dst|$dst, $src2}",
2256 "cmpsd\t{$cc, $src2, $dst|$dst, $src2, $cc}",
2257 SSE_ALU_F32S>, // same latency as 32 bit compare
2261 multiclass sse12_cmp_scalar_int<X86MemOperand x86memop, Operand CC,
2262 Intrinsic Int, string asm, OpndItins itins> {
2263 def rr : SIi8<0xC2, MRMSrcReg, (outs VR128:$dst),
2264 (ins VR128:$src1, VR128:$src, CC:$cc), asm,
2265 [(set VR128:$dst, (Int VR128:$src1,
2266 VR128:$src, imm:$cc))],
2268 def rm : SIi8<0xC2, MRMSrcMem, (outs VR128:$dst),
2269 (ins VR128:$src1, x86memop:$src, CC:$cc), asm,
2270 [(set VR128:$dst, (Int VR128:$src1,
2271 (load addr:$src), imm:$cc))],
2275 // Aliases to match intrinsics which expect XMM operand(s).
2276 defm Int_VCMPSS : sse12_cmp_scalar_int<f32mem, AVXCC, int_x86_sse_cmp_ss,
2277 "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}",
2280 defm Int_VCMPSD : sse12_cmp_scalar_int<f64mem, AVXCC, int_x86_sse2_cmp_sd,
2281 "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}",
2282 SSE_ALU_F32S>, // same latency as f32
2284 let Constraints = "$src1 = $dst" in {
2285 defm Int_CMPSS : sse12_cmp_scalar_int<f32mem, SSECC, int_x86_sse_cmp_ss,
2286 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
2288 defm Int_CMPSD : sse12_cmp_scalar_int<f64mem, SSECC, int_x86_sse2_cmp_sd,
2289 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
2290 SSE_ALU_F32S>, // same latency as f32
2295 // sse12_ord_cmp - Unordered/Ordered scalar fp compare and set EFLAGS
2296 multiclass sse12_ord_cmp<bits<8> opc, RegisterClass RC, SDNode OpNode,
2297 ValueType vt, X86MemOperand x86memop,
2298 PatFrag ld_frag, string OpcodeStr, Domain d> {
2299 def rr: PI<opc, MRMSrcReg, (outs), (ins RC:$src1, RC:$src2),
2300 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
2301 [(set EFLAGS, (OpNode (vt RC:$src1), RC:$src2))],
2302 IIC_SSE_COMIS_RR, d>;
2303 def rm: PI<opc, MRMSrcMem, (outs), (ins RC:$src1, x86memop:$src2),
2304 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
2305 [(set EFLAGS, (OpNode (vt RC:$src1),
2306 (ld_frag addr:$src2)))],
2307 IIC_SSE_COMIS_RM, d>;
2310 let Defs = [EFLAGS] in {
2311 defm VUCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
2312 "ucomiss", SSEPackedSingle>, TB, VEX, VEX_LIG;
2313 defm VUCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
2314 "ucomisd", SSEPackedDouble>, TB, OpSize, VEX,
2316 let Pattern = []<dag> in {
2317 defm VCOMISS : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
2318 "comiss", SSEPackedSingle>, TB, VEX,
2320 defm VCOMISD : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
2321 "comisd", SSEPackedDouble>, TB, OpSize, VEX,
2325 defm Int_VUCOMISS : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
2326 load, "ucomiss", SSEPackedSingle>, TB, VEX;
2327 defm Int_VUCOMISD : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
2328 load, "ucomisd", SSEPackedDouble>, TB, OpSize, VEX;
2330 defm Int_VCOMISS : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem,
2331 load, "comiss", SSEPackedSingle>, TB, VEX;
2332 defm Int_VCOMISD : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem,
2333 load, "comisd", SSEPackedDouble>, TB, OpSize, VEX;
2334 defm UCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
2335 "ucomiss", SSEPackedSingle>, TB;
2336 defm UCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
2337 "ucomisd", SSEPackedDouble>, TB, OpSize;
2339 let Pattern = []<dag> in {
2340 defm COMISS : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
2341 "comiss", SSEPackedSingle>, TB;
2342 defm COMISD : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
2343 "comisd", SSEPackedDouble>, TB, OpSize;
2346 defm Int_UCOMISS : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
2347 load, "ucomiss", SSEPackedSingle>, TB;
2348 defm Int_UCOMISD : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
2349 load, "ucomisd", SSEPackedDouble>, TB, OpSize;
2351 defm Int_COMISS : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem, load,
2352 "comiss", SSEPackedSingle>, TB;
2353 defm Int_COMISD : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem, load,
2354 "comisd", SSEPackedDouble>, TB, OpSize;
2355 } // Defs = [EFLAGS]
2357 // sse12_cmp_packed - sse 1 & 2 compare packed instructions
2358 multiclass sse12_cmp_packed<RegisterClass RC, X86MemOperand x86memop,
2359 Operand CC, Intrinsic Int, string asm,
2360 string asm_alt, Domain d> {
2361 def rri : PIi8<0xC2, MRMSrcReg,
2362 (outs RC:$dst), (ins RC:$src1, RC:$src2, CC:$cc), asm,
2363 [(set RC:$dst, (Int RC:$src1, RC:$src2, imm:$cc))],
2364 IIC_SSE_CMPP_RR, d>;
2365 def rmi : PIi8<0xC2, MRMSrcMem,
2366 (outs RC:$dst), (ins RC:$src1, x86memop:$src2, CC:$cc), asm,
2367 [(set RC:$dst, (Int RC:$src1, (memop addr:$src2), imm:$cc))],
2368 IIC_SSE_CMPP_RM, d>;
2370 // Accept explicit immediate argument form instead of comparison code.
2371 let neverHasSideEffects = 1 in {
2372 def rri_alt : PIi8<0xC2, MRMSrcReg,
2373 (outs RC:$dst), (ins RC:$src1, RC:$src2, i8imm:$cc),
2374 asm_alt, [], IIC_SSE_CMPP_RR, d>;
2375 def rmi_alt : PIi8<0xC2, MRMSrcMem,
2376 (outs RC:$dst), (ins RC:$src1, x86memop:$src2, i8imm:$cc),
2377 asm_alt, [], IIC_SSE_CMPP_RM, d>;
2381 defm VCMPPS : sse12_cmp_packed<VR128, f128mem, AVXCC, int_x86_sse_cmp_ps,
2382 "cmp${cc}ps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2383 "cmpps\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2384 SSEPackedSingle>, TB, VEX_4V;
2385 defm VCMPPD : sse12_cmp_packed<VR128, f128mem, AVXCC, int_x86_sse2_cmp_pd,
2386 "cmp${cc}pd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2387 "cmppd\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2388 SSEPackedDouble>, TB, OpSize, VEX_4V;
2389 defm VCMPPSY : sse12_cmp_packed<VR256, f256mem, AVXCC, int_x86_avx_cmp_ps_256,
2390 "cmp${cc}ps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2391 "cmpps\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2392 SSEPackedSingle>, TB, VEX_4V, VEX_L;
2393 defm VCMPPDY : sse12_cmp_packed<VR256, f256mem, AVXCC, int_x86_avx_cmp_pd_256,
2394 "cmp${cc}pd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2395 "cmppd\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}",
2396 SSEPackedDouble>, TB, OpSize, VEX_4V, VEX_L;
2397 let Constraints = "$src1 = $dst" in {
2398 defm CMPPS : sse12_cmp_packed<VR128, f128mem, SSECC, int_x86_sse_cmp_ps,
2399 "cmp${cc}ps\t{$src2, $dst|$dst, $src2}",
2400 "cmpps\t{$cc, $src2, $dst|$dst, $src2, $cc}",
2401 SSEPackedSingle>, TB;
2402 defm CMPPD : sse12_cmp_packed<VR128, f128mem, SSECC, int_x86_sse2_cmp_pd,
2403 "cmp${cc}pd\t{$src2, $dst|$dst, $src2}",
2404 "cmppd\t{$cc, $src2, $dst|$dst, $src2, $cc}",
2405 SSEPackedDouble>, TB, OpSize;
2408 let Predicates = [HasAVX] in {
2409 def : Pat<(v4i32 (X86cmpp (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
2410 (VCMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
2411 def : Pat<(v4i32 (X86cmpp (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
2412 (VCMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
2413 def : Pat<(v2i64 (X86cmpp (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
2414 (VCMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
2415 def : Pat<(v2i64 (X86cmpp (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
2416 (VCMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
2418 def : Pat<(v8i32 (X86cmpp (v8f32 VR256:$src1), VR256:$src2, imm:$cc)),
2419 (VCMPPSYrri (v8f32 VR256:$src1), (v8f32 VR256:$src2), imm:$cc)>;
2420 def : Pat<(v8i32 (X86cmpp (v8f32 VR256:$src1), (memop addr:$src2), imm:$cc)),
2421 (VCMPPSYrmi (v8f32 VR256:$src1), addr:$src2, imm:$cc)>;
2422 def : Pat<(v4i64 (X86cmpp (v4f64 VR256:$src1), VR256:$src2, imm:$cc)),
2423 (VCMPPDYrri VR256:$src1, VR256:$src2, imm:$cc)>;
2424 def : Pat<(v4i64 (X86cmpp (v4f64 VR256:$src1), (memop addr:$src2), imm:$cc)),
2425 (VCMPPDYrmi VR256:$src1, addr:$src2, imm:$cc)>;
2428 let Predicates = [UseSSE1] in {
2429 def : Pat<(v4i32 (X86cmpp (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
2430 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
2431 def : Pat<(v4i32 (X86cmpp (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
2432 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
2435 let Predicates = [UseSSE2] in {
2436 def : Pat<(v2i64 (X86cmpp (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
2437 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
2438 def : Pat<(v2i64 (X86cmpp (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
2439 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
2442 //===----------------------------------------------------------------------===//
2443 // SSE 1 & 2 - Shuffle Instructions
2444 //===----------------------------------------------------------------------===//
2446 /// sse12_shuffle - sse 1 & 2 shuffle instructions
2447 multiclass sse12_shuffle<RegisterClass RC, X86MemOperand x86memop,
2448 ValueType vt, string asm, PatFrag mem_frag,
2449 Domain d, bit IsConvertibleToThreeAddress = 0> {
2450 def rmi : PIi8<0xC6, MRMSrcMem, (outs RC:$dst),
2451 (ins RC:$src1, x86memop:$src2, i8imm:$src3), asm,
2452 [(set RC:$dst, (vt (X86Shufp RC:$src1, (mem_frag addr:$src2),
2453 (i8 imm:$src3))))], IIC_SSE_SHUFP, d>;
2454 let isConvertibleToThreeAddress = IsConvertibleToThreeAddress in
2455 def rri : PIi8<0xC6, MRMSrcReg, (outs RC:$dst),
2456 (ins RC:$src1, RC:$src2, i8imm:$src3), asm,
2457 [(set RC:$dst, (vt (X86Shufp RC:$src1, RC:$src2,
2458 (i8 imm:$src3))))], IIC_SSE_SHUFP, d>;
2461 defm VSHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
2462 "shufps\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
2463 memopv4f32, SSEPackedSingle>, TB, VEX_4V;
2464 defm VSHUFPSY : sse12_shuffle<VR256, f256mem, v8f32,
2465 "shufps\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
2466 memopv8f32, SSEPackedSingle>, TB, VEX_4V, VEX_L;
2467 defm VSHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
2468 "shufpd\t{$src3, $src2, $src1, $dst|$dst, $src2, $src2, $src3}",
2469 memopv2f64, SSEPackedDouble>, TB, OpSize, VEX_4V;
2470 defm VSHUFPDY : sse12_shuffle<VR256, f256mem, v4f64,
2471 "shufpd\t{$src3, $src2, $src1, $dst|$dst, $src2, $src2, $src3}",
2472 memopv4f64, SSEPackedDouble>, TB, OpSize, VEX_4V, VEX_L;
2474 let Constraints = "$src1 = $dst" in {
2475 defm SHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
2476 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2477 memopv4f32, SSEPackedSingle, 1 /* cvt to pshufd */>,
2479 defm SHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
2480 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2481 memopv2f64, SSEPackedDouble, 1 /* cvt to pshufd */>,
2485 let Predicates = [HasAVX] in {
2486 def : Pat<(v4i32 (X86Shufp VR128:$src1,
2487 (bc_v4i32 (memopv2i64 addr:$src2)), (i8 imm:$imm))),
2488 (VSHUFPSrmi VR128:$src1, addr:$src2, imm:$imm)>;
2489 def : Pat<(v4i32 (X86Shufp VR128:$src1, VR128:$src2, (i8 imm:$imm))),
2490 (VSHUFPSrri VR128:$src1, VR128:$src2, imm:$imm)>;
2492 def : Pat<(v2i64 (X86Shufp VR128:$src1,
2493 (memopv2i64 addr:$src2), (i8 imm:$imm))),
2494 (VSHUFPDrmi VR128:$src1, addr:$src2, imm:$imm)>;
2495 def : Pat<(v2i64 (X86Shufp VR128:$src1, VR128:$src2, (i8 imm:$imm))),
2496 (VSHUFPDrri VR128:$src1, VR128:$src2, imm:$imm)>;
2499 def : Pat<(v8i32 (X86Shufp VR256:$src1, VR256:$src2, (i8 imm:$imm))),
2500 (VSHUFPSYrri VR256:$src1, VR256:$src2, imm:$imm)>;
2501 def : Pat<(v8i32 (X86Shufp VR256:$src1,
2502 (bc_v8i32 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
2503 (VSHUFPSYrmi VR256:$src1, addr:$src2, imm:$imm)>;
2505 def : Pat<(v4i64 (X86Shufp VR256:$src1, VR256:$src2, (i8 imm:$imm))),
2506 (VSHUFPDYrri VR256:$src1, VR256:$src2, imm:$imm)>;
2507 def : Pat<(v4i64 (X86Shufp VR256:$src1,
2508 (memopv4i64 addr:$src2), (i8 imm:$imm))),
2509 (VSHUFPDYrmi VR256:$src1, addr:$src2, imm:$imm)>;
2512 let Predicates = [UseSSE1] in {
2513 def : Pat<(v4i32 (X86Shufp VR128:$src1,
2514 (bc_v4i32 (memopv2i64 addr:$src2)), (i8 imm:$imm))),
2515 (SHUFPSrmi VR128:$src1, addr:$src2, imm:$imm)>;
2516 def : Pat<(v4i32 (X86Shufp VR128:$src1, VR128:$src2, (i8 imm:$imm))),
2517 (SHUFPSrri VR128:$src1, VR128:$src2, imm:$imm)>;
2520 let Predicates = [UseSSE2] in {
2521 // Generic SHUFPD patterns
2522 def : Pat<(v2i64 (X86Shufp VR128:$src1,
2523 (memopv2i64 addr:$src2), (i8 imm:$imm))),
2524 (SHUFPDrmi VR128:$src1, addr:$src2, imm:$imm)>;
2525 def : Pat<(v2i64 (X86Shufp VR128:$src1, VR128:$src2, (i8 imm:$imm))),
2526 (SHUFPDrri VR128:$src1, VR128:$src2, imm:$imm)>;
2529 //===----------------------------------------------------------------------===//
2530 // SSE 1 & 2 - Unpack Instructions
2531 //===----------------------------------------------------------------------===//
2533 /// sse12_unpack_interleave - sse 1 & 2 unpack and interleave
2534 multiclass sse12_unpack_interleave<bits<8> opc, SDNode OpNode, ValueType vt,
2535 PatFrag mem_frag, RegisterClass RC,
2536 X86MemOperand x86memop, string asm,
2538 def rr : PI<opc, MRMSrcReg,
2539 (outs RC:$dst), (ins RC:$src1, RC:$src2),
2541 (vt (OpNode RC:$src1, RC:$src2)))],
2543 def rm : PI<opc, MRMSrcMem,
2544 (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
2546 (vt (OpNode RC:$src1,
2547 (mem_frag addr:$src2))))],
2551 defm VUNPCKHPS: sse12_unpack_interleave<0x15, X86Unpckh, v4f32, memopv4f32,
2552 VR128, f128mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2553 SSEPackedSingle>, TB, VEX_4V;
2554 defm VUNPCKHPD: sse12_unpack_interleave<0x15, X86Unpckh, v2f64, memopv2f64,
2555 VR128, f128mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2556 SSEPackedDouble>, TB, OpSize, VEX_4V;
2557 defm VUNPCKLPS: sse12_unpack_interleave<0x14, X86Unpckl, v4f32, memopv4f32,
2558 VR128, f128mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2559 SSEPackedSingle>, TB, VEX_4V;
2560 defm VUNPCKLPD: sse12_unpack_interleave<0x14, X86Unpckl, v2f64, memopv2f64,
2561 VR128, f128mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2562 SSEPackedDouble>, TB, OpSize, VEX_4V;
2564 defm VUNPCKHPSY: sse12_unpack_interleave<0x15, X86Unpckh, v8f32, memopv8f32,
2565 VR256, f256mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2566 SSEPackedSingle>, TB, VEX_4V, VEX_L;
2567 defm VUNPCKHPDY: sse12_unpack_interleave<0x15, X86Unpckh, v4f64, memopv4f64,
2568 VR256, f256mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2569 SSEPackedDouble>, TB, OpSize, VEX_4V, VEX_L;
2570 defm VUNPCKLPSY: sse12_unpack_interleave<0x14, X86Unpckl, v8f32, memopv8f32,
2571 VR256, f256mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2572 SSEPackedSingle>, TB, VEX_4V, VEX_L;
2573 defm VUNPCKLPDY: sse12_unpack_interleave<0x14, X86Unpckl, v4f64, memopv4f64,
2574 VR256, f256mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2575 SSEPackedDouble>, TB, OpSize, VEX_4V, VEX_L;
2577 let Constraints = "$src1 = $dst" in {
2578 defm UNPCKHPS: sse12_unpack_interleave<0x15, X86Unpckh, v4f32, memopv4f32,
2579 VR128, f128mem, "unpckhps\t{$src2, $dst|$dst, $src2}",
2580 SSEPackedSingle>, TB;
2581 defm UNPCKHPD: sse12_unpack_interleave<0x15, X86Unpckh, v2f64, memopv2f64,
2582 VR128, f128mem, "unpckhpd\t{$src2, $dst|$dst, $src2}",
2583 SSEPackedDouble>, TB, OpSize;
2584 defm UNPCKLPS: sse12_unpack_interleave<0x14, X86Unpckl, v4f32, memopv4f32,
2585 VR128, f128mem, "unpcklps\t{$src2, $dst|$dst, $src2}",
2586 SSEPackedSingle>, TB;
2587 defm UNPCKLPD: sse12_unpack_interleave<0x14, X86Unpckl, v2f64, memopv2f64,
2588 VR128, f128mem, "unpcklpd\t{$src2, $dst|$dst, $src2}",
2589 SSEPackedDouble>, TB, OpSize;
2590 } // Constraints = "$src1 = $dst"
2592 let Predicates = [HasAVX1Only] in {
2593 def : Pat<(v8i32 (X86Unpckl VR256:$src1, (bc_v8i32 (memopv4i64 addr:$src2)))),
2594 (VUNPCKLPSYrm VR256:$src1, addr:$src2)>;
2595 def : Pat<(v8i32 (X86Unpckl VR256:$src1, VR256:$src2)),
2596 (VUNPCKLPSYrr VR256:$src1, VR256:$src2)>;
2597 def : Pat<(v8i32 (X86Unpckh VR256:$src1, (bc_v8i32 (memopv4i64 addr:$src2)))),
2598 (VUNPCKHPSYrm VR256:$src1, addr:$src2)>;
2599 def : Pat<(v8i32 (X86Unpckh VR256:$src1, VR256:$src2)),
2600 (VUNPCKHPSYrr VR256:$src1, VR256:$src2)>;
2602 def : Pat<(v4i64 (X86Unpckl VR256:$src1, (memopv4i64 addr:$src2))),
2603 (VUNPCKLPDYrm VR256:$src1, addr:$src2)>;
2604 def : Pat<(v4i64 (X86Unpckl VR256:$src1, VR256:$src2)),
2605 (VUNPCKLPDYrr VR256:$src1, VR256:$src2)>;
2606 def : Pat<(v4i64 (X86Unpckh VR256:$src1, (memopv4i64 addr:$src2))),
2607 (VUNPCKHPDYrm VR256:$src1, addr:$src2)>;
2608 def : Pat<(v4i64 (X86Unpckh VR256:$src1, VR256:$src2)),
2609 (VUNPCKHPDYrr VR256:$src1, VR256:$src2)>;
2612 let Predicates = [HasAVX] in {
2613 // FIXME: Instead of X86Movddup, there should be a X86Unpckl here, the
2614 // problem is during lowering, where it's not possible to recognize the load
2615 // fold cause it has two uses through a bitcast. One use disappears at isel
2616 // time and the fold opportunity reappears.
2617 def : Pat<(v2f64 (X86Movddup VR128:$src)),
2618 (VUNPCKLPDrr VR128:$src, VR128:$src)>;
2621 let Predicates = [UseSSE2] in {
2622 // FIXME: Instead of X86Movddup, there should be a X86Unpckl here, the
2623 // problem is during lowering, where it's not possible to recognize the load
2624 // fold cause it has two uses through a bitcast. One use disappears at isel
2625 // time and the fold opportunity reappears.
2626 def : Pat<(v2f64 (X86Movddup VR128:$src)),
2627 (UNPCKLPDrr VR128:$src, VR128:$src)>;
2630 //===----------------------------------------------------------------------===//
2631 // SSE 1 & 2 - Extract Floating-Point Sign mask
2632 //===----------------------------------------------------------------------===//
2634 /// sse12_extr_sign_mask - sse 1 & 2 unpack and interleave
2635 multiclass sse12_extr_sign_mask<RegisterClass RC, Intrinsic Int, string asm,
2637 def rr32 : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins RC:$src),
2638 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
2639 [(set GR32:$dst, (Int RC:$src))], IIC_SSE_MOVMSK, d>;
2640 def rr64 : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins RC:$src),
2641 !strconcat(asm, "\t{$src, $dst|$dst, $src}"), [],
2642 IIC_SSE_MOVMSK, d>, REX_W;
2645 let Predicates = [HasAVX] in {
2646 defm VMOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps,
2647 "movmskps", SSEPackedSingle>, TB, VEX;
2648 defm VMOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd,
2649 "movmskpd", SSEPackedDouble>, TB,
2651 defm VMOVMSKPSY : sse12_extr_sign_mask<VR256, int_x86_avx_movmsk_ps_256,
2652 "movmskps", SSEPackedSingle>, TB,
2654 defm VMOVMSKPDY : sse12_extr_sign_mask<VR256, int_x86_avx_movmsk_pd_256,
2655 "movmskpd", SSEPackedDouble>, TB,
2658 def : Pat<(i32 (X86fgetsign FR32:$src)),
2659 (VMOVMSKPSrr32 (COPY_TO_REGCLASS FR32:$src, VR128))>;
2660 def : Pat<(i64 (X86fgetsign FR32:$src)),
2661 (VMOVMSKPSrr64 (COPY_TO_REGCLASS FR32:$src, VR128))>;
2662 def : Pat<(i32 (X86fgetsign FR64:$src)),
2663 (VMOVMSKPDrr32 (COPY_TO_REGCLASS FR64:$src, VR128))>;
2664 def : Pat<(i64 (X86fgetsign FR64:$src)),
2665 (VMOVMSKPDrr64 (COPY_TO_REGCLASS FR64:$src, VR128))>;
2668 def VMOVMSKPSr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
2669 "movmskps\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK,
2670 SSEPackedSingle>, TB, VEX;
2671 def VMOVMSKPDr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
2672 "movmskpd\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK,
2673 SSEPackedDouble>, TB,
2675 def VMOVMSKPSYr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR256:$src),
2676 "movmskps\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK,
2677 SSEPackedSingle>, TB, VEX, VEX_L;
2678 def VMOVMSKPDYr64r : PI<0x50, MRMSrcReg, (outs GR64:$dst), (ins VR256:$src),
2679 "movmskpd\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK,
2680 SSEPackedDouble>, TB,
2684 defm MOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps, "movmskps",
2685 SSEPackedSingle>, TB;
2686 defm MOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd, "movmskpd",
2687 SSEPackedDouble>, TB, OpSize;
2689 def : Pat<(i32 (X86fgetsign FR32:$src)),
2690 (MOVMSKPSrr32 (COPY_TO_REGCLASS FR32:$src, VR128))>,
2691 Requires<[UseSSE1]>;
2692 def : Pat<(i64 (X86fgetsign FR32:$src)),
2693 (MOVMSKPSrr64 (COPY_TO_REGCLASS FR32:$src, VR128))>,
2694 Requires<[UseSSE1]>;
2695 def : Pat<(i32 (X86fgetsign FR64:$src)),
2696 (MOVMSKPDrr32 (COPY_TO_REGCLASS FR64:$src, VR128))>,
2697 Requires<[UseSSE2]>;
2698 def : Pat<(i64 (X86fgetsign FR64:$src)),
2699 (MOVMSKPDrr64 (COPY_TO_REGCLASS FR64:$src, VR128))>,
2700 Requires<[UseSSE2]>;
2702 //===---------------------------------------------------------------------===//
2703 // SSE2 - Packed Integer Logical Instructions
2704 //===---------------------------------------------------------------------===//
2706 let ExeDomain = SSEPackedInt in { // SSE integer instructions
2708 /// PDI_binop_rm - Simple SSE2 binary operator.
2709 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
2710 ValueType OpVT, RegisterClass RC, PatFrag memop_frag,
2711 X86MemOperand x86memop, OpndItins itins,
2712 bit IsCommutable, bit Is2Addr> {
2713 let isCommutable = IsCommutable in
2714 def rr : PDI<opc, MRMSrcReg, (outs RC:$dst),
2715 (ins RC:$src1, RC:$src2),
2717 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2718 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2719 [(set RC:$dst, (OpVT (OpNode RC:$src1, RC:$src2)))], itins.rr>;
2720 def rm : PDI<opc, MRMSrcMem, (outs RC:$dst),
2721 (ins RC:$src1, x86memop:$src2),
2723 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2724 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
2725 [(set RC:$dst, (OpVT (OpNode RC:$src1,
2726 (bitconvert (memop_frag addr:$src2)))))],
2729 } // ExeDomain = SSEPackedInt
2731 multiclass PDI_binop_all<bits<8> opc, string OpcodeStr, SDNode Opcode,
2732 ValueType OpVT128, ValueType OpVT256,
2733 OpndItins itins, bit IsCommutable = 0> {
2734 let Predicates = [HasAVX] in
2735 defm V#NAME# : PDI_binop_rm<opc, !strconcat("v", OpcodeStr), Opcode, OpVT128,
2736 VR128, memopv2i64, i128mem, itins, IsCommutable, 0>, VEX_4V;
2738 let Constraints = "$src1 = $dst" in
2739 defm #NAME# : PDI_binop_rm<opc, OpcodeStr, Opcode, OpVT128, VR128,
2740 memopv2i64, i128mem, itins, IsCommutable, 1>;
2742 let Predicates = [HasAVX2] in
2743 defm V#NAME#Y : PDI_binop_rm<opc, !strconcat("v", OpcodeStr), Opcode,
2744 OpVT256, VR256, memopv4i64, i256mem, itins,
2745 IsCommutable, 0>, VEX_4V, VEX_L;
2748 // These are ordered here for pattern ordering requirements with the fp versions
2750 defm PAND : PDI_binop_all<0xDB, "pand", and, v2i64, v4i64, SSE_BIT_ITINS_P, 1>;
2751 defm POR : PDI_binop_all<0xEB, "por", or, v2i64, v4i64, SSE_BIT_ITINS_P, 1>;
2752 defm PXOR : PDI_binop_all<0xEF, "pxor", xor, v2i64, v4i64, SSE_BIT_ITINS_P, 1>;
2753 defm PANDN : PDI_binop_all<0xDF, "pandn", X86andnp, v2i64, v4i64,
2754 SSE_BIT_ITINS_P, 0>;
2756 //===----------------------------------------------------------------------===//
2757 // SSE 1 & 2 - Logical Instructions
2758 //===----------------------------------------------------------------------===//
2760 /// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
2762 multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
2763 SDNode OpNode, OpndItins itins> {
2764 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode,
2765 FR32, f32, f128mem, memopfsf32, SSEPackedSingle, itins, 0>,
2768 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode,
2769 FR64, f64, f128mem, memopfsf64, SSEPackedDouble, itins, 0>,
2772 let Constraints = "$src1 = $dst" in {
2773 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, FR32,
2774 f32, f128mem, memopfsf32, SSEPackedSingle, itins>,
2777 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, FR64,
2778 f64, f128mem, memopfsf64, SSEPackedDouble, itins>,
2783 // Alias bitwise logical operations using SSE logical ops on packed FP values.
2784 defm FsAND : sse12_fp_alias_pack_logical<0x54, "and", X86fand,
2786 defm FsOR : sse12_fp_alias_pack_logical<0x56, "or", X86for,
2788 defm FsXOR : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor,
2791 let neverHasSideEffects = 1, Pattern = []<dag>, isCommutable = 0 in
2792 defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef,
2795 /// sse12_fp_packed_logical - SSE 1 & 2 packed FP logical ops
2797 multiclass sse12_fp_packed_logical<bits<8> opc, string OpcodeStr,
2799 defm V#NAME#PSY : sse12_fp_packed_logical_rm<opc, VR256, SSEPackedSingle,
2800 !strconcat(OpcodeStr, "ps"), f256mem,
2801 [(set VR256:$dst, (v4i64 (OpNode VR256:$src1, VR256:$src2)))],
2802 [(set VR256:$dst, (OpNode (bc_v4i64 (v8f32 VR256:$src1)),
2803 (memopv4i64 addr:$src2)))], 0>, TB, VEX_4V, VEX_L;
2805 defm V#NAME#PDY : sse12_fp_packed_logical_rm<opc, VR256, SSEPackedDouble,
2806 !strconcat(OpcodeStr, "pd"), f256mem,
2807 [(set VR256:$dst, (OpNode (bc_v4i64 (v4f64 VR256:$src1)),
2808 (bc_v4i64 (v4f64 VR256:$src2))))],
2809 [(set VR256:$dst, (OpNode (bc_v4i64 (v4f64 VR256:$src1)),
2810 (memopv4i64 addr:$src2)))], 0>,
2811 TB, OpSize, VEX_4V, VEX_L;
2813 // In AVX no need to add a pattern for 128-bit logical rr ps, because they
2814 // are all promoted to v2i64, and the patterns are covered by the int
2815 // version. This is needed in SSE only, because v2i64 isn't supported on
2816 // SSE1, but only on SSE2.
2817 defm V#NAME#PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
2818 !strconcat(OpcodeStr, "ps"), f128mem, [],
2819 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
2820 (memopv2i64 addr:$src2)))], 0>, TB, VEX_4V;
2822 defm V#NAME#PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
2823 !strconcat(OpcodeStr, "pd"), f128mem,
2824 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
2825 (bc_v2i64 (v2f64 VR128:$src2))))],
2826 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
2827 (memopv2i64 addr:$src2)))], 0>,
2830 let Constraints = "$src1 = $dst" in {
2831 defm PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
2832 !strconcat(OpcodeStr, "ps"), f128mem,
2833 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))],
2834 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
2835 (memopv2i64 addr:$src2)))]>, TB;
2837 defm PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
2838 !strconcat(OpcodeStr, "pd"), f128mem,
2839 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
2840 (bc_v2i64 (v2f64 VR128:$src2))))],
2841 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
2842 (memopv2i64 addr:$src2)))]>, TB, OpSize;
2846 defm AND : sse12_fp_packed_logical<0x54, "and", and>;
2847 defm OR : sse12_fp_packed_logical<0x56, "or", or>;
2848 defm XOR : sse12_fp_packed_logical<0x57, "xor", xor>;
2849 let isCommutable = 0 in
2850 defm ANDN : sse12_fp_packed_logical<0x55, "andn", X86andnp>;
2852 //===----------------------------------------------------------------------===//
2853 // SSE 1 & 2 - Arithmetic Instructions
2854 //===----------------------------------------------------------------------===//
2856 /// basic_sse12_fp_binop_xxx - SSE 1 & 2 binops come in both scalar and
2859 /// In addition, we also have a special variant of the scalar form here to
2860 /// represent the associated intrinsic operation. This form is unlike the
2861 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
2862 /// and leaves the top elements unmodified (therefore these cannot be commuted).
2864 /// These three forms can each be reg+reg or reg+mem.
2867 /// FIXME: once all 256-bit intrinsics are matched, cleanup and refactor those
2869 multiclass basic_sse12_fp_binop_s<bits<8> opc, string OpcodeStr, SDNode OpNode,
2872 defm SS : sse12_fp_scalar<opc, !strconcat(OpcodeStr, "ss"),
2873 OpNode, FR32, f32mem,
2874 itins.s, Is2Addr>, XS;
2875 defm SD : sse12_fp_scalar<opc, !strconcat(OpcodeStr, "sd"),
2876 OpNode, FR64, f64mem,
2877 itins.d, Is2Addr>, XD;
2880 multiclass basic_sse12_fp_binop_p<bits<8> opc, string OpcodeStr,
2881 SDNode OpNode, SizeItins itins> {
2882 let Predicates = [HasAVX] in {
2883 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode,
2884 VR128, v4f32, f128mem, memopv4f32,
2885 SSEPackedSingle, itins.s, 0>, TB, VEX_4V;
2886 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode,
2887 VR128, v2f64, f128mem, memopv2f64,
2888 SSEPackedDouble, itins.d, 0>, TB, OpSize, VEX_4V;
2890 defm V#NAME#PSY : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"),
2891 OpNode, VR256, v8f32, f256mem, memopv8f32,
2892 SSEPackedSingle, itins.s, 0>, TB, VEX_4V, VEX_L;
2893 defm V#NAME#PDY : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"),
2894 OpNode, VR256, v4f64, f256mem, memopv4f64,
2895 SSEPackedDouble, itins.d, 0>, TB, OpSize, VEX_4V, VEX_L;
2898 let Constraints = "$src1 = $dst" in {
2899 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr, "ps"), OpNode, VR128,
2900 v4f32, f128mem, memopv4f32, SSEPackedSingle,
2902 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, VR128,
2903 v2f64, f128mem, memopv2f64, SSEPackedDouble,
2904 itins.d, 1>, TB, OpSize;
2908 multiclass basic_sse12_fp_binop_s_int<bits<8> opc, string OpcodeStr,
2911 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
2912 !strconcat(OpcodeStr, "ss"), "", "_ss", ssmem, sse_load_f32,
2913 itins.s, Is2Addr>, XS;
2914 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
2915 !strconcat(OpcodeStr, "sd"), "2", "_sd", sdmem, sse_load_f64,
2916 itins.d, Is2Addr>, XD;
2919 // Binary Arithmetic instructions
2920 defm ADD : basic_sse12_fp_binop_p<0x58, "add", fadd, SSE_ALU_ITINS_P>;
2921 defm MUL : basic_sse12_fp_binop_p<0x59, "mul", fmul, SSE_MUL_ITINS_P>;
2922 let isCommutable = 0 in {
2923 defm SUB : basic_sse12_fp_binop_p<0x5C, "sub", fsub, SSE_ALU_ITINS_P>;
2924 defm DIV : basic_sse12_fp_binop_p<0x5E, "div", fdiv, SSE_DIV_ITINS_P>;
2925 defm MAX : basic_sse12_fp_binop_p<0x5F, "max", X86fmax, SSE_ALU_ITINS_P>;
2926 defm MIN : basic_sse12_fp_binop_p<0x5D, "min", X86fmin, SSE_ALU_ITINS_P>;
2929 let isCodeGenOnly = 1 in {
2930 defm MAXC: basic_sse12_fp_binop_p<0x5F, "max", X86fmaxc, SSE_ALU_ITINS_P>;
2931 defm MINC: basic_sse12_fp_binop_p<0x5D, "min", X86fminc, SSE_ALU_ITINS_P>;
2934 defm VADD : basic_sse12_fp_binop_s<0x58, "add", fadd, SSE_ALU_ITINS_S, 0>,
2935 basic_sse12_fp_binop_s_int<0x58, "add", SSE_ALU_ITINS_S, 0>,
2937 defm VMUL : basic_sse12_fp_binop_s<0x59, "mul", fmul, SSE_MUL_ITINS_S, 0>,
2938 basic_sse12_fp_binop_s_int<0x59, "mul", SSE_MUL_ITINS_S, 0>,
2941 let isCommutable = 0 in {
2942 defm VSUB : basic_sse12_fp_binop_s<0x5C, "sub", fsub, SSE_ALU_ITINS_S, 0>,
2943 basic_sse12_fp_binop_s_int<0x5C, "sub", SSE_ALU_ITINS_S, 0>,
2945 defm VDIV : basic_sse12_fp_binop_s<0x5E, "div", fdiv, SSE_DIV_ITINS_S, 0>,
2946 basic_sse12_fp_binop_s_int<0x5E, "div", SSE_DIV_ITINS_S, 0>,
2948 defm VMAX : basic_sse12_fp_binop_s<0x5F, "max", X86fmax, SSE_ALU_ITINS_S, 0>,
2949 basic_sse12_fp_binop_s_int<0x5F, "max", SSE_ALU_ITINS_S, 0>,
2951 defm VMIN : basic_sse12_fp_binop_s<0x5D, "min", X86fmin, SSE_ALU_ITINS_S, 0>,
2952 basic_sse12_fp_binop_s_int<0x5D, "min", SSE_ALU_ITINS_S, 0>,
2956 let Constraints = "$src1 = $dst" in {
2957 defm ADD : basic_sse12_fp_binop_s<0x58, "add", fadd, SSE_ALU_ITINS_S>,
2958 basic_sse12_fp_binop_s_int<0x58, "add", SSE_ALU_ITINS_S>;
2959 defm MUL : basic_sse12_fp_binop_s<0x59, "mul", fmul, SSE_MUL_ITINS_S>,
2960 basic_sse12_fp_binop_s_int<0x59, "mul", SSE_MUL_ITINS_S>;
2962 let isCommutable = 0 in {
2963 defm SUB : basic_sse12_fp_binop_s<0x5C, "sub", fsub, SSE_ALU_ITINS_S>,
2964 basic_sse12_fp_binop_s_int<0x5C, "sub", SSE_ALU_ITINS_S>;
2965 defm DIV : basic_sse12_fp_binop_s<0x5E, "div", fdiv, SSE_DIV_ITINS_S>,
2966 basic_sse12_fp_binop_s_int<0x5E, "div", SSE_DIV_ITINS_S>;
2967 defm MAX : basic_sse12_fp_binop_s<0x5F, "max", X86fmax, SSE_ALU_ITINS_S>,
2968 basic_sse12_fp_binop_s_int<0x5F, "max", SSE_ALU_ITINS_S>;
2969 defm MIN : basic_sse12_fp_binop_s<0x5D, "min", X86fmin, SSE_ALU_ITINS_S>,
2970 basic_sse12_fp_binop_s_int<0x5D, "min", SSE_ALU_ITINS_S>;
2974 let isCodeGenOnly = 1 in {
2975 defm VMAXC: basic_sse12_fp_binop_s<0x5F, "max", X86fmaxc, SSE_ALU_ITINS_S, 0>,
2977 defm VMINC: basic_sse12_fp_binop_s<0x5D, "min", X86fminc, SSE_ALU_ITINS_S, 0>,
2979 let Constraints = "$src1 = $dst" in {
2980 defm MAXC: basic_sse12_fp_binop_s<0x5F, "max", X86fmaxc, SSE_ALU_ITINS_S>;
2981 defm MINC: basic_sse12_fp_binop_s<0x5D, "min", X86fminc, SSE_ALU_ITINS_S>;
2986 /// In addition, we also have a special variant of the scalar form here to
2987 /// represent the associated intrinsic operation. This form is unlike the
2988 /// plain scalar form, in that it takes an entire vector (instead of a
2989 /// scalar) and leaves the top elements undefined.
2991 /// And, we have a special variant form for a full-vector intrinsic form.
2993 def SSE_SQRTP : OpndItins<
2994 IIC_SSE_SQRTP_RR, IIC_SSE_SQRTP_RM
2997 def SSE_SQRTS : OpndItins<
2998 IIC_SSE_SQRTS_RR, IIC_SSE_SQRTS_RM
3001 def SSE_RCPP : OpndItins<
3002 IIC_SSE_RCPP_RR, IIC_SSE_RCPP_RM
3005 def SSE_RCPS : OpndItins<
3006 IIC_SSE_RCPS_RR, IIC_SSE_RCPS_RM
3009 /// sse1_fp_unop_s - SSE1 unops in scalar form.
3010 multiclass sse1_fp_unop_s<bits<8> opc, string OpcodeStr,
3011 SDNode OpNode, Intrinsic F32Int, OpndItins itins> {
3012 let Predicates = [HasAVX], hasSideEffects = 0 in {
3013 def V#NAME#SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst),
3014 (ins FR32:$src1, FR32:$src2),
3015 !strconcat(!strconcat("v", OpcodeStr),
3016 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3017 []>, VEX_4V, VEX_LIG;
3018 let mayLoad = 1 in {
3019 def V#NAME#SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst),
3020 (ins FR32:$src1,f32mem:$src2),
3021 !strconcat(!strconcat("v", OpcodeStr),
3022 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3023 []>, VEX_4V, VEX_LIG;
3024 def V#NAME#SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
3025 (ins VR128:$src1, ssmem:$src2),
3026 !strconcat(!strconcat("v", OpcodeStr),
3027 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3028 []>, VEX_4V, VEX_LIG;
3032 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
3033 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3034 [(set FR32:$dst, (OpNode FR32:$src))]>;
3035 // For scalar unary operations, fold a load into the operation
3036 // only in OptForSize mode. It eliminates an instruction, but it also
3037 // eliminates a whole-register clobber (the load), so it introduces a
3038 // partial register update condition.
3039 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
3040 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3041 [(set FR32:$dst, (OpNode (load addr:$src)))], itins.rm>, XS,
3042 Requires<[UseSSE1, OptForSize]>;
3043 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3044 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3045 [(set VR128:$dst, (F32Int VR128:$src))], itins.rr>;
3046 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
3047 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3048 [(set VR128:$dst, (F32Int sse_load_f32:$src))], itins.rm>;
3051 /// sse1_fp_unop_s_rw - SSE1 unops where vector form has a read-write operand.
3052 multiclass sse1_fp_unop_rw<bits<8> opc, string OpcodeStr, SDNode OpNode,
3054 let Predicates = [HasAVX], hasSideEffects = 0 in {
3055 def V#NAME#SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst),
3056 (ins FR32:$src1, FR32:$src2),
3057 !strconcat(!strconcat("v", OpcodeStr),
3058 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3059 []>, VEX_4V, VEX_LIG;
3060 let mayLoad = 1 in {
3061 def V#NAME#SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst),
3062 (ins FR32:$src1,f32mem:$src2),
3063 !strconcat(!strconcat("v", OpcodeStr),
3064 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3065 []>, VEX_4V, VEX_LIG;
3066 def V#NAME#SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
3067 (ins VR128:$src1, ssmem:$src2),
3068 !strconcat(!strconcat("v", OpcodeStr),
3069 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3070 []>, VEX_4V, VEX_LIG;
3074 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
3075 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3076 [(set FR32:$dst, (OpNode FR32:$src))]>;
3077 // For scalar unary operations, fold a load into the operation
3078 // only in OptForSize mode. It eliminates an instruction, but it also
3079 // eliminates a whole-register clobber (the load), so it introduces a
3080 // partial register update condition.
3081 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
3082 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
3083 [(set FR32:$dst, (OpNode (load addr:$src)))], itins.rm>, XS,
3084 Requires<[UseSSE1, OptForSize]>;
3085 let Constraints = "$src1 = $dst" in {
3086 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
3087 (ins VR128:$src1, VR128:$src2),
3088 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
3090 let mayLoad = 1, hasSideEffects = 0 in
3091 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
3092 (ins VR128:$src1, ssmem:$src2),
3093 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
3098 /// sse1_fp_unop_p - SSE1 unops in packed form.
3099 multiclass sse1_fp_unop_p<bits<8> opc, string OpcodeStr, SDNode OpNode,
3101 let Predicates = [HasAVX] in {
3102 def V#NAME#PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3103 !strconcat(!strconcat("v", OpcodeStr),
3104 "ps\t{$src, $dst|$dst, $src}"),
3105 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))],
3107 def V#NAME#PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3108 !strconcat(!strconcat("v", OpcodeStr),
3109 "ps\t{$src, $dst|$dst, $src}"),
3110 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))],
3112 def V#NAME#PSYr : PSI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3113 !strconcat(!strconcat("v", OpcodeStr),
3114 "ps\t{$src, $dst|$dst, $src}"),
3115 [(set VR256:$dst, (v8f32 (OpNode VR256:$src)))],
3116 itins.rr>, VEX, VEX_L;
3117 def V#NAME#PSYm : PSI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3118 !strconcat(!strconcat("v", OpcodeStr),
3119 "ps\t{$src, $dst|$dst, $src}"),
3120 [(set VR256:$dst, (OpNode (memopv8f32 addr:$src)))],
3121 itins.rm>, VEX, VEX_L;
3124 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3125 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3126 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))], itins.rr>;
3127 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3128 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3129 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))], itins.rm>;
3132 /// sse1_fp_unop_p_int - SSE1 intrinsics unops in packed forms.
3133 multiclass sse1_fp_unop_p_int<bits<8> opc, string OpcodeStr,
3134 Intrinsic V4F32Int, Intrinsic V8F32Int,
3136 let Predicates = [HasAVX] in {
3137 def V#NAME#PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3138 !strconcat(!strconcat("v", OpcodeStr),
3139 "ps\t{$src, $dst|$dst, $src}"),
3140 [(set VR128:$dst, (V4F32Int VR128:$src))],
3142 def V#NAME#PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3143 !strconcat(!strconcat("v", OpcodeStr),
3144 "ps\t{$src, $dst|$dst, $src}"),
3145 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))],
3147 def V#NAME#PSYr_Int : PSI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3148 !strconcat(!strconcat("v", OpcodeStr),
3149 "ps\t{$src, $dst|$dst, $src}"),
3150 [(set VR256:$dst, (V8F32Int VR256:$src))],
3151 itins.rr>, VEX, VEX_L;
3152 def V#NAME#PSYm_Int : PSI<opc, MRMSrcMem, (outs VR256:$dst),
3154 !strconcat(!strconcat("v", OpcodeStr),
3155 "ps\t{$src, $dst|$dst, $src}"),
3156 [(set VR256:$dst, (V8F32Int (memopv8f32 addr:$src)))],
3157 itins.rm>, VEX, VEX_L;
3160 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3161 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3162 [(set VR128:$dst, (V4F32Int VR128:$src))],
3164 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3165 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
3166 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))],
3170 /// sse2_fp_unop_s - SSE2 unops in scalar form.
3171 multiclass sse2_fp_unop_s<bits<8> opc, string OpcodeStr,
3172 SDNode OpNode, Intrinsic F64Int, OpndItins itins> {
3173 let Predicates = [HasAVX], hasSideEffects = 0 in {
3174 def V#NAME#SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst),
3175 (ins FR64:$src1, FR64:$src2),
3176 !strconcat(!strconcat("v", OpcodeStr),
3177 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3178 []>, VEX_4V, VEX_LIG;
3179 let mayLoad = 1 in {
3180 def V#NAME#SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst),
3181 (ins FR64:$src1,f64mem:$src2),
3182 !strconcat(!strconcat("v", OpcodeStr),
3183 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3184 []>, VEX_4V, VEX_LIG;
3185 def V#NAME#SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
3186 (ins VR128:$src1, sdmem:$src2),
3187 !strconcat(!strconcat("v", OpcodeStr),
3188 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3189 []>, VEX_4V, VEX_LIG;
3193 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
3194 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
3195 [(set FR64:$dst, (OpNode FR64:$src))], itins.rr>;
3196 // See the comments in sse1_fp_unop_s for why this is OptForSize.
3197 def SDm : I<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
3198 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
3199 [(set FR64:$dst, (OpNode (load addr:$src)))], itins.rm>, XD,
3200 Requires<[UseSSE2, OptForSize]>;
3201 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3202 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
3203 [(set VR128:$dst, (F64Int VR128:$src))], itins.rr>;
3204 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
3205 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
3206 [(set VR128:$dst, (F64Int sse_load_f64:$src))], itins.rm>;
3209 /// sse2_fp_unop_p - SSE2 unops in vector forms.
3210 multiclass sse2_fp_unop_p<bits<8> opc, string OpcodeStr,
3211 SDNode OpNode, OpndItins itins> {
3212 let Predicates = [HasAVX] in {
3213 def V#NAME#PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3214 !strconcat(!strconcat("v", OpcodeStr),
3215 "pd\t{$src, $dst|$dst, $src}"),
3216 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))],
3218 def V#NAME#PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3219 !strconcat(!strconcat("v", OpcodeStr),
3220 "pd\t{$src, $dst|$dst, $src}"),
3221 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))],
3223 def V#NAME#PDYr : PDI<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3224 !strconcat(!strconcat("v", OpcodeStr),
3225 "pd\t{$src, $dst|$dst, $src}"),
3226 [(set VR256:$dst, (v4f64 (OpNode VR256:$src)))],
3227 itins.rr>, VEX, VEX_L;
3228 def V#NAME#PDYm : PDI<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
3229 !strconcat(!strconcat("v", OpcodeStr),
3230 "pd\t{$src, $dst|$dst, $src}"),
3231 [(set VR256:$dst, (OpNode (memopv4f64 addr:$src)))],
3232 itins.rm>, VEX, VEX_L;
3235 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3236 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3237 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))], itins.rr>;
3238 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
3239 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
3240 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))], itins.rm>;
3244 defm SQRT : sse1_fp_unop_s<0x51, "sqrt", fsqrt, int_x86_sse_sqrt_ss,
3246 sse1_fp_unop_p<0x51, "sqrt", fsqrt, SSE_SQRTP>,
3247 sse2_fp_unop_s<0x51, "sqrt", fsqrt, int_x86_sse2_sqrt_sd,
3249 sse2_fp_unop_p<0x51, "sqrt", fsqrt, SSE_SQRTP>;
3251 // Reciprocal approximations. Note that these typically require refinement
3252 // in order to obtain suitable precision.
3253 defm RSQRT : sse1_fp_unop_rw<0x52, "rsqrt", X86frsqrt, SSE_SQRTS>,
3254 sse1_fp_unop_p<0x52, "rsqrt", X86frsqrt, SSE_SQRTP>,
3255 sse1_fp_unop_p_int<0x52, "rsqrt", int_x86_sse_rsqrt_ps,
3256 int_x86_avx_rsqrt_ps_256, SSE_SQRTP>;
3257 defm RCP : sse1_fp_unop_rw<0x53, "rcp", X86frcp, SSE_RCPS>,
3258 sse1_fp_unop_p<0x53, "rcp", X86frcp, SSE_RCPP>,
3259 sse1_fp_unop_p_int<0x53, "rcp", int_x86_sse_rcp_ps,
3260 int_x86_avx_rcp_ps_256, SSE_RCPP>;
3262 def : Pat<(f32 (fsqrt FR32:$src)),
3263 (VSQRTSSr (f32 (IMPLICIT_DEF)), FR32:$src)>, Requires<[HasAVX]>;
3264 def : Pat<(f32 (fsqrt (load addr:$src))),
3265 (VSQRTSSm (f32 (IMPLICIT_DEF)), addr:$src)>,
3266 Requires<[HasAVX, OptForSize]>;
3267 def : Pat<(f64 (fsqrt FR64:$src)),
3268 (VSQRTSDr (f64 (IMPLICIT_DEF)), FR64:$src)>, Requires<[HasAVX]>;
3269 def : Pat<(f64 (fsqrt (load addr:$src))),
3270 (VSQRTSDm (f64 (IMPLICIT_DEF)), addr:$src)>,
3271 Requires<[HasAVX, OptForSize]>;
3273 def : Pat<(f32 (X86frsqrt FR32:$src)),
3274 (VRSQRTSSr (f32 (IMPLICIT_DEF)), FR32:$src)>, Requires<[HasAVX]>;
3275 def : Pat<(f32 (X86frsqrt (load addr:$src))),
3276 (VRSQRTSSm (f32 (IMPLICIT_DEF)), addr:$src)>,
3277 Requires<[HasAVX, OptForSize]>;
3279 def : Pat<(f32 (X86frcp FR32:$src)),
3280 (VRCPSSr (f32 (IMPLICIT_DEF)), FR32:$src)>, Requires<[HasAVX]>;
3281 def : Pat<(f32 (X86frcp (load addr:$src))),
3282 (VRCPSSm (f32 (IMPLICIT_DEF)), addr:$src)>,
3283 Requires<[HasAVX, OptForSize]>;
3285 let Predicates = [HasAVX] in {
3286 def : Pat<(int_x86_sse_sqrt_ss VR128:$src),
3287 (COPY_TO_REGCLASS (VSQRTSSr (f32 (IMPLICIT_DEF)),
3288 (COPY_TO_REGCLASS VR128:$src, FR32)),
3290 def : Pat<(int_x86_sse_sqrt_ss sse_load_f32:$src),
3291 (VSQRTSSm_Int (v4f32 (IMPLICIT_DEF)), sse_load_f32:$src)>;
3293 def : Pat<(int_x86_sse2_sqrt_sd VR128:$src),
3294 (COPY_TO_REGCLASS (VSQRTSDr (f64 (IMPLICIT_DEF)),
3295 (COPY_TO_REGCLASS VR128:$src, FR64)),
3297 def : Pat<(int_x86_sse2_sqrt_sd sse_load_f64:$src),
3298 (VSQRTSDm_Int (v2f64 (IMPLICIT_DEF)), sse_load_f64:$src)>;
3300 def : Pat<(int_x86_sse_rsqrt_ss VR128:$src),
3301 (COPY_TO_REGCLASS (VRSQRTSSr (f32 (IMPLICIT_DEF)),
3302 (COPY_TO_REGCLASS VR128:$src, FR32)),
3304 def : Pat<(int_x86_sse_rsqrt_ss sse_load_f32:$src),
3305 (VRSQRTSSm_Int (v4f32 (IMPLICIT_DEF)), sse_load_f32:$src)>;
3307 def : Pat<(int_x86_sse_rcp_ss VR128:$src),
3308 (COPY_TO_REGCLASS (VRCPSSr (f32 (IMPLICIT_DEF)),
3309 (COPY_TO_REGCLASS VR128:$src, FR32)),
3311 def : Pat<(int_x86_sse_rcp_ss sse_load_f32:$src),
3312 (VRCPSSm_Int (v4f32 (IMPLICIT_DEF)), sse_load_f32:$src)>;
3315 // Reciprocal approximations. Note that these typically require refinement
3316 // in order to obtain suitable precision.
3317 let Predicates = [UseSSE1] in {
3318 def : Pat<(int_x86_sse_rsqrt_ss VR128:$src),
3319 (RSQRTSSr_Int VR128:$src, VR128:$src)>;
3320 def : Pat<(int_x86_sse_rcp_ss VR128:$src),
3321 (RCPSSr_Int VR128:$src, VR128:$src)>;
3324 // There is no f64 version of the reciprocal approximation instructions.
3326 //===----------------------------------------------------------------------===//
3327 // SSE 1 & 2 - Non-temporal stores
3328 //===----------------------------------------------------------------------===//
3330 let AddedComplexity = 400 in { // Prefer non-temporal versions
3331 def VMOVNTPSmr : VPSI<0x2B, MRMDestMem, (outs),
3332 (ins f128mem:$dst, VR128:$src),
3333 "movntps\t{$src, $dst|$dst, $src}",
3334 [(alignednontemporalstore (v4f32 VR128:$src),
3336 IIC_SSE_MOVNT>, VEX;
3337 def VMOVNTPDmr : VPDI<0x2B, MRMDestMem, (outs),
3338 (ins f128mem:$dst, VR128:$src),
3339 "movntpd\t{$src, $dst|$dst, $src}",
3340 [(alignednontemporalstore (v2f64 VR128:$src),
3342 IIC_SSE_MOVNT>, VEX;
3344 let ExeDomain = SSEPackedInt in
3345 def VMOVNTDQmr : VPDI<0xE7, MRMDestMem, (outs),
3346 (ins f128mem:$dst, VR128:$src),
3347 "movntdq\t{$src, $dst|$dst, $src}",
3348 [(alignednontemporalstore (v2i64 VR128:$src),
3350 IIC_SSE_MOVNT>, VEX;
3352 def : Pat<(alignednontemporalstore (v2i64 VR128:$src), addr:$dst),
3353 (VMOVNTDQmr addr:$dst, VR128:$src)>, Requires<[HasAVX]>;
3355 def VMOVNTPSYmr : VPSI<0x2B, MRMDestMem, (outs),
3356 (ins f256mem:$dst, VR256:$src),
3357 "movntps\t{$src, $dst|$dst, $src}",
3358 [(alignednontemporalstore (v8f32 VR256:$src),
3360 IIC_SSE_MOVNT>, VEX, VEX_L;
3361 def VMOVNTPDYmr : VPDI<0x2B, MRMDestMem, (outs),
3362 (ins f256mem:$dst, VR256:$src),
3363 "movntpd\t{$src, $dst|$dst, $src}",
3364 [(alignednontemporalstore (v4f64 VR256:$src),
3366 IIC_SSE_MOVNT>, VEX, VEX_L;
3367 let ExeDomain = SSEPackedInt in
3368 def VMOVNTDQYmr : VPDI<0xE7, MRMDestMem, (outs),
3369 (ins f256mem:$dst, VR256:$src),
3370 "movntdq\t{$src, $dst|$dst, $src}",
3371 [(alignednontemporalstore (v4i64 VR256:$src),
3373 IIC_SSE_MOVNT>, VEX, VEX_L;
3376 let AddedComplexity = 400 in { // Prefer non-temporal versions
3377 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
3378 "movntps\t{$src, $dst|$dst, $src}",
3379 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)],
3381 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
3382 "movntpd\t{$src, $dst|$dst, $src}",
3383 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)],
3386 let ExeDomain = SSEPackedInt in
3387 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
3388 "movntdq\t{$src, $dst|$dst, $src}",
3389 [(alignednontemporalstore (v2i64 VR128:$src), addr:$dst)],
3392 def : Pat<(alignednontemporalstore (v2i64 VR128:$src), addr:$dst),
3393 (MOVNTDQmr addr:$dst, VR128:$src)>, Requires<[UseSSE2]>;
3395 // There is no AVX form for instructions below this point
3396 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
3397 "movnti{l}\t{$src, $dst|$dst, $src}",
3398 [(nontemporalstore (i32 GR32:$src), addr:$dst)],
3400 TB, Requires<[HasSSE2]>;
3401 def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
3402 "movnti{q}\t{$src, $dst|$dst, $src}",
3403 [(nontemporalstore (i64 GR64:$src), addr:$dst)],
3405 TB, Requires<[HasSSE2]>;
3408 //===----------------------------------------------------------------------===//
3409 // SSE 1 & 2 - Prefetch and memory fence
3410 //===----------------------------------------------------------------------===//
3412 // Prefetch intrinsic.
3413 let Predicates = [HasSSE1] in {
3414 def PREFETCHT0 : I<0x18, MRM1m, (outs), (ins i8mem:$src),
3415 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3), (i32 1))],
3416 IIC_SSE_PREFETCH>, TB;
3417 def PREFETCHT1 : I<0x18, MRM2m, (outs), (ins i8mem:$src),
3418 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2), (i32 1))],
3419 IIC_SSE_PREFETCH>, TB;
3420 def PREFETCHT2 : I<0x18, MRM3m, (outs), (ins i8mem:$src),
3421 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1), (i32 1))],
3422 IIC_SSE_PREFETCH>, TB;
3423 def PREFETCHNTA : I<0x18, MRM0m, (outs), (ins i8mem:$src),
3424 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0), (i32 1))],
3425 IIC_SSE_PREFETCH>, TB;
3429 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
3430 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)],
3431 IIC_SSE_PREFETCH>, TB, Requires<[HasSSE2]>;
3433 // Pause. This "instruction" is encoded as "rep; nop", so even though it
3434 // was introduced with SSE2, it's backward compatible.
3435 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", [], IIC_SSE_PAUSE>, REP;
3437 // Load, store, and memory fence
3438 def SFENCE : I<0xAE, MRM_F8, (outs), (ins),
3439 "sfence", [(int_x86_sse_sfence)], IIC_SSE_SFENCE>,
3440 TB, Requires<[HasSSE1]>;
3441 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
3442 "lfence", [(int_x86_sse2_lfence)], IIC_SSE_LFENCE>,
3443 TB, Requires<[HasSSE2]>;
3444 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
3445 "mfence", [(int_x86_sse2_mfence)], IIC_SSE_MFENCE>,
3446 TB, Requires<[HasSSE2]>;
3448 def : Pat<(X86SFence), (SFENCE)>;
3449 def : Pat<(X86LFence), (LFENCE)>;
3450 def : Pat<(X86MFence), (MFENCE)>;
3452 //===----------------------------------------------------------------------===//
3453 // SSE 1 & 2 - Load/Store XCSR register
3454 //===----------------------------------------------------------------------===//
3456 def VLDMXCSR : VPSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
3457 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)],
3458 IIC_SSE_LDMXCSR>, VEX;
3459 def VSTMXCSR : VPSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
3460 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)],
3461 IIC_SSE_STMXCSR>, VEX;
3463 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
3464 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)],
3466 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
3467 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)],
3470 //===---------------------------------------------------------------------===//
3471 // SSE2 - Move Aligned/Unaligned Packed Integer Instructions
3472 //===---------------------------------------------------------------------===//
3474 let ExeDomain = SSEPackedInt in { // SSE integer instructions
3476 let neverHasSideEffects = 1 in {
3477 def VMOVDQArr : VPDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3478 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RR>,
3480 def VMOVDQAYrr : VPDI<0x6F, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3481 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RR>,
3483 def VMOVDQUrr : VSSI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3484 "movdqu\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVU_P_RR>,
3486 def VMOVDQUYrr : VSSI<0x6F, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
3487 "movdqu\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVU_P_RR>,
3492 let isCodeGenOnly = 1, hasSideEffects = 0 in {
3493 def VMOVDQArr_REV : VPDI<0x7F, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
3494 "movdqa\t{$src, $dst|$dst, $src}", [],
3497 def VMOVDQAYrr_REV : VPDI<0x7F, MRMDestReg, (outs VR256:$dst), (ins VR256:$src),
3498 "movdqa\t{$src, $dst|$dst, $src}", [],
3499 IIC_SSE_MOVA_P_RR>, VEX, VEX_L;
3500 def VMOVDQUrr_REV : VSSI<0x7F, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
3501 "movdqu\t{$src, $dst|$dst, $src}", [],
3504 def VMOVDQUYrr_REV : VSSI<0x7F, MRMDestReg, (outs VR256:$dst), (ins VR256:$src),
3505 "movdqu\t{$src, $dst|$dst, $src}", [],
3506 IIC_SSE_MOVU_P_RR>, VEX, VEX_L;
3509 let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1,
3510 neverHasSideEffects = 1 in {
3511 def VMOVDQArm : VPDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3512 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RM>,
3514 def VMOVDQAYrm : VPDI<0x6F, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
3515 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RM>,
3517 let Predicates = [HasAVX] in {
3518 def VMOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3519 "vmovdqu\t{$src, $dst|$dst, $src}",[], IIC_SSE_MOVU_P_RM>,
3521 def VMOVDQUYrm : I<0x6F, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
3522 "vmovdqu\t{$src, $dst|$dst, $src}",[], IIC_SSE_MOVU_P_RM>,
3527 let mayStore = 1, neverHasSideEffects = 1 in {
3528 def VMOVDQAmr : VPDI<0x7F, MRMDestMem, (outs),
3529 (ins i128mem:$dst, VR128:$src),
3530 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_MR>,
3532 def VMOVDQAYmr : VPDI<0x7F, MRMDestMem, (outs),
3533 (ins i256mem:$dst, VR256:$src),
3534 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_MR>,
3536 let Predicates = [HasAVX] in {
3537 def VMOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
3538 "vmovdqu\t{$src, $dst|$dst, $src}",[], IIC_SSE_MOVU_P_MR>,
3540 def VMOVDQUYmr : I<0x7F, MRMDestMem, (outs), (ins i256mem:$dst, VR256:$src),
3541 "vmovdqu\t{$src, $dst|$dst, $src}",[], IIC_SSE_MOVU_P_MR>,
3546 let neverHasSideEffects = 1 in
3547 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3548 "movdqa\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVA_P_RR>;
3550 def MOVDQUrr : I<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3551 "movdqu\t{$src, $dst|$dst, $src}",
3552 [], IIC_SSE_MOVU_P_RR>, XS, Requires<[UseSSE2]>;
3555 let isCodeGenOnly = 1, hasSideEffects = 0 in {
3556 def MOVDQArr_REV : PDI<0x7F, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
3557 "movdqa\t{$src, $dst|$dst, $src}", [],
3560 def MOVDQUrr_REV : I<0x7F, MRMDestReg, (outs VR128:$dst), (ins VR128:$src),
3561 "movdqu\t{$src, $dst|$dst, $src}",
3562 [], IIC_SSE_MOVU_P_RR>, XS, Requires<[UseSSE2]>;
3565 let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1,
3566 neverHasSideEffects = 1 in {
3567 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3568 "movdqa\t{$src, $dst|$dst, $src}",
3569 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/],
3571 def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3572 "movdqu\t{$src, $dst|$dst, $src}",
3573 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/],
3575 XS, Requires<[UseSSE2]>;
3578 let mayStore = 1 in {
3579 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
3580 "movdqa\t{$src, $dst|$dst, $src}",
3581 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/],
3583 def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
3584 "movdqu\t{$src, $dst|$dst, $src}",
3585 [/*(store (v2i64 VR128:$src), addr:$dst)*/],
3587 XS, Requires<[UseSSE2]>;
3590 } // ExeDomain = SSEPackedInt
3592 let Predicates = [HasAVX] in {
3593 def : Pat<(int_x86_sse2_storeu_dq addr:$dst, VR128:$src),
3594 (VMOVDQUmr addr:$dst, VR128:$src)>;
3595 def : Pat<(int_x86_avx_storeu_dq_256 addr:$dst, VR256:$src),
3596 (VMOVDQUYmr addr:$dst, VR256:$src)>;
3598 let Predicates = [UseSSE2] in
3599 def : Pat<(int_x86_sse2_storeu_dq addr:$dst, VR128:$src),
3600 (MOVDQUmr addr:$dst, VR128:$src)>;
3602 //===---------------------------------------------------------------------===//
3603 // SSE2 - Packed Integer Arithmetic Instructions
3604 //===---------------------------------------------------------------------===//
3606 def SSE_PMADD : OpndItins<
3607 IIC_SSE_PMADD, IIC_SSE_PMADD
3610 let ExeDomain = SSEPackedInt in { // SSE integer instructions
3612 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
3613 RegisterClass RC, PatFrag memop_frag,
3614 X86MemOperand x86memop,
3616 bit IsCommutable = 0,
3618 let isCommutable = IsCommutable in
3619 def rr : PDI<opc, MRMSrcReg, (outs RC:$dst),
3620 (ins RC:$src1, RC:$src2),
3622 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3623 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3624 [(set RC:$dst, (IntId RC:$src1, RC:$src2))], itins.rr>;
3625 def rm : PDI<opc, MRMSrcMem, (outs RC:$dst),
3626 (ins RC:$src1, x86memop:$src2),
3628 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3629 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3630 [(set RC:$dst, (IntId RC:$src1, (bitconvert (memop_frag addr:$src2))))],
3634 multiclass PDI_binop_all_int<bits<8> opc, string OpcodeStr, Intrinsic IntId128,
3635 Intrinsic IntId256, OpndItins itins,
3636 bit IsCommutable = 0> {
3637 let Predicates = [HasAVX] in
3638 defm V#NAME# : PDI_binop_rm_int<opc, !strconcat("v", OpcodeStr), IntId128,
3639 VR128, memopv2i64, i128mem, itins,
3640 IsCommutable, 0>, VEX_4V;
3642 let Constraints = "$src1 = $dst" in
3643 defm #NAME# : PDI_binop_rm_int<opc, OpcodeStr, IntId128, VR128, memopv2i64,
3644 i128mem, itins, IsCommutable, 1>;
3646 let Predicates = [HasAVX2] in
3647 defm V#NAME#Y : PDI_binop_rm_int<opc, !strconcat("v", OpcodeStr), IntId256,
3648 VR256, memopv4i64, i256mem, itins,
3649 IsCommutable, 0>, VEX_4V, VEX_L;
3652 multiclass PDI_binop_rmi<bits<8> opc, bits<8> opc2, Format ImmForm,
3653 string OpcodeStr, SDNode OpNode,
3654 SDNode OpNode2, RegisterClass RC,
3655 ValueType DstVT, ValueType SrcVT, PatFrag bc_frag,
3656 ShiftOpndItins itins,
3658 // src2 is always 128-bit
3659 def rr : PDI<opc, MRMSrcReg, (outs RC:$dst),
3660 (ins RC:$src1, VR128:$src2),
3662 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3663 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3664 [(set RC:$dst, (DstVT (OpNode RC:$src1, (SrcVT VR128:$src2))))],
3666 def rm : PDI<opc, MRMSrcMem, (outs RC:$dst),
3667 (ins RC:$src1, i128mem:$src2),
3669 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3670 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3671 [(set RC:$dst, (DstVT (OpNode RC:$src1,
3672 (bc_frag (memopv2i64 addr:$src2)))))], itins.rm>;
3673 def ri : PDIi8<opc2, ImmForm, (outs RC:$dst),
3674 (ins RC:$src1, i32i8imm:$src2),
3676 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3677 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3678 [(set RC:$dst, (DstVT (OpNode2 RC:$src1, (i32 imm:$src2))))], itins.ri>;
3681 /// PDI_binop_rm2 - Simple SSE2 binary operator with different src and dst types
3682 multiclass PDI_binop_rm2<bits<8> opc, string OpcodeStr, SDNode OpNode,
3683 ValueType DstVT, ValueType SrcVT, RegisterClass RC,
3684 PatFrag memop_frag, X86MemOperand x86memop,
3686 bit IsCommutable = 0, bit Is2Addr = 1> {
3687 let isCommutable = IsCommutable in
3688 def rr : PDI<opc, MRMSrcReg, (outs RC:$dst),
3689 (ins RC:$src1, RC:$src2),
3691 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3692 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3693 [(set RC:$dst, (DstVT (OpNode (SrcVT RC:$src1), RC:$src2)))]>;
3694 def rm : PDI<opc, MRMSrcMem, (outs RC:$dst),
3695 (ins RC:$src1, x86memop:$src2),
3697 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3698 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
3699 [(set RC:$dst, (DstVT (OpNode (SrcVT RC:$src1),
3700 (bitconvert (memop_frag addr:$src2)))))]>;
3702 } // ExeDomain = SSEPackedInt
3704 defm PADDB : PDI_binop_all<0xFC, "paddb", add, v16i8, v32i8,
3705 SSE_INTALU_ITINS_P, 1>;
3706 defm PADDW : PDI_binop_all<0xFD, "paddw", add, v8i16, v16i16,
3707 SSE_INTALU_ITINS_P, 1>;
3708 defm PADDD : PDI_binop_all<0xFE, "paddd", add, v4i32, v8i32,
3709 SSE_INTALU_ITINS_P, 1>;
3710 defm PADDQ : PDI_binop_all<0xD4, "paddq", add, v2i64, v4i64,
3711 SSE_INTALUQ_ITINS_P, 1>;
3712 defm PMULLW : PDI_binop_all<0xD5, "pmullw", mul, v8i16, v16i16,
3713 SSE_INTMUL_ITINS_P, 1>;
3714 defm PSUBB : PDI_binop_all<0xF8, "psubb", sub, v16i8, v32i8,
3715 SSE_INTALU_ITINS_P, 0>;
3716 defm PSUBW : PDI_binop_all<0xF9, "psubw", sub, v8i16, v16i16,
3717 SSE_INTALU_ITINS_P, 0>;
3718 defm PSUBD : PDI_binop_all<0xFA, "psubd", sub, v4i32, v8i32,
3719 SSE_INTALU_ITINS_P, 0>;
3720 defm PSUBQ : PDI_binop_all<0xFB, "psubq", sub, v2i64, v4i64,
3721 SSE_INTALUQ_ITINS_P, 0>;
3722 defm PSUBUSB : PDI_binop_all<0xD8, "psubusb", X86subus, v16i8, v32i8,
3723 SSE_INTALU_ITINS_P, 0>;
3724 defm PSUBUSW : PDI_binop_all<0xD9, "psubusw", X86subus, v8i16, v16i16,
3725 SSE_INTALU_ITINS_P, 0>;
3726 defm PMINUB : PDI_binop_all<0xDA, "pminub", X86umin, v16i8, v32i8,
3727 SSE_INTALU_ITINS_P, 1>;
3728 defm PMINSW : PDI_binop_all<0xEA, "pminsw", X86smin, v8i16, v16i16,
3729 SSE_INTALU_ITINS_P, 1>;
3730 defm PMAXUB : PDI_binop_all<0xDE, "pmaxub", X86umax, v16i8, v32i8,
3731 SSE_INTALU_ITINS_P, 1>;
3732 defm PMAXSW : PDI_binop_all<0xEE, "pmaxsw", X86smax, v8i16, v16i16,
3733 SSE_INTALU_ITINS_P, 1>;
3736 defm PSUBSB : PDI_binop_all_int<0xE8, "psubsb", int_x86_sse2_psubs_b,
3737 int_x86_avx2_psubs_b, SSE_INTALU_ITINS_P, 0>;
3738 defm PSUBSW : PDI_binop_all_int<0xE9, "psubsw" , int_x86_sse2_psubs_w,
3739 int_x86_avx2_psubs_w, SSE_INTALU_ITINS_P, 0>;
3740 defm PADDSB : PDI_binop_all_int<0xEC, "paddsb" , int_x86_sse2_padds_b,
3741 int_x86_avx2_padds_b, SSE_INTALU_ITINS_P, 1>;
3742 defm PADDSW : PDI_binop_all_int<0xED, "paddsw" , int_x86_sse2_padds_w,
3743 int_x86_avx2_padds_w, SSE_INTALU_ITINS_P, 1>;
3744 defm PADDUSB : PDI_binop_all_int<0xDC, "paddusb", int_x86_sse2_paddus_b,
3745 int_x86_avx2_paddus_b, SSE_INTALU_ITINS_P, 1>;
3746 defm PADDUSW : PDI_binop_all_int<0xDD, "paddusw", int_x86_sse2_paddus_w,
3747 int_x86_avx2_paddus_w, SSE_INTALU_ITINS_P, 1>;
3748 defm PMULHUW : PDI_binop_all_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w,
3749 int_x86_avx2_pmulhu_w, SSE_INTMUL_ITINS_P, 1>;
3750 defm PMULHW : PDI_binop_all_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w,
3751 int_x86_avx2_pmulh_w, SSE_INTMUL_ITINS_P, 1>;
3752 defm PMADDWD : PDI_binop_all_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd,
3753 int_x86_avx2_pmadd_wd, SSE_PMADD, 1>;
3754 defm PAVGB : PDI_binop_all_int<0xE0, "pavgb", int_x86_sse2_pavg_b,
3755 int_x86_avx2_pavg_b, SSE_INTALU_ITINS_P, 1>;
3756 defm PAVGW : PDI_binop_all_int<0xE3, "pavgw", int_x86_sse2_pavg_w,
3757 int_x86_avx2_pavg_w, SSE_INTALU_ITINS_P, 1>;
3758 defm PSADBW : PDI_binop_all_int<0xF6, "psadbw", int_x86_sse2_psad_bw,
3759 int_x86_avx2_psad_bw, SSE_INTALU_ITINS_P, 1>;
3761 let Predicates = [HasAVX] in
3762 defm VPMULUDQ : PDI_binop_rm2<0xF4, "vpmuludq", X86pmuludq, v2i64, v4i32, VR128,
3763 memopv2i64, i128mem, SSE_INTMUL_ITINS_P, 1, 0>,
3765 let Predicates = [HasAVX2] in
3766 defm VPMULUDQY : PDI_binop_rm2<0xF4, "vpmuludq", X86pmuludq, v4i64, v8i32,
3767 VR256, memopv4i64, i256mem,
3768 SSE_INTMUL_ITINS_P, 1, 0>, VEX_4V, VEX_L;
3769 let Constraints = "$src1 = $dst" in
3770 defm PMULUDQ : PDI_binop_rm2<0xF4, "pmuludq", X86pmuludq, v2i64, v4i32, VR128,
3771 memopv2i64, i128mem, SSE_INTMUL_ITINS_P, 1>;
3773 //===---------------------------------------------------------------------===//
3774 // SSE2 - Packed Integer Logical Instructions
3775 //===---------------------------------------------------------------------===//
3777 let Predicates = [HasAVX] in {
3778 defm VPSLLW : PDI_binop_rmi<0xF1, 0x71, MRM6r, "vpsllw", X86vshl, X86vshli,
3779 VR128, v8i16, v8i16, bc_v8i16,
3780 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3781 defm VPSLLD : PDI_binop_rmi<0xF2, 0x72, MRM6r, "vpslld", X86vshl, X86vshli,
3782 VR128, v4i32, v4i32, bc_v4i32,
3783 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3784 defm VPSLLQ : PDI_binop_rmi<0xF3, 0x73, MRM6r, "vpsllq", X86vshl, X86vshli,
3785 VR128, v2i64, v2i64, bc_v2i64,
3786 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3788 defm VPSRLW : PDI_binop_rmi<0xD1, 0x71, MRM2r, "vpsrlw", X86vsrl, X86vsrli,
3789 VR128, v8i16, v8i16, bc_v8i16,
3790 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3791 defm VPSRLD : PDI_binop_rmi<0xD2, 0x72, MRM2r, "vpsrld", X86vsrl, X86vsrli,
3792 VR128, v4i32, v4i32, bc_v4i32,
3793 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3794 defm VPSRLQ : PDI_binop_rmi<0xD3, 0x73, MRM2r, "vpsrlq", X86vsrl, X86vsrli,
3795 VR128, v2i64, v2i64, bc_v2i64,
3796 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3798 defm VPSRAW : PDI_binop_rmi<0xE1, 0x71, MRM4r, "vpsraw", X86vsra, X86vsrai,
3799 VR128, v8i16, v8i16, bc_v8i16,
3800 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3801 defm VPSRAD : PDI_binop_rmi<0xE2, 0x72, MRM4r, "vpsrad", X86vsra, X86vsrai,
3802 VR128, v4i32, v4i32, bc_v4i32,
3803 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V;
3805 let ExeDomain = SSEPackedInt in {
3806 // 128-bit logical shifts.
3807 def VPSLLDQri : PDIi8<0x73, MRM7r,
3808 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3809 "vpslldq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3811 (int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2))]>,
3813 def VPSRLDQri : PDIi8<0x73, MRM3r,
3814 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3815 "vpsrldq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3817 (int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2))]>,
3819 // PSRADQri doesn't exist in SSE[1-3].
3821 } // Predicates = [HasAVX]
3823 let Predicates = [HasAVX2] in {
3824 defm VPSLLWY : PDI_binop_rmi<0xF1, 0x71, MRM6r, "vpsllw", X86vshl, X86vshli,
3825 VR256, v16i16, v8i16, bc_v8i16,
3826 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V, VEX_L;
3827 defm VPSLLDY : PDI_binop_rmi<0xF2, 0x72, MRM6r, "vpslld", X86vshl, X86vshli,
3828 VR256, v8i32, v4i32, bc_v4i32,
3829 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V, VEX_L;
3830 defm VPSLLQY : PDI_binop_rmi<0xF3, 0x73, MRM6r, "vpsllq", X86vshl, X86vshli,
3831 VR256, v4i64, v2i64, bc_v2i64,
3832 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V, VEX_L;
3834 defm VPSRLWY : PDI_binop_rmi<0xD1, 0x71, MRM2r, "vpsrlw", X86vsrl, X86vsrli,
3835 VR256, v16i16, v8i16, bc_v8i16,
3836 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V, VEX_L;
3837 defm VPSRLDY : PDI_binop_rmi<0xD2, 0x72, MRM2r, "vpsrld", X86vsrl, X86vsrli,
3838 VR256, v8i32, v4i32, bc_v4i32,
3839 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V, VEX_L;
3840 defm VPSRLQY : PDI_binop_rmi<0xD3, 0x73, MRM2r, "vpsrlq", X86vsrl, X86vsrli,
3841 VR256, v4i64, v2i64, bc_v2i64,
3842 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V, VEX_L;
3844 defm VPSRAWY : PDI_binop_rmi<0xE1, 0x71, MRM4r, "vpsraw", X86vsra, X86vsrai,
3845 VR256, v16i16, v8i16, bc_v8i16,
3846 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V, VEX_L;
3847 defm VPSRADY : PDI_binop_rmi<0xE2, 0x72, MRM4r, "vpsrad", X86vsra, X86vsrai,
3848 VR256, v8i32, v4i32, bc_v4i32,
3849 SSE_INTSHIFT_ITINS_P, 0>, VEX_4V, VEX_L;
3851 let ExeDomain = SSEPackedInt in {
3852 // 256-bit logical shifts.
3853 def VPSLLDQYri : PDIi8<0x73, MRM7r,
3854 (outs VR256:$dst), (ins VR256:$src1, i32i8imm:$src2),
3855 "vpslldq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3857 (int_x86_avx2_psll_dq_bs VR256:$src1, imm:$src2))]>,
3859 def VPSRLDQYri : PDIi8<0x73, MRM3r,
3860 (outs VR256:$dst), (ins VR256:$src1, i32i8imm:$src2),
3861 "vpsrldq\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3863 (int_x86_avx2_psrl_dq_bs VR256:$src1, imm:$src2))]>,
3865 // PSRADQYri doesn't exist in SSE[1-3].
3867 } // Predicates = [HasAVX2]
3869 let Constraints = "$src1 = $dst" in {
3870 defm PSLLW : PDI_binop_rmi<0xF1, 0x71, MRM6r, "psllw", X86vshl, X86vshli,
3871 VR128, v8i16, v8i16, bc_v8i16,
3872 SSE_INTSHIFT_ITINS_P>;
3873 defm PSLLD : PDI_binop_rmi<0xF2, 0x72, MRM6r, "pslld", X86vshl, X86vshli,
3874 VR128, v4i32, v4i32, bc_v4i32,
3875 SSE_INTSHIFT_ITINS_P>;
3876 defm PSLLQ : PDI_binop_rmi<0xF3, 0x73, MRM6r, "psllq", X86vshl, X86vshli,
3877 VR128, v2i64, v2i64, bc_v2i64,
3878 SSE_INTSHIFT_ITINS_P>;
3880 defm PSRLW : PDI_binop_rmi<0xD1, 0x71, MRM2r, "psrlw", X86vsrl, X86vsrli,
3881 VR128, v8i16, v8i16, bc_v8i16,
3882 SSE_INTSHIFT_ITINS_P>;
3883 defm PSRLD : PDI_binop_rmi<0xD2, 0x72, MRM2r, "psrld", X86vsrl, X86vsrli,
3884 VR128, v4i32, v4i32, bc_v4i32,
3885 SSE_INTSHIFT_ITINS_P>;
3886 defm PSRLQ : PDI_binop_rmi<0xD3, 0x73, MRM2r, "psrlq", X86vsrl, X86vsrli,
3887 VR128, v2i64, v2i64, bc_v2i64,
3888 SSE_INTSHIFT_ITINS_P>;
3890 defm PSRAW : PDI_binop_rmi<0xE1, 0x71, MRM4r, "psraw", X86vsra, X86vsrai,
3891 VR128, v8i16, v8i16, bc_v8i16,
3892 SSE_INTSHIFT_ITINS_P>;
3893 defm PSRAD : PDI_binop_rmi<0xE2, 0x72, MRM4r, "psrad", X86vsra, X86vsrai,
3894 VR128, v4i32, v4i32, bc_v4i32,
3895 SSE_INTSHIFT_ITINS_P>;
3897 let ExeDomain = SSEPackedInt in {
3898 // 128-bit logical shifts.
3899 def PSLLDQri : PDIi8<0x73, MRM7r,
3900 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3901 "pslldq\t{$src2, $dst|$dst, $src2}",
3903 (int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2))]>;
3904 def PSRLDQri : PDIi8<0x73, MRM3r,
3905 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3906 "psrldq\t{$src2, $dst|$dst, $src2}",
3908 (int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2))]>;
3909 // PSRADQri doesn't exist in SSE[1-3].
3911 } // Constraints = "$src1 = $dst"
3913 let Predicates = [HasAVX] in {
3914 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
3915 (VPSLLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
3916 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
3917 (VPSRLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
3918 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
3919 (VPSRLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
3921 // Shift up / down and insert zero's.
3922 def : Pat<(v2i64 (X86vshldq VR128:$src, (i8 imm:$amt))),
3923 (VPSLLDQri VR128:$src, (BYTE_imm imm:$amt))>;
3924 def : Pat<(v2i64 (X86vshrdq VR128:$src, (i8 imm:$amt))),
3925 (VPSRLDQri VR128:$src, (BYTE_imm imm:$amt))>;
3928 let Predicates = [HasAVX2] in {
3929 def : Pat<(int_x86_avx2_psll_dq VR256:$src1, imm:$src2),
3930 (VPSLLDQYri VR256:$src1, (BYTE_imm imm:$src2))>;
3931 def : Pat<(int_x86_avx2_psrl_dq VR256:$src1, imm:$src2),
3932 (VPSRLDQYri VR256:$src1, (BYTE_imm imm:$src2))>;
3935 let Predicates = [UseSSE2] in {
3936 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
3937 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
3938 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
3939 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
3940 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
3941 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2))>;
3943 // Shift up / down and insert zero's.
3944 def : Pat<(v2i64 (X86vshldq VR128:$src, (i8 imm:$amt))),
3945 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt))>;
3946 def : Pat<(v2i64 (X86vshrdq VR128:$src, (i8 imm:$amt))),
3947 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt))>;
3950 //===---------------------------------------------------------------------===//
3951 // SSE2 - Packed Integer Comparison Instructions
3952 //===---------------------------------------------------------------------===//
3954 defm PCMPEQB : PDI_binop_all<0x74, "pcmpeqb", X86pcmpeq, v16i8, v32i8,
3955 SSE_INTALU_ITINS_P, 1>;
3956 defm PCMPEQW : PDI_binop_all<0x75, "pcmpeqw", X86pcmpeq, v8i16, v16i16,
3957 SSE_INTALU_ITINS_P, 1>;
3958 defm PCMPEQD : PDI_binop_all<0x76, "pcmpeqd", X86pcmpeq, v4i32, v8i32,
3959 SSE_INTALU_ITINS_P, 1>;
3960 defm PCMPGTB : PDI_binop_all<0x64, "pcmpgtb", X86pcmpgt, v16i8, v32i8,
3961 SSE_INTALU_ITINS_P, 0>;
3962 defm PCMPGTW : PDI_binop_all<0x65, "pcmpgtw", X86pcmpgt, v8i16, v16i16,
3963 SSE_INTALU_ITINS_P, 0>;
3964 defm PCMPGTD : PDI_binop_all<0x66, "pcmpgtd", X86pcmpgt, v4i32, v8i32,
3965 SSE_INTALU_ITINS_P, 0>;
3967 //===---------------------------------------------------------------------===//
3968 // SSE2 - Packed Integer Pack Instructions
3969 //===---------------------------------------------------------------------===//
3971 defm PACKSSWB : PDI_binop_all_int<0x63, "packsswb", int_x86_sse2_packsswb_128,
3972 int_x86_avx2_packsswb, SSE_INTALU_ITINS_P, 0>;
3973 defm PACKSSDW : PDI_binop_all_int<0x6B, "packssdw", int_x86_sse2_packssdw_128,
3974 int_x86_avx2_packssdw, SSE_INTALU_ITINS_P, 0>;
3975 defm PACKUSWB : PDI_binop_all_int<0x67, "packuswb", int_x86_sse2_packuswb_128,
3976 int_x86_avx2_packuswb, SSE_INTALU_ITINS_P, 0>;
3978 //===---------------------------------------------------------------------===//
3979 // SSE2 - Packed Integer Shuffle Instructions
3980 //===---------------------------------------------------------------------===//
3982 let ExeDomain = SSEPackedInt in {
3983 multiclass sse2_pshuffle<string OpcodeStr, ValueType vt128, ValueType vt256,
3985 let Predicates = [HasAVX] in {
3986 def V#NAME#ri : Ii8<0x70, MRMSrcReg, (outs VR128:$dst),
3987 (ins VR128:$src1, i8imm:$src2),
3988 !strconcat(!strconcat("v", OpcodeStr),
3989 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3991 (vt128 (OpNode VR128:$src1, (i8 imm:$src2))))],
3992 IIC_SSE_PSHUF>, VEX;
3993 def V#NAME#mi : Ii8<0x70, MRMSrcMem, (outs VR128:$dst),
3994 (ins i128mem:$src1, i8imm:$src2),
3995 !strconcat(!strconcat("v", OpcodeStr),
3996 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3998 (vt128 (OpNode (bitconvert (memopv2i64 addr:$src1)),
3999 (i8 imm:$src2))))], IIC_SSE_PSHUF>, VEX;
4002 let Predicates = [HasAVX2] in {
4003 def V#NAME#Yri : Ii8<0x70, MRMSrcReg, (outs VR256:$dst),
4004 (ins VR256:$src1, i8imm:$src2),
4005 !strconcat(!strconcat("v", OpcodeStr),
4006 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4008 (vt256 (OpNode VR256:$src1, (i8 imm:$src2))))],
4009 IIC_SSE_PSHUF>, VEX, VEX_L;
4010 def V#NAME#Ymi : Ii8<0x70, MRMSrcMem, (outs VR256:$dst),
4011 (ins i256mem:$src1, i8imm:$src2),
4012 !strconcat(!strconcat("v", OpcodeStr),
4013 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4015 (vt256 (OpNode (bitconvert (memopv4i64 addr:$src1)),
4016 (i8 imm:$src2))))], IIC_SSE_PSHUF>, VEX, VEX_L;
4019 let Predicates = [UseSSE2] in {
4020 def ri : Ii8<0x70, MRMSrcReg,
4021 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
4022 !strconcat(OpcodeStr,
4023 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4025 (vt128 (OpNode VR128:$src1, (i8 imm:$src2))))],
4027 def mi : Ii8<0x70, MRMSrcMem,
4028 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
4029 !strconcat(OpcodeStr,
4030 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4032 (vt128 (OpNode (bitconvert (memopv2i64 addr:$src1)),
4033 (i8 imm:$src2))))], IIC_SSE_PSHUF>;
4036 } // ExeDomain = SSEPackedInt
4038 defm PSHUFD : sse2_pshuffle<"pshufd", v4i32, v8i32, X86PShufd>, TB, OpSize;
4039 defm PSHUFHW : sse2_pshuffle<"pshufhw", v8i16, v16i16, X86PShufhw>, XS;
4040 defm PSHUFLW : sse2_pshuffle<"pshuflw", v8i16, v16i16, X86PShuflw>, XD;
4042 let Predicates = [HasAVX] in {
4043 def : Pat<(v4f32 (X86PShufd (memopv4f32 addr:$src1), (i8 imm:$imm))),
4044 (VPSHUFDmi addr:$src1, imm:$imm)>;
4045 def : Pat<(v4f32 (X86PShufd VR128:$src1, (i8 imm:$imm))),
4046 (VPSHUFDri VR128:$src1, imm:$imm)>;
4049 let Predicates = [UseSSE2] in {
4050 def : Pat<(v4f32 (X86PShufd (memopv4f32 addr:$src1), (i8 imm:$imm))),
4051 (PSHUFDmi addr:$src1, imm:$imm)>;
4052 def : Pat<(v4f32 (X86PShufd VR128:$src1, (i8 imm:$imm))),
4053 (PSHUFDri VR128:$src1, imm:$imm)>;
4056 //===---------------------------------------------------------------------===//
4057 // SSE2 - Packed Integer Unpack Instructions
4058 //===---------------------------------------------------------------------===//
4060 let ExeDomain = SSEPackedInt in {
4061 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
4062 SDNode OpNode, PatFrag bc_frag, bit Is2Addr = 1> {
4063 def rr : PDI<opc, MRMSrcReg,
4064 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
4066 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
4067 !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4068 [(set VR128:$dst, (vt (OpNode VR128:$src1, VR128:$src2)))],
4070 def rm : PDI<opc, MRMSrcMem,
4071 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
4073 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
4074 !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4075 [(set VR128:$dst, (OpNode VR128:$src1,
4076 (bc_frag (memopv2i64
4081 multiclass sse2_unpack_y<bits<8> opc, string OpcodeStr, ValueType vt,
4082 SDNode OpNode, PatFrag bc_frag> {
4083 def Yrr : PDI<opc, MRMSrcReg,
4084 (outs VR256:$dst), (ins VR256:$src1, VR256:$src2),
4085 !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4086 [(set VR256:$dst, (vt (OpNode VR256:$src1, VR256:$src2)))]>;
4087 def Yrm : PDI<opc, MRMSrcMem,
4088 (outs VR256:$dst), (ins VR256:$src1, i256mem:$src2),
4089 !strconcat(OpcodeStr,"\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
4090 [(set VR256:$dst, (OpNode VR256:$src1,
4091 (bc_frag (memopv4i64 addr:$src2))))]>;
4094 let Predicates = [HasAVX] in {
4095 defm VPUNPCKLBW : sse2_unpack<0x60, "vpunpcklbw", v16i8, X86Unpckl,
4096 bc_v16i8, 0>, VEX_4V;
4097 defm VPUNPCKLWD : sse2_unpack<0x61, "vpunpcklwd", v8i16, X86Unpckl,
4098 bc_v8i16, 0>, VEX_4V;
4099 defm VPUNPCKLDQ : sse2_unpack<0x62, "vpunpckldq", v4i32, X86Unpckl,
4100 bc_v4i32, 0>, VEX_4V;
4101 defm VPUNPCKLQDQ : sse2_unpack<0x6C, "vpunpcklqdq", v2i64, X86Unpckl,
4102 bc_v2i64, 0>, VEX_4V;
4104 defm VPUNPCKHBW : sse2_unpack<0x68, "vpunpckhbw", v16i8, X86Unpckh,
4105 bc_v16i8, 0>, VEX_4V;
4106 defm VPUNPCKHWD : sse2_unpack<0x69, "vpunpckhwd", v8i16, X86Unpckh,
4107 bc_v8i16, 0>, VEX_4V;
4108 defm VPUNPCKHDQ : sse2_unpack<0x6A, "vpunpckhdq", v4i32, X86Unpckh,
4109 bc_v4i32, 0>, VEX_4V;
4110 defm VPUNPCKHQDQ : sse2_unpack<0x6D, "vpunpckhqdq", v2i64, X86Unpckh,
4111 bc_v2i64, 0>, VEX_4V;
4114 let Predicates = [HasAVX2] in {
4115 defm VPUNPCKLBW : sse2_unpack_y<0x60, "vpunpcklbw", v32i8, X86Unpckl,
4116 bc_v32i8>, VEX_4V, VEX_L;
4117 defm VPUNPCKLWD : sse2_unpack_y<0x61, "vpunpcklwd", v16i16, X86Unpckl,
4118 bc_v16i16>, VEX_4V, VEX_L;
4119 defm VPUNPCKLDQ : sse2_unpack_y<0x62, "vpunpckldq", v8i32, X86Unpckl,
4120 bc_v8i32>, VEX_4V, VEX_L;
4121 defm VPUNPCKLQDQ : sse2_unpack_y<0x6C, "vpunpcklqdq", v4i64, X86Unpckl,
4122 bc_v4i64>, VEX_4V, VEX_L;
4124 defm VPUNPCKHBW : sse2_unpack_y<0x68, "vpunpckhbw", v32i8, X86Unpckh,
4125 bc_v32i8>, VEX_4V, VEX_L;
4126 defm VPUNPCKHWD : sse2_unpack_y<0x69, "vpunpckhwd", v16i16, X86Unpckh,
4127 bc_v16i16>, VEX_4V, VEX_L;
4128 defm VPUNPCKHDQ : sse2_unpack_y<0x6A, "vpunpckhdq", v8i32, X86Unpckh,
4129 bc_v8i32>, VEX_4V, VEX_L;
4130 defm VPUNPCKHQDQ : sse2_unpack_y<0x6D, "vpunpckhqdq", v4i64, X86Unpckh,
4131 bc_v4i64>, VEX_4V, VEX_L;
4134 let Constraints = "$src1 = $dst" in {
4135 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, X86Unpckl,
4137 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, X86Unpckl,
4139 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, X86Unpckl,
4141 defm PUNPCKLQDQ : sse2_unpack<0x6C, "punpcklqdq", v2i64, X86Unpckl,
4144 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, X86Unpckh,
4146 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, X86Unpckh,
4148 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, X86Unpckh,
4150 defm PUNPCKHQDQ : sse2_unpack<0x6D, "punpckhqdq", v2i64, X86Unpckh,
4153 } // ExeDomain = SSEPackedInt
4155 //===---------------------------------------------------------------------===//
4156 // SSE2 - Packed Integer Extract and Insert
4157 //===---------------------------------------------------------------------===//
4159 let ExeDomain = SSEPackedInt in {
4160 multiclass sse2_pinsrw<bit Is2Addr = 1> {
4161 def rri : Ii8<0xC4, MRMSrcReg,
4162 (outs VR128:$dst), (ins VR128:$src1,
4163 GR32:$src2, i32i8imm:$src3),
4165 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
4166 "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4168 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))], IIC_SSE_PINSRW>;
4169 def rmi : Ii8<0xC4, MRMSrcMem,
4170 (outs VR128:$dst), (ins VR128:$src1,
4171 i16mem:$src2, i32i8imm:$src3),
4173 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
4174 "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
4176 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
4177 imm:$src3))], IIC_SSE_PINSRW>;
4181 let Predicates = [HasAVX] in
4182 def VPEXTRWri : Ii8<0xC5, MRMSrcReg,
4183 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
4184 "vpextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
4185 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
4186 imm:$src2))]>, TB, OpSize, VEX;
4187 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
4188 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
4189 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
4190 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
4191 imm:$src2))], IIC_SSE_PEXTRW>;
4194 let Predicates = [HasAVX] in {
4195 defm VPINSRW : sse2_pinsrw<0>, TB, OpSize, VEX_4V;
4196 def VPINSRWrr64i : Ii8<0xC4, MRMSrcReg, (outs VR128:$dst),
4197 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
4198 "vpinsrw\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
4199 []>, TB, OpSize, VEX_4V;
4202 let Constraints = "$src1 = $dst" in
4203 defm PINSRW : sse2_pinsrw, TB, OpSize, Requires<[UseSSE2]>;
4205 } // ExeDomain = SSEPackedInt
4207 //===---------------------------------------------------------------------===//
4208 // SSE2 - Packed Mask Creation
4209 //===---------------------------------------------------------------------===//
4211 let ExeDomain = SSEPackedInt in {
4213 def VPMOVMSKBrr : VPDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
4214 "pmovmskb\t{$src, $dst|$dst, $src}",
4215 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))],
4216 IIC_SSE_MOVMSK>, VEX;
4217 def VPMOVMSKBr64r : VPDI<0xD7, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
4218 "pmovmskb\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVMSK>, VEX;
4220 let Predicates = [HasAVX2] in {
4221 def VPMOVMSKBYrr : VPDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR256:$src),
4222 "pmovmskb\t{$src, $dst|$dst, $src}",
4223 [(set GR32:$dst, (int_x86_avx2_pmovmskb VR256:$src))]>, VEX, VEX_L;
4224 def VPMOVMSKBYr64r : VPDI<0xD7, MRMSrcReg, (outs GR64:$dst), (ins VR256:$src),
4225 "pmovmskb\t{$src, $dst|$dst, $src}", []>, VEX, VEX_L;
4228 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
4229 "pmovmskb\t{$src, $dst|$dst, $src}",
4230 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))],
4233 } // ExeDomain = SSEPackedInt
4235 //===---------------------------------------------------------------------===//
4236 // SSE2 - Conditional Store
4237 //===---------------------------------------------------------------------===//
4239 let ExeDomain = SSEPackedInt in {
4242 def VMASKMOVDQU : VPDI<0xF7, MRMSrcReg, (outs),
4243 (ins VR128:$src, VR128:$mask),
4244 "maskmovdqu\t{$mask, $src|$src, $mask}",
4245 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)],
4246 IIC_SSE_MASKMOV>, VEX;
4248 def VMASKMOVDQU64 : VPDI<0xF7, MRMSrcReg, (outs),
4249 (ins VR128:$src, VR128:$mask),
4250 "maskmovdqu\t{$mask, $src|$src, $mask}",
4251 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)],
4252 IIC_SSE_MASKMOV>, VEX;
4255 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
4256 "maskmovdqu\t{$mask, $src|$src, $mask}",
4257 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)],
4260 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
4261 "maskmovdqu\t{$mask, $src|$src, $mask}",
4262 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)],
4265 } // ExeDomain = SSEPackedInt
4267 //===---------------------------------------------------------------------===//
4268 // SSE2 - Move Doubleword
4269 //===---------------------------------------------------------------------===//
4271 //===---------------------------------------------------------------------===//
4272 // Move Int Doubleword to Packed Double Int
4274 def VMOVDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
4275 "movd\t{$src, $dst|$dst, $src}",
4277 (v4i32 (scalar_to_vector GR32:$src)))], IIC_SSE_MOVDQ>,
4279 def VMOVDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
4280 "movd\t{$src, $dst|$dst, $src}",
4282 (v4i32 (scalar_to_vector (loadi32 addr:$src))))],
4285 def VMOV64toPQIrr : VRPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4286 "mov{d|q}\t{$src, $dst|$dst, $src}",
4288 (v2i64 (scalar_to_vector GR64:$src)))],
4289 IIC_SSE_MOVDQ>, VEX;
4290 def VMOV64toSDrr : VRPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
4291 "mov{d|q}\t{$src, $dst|$dst, $src}",
4292 [(set FR64:$dst, (bitconvert GR64:$src))],
4293 IIC_SSE_MOVDQ>, VEX;
4295 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
4296 "movd\t{$src, $dst|$dst, $src}",
4298 (v4i32 (scalar_to_vector GR32:$src)))], IIC_SSE_MOVDQ>;
4299 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
4300 "movd\t{$src, $dst|$dst, $src}",
4302 (v4i32 (scalar_to_vector (loadi32 addr:$src))))],
4304 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4305 "mov{d|q}\t{$src, $dst|$dst, $src}",
4307 (v2i64 (scalar_to_vector GR64:$src)))],
4309 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
4310 "mov{d|q}\t{$src, $dst|$dst, $src}",
4311 [(set FR64:$dst, (bitconvert GR64:$src))],
4314 //===---------------------------------------------------------------------===//
4315 // Move Int Doubleword to Single Scalar
4317 def VMOVDI2SSrr : VPDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
4318 "movd\t{$src, $dst|$dst, $src}",
4319 [(set FR32:$dst, (bitconvert GR32:$src))],
4320 IIC_SSE_MOVDQ>, VEX;
4322 def VMOVDI2SSrm : VPDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
4323 "movd\t{$src, $dst|$dst, $src}",
4324 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))],
4327 def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
4328 "movd\t{$src, $dst|$dst, $src}",
4329 [(set FR32:$dst, (bitconvert GR32:$src))],
4332 def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
4333 "movd\t{$src, $dst|$dst, $src}",
4334 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))],
4337 //===---------------------------------------------------------------------===//
4338 // Move Packed Doubleword Int to Packed Double Int
4340 def VMOVPDI2DIrr : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
4341 "movd\t{$src, $dst|$dst, $src}",
4342 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
4343 (iPTR 0)))], IIC_SSE_MOVD_ToGP>, VEX;
4344 def VMOVPDI2DImr : VPDI<0x7E, MRMDestMem, (outs),
4345 (ins i32mem:$dst, VR128:$src),
4346 "movd\t{$src, $dst|$dst, $src}",
4347 [(store (i32 (vector_extract (v4i32 VR128:$src),
4348 (iPTR 0))), addr:$dst)], IIC_SSE_MOVDQ>,
4350 def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
4351 "movd\t{$src, $dst|$dst, $src}",
4352 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
4353 (iPTR 0)))], IIC_SSE_MOVD_ToGP>;
4354 def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
4355 "movd\t{$src, $dst|$dst, $src}",
4356 [(store (i32 (vector_extract (v4i32 VR128:$src),
4357 (iPTR 0))), addr:$dst)],
4360 //===---------------------------------------------------------------------===//
4361 // Move Packed Doubleword Int first element to Doubleword Int
4363 def VMOVPQIto64rr : I<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
4364 "vmov{d|q}\t{$src, $dst|$dst, $src}",
4365 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
4368 TB, OpSize, VEX, VEX_W, Requires<[HasAVX, In64BitMode]>;
4370 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
4371 "mov{d|q}\t{$src, $dst|$dst, $src}",
4372 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
4376 //===---------------------------------------------------------------------===//
4377 // Bitcast FR64 <-> GR64
4379 let Predicates = [HasAVX] in
4380 def VMOV64toSDrm : S2SI<0x7E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
4381 "vmovq\t{$src, $dst|$dst, $src}",
4382 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>,
4384 def VMOVSDto64rr : VRPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
4385 "mov{d|q}\t{$src, $dst|$dst, $src}",
4386 [(set GR64:$dst, (bitconvert FR64:$src))],
4387 IIC_SSE_MOVDQ>, VEX;
4388 def VMOVSDto64mr : VRPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
4389 "movq\t{$src, $dst|$dst, $src}",
4390 [(store (i64 (bitconvert FR64:$src)), addr:$dst)],
4391 IIC_SSE_MOVDQ>, VEX;
4393 def MOV64toSDrm : S2SI<0x7E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
4394 "movq\t{$src, $dst|$dst, $src}",
4395 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))],
4397 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
4398 "mov{d|q}\t{$src, $dst|$dst, $src}",
4399 [(set GR64:$dst, (bitconvert FR64:$src))],
4401 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
4402 "movq\t{$src, $dst|$dst, $src}",
4403 [(store (i64 (bitconvert FR64:$src)), addr:$dst)],
4406 //===---------------------------------------------------------------------===//
4407 // Move Scalar Single to Double Int
4409 def VMOVSS2DIrr : VPDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
4410 "movd\t{$src, $dst|$dst, $src}",
4411 [(set GR32:$dst, (bitconvert FR32:$src))],
4412 IIC_SSE_MOVD_ToGP>, VEX;
4413 def VMOVSS2DImr : VPDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
4414 "movd\t{$src, $dst|$dst, $src}",
4415 [(store (i32 (bitconvert FR32:$src)), addr:$dst)],
4416 IIC_SSE_MOVDQ>, VEX;
4417 def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
4418 "movd\t{$src, $dst|$dst, $src}",
4419 [(set GR32:$dst, (bitconvert FR32:$src))],
4421 def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
4422 "movd\t{$src, $dst|$dst, $src}",
4423 [(store (i32 (bitconvert FR32:$src)), addr:$dst)],
4426 //===---------------------------------------------------------------------===//
4427 // Patterns and instructions to describe movd/movq to XMM register zero-extends
4429 let AddedComplexity = 15 in {
4430 def VMOVZDI2PDIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
4431 "movd\t{$src, $dst|$dst, $src}",
4432 [(set VR128:$dst, (v4i32 (X86vzmovl
4433 (v4i32 (scalar_to_vector GR32:$src)))))],
4434 IIC_SSE_MOVDQ>, VEX;
4435 def VMOVZQI2PQIrr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4436 "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
4437 [(set VR128:$dst, (v2i64 (X86vzmovl
4438 (v2i64 (scalar_to_vector GR64:$src)))))],
4442 let AddedComplexity = 15 in {
4443 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
4444 "movd\t{$src, $dst|$dst, $src}",
4445 [(set VR128:$dst, (v4i32 (X86vzmovl
4446 (v4i32 (scalar_to_vector GR32:$src)))))],
4448 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4449 "mov{d|q}\t{$src, $dst|$dst, $src}", // X86-64 only
4450 [(set VR128:$dst, (v2i64 (X86vzmovl
4451 (v2i64 (scalar_to_vector GR64:$src)))))],
4455 let AddedComplexity = 20 in {
4456 def VMOVZDI2PDIrm : VPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
4457 "movd\t{$src, $dst|$dst, $src}",
4459 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
4460 (loadi32 addr:$src))))))],
4461 IIC_SSE_MOVDQ>, VEX;
4462 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
4463 "movd\t{$src, $dst|$dst, $src}",
4465 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
4466 (loadi32 addr:$src))))))],
4470 let Predicates = [HasAVX] in {
4471 // AVX 128-bit movd/movq instruction write zeros in the high 128-bit part.
4472 let AddedComplexity = 20 in {
4473 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
4474 (VMOVZDI2PDIrm addr:$src)>;
4475 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
4476 (VMOVZDI2PDIrm addr:$src)>;
4478 // Use regular 128-bit instructions to match 256-bit scalar_to_vec+zext.
4479 def : Pat<(v8i32 (X86vzmovl (insert_subvector undef,
4480 (v4i32 (scalar_to_vector GR32:$src)),(iPTR 0)))),
4481 (SUBREG_TO_REG (i32 0), (VMOVZDI2PDIrr GR32:$src), sub_xmm)>;
4482 def : Pat<(v4i64 (X86vzmovl (insert_subvector undef,
4483 (v2i64 (scalar_to_vector GR64:$src)),(iPTR 0)))),
4484 (SUBREG_TO_REG (i64 0), (VMOVZQI2PQIrr GR64:$src), sub_xmm)>;
4487 let Predicates = [UseSSE2], AddedComplexity = 20 in {
4488 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
4489 (MOVZDI2PDIrm addr:$src)>;
4490 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
4491 (MOVZDI2PDIrm addr:$src)>;
4494 // These are the correct encodings of the instructions so that we know how to
4495 // read correct assembly, even though we continue to emit the wrong ones for
4496 // compatibility with Darwin's buggy assembler.
4497 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4498 (MOV64toPQIrr VR128:$dst, GR64:$src), 0>;
4499 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4500 (MOV64toSDrr FR64:$dst, GR64:$src), 0>;
4501 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4502 (MOVPQIto64rr GR64:$dst, VR128:$src), 0>;
4503 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4504 (MOVSDto64rr GR64:$dst, FR64:$src), 0>;
4505 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4506 (VMOVZQI2PQIrr VR128:$dst, GR64:$src), 0>;
4507 def : InstAlias<"movq\t{$src, $dst|$dst, $src}",
4508 (MOVZQI2PQIrr VR128:$dst, GR64:$src), 0>;
4510 //===---------------------------------------------------------------------===//
4511 // SSE2 - Move Quadword
4512 //===---------------------------------------------------------------------===//
4514 //===---------------------------------------------------------------------===//
4515 // Move Quadword Int to Packed Quadword Int
4517 def VMOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
4518 "vmovq\t{$src, $dst|$dst, $src}",
4520 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
4521 VEX, Requires<[HasAVX]>;
4522 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
4523 "movq\t{$src, $dst|$dst, $src}",
4525 (v2i64 (scalar_to_vector (loadi64 addr:$src))))],
4527 Requires<[UseSSE2]>; // SSE2 instruction with XS Prefix
4529 //===---------------------------------------------------------------------===//
4530 // Move Packed Quadword Int to Quadword Int
4532 def VMOVPQI2QImr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
4533 "movq\t{$src, $dst|$dst, $src}",
4534 [(store (i64 (vector_extract (v2i64 VR128:$src),
4535 (iPTR 0))), addr:$dst)],
4536 IIC_SSE_MOVDQ>, VEX;
4537 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
4538 "movq\t{$src, $dst|$dst, $src}",
4539 [(store (i64 (vector_extract (v2i64 VR128:$src),
4540 (iPTR 0))), addr:$dst)],
4543 //===---------------------------------------------------------------------===//
4544 // Store / copy lower 64-bits of a XMM register.
4546 def VMOVLQ128mr : VPDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
4547 "movq\t{$src, $dst|$dst, $src}",
4548 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>, VEX;
4549 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
4550 "movq\t{$src, $dst|$dst, $src}",
4551 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)],
4554 let AddedComplexity = 20 in
4555 def VMOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
4556 "vmovq\t{$src, $dst|$dst, $src}",
4558 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
4559 (loadi64 addr:$src))))))],
4561 XS, VEX, Requires<[HasAVX]>;
4563 let AddedComplexity = 20 in
4564 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
4565 "movq\t{$src, $dst|$dst, $src}",
4567 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
4568 (loadi64 addr:$src))))))],
4570 XS, Requires<[UseSSE2]>;
4572 let Predicates = [HasAVX], AddedComplexity = 20 in {
4573 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
4574 (VMOVZQI2PQIrm addr:$src)>;
4575 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
4576 (VMOVZQI2PQIrm addr:$src)>;
4577 def : Pat<(v2i64 (X86vzload addr:$src)),
4578 (VMOVZQI2PQIrm addr:$src)>;
4581 let Predicates = [UseSSE2], AddedComplexity = 20 in {
4582 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
4583 (MOVZQI2PQIrm addr:$src)>;
4584 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
4585 (MOVZQI2PQIrm addr:$src)>;
4586 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
4589 let Predicates = [HasAVX] in {
4590 def : Pat<(v4i64 (alignedX86vzload addr:$src)),
4591 (SUBREG_TO_REG (i32 0), (VMOVAPSrm addr:$src), sub_xmm)>;
4592 def : Pat<(v4i64 (X86vzload addr:$src)),
4593 (SUBREG_TO_REG (i32 0), (VMOVUPSrm addr:$src), sub_xmm)>;
4596 //===---------------------------------------------------------------------===//
4597 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
4598 // IA32 document. movq xmm1, xmm2 does clear the high bits.
4600 let AddedComplexity = 15 in
4601 def VMOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4602 "vmovq\t{$src, $dst|$dst, $src}",
4603 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))],
4605 XS, VEX, Requires<[HasAVX]>;
4606 let AddedComplexity = 15 in
4607 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4608 "movq\t{$src, $dst|$dst, $src}",
4609 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))],
4611 XS, Requires<[UseSSE2]>;
4613 let AddedComplexity = 20 in
4614 def VMOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4615 "vmovq\t{$src, $dst|$dst, $src}",
4616 [(set VR128:$dst, (v2i64 (X86vzmovl
4617 (loadv2i64 addr:$src))))],
4619 XS, VEX, Requires<[HasAVX]>;
4620 let AddedComplexity = 20 in {
4621 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4622 "movq\t{$src, $dst|$dst, $src}",
4623 [(set VR128:$dst, (v2i64 (X86vzmovl
4624 (loadv2i64 addr:$src))))],
4626 XS, Requires<[UseSSE2]>;
4629 let AddedComplexity = 20 in {
4630 let Predicates = [HasAVX] in {
4631 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
4632 (VMOVZPQILo2PQIrm addr:$src)>;
4633 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
4634 (VMOVZPQILo2PQIrr VR128:$src)>;
4636 let Predicates = [UseSSE2] in {
4637 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
4638 (MOVZPQILo2PQIrm addr:$src)>;
4639 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
4640 (MOVZPQILo2PQIrr VR128:$src)>;
4644 // Instructions to match in the assembler
4645 def VMOVQs64rr : VPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
4646 "movq\t{$src, $dst|$dst, $src}", [],
4647 IIC_SSE_MOVDQ>, VEX, VEX_W;
4648 def VMOVQd64rr : VPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
4649 "movq\t{$src, $dst|$dst, $src}", [],
4650 IIC_SSE_MOVDQ>, VEX, VEX_W;
4651 // Recognize "movd" with GR64 destination, but encode as a "movq"
4652 def VMOVQd64rr_alt : VPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
4653 "movd\t{$src, $dst|$dst, $src}", [],
4654 IIC_SSE_MOVDQ>, VEX, VEX_W;
4656 // Instructions for the disassembler
4657 // xr = XMM register
4660 let Predicates = [HasAVX] in
4661 def VMOVQxrxr: I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4662 "vmovq\t{$src, $dst|$dst, $src}", []>, VEX, XS;
4663 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4664 "movq\t{$src, $dst|$dst, $src}", [], IIC_SSE_MOVQ_RR>, XS;
4666 //===---------------------------------------------------------------------===//
4667 // SSE3 - Replicate Single FP - MOVSHDUP and MOVSLDUP
4668 //===---------------------------------------------------------------------===//
4669 multiclass sse3_replicate_sfp<bits<8> op, SDNode OpNode, string OpcodeStr,
4670 ValueType vt, RegisterClass RC, PatFrag mem_frag,
4671 X86MemOperand x86memop> {
4672 def rr : S3SI<op, MRMSrcReg, (outs RC:$dst), (ins RC:$src),
4673 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4674 [(set RC:$dst, (vt (OpNode RC:$src)))],
4676 def rm : S3SI<op, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
4677 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4678 [(set RC:$dst, (OpNode (mem_frag addr:$src)))],
4682 let Predicates = [HasAVX] in {
4683 defm VMOVSHDUP : sse3_replicate_sfp<0x16, X86Movshdup, "vmovshdup",
4684 v4f32, VR128, memopv4f32, f128mem>, VEX;
4685 defm VMOVSLDUP : sse3_replicate_sfp<0x12, X86Movsldup, "vmovsldup",
4686 v4f32, VR128, memopv4f32, f128mem>, VEX;
4687 defm VMOVSHDUPY : sse3_replicate_sfp<0x16, X86Movshdup, "vmovshdup",
4688 v8f32, VR256, memopv8f32, f256mem>, VEX, VEX_L;
4689 defm VMOVSLDUPY : sse3_replicate_sfp<0x12, X86Movsldup, "vmovsldup",
4690 v8f32, VR256, memopv8f32, f256mem>, VEX, VEX_L;
4692 defm MOVSHDUP : sse3_replicate_sfp<0x16, X86Movshdup, "movshdup", v4f32, VR128,
4693 memopv4f32, f128mem>;
4694 defm MOVSLDUP : sse3_replicate_sfp<0x12, X86Movsldup, "movsldup", v4f32, VR128,
4695 memopv4f32, f128mem>;
4697 let Predicates = [HasAVX] in {
4698 def : Pat<(v4i32 (X86Movshdup VR128:$src)),
4699 (VMOVSHDUPrr VR128:$src)>;
4700 def : Pat<(v4i32 (X86Movshdup (bc_v4i32 (memopv2i64 addr:$src)))),
4701 (VMOVSHDUPrm addr:$src)>;
4702 def : Pat<(v4i32 (X86Movsldup VR128:$src)),
4703 (VMOVSLDUPrr VR128:$src)>;
4704 def : Pat<(v4i32 (X86Movsldup (bc_v4i32 (memopv2i64 addr:$src)))),
4705 (VMOVSLDUPrm addr:$src)>;
4706 def : Pat<(v8i32 (X86Movshdup VR256:$src)),
4707 (VMOVSHDUPYrr VR256:$src)>;
4708 def : Pat<(v8i32 (X86Movshdup (bc_v8i32 (memopv4i64 addr:$src)))),
4709 (VMOVSHDUPYrm addr:$src)>;
4710 def : Pat<(v8i32 (X86Movsldup VR256:$src)),
4711 (VMOVSLDUPYrr VR256:$src)>;
4712 def : Pat<(v8i32 (X86Movsldup (bc_v8i32 (memopv4i64 addr:$src)))),
4713 (VMOVSLDUPYrm addr:$src)>;
4716 let Predicates = [UseSSE3] in {
4717 def : Pat<(v4i32 (X86Movshdup VR128:$src)),
4718 (MOVSHDUPrr VR128:$src)>;
4719 def : Pat<(v4i32 (X86Movshdup (bc_v4i32 (memopv2i64 addr:$src)))),
4720 (MOVSHDUPrm addr:$src)>;
4721 def : Pat<(v4i32 (X86Movsldup VR128:$src)),
4722 (MOVSLDUPrr VR128:$src)>;
4723 def : Pat<(v4i32 (X86Movsldup (bc_v4i32 (memopv2i64 addr:$src)))),
4724 (MOVSLDUPrm addr:$src)>;
4727 //===---------------------------------------------------------------------===//
4728 // SSE3 - Replicate Double FP - MOVDDUP
4729 //===---------------------------------------------------------------------===//
4731 multiclass sse3_replicate_dfp<string OpcodeStr> {
4732 let neverHasSideEffects = 1 in
4733 def rr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
4734 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4735 [], IIC_SSE_MOV_LH>;
4736 def rm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
4737 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4740 (scalar_to_vector (loadf64 addr:$src)))))],
4744 // FIXME: Merge with above classe when there're patterns for the ymm version
4745 multiclass sse3_replicate_dfp_y<string OpcodeStr> {
4746 def rr : S3DI<0x12, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
4747 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4748 [(set VR256:$dst, (v4f64 (X86Movddup VR256:$src)))]>;
4749 def rm : S3DI<0x12, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
4750 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4753 (scalar_to_vector (loadf64 addr:$src)))))]>;
4756 let Predicates = [HasAVX] in {
4757 defm VMOVDDUP : sse3_replicate_dfp<"vmovddup">, VEX;
4758 defm VMOVDDUPY : sse3_replicate_dfp_y<"vmovddup">, VEX, VEX_L;
4761 defm MOVDDUP : sse3_replicate_dfp<"movddup">;
4763 let Predicates = [HasAVX] in {
4764 def : Pat<(X86Movddup (memopv2f64 addr:$src)),
4765 (VMOVDDUPrm addr:$src)>, Requires<[HasAVX]>;
4766 def : Pat<(X86Movddup (bc_v2f64 (memopv4f32 addr:$src))),
4767 (VMOVDDUPrm addr:$src)>, Requires<[HasAVX]>;
4768 def : Pat<(X86Movddup (bc_v2f64 (memopv2i64 addr:$src))),
4769 (VMOVDDUPrm addr:$src)>, Requires<[HasAVX]>;
4770 def : Pat<(X86Movddup (bc_v2f64
4771 (v2i64 (scalar_to_vector (loadi64 addr:$src))))),
4772 (VMOVDDUPrm addr:$src)>, Requires<[HasAVX]>;
4775 def : Pat<(X86Movddup (memopv4f64 addr:$src)),
4776 (VMOVDDUPYrm addr:$src)>;
4777 def : Pat<(X86Movddup (memopv4i64 addr:$src)),
4778 (VMOVDDUPYrm addr:$src)>;
4779 def : Pat<(X86Movddup (v4i64 (scalar_to_vector (loadi64 addr:$src)))),
4780 (VMOVDDUPYrm addr:$src)>;
4781 def : Pat<(X86Movddup (v4i64 VR256:$src)),
4782 (VMOVDDUPYrr VR256:$src)>;
4785 let Predicates = [UseSSE3] in {
4786 def : Pat<(X86Movddup (memopv2f64 addr:$src)),
4787 (MOVDDUPrm addr:$src)>;
4788 def : Pat<(X86Movddup (bc_v2f64 (memopv4f32 addr:$src))),
4789 (MOVDDUPrm addr:$src)>;
4790 def : Pat<(X86Movddup (bc_v2f64 (memopv2i64 addr:$src))),
4791 (MOVDDUPrm addr:$src)>;
4792 def : Pat<(X86Movddup (bc_v2f64
4793 (v2i64 (scalar_to_vector (loadi64 addr:$src))))),
4794 (MOVDDUPrm addr:$src)>;
4797 //===---------------------------------------------------------------------===//
4798 // SSE3 - Move Unaligned Integer
4799 //===---------------------------------------------------------------------===//
4801 let Predicates = [HasAVX] in {
4802 def VLDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4803 "vlddqu\t{$src, $dst|$dst, $src}",
4804 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>, VEX;
4805 def VLDDQUYrm : S3DI<0xF0, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
4806 "vlddqu\t{$src, $dst|$dst, $src}",
4807 [(set VR256:$dst, (int_x86_avx_ldu_dq_256 addr:$src))]>,
4810 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
4811 "lddqu\t{$src, $dst|$dst, $src}",
4812 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))],
4815 //===---------------------------------------------------------------------===//
4816 // SSE3 - Arithmetic
4817 //===---------------------------------------------------------------------===//
4819 multiclass sse3_addsub<Intrinsic Int, string OpcodeStr, RegisterClass RC,
4820 X86MemOperand x86memop, OpndItins itins,
4822 def rr : I<0xD0, MRMSrcReg,
4823 (outs RC:$dst), (ins RC:$src1, RC:$src2),
4825 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4826 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4827 [(set RC:$dst, (Int RC:$src1, RC:$src2))], itins.rr>;
4828 def rm : I<0xD0, MRMSrcMem,
4829 (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
4831 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4832 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4833 [(set RC:$dst, (Int RC:$src1, (memop addr:$src2)))], itins.rr>;
4836 let Predicates = [HasAVX] in {
4837 let ExeDomain = SSEPackedSingle in {
4838 defm VADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "vaddsubps", VR128,
4839 f128mem, SSE_ALU_F32P, 0>, TB, XD, VEX_4V;
4840 defm VADDSUBPSY : sse3_addsub<int_x86_avx_addsub_ps_256, "vaddsubps", VR256,
4841 f256mem, SSE_ALU_F32P, 0>, TB, XD, VEX_4V, VEX_L;
4843 let ExeDomain = SSEPackedDouble in {
4844 defm VADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "vaddsubpd", VR128,
4845 f128mem, SSE_ALU_F64P, 0>, TB, OpSize, VEX_4V;
4846 defm VADDSUBPDY : sse3_addsub<int_x86_avx_addsub_pd_256, "vaddsubpd", VR256,
4847 f256mem, SSE_ALU_F64P, 0>, TB, OpSize, VEX_4V, VEX_L;
4850 let Constraints = "$src1 = $dst", Predicates = [UseSSE3] in {
4851 let ExeDomain = SSEPackedSingle in
4852 defm ADDSUBPS : sse3_addsub<int_x86_sse3_addsub_ps, "addsubps", VR128,
4853 f128mem, SSE_ALU_F32P>, TB, XD;
4854 let ExeDomain = SSEPackedDouble in
4855 defm ADDSUBPD : sse3_addsub<int_x86_sse3_addsub_pd, "addsubpd", VR128,
4856 f128mem, SSE_ALU_F64P>, TB, OpSize;
4859 //===---------------------------------------------------------------------===//
4860 // SSE3 Instructions
4861 //===---------------------------------------------------------------------===//
4864 multiclass S3D_Int<bits<8> o, string OpcodeStr, ValueType vt, RegisterClass RC,
4865 X86MemOperand x86memop, SDNode OpNode, bit Is2Addr = 1> {
4866 def rr : S3DI<o, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
4868 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4869 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4870 [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))], IIC_SSE_HADDSUB_RR>;
4872 def rm : S3DI<o, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
4874 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4875 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4876 [(set RC:$dst, (vt (OpNode RC:$src1, (memop addr:$src2))))],
4877 IIC_SSE_HADDSUB_RM>;
4879 multiclass S3_Int<bits<8> o, string OpcodeStr, ValueType vt, RegisterClass RC,
4880 X86MemOperand x86memop, SDNode OpNode, bit Is2Addr = 1> {
4881 def rr : S3I<o, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
4883 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4884 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4885 [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))], IIC_SSE_HADDSUB_RR>;
4887 def rm : S3I<o, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
4889 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
4890 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
4891 [(set RC:$dst, (vt (OpNode RC:$src1, (memop addr:$src2))))],
4892 IIC_SSE_HADDSUB_RM>;
4895 let Predicates = [HasAVX] in {
4896 let ExeDomain = SSEPackedSingle in {
4897 defm VHADDPS : S3D_Int<0x7C, "vhaddps", v4f32, VR128, f128mem,
4898 X86fhadd, 0>, VEX_4V;
4899 defm VHSUBPS : S3D_Int<0x7D, "vhsubps", v4f32, VR128, f128mem,
4900 X86fhsub, 0>, VEX_4V;
4901 defm VHADDPSY : S3D_Int<0x7C, "vhaddps", v8f32, VR256, f256mem,
4902 X86fhadd, 0>, VEX_4V, VEX_L;
4903 defm VHSUBPSY : S3D_Int<0x7D, "vhsubps", v8f32, VR256, f256mem,
4904 X86fhsub, 0>, VEX_4V, VEX_L;
4906 let ExeDomain = SSEPackedDouble in {
4907 defm VHADDPD : S3_Int <0x7C, "vhaddpd", v2f64, VR128, f128mem,
4908 X86fhadd, 0>, VEX_4V;
4909 defm VHSUBPD : S3_Int <0x7D, "vhsubpd", v2f64, VR128, f128mem,
4910 X86fhsub, 0>, VEX_4V;
4911 defm VHADDPDY : S3_Int <0x7C, "vhaddpd", v4f64, VR256, f256mem,
4912 X86fhadd, 0>, VEX_4V, VEX_L;
4913 defm VHSUBPDY : S3_Int <0x7D, "vhsubpd", v4f64, VR256, f256mem,
4914 X86fhsub, 0>, VEX_4V, VEX_L;
4918 let Constraints = "$src1 = $dst" in {
4919 let ExeDomain = SSEPackedSingle in {
4920 defm HADDPS : S3D_Int<0x7C, "haddps", v4f32, VR128, f128mem, X86fhadd>;
4921 defm HSUBPS : S3D_Int<0x7D, "hsubps", v4f32, VR128, f128mem, X86fhsub>;
4923 let ExeDomain = SSEPackedDouble in {
4924 defm HADDPD : S3_Int<0x7C, "haddpd", v2f64, VR128, f128mem, X86fhadd>;
4925 defm HSUBPD : S3_Int<0x7D, "hsubpd", v2f64, VR128, f128mem, X86fhsub>;
4929 //===---------------------------------------------------------------------===//
4930 // SSSE3 - Packed Absolute Instructions
4931 //===---------------------------------------------------------------------===//
4934 /// SS3I_unop_rm_int - Simple SSSE3 unary op whose type can be v*{i8,i16,i32}.
4935 multiclass SS3I_unop_rm_int<bits<8> opc, string OpcodeStr,
4936 Intrinsic IntId128> {
4937 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
4939 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4940 [(set VR128:$dst, (IntId128 VR128:$src))], IIC_SSE_PABS_RR>,
4943 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
4945 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4948 (bitconvert (memopv2i64 addr:$src))))], IIC_SSE_PABS_RM>,
4952 /// SS3I_unop_rm_int_y - Simple SSSE3 unary op whose type can be v*{i8,i16,i32}.
4953 multiclass SS3I_unop_rm_int_y<bits<8> opc, string OpcodeStr,
4954 Intrinsic IntId256> {
4955 def rr256 : SS38I<opc, MRMSrcReg, (outs VR256:$dst),
4957 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4958 [(set VR256:$dst, (IntId256 VR256:$src))]>,
4961 def rm256 : SS38I<opc, MRMSrcMem, (outs VR256:$dst),
4963 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
4966 (bitconvert (memopv4i64 addr:$src))))]>, OpSize;
4969 let Predicates = [HasAVX] in {
4970 defm VPABSB : SS3I_unop_rm_int<0x1C, "vpabsb",
4971 int_x86_ssse3_pabs_b_128>, VEX;
4972 defm VPABSW : SS3I_unop_rm_int<0x1D, "vpabsw",
4973 int_x86_ssse3_pabs_w_128>, VEX;
4974 defm VPABSD : SS3I_unop_rm_int<0x1E, "vpabsd",
4975 int_x86_ssse3_pabs_d_128>, VEX;
4978 let Predicates = [HasAVX2] in {
4979 defm VPABSB : SS3I_unop_rm_int_y<0x1C, "vpabsb",
4980 int_x86_avx2_pabs_b>, VEX, VEX_L;
4981 defm VPABSW : SS3I_unop_rm_int_y<0x1D, "vpabsw",
4982 int_x86_avx2_pabs_w>, VEX, VEX_L;
4983 defm VPABSD : SS3I_unop_rm_int_y<0x1E, "vpabsd",
4984 int_x86_avx2_pabs_d>, VEX, VEX_L;
4987 defm PABSB : SS3I_unop_rm_int<0x1C, "pabsb",
4988 int_x86_ssse3_pabs_b_128>;
4989 defm PABSW : SS3I_unop_rm_int<0x1D, "pabsw",
4990 int_x86_ssse3_pabs_w_128>;
4991 defm PABSD : SS3I_unop_rm_int<0x1E, "pabsd",
4992 int_x86_ssse3_pabs_d_128>;
4994 //===---------------------------------------------------------------------===//
4995 // SSSE3 - Packed Binary Operator Instructions
4996 //===---------------------------------------------------------------------===//
4998 def SSE_PHADDSUBD : OpndItins<
4999 IIC_SSE_PHADDSUBD_RR, IIC_SSE_PHADDSUBD_RM
5001 def SSE_PHADDSUBSW : OpndItins<
5002 IIC_SSE_PHADDSUBSW_RR, IIC_SSE_PHADDSUBSW_RM
5004 def SSE_PHADDSUBW : OpndItins<
5005 IIC_SSE_PHADDSUBW_RR, IIC_SSE_PHADDSUBW_RM
5007 def SSE_PSHUFB : OpndItins<
5008 IIC_SSE_PSHUFB_RR, IIC_SSE_PSHUFB_RM
5010 def SSE_PSIGN : OpndItins<
5011 IIC_SSE_PSIGN_RR, IIC_SSE_PSIGN_RM
5013 def SSE_PMULHRSW : OpndItins<
5014 IIC_SSE_PMULHRSW, IIC_SSE_PMULHRSW
5017 /// SS3I_binop_rm - Simple SSSE3 bin op
5018 multiclass SS3I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
5019 ValueType OpVT, RegisterClass RC, PatFrag memop_frag,
5020 X86MemOperand x86memop, OpndItins itins,
5022 let isCommutable = 1 in
5023 def rr : SS38I<opc, MRMSrcReg, (outs RC:$dst),
5024 (ins RC:$src1, RC:$src2),
5026 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5027 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5028 [(set RC:$dst, (OpVT (OpNode RC:$src1, RC:$src2)))], itins.rr>,
5030 def rm : SS38I<opc, MRMSrcMem, (outs RC:$dst),
5031 (ins RC:$src1, x86memop:$src2),
5033 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5034 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5036 (OpVT (OpNode RC:$src1,
5037 (bitconvert (memop_frag addr:$src2)))))], itins.rm>, OpSize;
5040 /// SS3I_binop_rm_int - Simple SSSE3 bin op whose type can be v*{i8,i16,i32}.
5041 multiclass SS3I_binop_rm_int<bits<8> opc, string OpcodeStr,
5042 Intrinsic IntId128, OpndItins itins,
5044 let isCommutable = 1 in
5045 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
5046 (ins VR128:$src1, VR128:$src2),
5048 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5049 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5050 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
5052 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
5053 (ins VR128:$src1, i128mem:$src2),
5055 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
5056 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
5058 (IntId128 VR128:$src1,
5059 (bitconvert (memopv2i64 addr:$src2))))]>, OpSize;
5062 multiclass SS3I_binop_rm_int_y<bits<8> opc, string OpcodeStr,
5063 Intrinsic IntId256> {
5064 let isCommutable = 1 in
5065 def rr256 : SS38I<opc, MRMSrcReg, (outs VR256:$dst),
5066 (ins VR256:$src1, VR256:$src2),
5067 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5068 [(set VR256:$dst, (IntId256 VR256:$src1, VR256:$src2))]>,
5070 def rm256 : SS38I<opc, MRMSrcMem, (outs VR256:$dst),
5071 (ins VR256:$src1, i256mem:$src2),
5072 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5074 (IntId256 VR256:$src1,
5075 (bitconvert (memopv4i64 addr:$src2))))]>, OpSize;
5078 let ImmT = NoImm, Predicates = [HasAVX] in {
5079 let isCommutable = 0 in {
5080 defm VPHADDW : SS3I_binop_rm<0x01, "vphaddw", X86hadd, v8i16, VR128,
5081 memopv2i64, i128mem,
5082 SSE_PHADDSUBW, 0>, VEX_4V;
5083 defm VPHADDD : SS3I_binop_rm<0x02, "vphaddd", X86hadd, v4i32, VR128,
5084 memopv2i64, i128mem,
5085 SSE_PHADDSUBD, 0>, VEX_4V;
5086 defm VPHSUBW : SS3I_binop_rm<0x05, "vphsubw", X86hsub, v8i16, VR128,
5087 memopv2i64, i128mem,
5088 SSE_PHADDSUBW, 0>, VEX_4V;
5089 defm VPHSUBD : SS3I_binop_rm<0x06, "vphsubd", X86hsub, v4i32, VR128,
5090 memopv2i64, i128mem,
5091 SSE_PHADDSUBD, 0>, VEX_4V;
5092 defm VPSIGNB : SS3I_binop_rm<0x08, "vpsignb", X86psign, v16i8, VR128,
5093 memopv2i64, i128mem,
5094 SSE_PSIGN, 0>, VEX_4V;
5095 defm VPSIGNW : SS3I_binop_rm<0x09, "vpsignw", X86psign, v8i16, VR128,
5096 memopv2i64, i128mem,
5097 SSE_PSIGN, 0>, VEX_4V;
5098 defm VPSIGND : SS3I_binop_rm<0x0A, "vpsignd", X86psign, v4i32, VR128,
5099 memopv2i64, i128mem,
5100 SSE_PSIGN, 0>, VEX_4V;
5101 defm VPSHUFB : SS3I_binop_rm<0x00, "vpshufb", X86pshufb, v16i8, VR128,
5102 memopv2i64, i128mem,
5103 SSE_PSHUFB, 0>, VEX_4V;
5104 defm VPHADDSW : SS3I_binop_rm_int<0x03, "vphaddsw",
5105 int_x86_ssse3_phadd_sw_128,
5106 SSE_PHADDSUBSW, 0>, VEX_4V;
5107 defm VPHSUBSW : SS3I_binop_rm_int<0x07, "vphsubsw",
5108 int_x86_ssse3_phsub_sw_128,
5109 SSE_PHADDSUBSW, 0>, VEX_4V;
5110 defm VPMADDUBSW : SS3I_binop_rm_int<0x04, "vpmaddubsw",
5111 int_x86_ssse3_pmadd_ub_sw_128,
5112 SSE_PMADD, 0>, VEX_4V;
5114 defm VPMULHRSW : SS3I_binop_rm_int<0x0B, "vpmulhrsw",
5115 int_x86_ssse3_pmul_hr_sw_128,
5116 SSE_PMULHRSW, 0>, VEX_4V;
5119 let ImmT = NoImm, Predicates = [HasAVX2] in {
5120 let isCommutable = 0 in {
5121 defm VPHADDWY : SS3I_binop_rm<0x01, "vphaddw", X86hadd, v16i16, VR256,
5122 memopv4i64, i256mem,
5123 SSE_PHADDSUBW, 0>, VEX_4V, VEX_L;
5124 defm VPHADDDY : SS3I_binop_rm<0x02, "vphaddd", X86hadd, v8i32, VR256,
5125 memopv4i64, i256mem,
5126 SSE_PHADDSUBW, 0>, VEX_4V, VEX_L;
5127 defm VPHSUBWY : SS3I_binop_rm<0x05, "vphsubw", X86hsub, v16i16, VR256,
5128 memopv4i64, i256mem,
5129 SSE_PHADDSUBW, 0>, VEX_4V, VEX_L;
5130 defm VPHSUBDY : SS3I_binop_rm<0x06, "vphsubd", X86hsub, v8i32, VR256,
5131 memopv4i64, i256mem,
5132 SSE_PHADDSUBW, 0>, VEX_4V, VEX_L;
5133 defm VPSIGNBY : SS3I_binop_rm<0x08, "vpsignb", X86psign, v32i8, VR256,
5134 memopv4i64, i256mem,
5135 SSE_PHADDSUBW, 0>, VEX_4V, VEX_L;
5136 defm VPSIGNWY : SS3I_binop_rm<0x09, "vpsignw", X86psign, v16i16, VR256,
5137 memopv4i64, i256mem,
5138 SSE_PHADDSUBW, 0>, VEX_4V, VEX_L;
5139 defm VPSIGNDY : SS3I_binop_rm<0x0A, "vpsignd", X86psign, v8i32, VR256,
5140 memopv4i64, i256mem,
5141 SSE_PHADDSUBW, 0>, VEX_4V, VEX_L;
5142 defm VPSHUFBY : SS3I_binop_rm<0x00, "vpshufb", X86pshufb, v32i8, VR256,
5143 memopv4i64, i256mem,
5144 SSE_PHADDSUBW, 0>, VEX_4V, VEX_L;
5145 defm VPHADDSW : SS3I_binop_rm_int_y<0x03, "vphaddsw",
5146 int_x86_avx2_phadd_sw>, VEX_4V, VEX_L;
5147 defm VPHSUBSW : SS3I_binop_rm_int_y<0x07, "vphsubsw",
5148 int_x86_avx2_phsub_sw>, VEX_4V, VEX_L;
5149 defm VPMADDUBSW : SS3I_binop_rm_int_y<0x04, "vpmaddubsw",
5150 int_x86_avx2_pmadd_ub_sw>, VEX_4V, VEX_L;
5152 defm VPMULHRSW : SS3I_binop_rm_int_y<0x0B, "vpmulhrsw",
5153 int_x86_avx2_pmul_hr_sw>, VEX_4V, VEX_L;
5156 // None of these have i8 immediate fields.
5157 let ImmT = NoImm, Constraints = "$src1 = $dst" in {
5158 let isCommutable = 0 in {
5159 defm PHADDW : SS3I_binop_rm<0x01, "phaddw", X86hadd, v8i16, VR128,
5160 memopv2i64, i128mem, SSE_PHADDSUBW>;
5161 defm PHADDD : SS3I_binop_rm<0x02, "phaddd", X86hadd, v4i32, VR128,
5162 memopv2i64, i128mem, SSE_PHADDSUBD>;
5163 defm PHSUBW : SS3I_binop_rm<0x05, "phsubw", X86hsub, v8i16, VR128,
5164 memopv2i64, i128mem, SSE_PHADDSUBW>;
5165 defm PHSUBD : SS3I_binop_rm<0x06, "phsubd", X86hsub, v4i32, VR128,
5166 memopv2i64, i128mem, SSE_PHADDSUBD>;
5167 defm PSIGNB : SS3I_binop_rm<0x08, "psignb", X86psign, v16i8, VR128,
5168 memopv2i64, i128mem, SSE_PSIGN>;
5169 defm PSIGNW : SS3I_binop_rm<0x09, "psignw", X86psign, v8i16, VR128,
5170 memopv2i64, i128mem, SSE_PSIGN>;
5171 defm PSIGND : SS3I_binop_rm<0x0A, "psignd", X86psign, v4i32, VR128,
5172 memopv2i64, i128mem, SSE_PSIGN>;
5173 defm PSHUFB : SS3I_binop_rm<0x00, "pshufb", X86pshufb, v16i8, VR128,
5174 memopv2i64, i128mem, SSE_PSHUFB>;
5175 defm PHADDSW : SS3I_binop_rm_int<0x03, "phaddsw",
5176 int_x86_ssse3_phadd_sw_128,
5178 defm PHSUBSW : SS3I_binop_rm_int<0x07, "phsubsw",
5179 int_x86_ssse3_phsub_sw_128,
5181 defm PMADDUBSW : SS3I_binop_rm_int<0x04, "pmaddubsw",
5182 int_x86_ssse3_pmadd_ub_sw_128, SSE_PMADD>;
5184 defm PMULHRSW : SS3I_binop_rm_int<0x0B, "pmulhrsw",
5185 int_x86_ssse3_pmul_hr_sw_128,
5189 //===---------------------------------------------------------------------===//
5190 // SSSE3 - Packed Align Instruction Patterns
5191 //===---------------------------------------------------------------------===//
5193 multiclass ssse3_palign<string asm, bit Is2Addr = 1> {
5194 let neverHasSideEffects = 1 in {
5195 def R128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
5196 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
5198 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5200 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5201 [], IIC_SSE_PALIGNR>, OpSize;
5203 def R128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
5204 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
5206 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5208 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5209 [], IIC_SSE_PALIGNR>, OpSize;
5213 multiclass ssse3_palign_y<string asm, bit Is2Addr = 1> {
5214 let neverHasSideEffects = 1 in {
5215 def R256rr : SS3AI<0x0F, MRMSrcReg, (outs VR256:$dst),
5216 (ins VR256:$src1, VR256:$src2, i8imm:$src3),
5218 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
5221 def R256rm : SS3AI<0x0F, MRMSrcMem, (outs VR256:$dst),
5222 (ins VR256:$src1, i256mem:$src2, i8imm:$src3),
5224 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
5229 let Predicates = [HasAVX] in
5230 defm VPALIGN : ssse3_palign<"vpalignr", 0>, VEX_4V;
5231 let Predicates = [HasAVX2] in
5232 defm VPALIGN : ssse3_palign_y<"vpalignr", 0>, VEX_4V, VEX_L;
5233 let Constraints = "$src1 = $dst", Predicates = [UseSSSE3] in
5234 defm PALIGN : ssse3_palign<"palignr">;
5236 let Predicates = [HasAVX2] in {
5237 def : Pat<(v8i32 (X86PAlign VR256:$src1, VR256:$src2, (i8 imm:$imm))),
5238 (VPALIGNR256rr VR256:$src2, VR256:$src1, imm:$imm)>;
5239 def : Pat<(v8f32 (X86PAlign VR256:$src1, VR256:$src2, (i8 imm:$imm))),
5240 (VPALIGNR256rr VR256:$src2, VR256:$src1, imm:$imm)>;
5241 def : Pat<(v16i16 (X86PAlign VR256:$src1, VR256:$src2, (i8 imm:$imm))),
5242 (VPALIGNR256rr VR256:$src2, VR256:$src1, imm:$imm)>;
5243 def : Pat<(v32i8 (X86PAlign VR256:$src1, VR256:$src2, (i8 imm:$imm))),
5244 (VPALIGNR256rr VR256:$src2, VR256:$src1, imm:$imm)>;
5247 let Predicates = [HasAVX] in {
5248 def : Pat<(v4i32 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5249 (VPALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5250 def : Pat<(v4f32 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5251 (VPALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5252 def : Pat<(v8i16 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5253 (VPALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5254 def : Pat<(v16i8 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5255 (VPALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5258 let Predicates = [UseSSSE3] in {
5259 def : Pat<(v4i32 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5260 (PALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5261 def : Pat<(v4f32 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5262 (PALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5263 def : Pat<(v8i16 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5264 (PALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5265 def : Pat<(v16i8 (X86PAlign VR128:$src1, VR128:$src2, (i8 imm:$imm))),
5266 (PALIGNR128rr VR128:$src2, VR128:$src1, imm:$imm)>;
5269 //===---------------------------------------------------------------------===//
5270 // SSSE3 - Thread synchronization
5271 //===---------------------------------------------------------------------===//
5273 let usesCustomInserter = 1 in {
5274 def MONITOR : PseudoI<(outs), (ins i32mem:$src1, GR32:$src2, GR32:$src3),
5275 [(int_x86_sse3_monitor addr:$src1, GR32:$src2, GR32:$src3)]>,
5276 Requires<[HasSSE3]>;
5279 let Uses = [EAX, ECX, EDX] in
5280 def MONITORrrr : I<0x01, MRM_C8, (outs), (ins), "monitor", [], IIC_SSE_MONITOR>,
5281 TB, Requires<[HasSSE3]>;
5282 let Uses = [ECX, EAX] in
5283 def MWAITrr : I<0x01, MRM_C9, (outs), (ins), "mwait",
5284 [(int_x86_sse3_mwait ECX, EAX)], IIC_SSE_MWAIT>,
5285 TB, Requires<[HasSSE3]>;
5287 def : InstAlias<"mwait %eax, %ecx", (MWAITrr)>, Requires<[In32BitMode]>;
5288 def : InstAlias<"mwait %rax, %rcx", (MWAITrr)>, Requires<[In64BitMode]>;
5290 def : InstAlias<"monitor %eax, %ecx, %edx", (MONITORrrr)>,
5291 Requires<[In32BitMode]>;
5292 def : InstAlias<"monitor %rax, %rcx, %rdx", (MONITORrrr)>,
5293 Requires<[In64BitMode]>;
5295 //===----------------------------------------------------------------------===//
5296 // SSE4.1 - Packed Move with Sign/Zero Extend
5297 //===----------------------------------------------------------------------===//
5299 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
5300 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
5301 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5302 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
5304 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
5305 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5307 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
5311 multiclass SS41I_binop_rm_int16_y<bits<8> opc, string OpcodeStr,
5313 def Yrr : SS48I<opc, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
5314 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5315 [(set VR256:$dst, (IntId VR128:$src))]>, OpSize;
5317 def Yrm : SS48I<opc, MRMSrcMem, (outs VR256:$dst), (ins i128mem:$src),
5318 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5319 [(set VR256:$dst, (IntId (load addr:$src)))]>, OpSize;
5322 let Predicates = [HasAVX] in {
5323 defm VPMOVSXBW : SS41I_binop_rm_int8<0x20, "vpmovsxbw", int_x86_sse41_pmovsxbw>,
5325 defm VPMOVSXWD : SS41I_binop_rm_int8<0x23, "vpmovsxwd", int_x86_sse41_pmovsxwd>,
5327 defm VPMOVSXDQ : SS41I_binop_rm_int8<0x25, "vpmovsxdq", int_x86_sse41_pmovsxdq>,
5329 defm VPMOVZXBW : SS41I_binop_rm_int8<0x30, "vpmovzxbw", int_x86_sse41_pmovzxbw>,
5331 defm VPMOVZXWD : SS41I_binop_rm_int8<0x33, "vpmovzxwd", int_x86_sse41_pmovzxwd>,
5333 defm VPMOVZXDQ : SS41I_binop_rm_int8<0x35, "vpmovzxdq", int_x86_sse41_pmovzxdq>,
5337 let Predicates = [HasAVX2] in {
5338 defm VPMOVSXBW : SS41I_binop_rm_int16_y<0x20, "vpmovsxbw",
5339 int_x86_avx2_pmovsxbw>, VEX, VEX_L;
5340 defm VPMOVSXWD : SS41I_binop_rm_int16_y<0x23, "vpmovsxwd",
5341 int_x86_avx2_pmovsxwd>, VEX, VEX_L;
5342 defm VPMOVSXDQ : SS41I_binop_rm_int16_y<0x25, "vpmovsxdq",
5343 int_x86_avx2_pmovsxdq>, VEX, VEX_L;
5344 defm VPMOVZXBW : SS41I_binop_rm_int16_y<0x30, "vpmovzxbw",
5345 int_x86_avx2_pmovzxbw>, VEX, VEX_L;
5346 defm VPMOVZXWD : SS41I_binop_rm_int16_y<0x33, "vpmovzxwd",
5347 int_x86_avx2_pmovzxwd>, VEX, VEX_L;
5348 defm VPMOVZXDQ : SS41I_binop_rm_int16_y<0x35, "vpmovzxdq",
5349 int_x86_avx2_pmovzxdq>, VEX, VEX_L;
5352 defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
5353 defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
5354 defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
5355 defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
5356 defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
5357 defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
5359 let Predicates = [HasAVX] in {
5360 // Common patterns involving scalar load.
5361 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
5362 (VPMOVSXBWrm addr:$src)>;
5363 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
5364 (VPMOVSXBWrm addr:$src)>;
5365 def : Pat<(int_x86_sse41_pmovsxbw (bc_v16i8 (loadv2i64 addr:$src))),
5366 (VPMOVSXBWrm addr:$src)>;
5368 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
5369 (VPMOVSXWDrm addr:$src)>;
5370 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
5371 (VPMOVSXWDrm addr:$src)>;
5372 def : Pat<(int_x86_sse41_pmovsxwd (bc_v8i16 (loadv2i64 addr:$src))),
5373 (VPMOVSXWDrm addr:$src)>;
5375 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
5376 (VPMOVSXDQrm addr:$src)>;
5377 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
5378 (VPMOVSXDQrm addr:$src)>;
5379 def : Pat<(int_x86_sse41_pmovsxdq (bc_v4i32 (loadv2i64 addr:$src))),
5380 (VPMOVSXDQrm addr:$src)>;
5382 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
5383 (VPMOVZXBWrm addr:$src)>;
5384 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
5385 (VPMOVZXBWrm addr:$src)>;
5386 def : Pat<(int_x86_sse41_pmovzxbw (bc_v16i8 (loadv2i64 addr:$src))),
5387 (VPMOVZXBWrm addr:$src)>;
5389 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
5390 (VPMOVZXWDrm addr:$src)>;
5391 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
5392 (VPMOVZXWDrm addr:$src)>;
5393 def : Pat<(int_x86_sse41_pmovzxwd (bc_v8i16 (loadv2i64 addr:$src))),
5394 (VPMOVZXWDrm addr:$src)>;
5396 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
5397 (VPMOVZXDQrm addr:$src)>;
5398 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
5399 (VPMOVZXDQrm addr:$src)>;
5400 def : Pat<(int_x86_sse41_pmovzxdq (bc_v4i32 (loadv2i64 addr:$src))),
5401 (VPMOVZXDQrm addr:$src)>;
5404 let Predicates = [UseSSE41] in {
5405 // Common patterns involving scalar load.
5406 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
5407 (PMOVSXBWrm addr:$src)>;
5408 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
5409 (PMOVSXBWrm addr:$src)>;
5410 def : Pat<(int_x86_sse41_pmovsxbw (bc_v16i8 (loadv2i64 addr:$src))),
5411 (PMOVSXBWrm addr:$src)>;
5413 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
5414 (PMOVSXWDrm addr:$src)>;
5415 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
5416 (PMOVSXWDrm addr:$src)>;
5417 def : Pat<(int_x86_sse41_pmovsxwd (bc_v8i16 (loadv2i64 addr:$src))),
5418 (PMOVSXWDrm addr:$src)>;
5420 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
5421 (PMOVSXDQrm addr:$src)>;
5422 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
5423 (PMOVSXDQrm addr:$src)>;
5424 def : Pat<(int_x86_sse41_pmovsxdq (bc_v4i32 (loadv2i64 addr:$src))),
5425 (PMOVSXDQrm addr:$src)>;
5427 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
5428 (PMOVZXBWrm addr:$src)>;
5429 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
5430 (PMOVZXBWrm addr:$src)>;
5431 def : Pat<(int_x86_sse41_pmovzxbw (bc_v16i8 (loadv2i64 addr:$src))),
5432 (PMOVZXBWrm addr:$src)>;
5434 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
5435 (PMOVZXWDrm addr:$src)>;
5436 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
5437 (PMOVZXWDrm addr:$src)>;
5438 def : Pat<(int_x86_sse41_pmovzxwd (bc_v8i16 (loadv2i64 addr:$src))),
5439 (PMOVZXWDrm addr:$src)>;
5441 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
5442 (PMOVZXDQrm addr:$src)>;
5443 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
5444 (PMOVZXDQrm addr:$src)>;
5445 def : Pat<(int_x86_sse41_pmovzxdq (bc_v4i32 (loadv2i64 addr:$src))),
5446 (PMOVZXDQrm addr:$src)>;
5449 let Predicates = [HasAVX2] in {
5450 let AddedComplexity = 15 in {
5451 def : Pat<(v4i64 (X86vzmovly (v4i32 VR128:$src))),
5452 (VPMOVZXDQYrr VR128:$src)>;
5453 def : Pat<(v8i32 (X86vzmovly (v8i16 VR128:$src))),
5454 (VPMOVZXWDYrr VR128:$src)>;
5457 def : Pat<(v4i64 (X86vsmovl (v4i32 VR128:$src))), (VPMOVSXDQYrr VR128:$src)>;
5458 def : Pat<(v8i32 (X86vsmovl (v8i16 VR128:$src))), (VPMOVSXWDYrr VR128:$src)>;
5461 let Predicates = [HasAVX] in {
5462 def : Pat<(v2i64 (X86vsmovl (v4i32 VR128:$src))), (VPMOVSXDQrr VR128:$src)>;
5463 def : Pat<(v4i32 (X86vsmovl (v8i16 VR128:$src))), (VPMOVSXWDrr VR128:$src)>;
5466 let Predicates = [UseSSE41] in {
5467 def : Pat<(v2i64 (X86vsmovl (v4i32 VR128:$src))), (PMOVSXDQrr VR128:$src)>;
5468 def : Pat<(v4i32 (X86vsmovl (v8i16 VR128:$src))), (PMOVSXWDrr VR128:$src)>;
5472 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
5473 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
5474 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5475 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
5477 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
5478 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5480 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
5484 multiclass SS41I_binop_rm_int8_y<bits<8> opc, string OpcodeStr,
5486 def Yrr : SS48I<opc, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
5487 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5488 [(set VR256:$dst, (IntId VR128:$src))]>, OpSize;
5490 def Yrm : SS48I<opc, MRMSrcMem, (outs VR256:$dst), (ins i32mem:$src),
5491 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5493 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
5497 let Predicates = [HasAVX] in {
5498 defm VPMOVSXBD : SS41I_binop_rm_int4<0x21, "vpmovsxbd", int_x86_sse41_pmovsxbd>,
5500 defm VPMOVSXWQ : SS41I_binop_rm_int4<0x24, "vpmovsxwq", int_x86_sse41_pmovsxwq>,
5502 defm VPMOVZXBD : SS41I_binop_rm_int4<0x31, "vpmovzxbd", int_x86_sse41_pmovzxbd>,
5504 defm VPMOVZXWQ : SS41I_binop_rm_int4<0x34, "vpmovzxwq", int_x86_sse41_pmovzxwq>,
5508 let Predicates = [HasAVX2] in {
5509 defm VPMOVSXBD : SS41I_binop_rm_int8_y<0x21, "vpmovsxbd",
5510 int_x86_avx2_pmovsxbd>, VEX, VEX_L;
5511 defm VPMOVSXWQ : SS41I_binop_rm_int8_y<0x24, "vpmovsxwq",
5512 int_x86_avx2_pmovsxwq>, VEX, VEX_L;
5513 defm VPMOVZXBD : SS41I_binop_rm_int8_y<0x31, "vpmovzxbd",
5514 int_x86_avx2_pmovzxbd>, VEX, VEX_L;
5515 defm VPMOVZXWQ : SS41I_binop_rm_int8_y<0x34, "vpmovzxwq",
5516 int_x86_avx2_pmovzxwq>, VEX, VEX_L;
5519 defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
5520 defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
5521 defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
5522 defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
5524 let Predicates = [HasAVX] in {
5525 // Common patterns involving scalar load
5526 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
5527 (VPMOVSXBDrm addr:$src)>;
5528 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
5529 (VPMOVSXWQrm addr:$src)>;
5531 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
5532 (VPMOVZXBDrm addr:$src)>;
5533 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
5534 (VPMOVZXWQrm addr:$src)>;
5537 let Predicates = [UseSSE41] in {
5538 // Common patterns involving scalar load
5539 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
5540 (PMOVSXBDrm addr:$src)>;
5541 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
5542 (PMOVSXWQrm addr:$src)>;
5544 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
5545 (PMOVZXBDrm addr:$src)>;
5546 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
5547 (PMOVZXWQrm addr:$src)>;
5550 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
5551 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
5552 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5553 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
5555 // Expecting a i16 load any extended to i32 value.
5556 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
5557 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5558 [(set VR128:$dst, (IntId (bitconvert
5559 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
5563 multiclass SS41I_binop_rm_int4_y<bits<8> opc, string OpcodeStr,
5565 def Yrr : SS48I<opc, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
5566 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5567 [(set VR256:$dst, (IntId VR128:$src))]>, OpSize;
5569 // Expecting a i16 load any extended to i32 value.
5570 def Yrm : SS48I<opc, MRMSrcMem, (outs VR256:$dst), (ins i16mem:$src),
5571 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
5572 [(set VR256:$dst, (IntId (bitconvert
5573 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
5577 let Predicates = [HasAVX] in {
5578 defm VPMOVSXBQ : SS41I_binop_rm_int2<0x22, "vpmovsxbq", int_x86_sse41_pmovsxbq>,
5580 defm VPMOVZXBQ : SS41I_binop_rm_int2<0x32, "vpmovzxbq", int_x86_sse41_pmovzxbq>,
5583 let Predicates = [HasAVX2] in {
5584 defm VPMOVSXBQ : SS41I_binop_rm_int4_y<0x22, "vpmovsxbq",
5585 int_x86_avx2_pmovsxbq>, VEX, VEX_L;
5586 defm VPMOVZXBQ : SS41I_binop_rm_int4_y<0x32, "vpmovzxbq",
5587 int_x86_avx2_pmovzxbq>, VEX, VEX_L;
5589 defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
5590 defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
5592 let Predicates = [HasAVX2] in {
5593 def : Pat<(v8i32 (X86vsmovl (v8i16 (bitconvert (v2i64 (load addr:$src)))))),
5594 (VPMOVSXWDYrm addr:$src)>;
5595 def : Pat<(v4i64 (X86vsmovl (v4i32 (bitconvert (v2i64 (load addr:$src)))))),
5596 (VPMOVSXDQYrm addr:$src)>;
5598 def : Pat<(v8i32 (X86vsext (v16i8 (bitconvert (v2i64
5599 (scalar_to_vector (loadi64 addr:$src))))))),
5600 (VPMOVSXBDYrm addr:$src)>;
5601 def : Pat<(v8i32 (X86vsext (v16i8 (bitconvert (v2f64
5602 (scalar_to_vector (loadf64 addr:$src))))))),
5603 (VPMOVSXBDYrm addr:$src)>;
5605 def : Pat<(v4i64 (X86vsext (v8i16 (bitconvert (v2i64
5606 (scalar_to_vector (loadi64 addr:$src))))))),
5607 (VPMOVSXWQYrm addr:$src)>;
5608 def : Pat<(v4i64 (X86vsext (v8i16 (bitconvert (v2f64
5609 (scalar_to_vector (loadf64 addr:$src))))))),
5610 (VPMOVSXWQYrm addr:$src)>;
5612 def : Pat<(v4i64 (X86vsext (v16i8 (bitconvert (v4i32
5613 (scalar_to_vector (loadi32 addr:$src))))))),
5614 (VPMOVSXBQYrm addr:$src)>;
5617 let Predicates = [HasAVX] in {
5618 // Common patterns involving scalar load
5619 def : Pat<(int_x86_sse41_pmovsxbq
5620 (bitconvert (v4i32 (X86vzmovl
5621 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5622 (VPMOVSXBQrm addr:$src)>;
5624 def : Pat<(int_x86_sse41_pmovzxbq
5625 (bitconvert (v4i32 (X86vzmovl
5626 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5627 (VPMOVZXBQrm addr:$src)>;
5630 let Predicates = [UseSSE41] in {
5631 // Common patterns involving scalar load
5632 def : Pat<(int_x86_sse41_pmovsxbq
5633 (bitconvert (v4i32 (X86vzmovl
5634 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5635 (PMOVSXBQrm addr:$src)>;
5637 def : Pat<(int_x86_sse41_pmovzxbq
5638 (bitconvert (v4i32 (X86vzmovl
5639 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5640 (PMOVZXBQrm addr:$src)>;
5642 def : Pat<(v4i32 (X86vsext (v8i16 (bitconvert (v2i64
5643 (scalar_to_vector (loadi64 addr:$src))))))),
5644 (PMOVSXWDrm addr:$src)>;
5645 def : Pat<(v4i32 (X86vsext (v8i16 (bitconvert (v2f64
5646 (scalar_to_vector (loadf64 addr:$src))))))),
5647 (PMOVSXWDrm addr:$src)>;
5648 def : Pat<(v4i32 (X86vsext (v16i8 (bitconvert (v4i32
5649 (scalar_to_vector (loadi32 addr:$src))))))),
5650 (PMOVSXBDrm addr:$src)>;
5651 def : Pat<(v2i64 (X86vsext (v8i16 (bitconvert (v4i32
5652 (scalar_to_vector (loadi32 addr:$src))))))),
5653 (PMOVSXWQrm addr:$src)>;
5654 def : Pat<(v2i64 (X86vsext (v16i8 (bitconvert (v4i32
5655 (scalar_to_vector (extloadi32i16 addr:$src))))))),
5656 (PMOVSXBQrm addr:$src)>;
5657 def : Pat<(v2i64 (X86vsext (v4i32 (bitconvert (v2i64
5658 (scalar_to_vector (loadi64 addr:$src))))))),
5659 (PMOVSXDQrm addr:$src)>;
5660 def : Pat<(v2i64 (X86vsext (v4i32 (bitconvert (v2f64
5661 (scalar_to_vector (loadf64 addr:$src))))))),
5662 (PMOVSXDQrm addr:$src)>;
5663 def : Pat<(v8i16 (X86vsext (v16i8 (bitconvert (v2i64
5664 (scalar_to_vector (loadi64 addr:$src))))))),
5665 (PMOVSXBWrm addr:$src)>;
5666 def : Pat<(v8i16 (X86vsext (v16i8 (bitconvert (v2f64
5667 (scalar_to_vector (loadf64 addr:$src))))))),
5668 (PMOVSXBWrm addr:$src)>;
5671 let Predicates = [HasAVX2] in {
5672 def : Pat<(v16i16 (X86vzext (v16i8 VR128:$src))), (VPMOVZXBWYrr VR128:$src)>;
5673 def : Pat<(v8i32 (X86vzext (v16i8 VR128:$src))), (VPMOVZXBDYrr VR128:$src)>;
5674 def : Pat<(v4i64 (X86vzext (v16i8 VR128:$src))), (VPMOVZXBQYrr VR128:$src)>;
5676 def : Pat<(v8i32 (X86vzext (v8i16 VR128:$src))), (VPMOVZXWDYrr VR128:$src)>;
5677 def : Pat<(v4i64 (X86vzext (v8i16 VR128:$src))), (VPMOVZXWQYrr VR128:$src)>;
5679 def : Pat<(v4i64 (X86vzext (v4i32 VR128:$src))), (VPMOVZXDQYrr VR128:$src)>;
5681 def : Pat<(v16i16 (X86vzext (v32i8 VR256:$src))),
5682 (VPMOVZXBWYrr (EXTRACT_SUBREG VR256:$src, sub_xmm))>;
5683 def : Pat<(v8i32 (X86vzext (v32i8 VR256:$src))),
5684 (VPMOVZXBDYrr (EXTRACT_SUBREG VR256:$src, sub_xmm))>;
5685 def : Pat<(v4i64 (X86vzext (v32i8 VR256:$src))),
5686 (VPMOVZXBQYrr (EXTRACT_SUBREG VR256:$src, sub_xmm))>;
5688 def : Pat<(v8i32 (X86vzext (v16i16 VR256:$src))),
5689 (VPMOVZXWDYrr (EXTRACT_SUBREG VR256:$src, sub_xmm))>;
5690 def : Pat<(v4i64 (X86vzext (v16i16 VR256:$src))),
5691 (VPMOVZXWQYrr (EXTRACT_SUBREG VR256:$src, sub_xmm))>;
5693 def : Pat<(v4i64 (X86vzext (v8i32 VR256:$src))),
5694 (VPMOVZXDQYrr (EXTRACT_SUBREG VR256:$src, sub_xmm))>;
5697 let Predicates = [HasAVX] in {
5698 def : Pat<(v8i16 (X86vzext (v16i8 VR128:$src))), (VPMOVZXBWrr VR128:$src)>;
5699 def : Pat<(v4i32 (X86vzext (v16i8 VR128:$src))), (VPMOVZXBDrr VR128:$src)>;
5700 def : Pat<(v2i64 (X86vzext (v16i8 VR128:$src))), (VPMOVZXBQrr VR128:$src)>;
5702 def : Pat<(v4i32 (X86vzext (v8i16 VR128:$src))), (VPMOVZXWDrr VR128:$src)>;
5703 def : Pat<(v2i64 (X86vzext (v8i16 VR128:$src))), (VPMOVZXWQrr VR128:$src)>;
5705 def : Pat<(v2i64 (X86vzext (v4i32 VR128:$src))), (VPMOVZXDQrr VR128:$src)>;
5707 def : Pat<(v8i16 (X86vzext (v16i8 (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))),
5708 (VPMOVZXBWrm addr:$src)>;
5709 def : Pat<(v8i16 (X86vzext (v16i8 (bitconvert (v2f64 (scalar_to_vector (loadf64 addr:$src))))))),
5710 (VPMOVZXBWrm addr:$src)>;
5711 def : Pat<(v4i32 (X86vzext (v16i8 (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5712 (VPMOVZXBDrm addr:$src)>;
5713 def : Pat<(v2i64 (X86vzext (v16i8 (bitconvert (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))),
5714 (VPMOVZXBQrm addr:$src)>;
5716 def : Pat<(v4i32 (X86vzext (v8i16 (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))),
5717 (VPMOVZXWDrm addr:$src)>;
5718 def : Pat<(v4i32 (X86vzext (v8i16 (bitconvert (v2f64 (scalar_to_vector (loadf64 addr:$src))))))),
5719 (VPMOVZXWDrm addr:$src)>;
5720 def : Pat<(v2i64 (X86vzext (v8i16 (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5721 (VPMOVZXWQrm addr:$src)>;
5723 def : Pat<(v2i64 (X86vzext (v4i32 (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))),
5724 (VPMOVZXDQrm addr:$src)>;
5725 def : Pat<(v2i64 (X86vzext (v4i32 (bitconvert (v2f64 (scalar_to_vector (loadf64 addr:$src))))))),
5726 (VPMOVZXDQrm addr:$src)>;
5727 def : Pat<(v2i64 (X86vzext (v4i32 (bitconvert (v2i64 (X86vzload addr:$src)))))),
5728 (VPMOVZXDQrm addr:$src)>;
5730 def : Pat<(v4i32 (X86vsext (v8i16 (bitconvert (v2i64
5731 (scalar_to_vector (loadi64 addr:$src))))))),
5732 (VPMOVSXWDrm addr:$src)>;
5733 def : Pat<(v2i64 (X86vsext (v4i32 (bitconvert (v2i64
5734 (scalar_to_vector (loadi64 addr:$src))))))),
5735 (VPMOVSXDQrm addr:$src)>;
5736 def : Pat<(v4i32 (X86vsext (v8i16 (bitconvert (v2f64
5737 (scalar_to_vector (loadf64 addr:$src))))))),
5738 (VPMOVSXWDrm addr:$src)>;
5739 def : Pat<(v2i64 (X86vsext (v4i32 (bitconvert (v2f64
5740 (scalar_to_vector (loadf64 addr:$src))))))),
5741 (VPMOVSXDQrm addr:$src)>;
5742 def : Pat<(v8i16 (X86vsext (v16i8 (bitconvert (v2i64
5743 (scalar_to_vector (loadi64 addr:$src))))))),
5744 (VPMOVSXBWrm addr:$src)>;
5745 def : Pat<(v8i16 (X86vsext (v16i8 (bitconvert (v2f64
5746 (scalar_to_vector (loadf64 addr:$src))))))),
5747 (VPMOVSXBWrm addr:$src)>;
5749 def : Pat<(v4i32 (X86vsext (v16i8 (bitconvert (v4i32
5750 (scalar_to_vector (loadi32 addr:$src))))))),
5751 (VPMOVSXBDrm addr:$src)>;
5752 def : Pat<(v2i64 (X86vsext (v8i16 (bitconvert (v4i32
5753 (scalar_to_vector (loadi32 addr:$src))))))),
5754 (VPMOVSXWQrm addr:$src)>;
5755 def : Pat<(v2i64 (X86vsext (v16i8 (bitconvert (v4i32
5756 (scalar_to_vector (extloadi32i16 addr:$src))))))),
5757 (VPMOVSXBQrm addr:$src)>;
5760 let Predicates = [UseSSE41] in {
5761 def : Pat<(v8i16 (X86vzext (v16i8 VR128:$src))), (PMOVZXBWrr VR128:$src)>;
5762 def : Pat<(v4i32 (X86vzext (v16i8 VR128:$src))), (PMOVZXBDrr VR128:$src)>;
5763 def : Pat<(v2i64 (X86vzext (v16i8 VR128:$src))), (PMOVZXBQrr VR128:$src)>;
5765 def : Pat<(v4i32 (X86vzext (v8i16 VR128:$src))), (PMOVZXWDrr VR128:$src)>;
5766 def : Pat<(v2i64 (X86vzext (v8i16 VR128:$src))), (PMOVZXWQrr VR128:$src)>;
5768 def : Pat<(v2i64 (X86vzext (v4i32 VR128:$src))), (PMOVZXDQrr VR128:$src)>;
5770 def : Pat<(v8i16 (X86vzext (v16i8 (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))),
5771 (PMOVZXBWrm addr:$src)>;
5772 def : Pat<(v8i16 (X86vzext (v16i8 (bitconvert (v2f64 (scalar_to_vector (loadf64 addr:$src))))))),
5773 (PMOVZXBWrm addr:$src)>;
5774 def : Pat<(v4i32 (X86vzext (v16i8 (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5775 (PMOVZXBDrm addr:$src)>;
5776 def : Pat<(v2i64 (X86vzext (v16i8 (bitconvert (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))),
5777 (PMOVZXBQrm addr:$src)>;
5779 def : Pat<(v4i32 (X86vzext (v8i16 (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))),
5780 (PMOVZXWDrm addr:$src)>;
5781 def : Pat<(v4i32 (X86vzext (v8i16 (bitconvert (v2f64 (scalar_to_vector (loadf64 addr:$src))))))),
5782 (PMOVZXWDrm addr:$src)>;
5783 def : Pat<(v2i64 (X86vzext (v8i16 (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
5784 (PMOVZXWQrm addr:$src)>;
5786 def : Pat<(v2i64 (X86vzext (v4i32 (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))),
5787 (PMOVZXDQrm addr:$src)>;
5788 def : Pat<(v2i64 (X86vzext (v4i32 (bitconvert (v2f64 (scalar_to_vector (loadf64 addr:$src))))))),
5789 (PMOVZXDQrm addr:$src)>;
5790 def : Pat<(v2i64 (X86vzext (v4i32 (bitconvert (v2i64 (X86vzload addr:$src)))))),
5791 (PMOVZXDQrm addr:$src)>;
5794 //===----------------------------------------------------------------------===//
5795 // SSE4.1 - Extract Instructions
5796 //===----------------------------------------------------------------------===//
5798 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
5799 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
5800 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
5801 (ins VR128:$src1, i32i8imm:$src2),
5802 !strconcat(OpcodeStr,
5803 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5804 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
5806 let neverHasSideEffects = 1, mayStore = 1 in
5807 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5808 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
5809 !strconcat(OpcodeStr,
5810 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5813 // There's an AssertZext in the way of writing the store pattern
5814 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
5817 let Predicates = [HasAVX] in {
5818 defm VPEXTRB : SS41I_extract8<0x14, "vpextrb">, VEX;
5819 def VPEXTRBrr64 : SS4AIi8<0x14, MRMDestReg, (outs GR64:$dst),
5820 (ins VR128:$src1, i32i8imm:$src2),
5821 "vpextrb\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>, OpSize, VEX;
5824 defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
5827 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
5828 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
5829 let neverHasSideEffects = 1, mayStore = 1 in
5830 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5831 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
5832 !strconcat(OpcodeStr,
5833 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5836 // There's an AssertZext in the way of writing the store pattern
5837 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
5840 let Predicates = [HasAVX] in
5841 defm VPEXTRW : SS41I_extract16<0x15, "vpextrw">, VEX;
5843 defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
5846 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
5847 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
5848 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
5849 (ins VR128:$src1, i32i8imm:$src2),
5850 !strconcat(OpcodeStr,
5851 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5853 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
5854 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5855 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
5856 !strconcat(OpcodeStr,
5857 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5858 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
5859 addr:$dst)]>, OpSize;
5862 let Predicates = [HasAVX] in
5863 defm VPEXTRD : SS41I_extract32<0x16, "vpextrd">, VEX;
5865 defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
5867 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
5868 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
5869 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
5870 (ins VR128:$src1, i32i8imm:$src2),
5871 !strconcat(OpcodeStr,
5872 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5874 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
5875 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5876 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
5877 !strconcat(OpcodeStr,
5878 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5879 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
5880 addr:$dst)]>, OpSize, REX_W;
5883 let Predicates = [HasAVX] in
5884 defm VPEXTRQ : SS41I_extract64<0x16, "vpextrq">, VEX, VEX_W;
5886 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
5888 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
5890 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
5891 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
5892 (ins VR128:$src1, i32i8imm:$src2),
5893 !strconcat(OpcodeStr,
5894 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5896 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
5898 def mr : SS4AIi8<opc, MRMDestMem, (outs),
5899 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
5900 !strconcat(OpcodeStr,
5901 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
5902 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
5903 addr:$dst)]>, OpSize;
5906 let ExeDomain = SSEPackedSingle in {
5907 let Predicates = [HasAVX] in {
5908 defm VEXTRACTPS : SS41I_extractf32<0x17, "vextractps">, VEX;
5909 def VEXTRACTPSrr64 : SS4AIi8<0x17, MRMDestReg, (outs GR64:$dst),
5910 (ins VR128:$src1, i32i8imm:$src2),
5911 "vextractps \t{$src2, $src1, $dst|$dst, $src1, $src2}",
5914 defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
5917 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
5918 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
5921 (VEXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
5923 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
5926 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
5927 Requires<[UseSSE41]>;
5929 //===----------------------------------------------------------------------===//
5930 // SSE4.1 - Insert Instructions
5931 //===----------------------------------------------------------------------===//
5933 multiclass SS41I_insert8<bits<8> opc, string asm, bit Is2Addr = 1> {
5934 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
5935 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
5937 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5939 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5941 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
5942 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
5943 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
5945 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5947 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5949 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
5950 imm:$src3))]>, OpSize;
5953 let Predicates = [HasAVX] in
5954 defm VPINSRB : SS41I_insert8<0x20, "vpinsrb", 0>, VEX_4V;
5955 let Constraints = "$src1 = $dst" in
5956 defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
5958 multiclass SS41I_insert32<bits<8> opc, string asm, bit Is2Addr = 1> {
5959 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
5960 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
5962 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5964 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5966 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
5968 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
5969 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
5971 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5973 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5975 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
5976 imm:$src3)))]>, OpSize;
5979 let Predicates = [HasAVX] in
5980 defm VPINSRD : SS41I_insert32<0x22, "vpinsrd", 0>, VEX_4V;
5981 let Constraints = "$src1 = $dst" in
5982 defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
5984 multiclass SS41I_insert64<bits<8> opc, string asm, bit Is2Addr = 1> {
5985 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
5986 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
5988 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5990 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
5992 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
5994 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
5995 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
5997 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
5999 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6001 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
6002 imm:$src3)))]>, OpSize;
6005 let Predicates = [HasAVX] in
6006 defm VPINSRQ : SS41I_insert64<0x22, "vpinsrq", 0>, VEX_4V, VEX_W;
6007 let Constraints = "$src1 = $dst" in
6008 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">, REX_W;
6010 // insertps has a few different modes, there's the first two here below which
6011 // are optimized inserts that won't zero arbitrary elements in the destination
6012 // vector. The next one matches the intrinsic and could zero arbitrary elements
6013 // in the target vector.
6014 multiclass SS41I_insertf32<bits<8> opc, string asm, bit Is2Addr = 1> {
6015 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
6016 (ins VR128:$src1, VR128:$src2, u32u8imm:$src3),
6018 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6020 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6022 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
6024 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
6025 (ins VR128:$src1, f32mem:$src2, u32u8imm:$src3),
6027 !strconcat(asm, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6029 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6031 (X86insrtps VR128:$src1,
6032 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
6033 imm:$src3))]>, OpSize;
6036 let ExeDomain = SSEPackedSingle in {
6037 let Predicates = [HasAVX] in
6038 defm VINSERTPS : SS41I_insertf32<0x21, "vinsertps", 0>, VEX_4V;
6039 let Constraints = "$src1 = $dst" in
6040 defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
6043 //===----------------------------------------------------------------------===//
6044 // SSE4.1 - Round Instructions
6045 //===----------------------------------------------------------------------===//
6047 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd, string OpcodeStr,
6048 X86MemOperand x86memop, RegisterClass RC,
6049 PatFrag mem_frag32, PatFrag mem_frag64,
6050 Intrinsic V4F32Int, Intrinsic V2F64Int> {
6051 let ExeDomain = SSEPackedSingle in {
6052 // Intrinsic operation, reg.
6053 // Vector intrinsic operation, reg
6054 def PSr : SS4AIi8<opcps, MRMSrcReg,
6055 (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
6056 !strconcat(OpcodeStr,
6057 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6058 [(set RC:$dst, (V4F32Int RC:$src1, imm:$src2))]>,
6061 // Vector intrinsic operation, mem
6062 def PSm : SS4AIi8<opcps, MRMSrcMem,
6063 (outs RC:$dst), (ins x86memop:$src1, i32i8imm:$src2),
6064 !strconcat(OpcodeStr,
6065 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6067 (V4F32Int (mem_frag32 addr:$src1),imm:$src2))]>,
6069 } // ExeDomain = SSEPackedSingle
6071 let ExeDomain = SSEPackedDouble in {
6072 // Vector intrinsic operation, reg
6073 def PDr : SS4AIi8<opcpd, MRMSrcReg,
6074 (outs RC:$dst), (ins RC:$src1, i32i8imm:$src2),
6075 !strconcat(OpcodeStr,
6076 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6077 [(set RC:$dst, (V2F64Int RC:$src1, imm:$src2))]>,
6080 // Vector intrinsic operation, mem
6081 def PDm : SS4AIi8<opcpd, MRMSrcMem,
6082 (outs RC:$dst), (ins x86memop:$src1, i32i8imm:$src2),
6083 !strconcat(OpcodeStr,
6084 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6086 (V2F64Int (mem_frag64 addr:$src1),imm:$src2))]>,
6088 } // ExeDomain = SSEPackedDouble
6091 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
6094 Intrinsic F64Int, bit Is2Addr = 1> {
6095 let ExeDomain = GenericDomain in {
6097 let hasSideEffects = 0 in
6098 def SSr : SS4AIi8<opcss, MRMSrcReg,
6099 (outs FR32:$dst), (ins FR32:$src1, FR32:$src2, i32i8imm:$src3),
6101 !strconcat(OpcodeStr,
6102 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6103 !strconcat(OpcodeStr,
6104 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6107 // Intrinsic operation, reg.
6108 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
6109 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
6111 !strconcat(OpcodeStr,
6112 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6113 !strconcat(OpcodeStr,
6114 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6115 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
6118 // Intrinsic operation, mem.
6119 def SSm : SS4AIi8<opcss, MRMSrcMem,
6120 (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
6122 !strconcat(OpcodeStr,
6123 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6124 !strconcat(OpcodeStr,
6125 "ss\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6127 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
6131 let hasSideEffects = 0 in
6132 def SDr : SS4AIi8<opcsd, MRMSrcReg,
6133 (outs FR64:$dst), (ins FR64:$src1, FR64:$src2, i32i8imm:$src3),
6135 !strconcat(OpcodeStr,
6136 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6137 !strconcat(OpcodeStr,
6138 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6141 // Intrinsic operation, reg.
6142 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
6143 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
6145 !strconcat(OpcodeStr,
6146 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6147 !strconcat(OpcodeStr,
6148 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6149 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
6152 // Intrinsic operation, mem.
6153 def SDm : SS4AIi8<opcsd, MRMSrcMem,
6154 (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
6156 !strconcat(OpcodeStr,
6157 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6158 !strconcat(OpcodeStr,
6159 "sd\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6161 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
6163 } // ExeDomain = GenericDomain
6166 // FP round - roundss, roundps, roundsd, roundpd
6167 let Predicates = [HasAVX] in {
6169 defm VROUND : sse41_fp_unop_rm<0x08, 0x09, "vround", f128mem, VR128,
6170 memopv4f32, memopv2f64,
6171 int_x86_sse41_round_ps,
6172 int_x86_sse41_round_pd>, VEX;
6173 defm VROUNDY : sse41_fp_unop_rm<0x08, 0x09, "vround", f256mem, VR256,
6174 memopv8f32, memopv4f64,
6175 int_x86_avx_round_ps_256,
6176 int_x86_avx_round_pd_256>, VEX, VEX_L;
6177 defm VROUND : sse41_fp_binop_rm<0x0A, 0x0B, "vround",
6178 int_x86_sse41_round_ss,
6179 int_x86_sse41_round_sd, 0>, VEX_4V, VEX_LIG;
6181 def : Pat<(ffloor FR32:$src),
6182 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x1))>;
6183 def : Pat<(f64 (ffloor FR64:$src)),
6184 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x1))>;
6185 def : Pat<(f32 (fnearbyint FR32:$src)),
6186 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0xC))>;
6187 def : Pat<(f64 (fnearbyint FR64:$src)),
6188 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0xC))>;
6189 def : Pat<(f32 (fceil FR32:$src)),
6190 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x2))>;
6191 def : Pat<(f64 (fceil FR64:$src)),
6192 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x2))>;
6193 def : Pat<(f32 (frint FR32:$src)),
6194 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x4))>;
6195 def : Pat<(f64 (frint FR64:$src)),
6196 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x4))>;
6197 def : Pat<(f32 (ftrunc FR32:$src)),
6198 (VROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x3))>;
6199 def : Pat<(f64 (ftrunc FR64:$src)),
6200 (VROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x3))>;
6202 def : Pat<(v4f32 (ffloor VR128:$src)),
6203 (VROUNDPSr VR128:$src, (i32 0x1))>;
6204 def : Pat<(v4f32 (fnearbyint VR128:$src)),
6205 (VROUNDPSr VR128:$src, (i32 0xC))>;
6206 def : Pat<(v4f32 (fceil VR128:$src)),
6207 (VROUNDPSr VR128:$src, (i32 0x2))>;
6208 def : Pat<(v4f32 (frint VR128:$src)),
6209 (VROUNDPSr VR128:$src, (i32 0x4))>;
6210 def : Pat<(v4f32 (ftrunc VR128:$src)),
6211 (VROUNDPSr VR128:$src, (i32 0x3))>;
6213 def : Pat<(v2f64 (ffloor VR128:$src)),
6214 (VROUNDPDr VR128:$src, (i32 0x1))>;
6215 def : Pat<(v2f64 (fnearbyint VR128:$src)),
6216 (VROUNDPDr VR128:$src, (i32 0xC))>;
6217 def : Pat<(v2f64 (fceil VR128:$src)),
6218 (VROUNDPDr VR128:$src, (i32 0x2))>;
6219 def : Pat<(v2f64 (frint VR128:$src)),
6220 (VROUNDPDr VR128:$src, (i32 0x4))>;
6221 def : Pat<(v2f64 (ftrunc VR128:$src)),
6222 (VROUNDPDr VR128:$src, (i32 0x3))>;
6224 def : Pat<(v8f32 (ffloor VR256:$src)),
6225 (VROUNDYPSr VR256:$src, (i32 0x1))>;
6226 def : Pat<(v8f32 (fnearbyint VR256:$src)),
6227 (VROUNDYPSr VR256:$src, (i32 0xC))>;
6228 def : Pat<(v8f32 (fceil VR256:$src)),
6229 (VROUNDYPSr VR256:$src, (i32 0x2))>;
6230 def : Pat<(v8f32 (frint VR256:$src)),
6231 (VROUNDYPSr VR256:$src, (i32 0x4))>;
6232 def : Pat<(v8f32 (ftrunc VR256:$src)),
6233 (VROUNDYPSr VR256:$src, (i32 0x3))>;
6235 def : Pat<(v4f64 (ffloor VR256:$src)),
6236 (VROUNDYPDr VR256:$src, (i32 0x1))>;
6237 def : Pat<(v4f64 (fnearbyint VR256:$src)),
6238 (VROUNDYPDr VR256:$src, (i32 0xC))>;
6239 def : Pat<(v4f64 (fceil VR256:$src)),
6240 (VROUNDYPDr VR256:$src, (i32 0x2))>;
6241 def : Pat<(v4f64 (frint VR256:$src)),
6242 (VROUNDYPDr VR256:$src, (i32 0x4))>;
6243 def : Pat<(v4f64 (ftrunc VR256:$src)),
6244 (VROUNDYPDr VR256:$src, (i32 0x3))>;
6247 defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round", f128mem, VR128,
6248 memopv4f32, memopv2f64,
6249 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
6250 let Constraints = "$src1 = $dst" in
6251 defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
6252 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
6254 let Predicates = [UseSSE41] in {
6255 def : Pat<(ffloor FR32:$src),
6256 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x1))>;
6257 def : Pat<(f64 (ffloor FR64:$src)),
6258 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x1))>;
6259 def : Pat<(f32 (fnearbyint FR32:$src)),
6260 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0xC))>;
6261 def : Pat<(f64 (fnearbyint FR64:$src)),
6262 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0xC))>;
6263 def : Pat<(f32 (fceil FR32:$src)),
6264 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x2))>;
6265 def : Pat<(f64 (fceil FR64:$src)),
6266 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x2))>;
6267 def : Pat<(f32 (frint FR32:$src)),
6268 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x4))>;
6269 def : Pat<(f64 (frint FR64:$src)),
6270 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x4))>;
6271 def : Pat<(f32 (ftrunc FR32:$src)),
6272 (ROUNDSSr (f32 (IMPLICIT_DEF)), FR32:$src, (i32 0x3))>;
6273 def : Pat<(f64 (ftrunc FR64:$src)),
6274 (ROUNDSDr (f64 (IMPLICIT_DEF)), FR64:$src, (i32 0x3))>;
6276 def : Pat<(v4f32 (ffloor VR128:$src)),
6277 (ROUNDPSr VR128:$src, (i32 0x1))>;
6278 def : Pat<(v4f32 (fnearbyint VR128:$src)),
6279 (ROUNDPSr VR128:$src, (i32 0xC))>;
6280 def : Pat<(v4f32 (fceil VR128:$src)),
6281 (ROUNDPSr VR128:$src, (i32 0x2))>;
6282 def : Pat<(v4f32 (frint VR128:$src)),
6283 (ROUNDPSr VR128:$src, (i32 0x4))>;
6284 def : Pat<(v4f32 (ftrunc VR128:$src)),
6285 (ROUNDPSr VR128:$src, (i32 0x3))>;
6287 def : Pat<(v2f64 (ffloor VR128:$src)),
6288 (ROUNDPDr VR128:$src, (i32 0x1))>;
6289 def : Pat<(v2f64 (fnearbyint VR128:$src)),
6290 (ROUNDPDr VR128:$src, (i32 0xC))>;
6291 def : Pat<(v2f64 (fceil VR128:$src)),
6292 (ROUNDPDr VR128:$src, (i32 0x2))>;
6293 def : Pat<(v2f64 (frint VR128:$src)),
6294 (ROUNDPDr VR128:$src, (i32 0x4))>;
6295 def : Pat<(v2f64 (ftrunc VR128:$src)),
6296 (ROUNDPDr VR128:$src, (i32 0x3))>;
6299 //===----------------------------------------------------------------------===//
6300 // SSE4.1 - Packed Bit Test
6301 //===----------------------------------------------------------------------===//
6303 // ptest instruction we'll lower to this in X86ISelLowering primarily from
6304 // the intel intrinsic that corresponds to this.
6305 let Defs = [EFLAGS], Predicates = [HasAVX] in {
6306 def VPTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
6307 "vptest\t{$src2, $src1|$src1, $src2}",
6308 [(set EFLAGS, (X86ptest VR128:$src1, (v2i64 VR128:$src2)))]>,
6310 def VPTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
6311 "vptest\t{$src2, $src1|$src1, $src2}",
6312 [(set EFLAGS,(X86ptest VR128:$src1, (memopv2i64 addr:$src2)))]>,
6315 def VPTESTYrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR256:$src1, VR256:$src2),
6316 "vptest\t{$src2, $src1|$src1, $src2}",
6317 [(set EFLAGS, (X86ptest VR256:$src1, (v4i64 VR256:$src2)))]>,
6319 def VPTESTYrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR256:$src1, i256mem:$src2),
6320 "vptest\t{$src2, $src1|$src1, $src2}",
6321 [(set EFLAGS,(X86ptest VR256:$src1, (memopv4i64 addr:$src2)))]>,
6325 let Defs = [EFLAGS] in {
6326 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
6327 "ptest\t{$src2, $src1|$src1, $src2}",
6328 [(set EFLAGS, (X86ptest VR128:$src1, (v2i64 VR128:$src2)))]>,
6330 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
6331 "ptest\t{$src2, $src1|$src1, $src2}",
6332 [(set EFLAGS, (X86ptest VR128:$src1, (memopv2i64 addr:$src2)))]>,
6336 // The bit test instructions below are AVX only
6337 multiclass avx_bittest<bits<8> opc, string OpcodeStr, RegisterClass RC,
6338 X86MemOperand x86memop, PatFrag mem_frag, ValueType vt> {
6339 def rr : SS48I<opc, MRMSrcReg, (outs), (ins RC:$src1, RC:$src2),
6340 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
6341 [(set EFLAGS, (X86testp RC:$src1, (vt RC:$src2)))]>, OpSize, VEX;
6342 def rm : SS48I<opc, MRMSrcMem, (outs), (ins RC:$src1, x86memop:$src2),
6343 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
6344 [(set EFLAGS, (X86testp RC:$src1, (mem_frag addr:$src2)))]>,
6348 let Defs = [EFLAGS], Predicates = [HasAVX] in {
6349 let ExeDomain = SSEPackedSingle in {
6350 defm VTESTPS : avx_bittest<0x0E, "vtestps", VR128, f128mem, memopv4f32, v4f32>;
6351 defm VTESTPSY : avx_bittest<0x0E, "vtestps", VR256, f256mem, memopv8f32, v8f32>,
6354 let ExeDomain = SSEPackedDouble in {
6355 defm VTESTPD : avx_bittest<0x0F, "vtestpd", VR128, f128mem, memopv2f64, v2f64>;
6356 defm VTESTPDY : avx_bittest<0x0F, "vtestpd", VR256, f256mem, memopv4f64, v4f64>,
6361 //===----------------------------------------------------------------------===//
6362 // SSE4.1 - Misc Instructions
6363 //===----------------------------------------------------------------------===//
6365 let Defs = [EFLAGS], Predicates = [HasPOPCNT] in {
6366 def POPCNT16rr : I<0xB8, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
6367 "popcnt{w}\t{$src, $dst|$dst, $src}",
6368 [(set GR16:$dst, (ctpop GR16:$src)), (implicit EFLAGS)]>,
6370 def POPCNT16rm : I<0xB8, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
6371 "popcnt{w}\t{$src, $dst|$dst, $src}",
6372 [(set GR16:$dst, (ctpop (loadi16 addr:$src))),
6373 (implicit EFLAGS)]>, OpSize, XS;
6375 def POPCNT32rr : I<0xB8, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
6376 "popcnt{l}\t{$src, $dst|$dst, $src}",
6377 [(set GR32:$dst, (ctpop GR32:$src)), (implicit EFLAGS)]>,
6379 def POPCNT32rm : I<0xB8, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
6380 "popcnt{l}\t{$src, $dst|$dst, $src}",
6381 [(set GR32:$dst, (ctpop (loadi32 addr:$src))),
6382 (implicit EFLAGS)]>, XS;
6384 def POPCNT64rr : RI<0xB8, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
6385 "popcnt{q}\t{$src, $dst|$dst, $src}",
6386 [(set GR64:$dst, (ctpop GR64:$src)), (implicit EFLAGS)]>,
6388 def POPCNT64rm : RI<0xB8, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
6389 "popcnt{q}\t{$src, $dst|$dst, $src}",
6390 [(set GR64:$dst, (ctpop (loadi64 addr:$src))),
6391 (implicit EFLAGS)]>, XS;
6396 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
6397 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
6398 Intrinsic IntId128> {
6399 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
6401 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
6402 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
6403 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
6405 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
6408 (bitconvert (memopv2i64 addr:$src))))]>, OpSize;
6411 let Predicates = [HasAVX] in
6412 defm VPHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "vphminposuw",
6413 int_x86_sse41_phminposuw>, VEX;
6414 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
6415 int_x86_sse41_phminposuw>;
6417 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
6418 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
6419 Intrinsic IntId128, bit Is2Addr = 1> {
6420 let isCommutable = 1 in
6421 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
6422 (ins VR128:$src1, VR128:$src2),
6424 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6425 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6426 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>, OpSize;
6427 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
6428 (ins VR128:$src1, i128mem:$src2),
6430 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6431 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6433 (IntId128 VR128:$src1,
6434 (bitconvert (memopv2i64 addr:$src2))))]>, OpSize;
6437 /// SS41I_binop_rm_int_y - Simple SSE 4.1 binary operator
6438 multiclass SS41I_binop_rm_int_y<bits<8> opc, string OpcodeStr,
6439 Intrinsic IntId256> {
6440 let isCommutable = 1 in
6441 def Yrr : SS48I<opc, MRMSrcReg, (outs VR256:$dst),
6442 (ins VR256:$src1, VR256:$src2),
6443 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6444 [(set VR256:$dst, (IntId256 VR256:$src1, VR256:$src2))]>, OpSize;
6445 def Yrm : SS48I<opc, MRMSrcMem, (outs VR256:$dst),
6446 (ins VR256:$src1, i256mem:$src2),
6447 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
6449 (IntId256 VR256:$src1,
6450 (bitconvert (memopv4i64 addr:$src2))))]>, OpSize;
6454 /// SS48I_binop_rm - Simple SSE41 binary operator.
6455 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
6456 ValueType OpVT, RegisterClass RC, PatFrag memop_frag,
6457 X86MemOperand x86memop, bit Is2Addr = 1> {
6458 let isCommutable = 1 in
6459 def rr : SS48I<opc, MRMSrcReg, (outs RC:$dst),
6460 (ins RC:$src1, RC:$src2),
6462 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6463 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6464 [(set RC:$dst, (OpVT (OpNode RC:$src1, RC:$src2)))]>, OpSize;
6465 def rm : SS48I<opc, MRMSrcMem, (outs RC:$dst),
6466 (ins RC:$src1, x86memop:$src2),
6468 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6469 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6471 (OpVT (OpNode RC:$src1,
6472 (bitconvert (memop_frag addr:$src2)))))]>, OpSize;
6475 let Predicates = [HasAVX] in {
6476 let isCommutable = 0 in
6477 defm VPACKUSDW : SS41I_binop_rm_int<0x2B, "vpackusdw", int_x86_sse41_packusdw,
6479 defm VPMINSB : SS48I_binop_rm<0x38, "vpminsb", X86smin, v16i8, VR128,
6480 memopv2i64, i128mem, 0>, VEX_4V;
6481 defm VPMINSD : SS48I_binop_rm<0x39, "vpminsd", X86smin, v4i32, VR128,
6482 memopv2i64, i128mem, 0>, VEX_4V;
6483 defm VPMINUD : SS48I_binop_rm<0x3B, "vpminud", X86umin, v4i32, VR128,
6484 memopv2i64, i128mem, 0>, VEX_4V;
6485 defm VPMINUW : SS48I_binop_rm<0x3A, "vpminuw", X86umin, v8i16, VR128,
6486 memopv2i64, i128mem, 0>, VEX_4V;
6487 defm VPMAXSB : SS48I_binop_rm<0x3C, "vpmaxsb", X86smax, v16i8, VR128,
6488 memopv2i64, i128mem, 0>, VEX_4V;
6489 defm VPMAXSD : SS48I_binop_rm<0x3D, "vpmaxsd", X86smax, v4i32, VR128,
6490 memopv2i64, i128mem, 0>, VEX_4V;
6491 defm VPMAXUD : SS48I_binop_rm<0x3F, "vpmaxud", X86umax, v4i32, VR128,
6492 memopv2i64, i128mem, 0>, VEX_4V;
6493 defm VPMAXUW : SS48I_binop_rm<0x3E, "vpmaxuw", X86umax, v8i16, VR128,
6494 memopv2i64, i128mem, 0>, VEX_4V;
6495 defm VPMULDQ : SS41I_binop_rm_int<0x28, "vpmuldq", int_x86_sse41_pmuldq,
6499 let Predicates = [HasAVX2] in {
6500 let isCommutable = 0 in
6501 defm VPACKUSDW : SS41I_binop_rm_int_y<0x2B, "vpackusdw",
6502 int_x86_avx2_packusdw>, VEX_4V, VEX_L;
6503 defm VPMINSBY : SS48I_binop_rm<0x38, "vpminsb", X86smin, v32i8, VR256,
6504 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6505 defm VPMINSDY : SS48I_binop_rm<0x39, "vpminsd", X86smin, v8i32, VR256,
6506 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6507 defm VPMINUDY : SS48I_binop_rm<0x3B, "vpminud", X86umin, v8i32, VR256,
6508 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6509 defm VPMINUWY : SS48I_binop_rm<0x3A, "vpminuw", X86umin, v16i16, VR256,
6510 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6511 defm VPMAXSBY : SS48I_binop_rm<0x3C, "vpmaxsb", X86smax, v32i8, VR256,
6512 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6513 defm VPMAXSDY : SS48I_binop_rm<0x3D, "vpmaxsd", X86smax, v8i32, VR256,
6514 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6515 defm VPMAXUDY : SS48I_binop_rm<0x3F, "vpmaxud", X86umax, v8i32, VR256,
6516 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6517 defm VPMAXUWY : SS48I_binop_rm<0x3E, "vpmaxuw", X86umax, v16i16, VR256,
6518 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6519 defm VPMULDQ : SS41I_binop_rm_int_y<0x28, "vpmuldq",
6520 int_x86_avx2_pmul_dq>, VEX_4V, VEX_L;
6523 let Constraints = "$src1 = $dst" in {
6524 let isCommutable = 0 in
6525 defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw", int_x86_sse41_packusdw>;
6526 defm PMINSB : SS48I_binop_rm<0x38, "pminsb", X86smin, v16i8, VR128,
6527 memopv2i64, i128mem>;
6528 defm PMINSD : SS48I_binop_rm<0x39, "pminsd", X86smin, v4i32, VR128,
6529 memopv2i64, i128mem>;
6530 defm PMINUD : SS48I_binop_rm<0x3B, "pminud", X86umin, v4i32, VR128,
6531 memopv2i64, i128mem>;
6532 defm PMINUW : SS48I_binop_rm<0x3A, "pminuw", X86umin, v8i16, VR128,
6533 memopv2i64, i128mem>;
6534 defm PMAXSB : SS48I_binop_rm<0x3C, "pmaxsb", X86smax, v16i8, VR128,
6535 memopv2i64, i128mem>;
6536 defm PMAXSD : SS48I_binop_rm<0x3D, "pmaxsd", X86smax, v4i32, VR128,
6537 memopv2i64, i128mem>;
6538 defm PMAXUD : SS48I_binop_rm<0x3F, "pmaxud", X86umax, v4i32, VR128,
6539 memopv2i64, i128mem>;
6540 defm PMAXUW : SS48I_binop_rm<0x3E, "pmaxuw", X86umax, v8i16, VR128,
6541 memopv2i64, i128mem>;
6542 defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq>;
6545 let Predicates = [HasAVX] in {
6546 defm VPMULLD : SS48I_binop_rm<0x40, "vpmulld", mul, v4i32, VR128,
6547 memopv2i64, i128mem, 0>, VEX_4V;
6548 defm VPCMPEQQ : SS48I_binop_rm<0x29, "vpcmpeqq", X86pcmpeq, v2i64, VR128,
6549 memopv2i64, i128mem, 0>, VEX_4V;
6551 let Predicates = [HasAVX2] in {
6552 defm VPMULLDY : SS48I_binop_rm<0x40, "vpmulld", mul, v8i32, VR256,
6553 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6554 defm VPCMPEQQY : SS48I_binop_rm<0x29, "vpcmpeqq", X86pcmpeq, v4i64, VR256,
6555 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6558 let Constraints = "$src1 = $dst" in {
6559 defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, VR128,
6560 memopv2i64, i128mem>;
6561 defm PCMPEQQ : SS48I_binop_rm<0x29, "pcmpeqq", X86pcmpeq, v2i64, VR128,
6562 memopv2i64, i128mem>;
6565 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
6566 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
6567 Intrinsic IntId, RegisterClass RC, PatFrag memop_frag,
6568 X86MemOperand x86memop, bit Is2Addr = 1> {
6569 let isCommutable = 1 in
6570 def rri : SS4AIi8<opc, MRMSrcReg, (outs RC:$dst),
6571 (ins RC:$src1, RC:$src2, u32u8imm:$src3),
6573 !strconcat(OpcodeStr,
6574 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6575 !strconcat(OpcodeStr,
6576 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6577 [(set RC:$dst, (IntId RC:$src1, RC:$src2, imm:$src3))]>,
6579 def rmi : SS4AIi8<opc, MRMSrcMem, (outs RC:$dst),
6580 (ins RC:$src1, x86memop:$src2, u32u8imm:$src3),
6582 !strconcat(OpcodeStr,
6583 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
6584 !strconcat(OpcodeStr,
6585 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}")),
6588 (bitconvert (memop_frag addr:$src2)), imm:$src3))]>,
6592 let Predicates = [HasAVX] in {
6593 let isCommutable = 0 in {
6594 let ExeDomain = SSEPackedSingle in {
6595 defm VBLENDPS : SS41I_binop_rmi_int<0x0C, "vblendps", int_x86_sse41_blendps,
6596 VR128, memopv4f32, f128mem, 0>, VEX_4V;
6597 defm VBLENDPSY : SS41I_binop_rmi_int<0x0C, "vblendps",
6598 int_x86_avx_blend_ps_256, VR256, memopv8f32,
6599 f256mem, 0>, VEX_4V, VEX_L;
6601 let ExeDomain = SSEPackedDouble in {
6602 defm VBLENDPD : SS41I_binop_rmi_int<0x0D, "vblendpd", int_x86_sse41_blendpd,
6603 VR128, memopv2f64, f128mem, 0>, VEX_4V;
6604 defm VBLENDPDY : SS41I_binop_rmi_int<0x0D, "vblendpd",
6605 int_x86_avx_blend_pd_256,VR256, memopv4f64,
6606 f256mem, 0>, VEX_4V, VEX_L;
6608 defm VPBLENDW : SS41I_binop_rmi_int<0x0E, "vpblendw", int_x86_sse41_pblendw,
6609 VR128, memopv2i64, i128mem, 0>, VEX_4V;
6610 defm VMPSADBW : SS41I_binop_rmi_int<0x42, "vmpsadbw", int_x86_sse41_mpsadbw,
6611 VR128, memopv2i64, i128mem, 0>, VEX_4V;
6613 let ExeDomain = SSEPackedSingle in
6614 defm VDPPS : SS41I_binop_rmi_int<0x40, "vdpps", int_x86_sse41_dpps,
6615 VR128, memopv4f32, f128mem, 0>, VEX_4V;
6616 let ExeDomain = SSEPackedDouble in
6617 defm VDPPD : SS41I_binop_rmi_int<0x41, "vdppd", int_x86_sse41_dppd,
6618 VR128, memopv2f64, f128mem, 0>, VEX_4V;
6619 let ExeDomain = SSEPackedSingle in
6620 defm VDPPSY : SS41I_binop_rmi_int<0x40, "vdpps", int_x86_avx_dp_ps_256,
6621 VR256, memopv8f32, i256mem, 0>, VEX_4V, VEX_L;
6624 let Predicates = [HasAVX2] in {
6625 let isCommutable = 0 in {
6626 defm VPBLENDWY : SS41I_binop_rmi_int<0x0E, "vpblendw", int_x86_avx2_pblendw,
6627 VR256, memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6628 defm VMPSADBWY : SS41I_binop_rmi_int<0x42, "vmpsadbw", int_x86_avx2_mpsadbw,
6629 VR256, memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6633 let Constraints = "$src1 = $dst" in {
6634 let isCommutable = 0 in {
6635 let ExeDomain = SSEPackedSingle in
6636 defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps", int_x86_sse41_blendps,
6637 VR128, memopv4f32, f128mem>;
6638 let ExeDomain = SSEPackedDouble in
6639 defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd", int_x86_sse41_blendpd,
6640 VR128, memopv2f64, f128mem>;
6641 defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw", int_x86_sse41_pblendw,
6642 VR128, memopv2i64, i128mem>;
6643 defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw", int_x86_sse41_mpsadbw,
6644 VR128, memopv2i64, i128mem>;
6646 let ExeDomain = SSEPackedSingle in
6647 defm DPPS : SS41I_binop_rmi_int<0x40, "dpps", int_x86_sse41_dpps,
6648 VR128, memopv4f32, f128mem>;
6649 let ExeDomain = SSEPackedDouble in
6650 defm DPPD : SS41I_binop_rmi_int<0x41, "dppd", int_x86_sse41_dppd,
6651 VR128, memopv2f64, f128mem>;
6654 /// SS41I_quaternary_int_avx - AVX SSE 4.1 with 4 operators
6655 multiclass SS41I_quaternary_int_avx<bits<8> opc, string OpcodeStr,
6656 RegisterClass RC, X86MemOperand x86memop,
6657 PatFrag mem_frag, Intrinsic IntId> {
6658 def rr : Ii8<opc, MRMSrcReg, (outs RC:$dst),
6659 (ins RC:$src1, RC:$src2, RC:$src3),
6660 !strconcat(OpcodeStr,
6661 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
6662 [(set RC:$dst, (IntId RC:$src1, RC:$src2, RC:$src3))],
6663 IIC_DEFAULT, SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
6665 def rm : Ii8<opc, MRMSrcMem, (outs RC:$dst),
6666 (ins RC:$src1, x86memop:$src2, RC:$src3),
6667 !strconcat(OpcodeStr,
6668 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
6670 (IntId RC:$src1, (bitconvert (mem_frag addr:$src2)),
6672 IIC_DEFAULT, SSEPackedInt>, OpSize, TA, VEX_4V, VEX_I8IMM;
6675 let Predicates = [HasAVX] in {
6676 let ExeDomain = SSEPackedDouble in {
6677 defm VBLENDVPD : SS41I_quaternary_int_avx<0x4B, "vblendvpd", VR128, f128mem,
6678 memopv2f64, int_x86_sse41_blendvpd>;
6679 defm VBLENDVPDY : SS41I_quaternary_int_avx<0x4B, "vblendvpd", VR256, f256mem,
6680 memopv4f64, int_x86_avx_blendv_pd_256>, VEX_L;
6681 } // ExeDomain = SSEPackedDouble
6682 let ExeDomain = SSEPackedSingle in {
6683 defm VBLENDVPS : SS41I_quaternary_int_avx<0x4A, "vblendvps", VR128, f128mem,
6684 memopv4f32, int_x86_sse41_blendvps>;
6685 defm VBLENDVPSY : SS41I_quaternary_int_avx<0x4A, "vblendvps", VR256, f256mem,
6686 memopv8f32, int_x86_avx_blendv_ps_256>, VEX_L;
6687 } // ExeDomain = SSEPackedSingle
6688 defm VPBLENDVB : SS41I_quaternary_int_avx<0x4C, "vpblendvb", VR128, i128mem,
6689 memopv2i64, int_x86_sse41_pblendvb>;
6692 let Predicates = [HasAVX2] in {
6693 defm VPBLENDVBY : SS41I_quaternary_int_avx<0x4C, "vpblendvb", VR256, i256mem,
6694 memopv4i64, int_x86_avx2_pblendvb>, VEX_L;
6697 let Predicates = [HasAVX] in {
6698 def : Pat<(v16i8 (vselect (v16i8 VR128:$mask), (v16i8 VR128:$src1),
6699 (v16i8 VR128:$src2))),
6700 (VPBLENDVBrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6701 def : Pat<(v4i32 (vselect (v4i32 VR128:$mask), (v4i32 VR128:$src1),
6702 (v4i32 VR128:$src2))),
6703 (VBLENDVPSrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6704 def : Pat<(v4f32 (vselect (v4i32 VR128:$mask), (v4f32 VR128:$src1),
6705 (v4f32 VR128:$src2))),
6706 (VBLENDVPSrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6707 def : Pat<(v2i64 (vselect (v2i64 VR128:$mask), (v2i64 VR128:$src1),
6708 (v2i64 VR128:$src2))),
6709 (VBLENDVPDrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6710 def : Pat<(v2f64 (vselect (v2i64 VR128:$mask), (v2f64 VR128:$src1),
6711 (v2f64 VR128:$src2))),
6712 (VBLENDVPDrr VR128:$src2, VR128:$src1, VR128:$mask)>;
6713 def : Pat<(v8i32 (vselect (v8i32 VR256:$mask), (v8i32 VR256:$src1),
6714 (v8i32 VR256:$src2))),
6715 (VBLENDVPSYrr VR256:$src2, VR256:$src1, VR256:$mask)>;
6716 def : Pat<(v8f32 (vselect (v8i32 VR256:$mask), (v8f32 VR256:$src1),
6717 (v8f32 VR256:$src2))),
6718 (VBLENDVPSYrr VR256:$src2, VR256:$src1, VR256:$mask)>;
6719 def : Pat<(v4i64 (vselect (v4i64 VR256:$mask), (v4i64 VR256:$src1),
6720 (v4i64 VR256:$src2))),
6721 (VBLENDVPDYrr VR256:$src2, VR256:$src1, VR256:$mask)>;
6722 def : Pat<(v4f64 (vselect (v4i64 VR256:$mask), (v4f64 VR256:$src1),
6723 (v4f64 VR256:$src2))),
6724 (VBLENDVPDYrr VR256:$src2, VR256:$src1, VR256:$mask)>;
6726 def : Pat<(v8f32 (X86Blendi (v8f32 VR256:$src1), (v8f32 VR256:$src2),
6728 (VBLENDPSYrri VR256:$src1, VR256:$src2, imm:$mask)>;
6729 def : Pat<(v4f64 (X86Blendi (v4f64 VR256:$src1), (v4f64 VR256:$src2),
6731 (VBLENDPDYrri VR256:$src1, VR256:$src2, imm:$mask)>;
6733 def : Pat<(v8i16 (X86Blendi (v8i16 VR128:$src1), (v8i16 VR128:$src2),
6735 (VPBLENDWrri VR128:$src1, VR128:$src2, imm:$mask)>;
6736 def : Pat<(v4f32 (X86Blendi (v4f32 VR128:$src1), (v4f32 VR128:$src2),
6738 (VBLENDPSrri VR128:$src1, VR128:$src2, imm:$mask)>;
6739 def : Pat<(v2f64 (X86Blendi (v2f64 VR128:$src1), (v2f64 VR128:$src2),
6741 (VBLENDPDrri VR128:$src1, VR128:$src2, imm:$mask)>;
6744 let Predicates = [HasAVX2] in {
6745 def : Pat<(v32i8 (vselect (v32i8 VR256:$mask), (v32i8 VR256:$src1),
6746 (v32i8 VR256:$src2))),
6747 (VPBLENDVBYrr VR256:$src1, VR256:$src2, VR256:$mask)>;
6748 def : Pat<(v16i16 (X86Blendi (v16i16 VR256:$src1), (v16i16 VR256:$src2),
6750 (VPBLENDWYrri VR256:$src1, VR256:$src2, imm:$mask)>;
6753 /// SS41I_ternary_int - SSE 4.1 ternary operator
6754 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
6755 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, PatFrag mem_frag,
6756 X86MemOperand x86memop, Intrinsic IntId> {
6757 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
6758 (ins VR128:$src1, VR128:$src2),
6759 !strconcat(OpcodeStr,
6760 "\t{$src2, $dst|$dst, $src2}"),
6761 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
6764 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
6765 (ins VR128:$src1, x86memop:$src2),
6766 !strconcat(OpcodeStr,
6767 "\t{$src2, $dst|$dst, $src2}"),
6770 (bitconvert (mem_frag addr:$src2)), XMM0))]>, OpSize;
6774 let ExeDomain = SSEPackedDouble in
6775 defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", memopv2f64, f128mem,
6776 int_x86_sse41_blendvpd>;
6777 let ExeDomain = SSEPackedSingle in
6778 defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", memopv4f32, f128mem,
6779 int_x86_sse41_blendvps>;
6780 defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", memopv2i64, i128mem,
6781 int_x86_sse41_pblendvb>;
6783 // Aliases with the implicit xmm0 argument
6784 def : InstAlias<"blendvpd\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6785 (BLENDVPDrr0 VR128:$dst, VR128:$src2)>;
6786 def : InstAlias<"blendvpd\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6787 (BLENDVPDrm0 VR128:$dst, f128mem:$src2)>;
6788 def : InstAlias<"blendvps\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6789 (BLENDVPSrr0 VR128:$dst, VR128:$src2)>;
6790 def : InstAlias<"blendvps\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6791 (BLENDVPSrm0 VR128:$dst, f128mem:$src2)>;
6792 def : InstAlias<"pblendvb\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6793 (PBLENDVBrr0 VR128:$dst, VR128:$src2)>;
6794 def : InstAlias<"pblendvb\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}",
6795 (PBLENDVBrm0 VR128:$dst, i128mem:$src2)>;
6797 let Predicates = [UseSSE41] in {
6798 def : Pat<(v16i8 (vselect (v16i8 XMM0), (v16i8 VR128:$src1),
6799 (v16i8 VR128:$src2))),
6800 (PBLENDVBrr0 VR128:$src2, VR128:$src1)>;
6801 def : Pat<(v4i32 (vselect (v4i32 XMM0), (v4i32 VR128:$src1),
6802 (v4i32 VR128:$src2))),
6803 (BLENDVPSrr0 VR128:$src2, VR128:$src1)>;
6804 def : Pat<(v4f32 (vselect (v4i32 XMM0), (v4f32 VR128:$src1),
6805 (v4f32 VR128:$src2))),
6806 (BLENDVPSrr0 VR128:$src2, VR128:$src1)>;
6807 def : Pat<(v2i64 (vselect (v2i64 XMM0), (v2i64 VR128:$src1),
6808 (v2i64 VR128:$src2))),
6809 (BLENDVPDrr0 VR128:$src2, VR128:$src1)>;
6810 def : Pat<(v2f64 (vselect (v2i64 XMM0), (v2f64 VR128:$src1),
6811 (v2f64 VR128:$src2))),
6812 (BLENDVPDrr0 VR128:$src2, VR128:$src1)>;
6814 def : Pat<(v8i16 (X86Blendi (v8i16 VR128:$src1), (v8i16 VR128:$src2),
6816 (PBLENDWrri VR128:$src1, VR128:$src2, imm:$mask)>;
6817 def : Pat<(v4f32 (X86Blendi (v4f32 VR128:$src1), (v4f32 VR128:$src2),
6819 (BLENDPSrri VR128:$src1, VR128:$src2, imm:$mask)>;
6820 def : Pat<(v2f64 (X86Blendi (v2f64 VR128:$src1), (v2f64 VR128:$src2),
6822 (BLENDPDrri VR128:$src1, VR128:$src2, imm:$mask)>;
6826 let Predicates = [HasAVX] in
6827 def VMOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
6828 "vmovntdqa\t{$src, $dst|$dst, $src}",
6829 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
6831 let Predicates = [HasAVX2] in
6832 def VMOVNTDQAYrm : SS48I<0x2A, MRMSrcMem, (outs VR256:$dst), (ins i256mem:$src),
6833 "vmovntdqa\t{$src, $dst|$dst, $src}",
6834 [(set VR256:$dst, (int_x86_avx2_movntdqa addr:$src))]>,
6836 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
6837 "movntdqa\t{$src, $dst|$dst, $src}",
6838 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
6841 //===----------------------------------------------------------------------===//
6842 // SSE4.2 - Compare Instructions
6843 //===----------------------------------------------------------------------===//
6845 /// SS42I_binop_rm - Simple SSE 4.2 binary operator
6846 multiclass SS42I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
6847 ValueType OpVT, RegisterClass RC, PatFrag memop_frag,
6848 X86MemOperand x86memop, bit Is2Addr = 1> {
6849 def rr : SS428I<opc, MRMSrcReg, (outs RC:$dst),
6850 (ins RC:$src1, RC:$src2),
6852 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6853 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6854 [(set RC:$dst, (OpVT (OpNode RC:$src1, RC:$src2)))]>,
6856 def rm : SS428I<opc, MRMSrcMem, (outs RC:$dst),
6857 (ins RC:$src1, x86memop:$src2),
6859 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
6860 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
6862 (OpVT (OpNode RC:$src1, (memop_frag addr:$src2))))]>, OpSize;
6865 let Predicates = [HasAVX] in
6866 defm VPCMPGTQ : SS42I_binop_rm<0x37, "vpcmpgtq", X86pcmpgt, v2i64, VR128,
6867 memopv2i64, i128mem, 0>, VEX_4V;
6869 let Predicates = [HasAVX2] in
6870 defm VPCMPGTQY : SS42I_binop_rm<0x37, "vpcmpgtq", X86pcmpgt, v4i64, VR256,
6871 memopv4i64, i256mem, 0>, VEX_4V, VEX_L;
6873 let Constraints = "$src1 = $dst" in
6874 defm PCMPGTQ : SS42I_binop_rm<0x37, "pcmpgtq", X86pcmpgt, v2i64, VR128,
6875 memopv2i64, i128mem>;
6877 //===----------------------------------------------------------------------===//
6878 // SSE4.2 - String/text Processing Instructions
6879 //===----------------------------------------------------------------------===//
6881 // Packed Compare Implicit Length Strings, Return Mask
6882 multiclass pseudo_pcmpistrm<string asm> {
6883 def REG : PseudoI<(outs VR128:$dst),
6884 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
6885 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
6887 def MEM : PseudoI<(outs VR128:$dst),
6888 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
6889 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1,
6890 (bc_v16i8 (memopv2i64 addr:$src2)), imm:$src3))]>;
6893 let Defs = [EFLAGS], usesCustomInserter = 1 in {
6894 defm VPCMPISTRM128 : pseudo_pcmpistrm<"#VPCMPISTRM128">, Requires<[HasAVX]>;
6895 defm PCMPISTRM128 : pseudo_pcmpistrm<"#PCMPISTRM128">, Requires<[UseSSE42]>;
6898 multiclass pcmpistrm_SS42AI<string asm> {
6899 def rr : SS42AI<0x62, MRMSrcReg, (outs),
6900 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
6901 !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
6904 def rm :SS42AI<0x62, MRMSrcMem, (outs),
6905 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
6906 !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
6910 let Defs = [XMM0, EFLAGS], neverHasSideEffects = 1 in {
6911 let Predicates = [HasAVX] in
6912 defm VPCMPISTRM128 : pcmpistrm_SS42AI<"vpcmpistrm">, VEX;
6913 defm PCMPISTRM128 : pcmpistrm_SS42AI<"pcmpistrm"> ;
6916 // Packed Compare Explicit Length Strings, Return Mask
6917 multiclass pseudo_pcmpestrm<string asm> {
6918 def REG : PseudoI<(outs VR128:$dst),
6919 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
6920 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
6921 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>;
6922 def MEM : PseudoI<(outs VR128:$dst),
6923 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
6924 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128 VR128:$src1, EAX,
6925 (bc_v16i8 (memopv2i64 addr:$src3)), EDX, imm:$src5))]>;
6928 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
6929 defm VPCMPESTRM128 : pseudo_pcmpestrm<"#VPCMPESTRM128">, Requires<[HasAVX]>;
6930 defm PCMPESTRM128 : pseudo_pcmpestrm<"#PCMPESTRM128">, Requires<[UseSSE42]>;
6933 multiclass SS42AI_pcmpestrm<string asm> {
6934 def rr : SS42AI<0x60, MRMSrcReg, (outs),
6935 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
6936 !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
6939 def rm : SS42AI<0x60, MRMSrcMem, (outs),
6940 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
6941 !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
6945 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX], neverHasSideEffects = 1 in {
6946 let Predicates = [HasAVX] in
6947 defm VPCMPESTRM128 : SS42AI_pcmpestrm<"vpcmpestrm">, VEX;
6948 defm PCMPESTRM128 : SS42AI_pcmpestrm<"pcmpestrm">;
6951 // Packed Compare Implicit Length Strings, Return Index
6952 multiclass pseudo_pcmpistri<string asm> {
6953 def REG : PseudoI<(outs GR32:$dst),
6954 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
6955 [(set GR32:$dst, EFLAGS,
6956 (X86pcmpistri VR128:$src1, VR128:$src2, imm:$src3))]>;
6957 def MEM : PseudoI<(outs GR32:$dst),
6958 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
6959 [(set GR32:$dst, EFLAGS, (X86pcmpistri VR128:$src1,
6960 (bc_v16i8 (memopv2i64 addr:$src2)), imm:$src3))]>;
6963 let Defs = [EFLAGS], usesCustomInserter = 1 in {
6964 defm VPCMPISTRI : pseudo_pcmpistri<"#VPCMPISTRI">, Requires<[HasAVX]>;
6965 defm PCMPISTRI : pseudo_pcmpistri<"#PCMPISTRI">, Requires<[UseSSE42]>;
6968 multiclass SS42AI_pcmpistri<string asm> {
6969 def rr : SS42AI<0x63, MRMSrcReg, (outs),
6970 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
6971 !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
6974 def rm : SS42AI<0x63, MRMSrcMem, (outs),
6975 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
6976 !strconcat(asm, "\t{$src3, $src2, $src1|$src1, $src2, $src3}"),
6980 let Defs = [ECX, EFLAGS], neverHasSideEffects = 1 in {
6981 let Predicates = [HasAVX] in
6982 defm VPCMPISTRI : SS42AI_pcmpistri<"vpcmpistri">, VEX;
6983 defm PCMPISTRI : SS42AI_pcmpistri<"pcmpistri">;
6986 // Packed Compare Explicit Length Strings, Return Index
6987 multiclass pseudo_pcmpestri<string asm> {
6988 def REG : PseudoI<(outs GR32:$dst),
6989 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
6990 [(set GR32:$dst, EFLAGS,
6991 (X86pcmpestri VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>;
6992 def MEM : PseudoI<(outs GR32:$dst),
6993 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
6994 [(set GR32:$dst, EFLAGS,
6995 (X86pcmpestri VR128:$src1, EAX, (bc_v16i8 (memopv2i64 addr:$src3)), EDX,
6999 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
7000 defm VPCMPESTRI : pseudo_pcmpestri<"#VPCMPESTRI">, Requires<[HasAVX]>;
7001 defm PCMPESTRI : pseudo_pcmpestri<"#PCMPESTRI">, Requires<[UseSSE42]>;
7004 multiclass SS42AI_pcmpestri<string asm> {
7005 def rr : SS42AI<0x61, MRMSrcReg, (outs),
7006 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
7007 !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
7010 def rm : SS42AI<0x61, MRMSrcMem, (outs),
7011 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
7012 !strconcat(asm, "\t{$src5, $src3, $src1|$src1, $src3, $src5}"),
7016 let Defs = [ECX, EFLAGS], Uses = [EAX, EDX], neverHasSideEffects = 1 in {
7017 let Predicates = [HasAVX] in
7018 defm VPCMPESTRI : SS42AI_pcmpestri<"vpcmpestri">, VEX;
7019 defm PCMPESTRI : SS42AI_pcmpestri<"pcmpestri">;
7022 //===----------------------------------------------------------------------===//
7023 // SSE4.2 - CRC Instructions
7024 //===----------------------------------------------------------------------===//
7026 // No CRC instructions have AVX equivalents
7028 // crc intrinsic instruction
7029 // This set of instructions are only rm, the only difference is the size
7031 let Constraints = "$src1 = $dst" in {
7032 def CRC32r32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
7033 (ins GR32:$src1, i8mem:$src2),
7034 "crc32{b} \t{$src2, $src1|$src1, $src2}",
7036 (int_x86_sse42_crc32_32_8 GR32:$src1,
7037 (load addr:$src2)))]>;
7038 def CRC32r32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
7039 (ins GR32:$src1, GR8:$src2),
7040 "crc32{b} \t{$src2, $src1|$src1, $src2}",
7042 (int_x86_sse42_crc32_32_8 GR32:$src1, GR8:$src2))]>;
7043 def CRC32r32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
7044 (ins GR32:$src1, i16mem:$src2),
7045 "crc32{w} \t{$src2, $src1|$src1, $src2}",
7047 (int_x86_sse42_crc32_32_16 GR32:$src1,
7048 (load addr:$src2)))]>,
7050 def CRC32r32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
7051 (ins GR32:$src1, GR16:$src2),
7052 "crc32{w} \t{$src2, $src1|$src1, $src2}",
7054 (int_x86_sse42_crc32_32_16 GR32:$src1, GR16:$src2))]>,
7056 def CRC32r32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
7057 (ins GR32:$src1, i32mem:$src2),
7058 "crc32{l} \t{$src2, $src1|$src1, $src2}",
7060 (int_x86_sse42_crc32_32_32 GR32:$src1,
7061 (load addr:$src2)))]>;
7062 def CRC32r32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
7063 (ins GR32:$src1, GR32:$src2),
7064 "crc32{l} \t{$src2, $src1|$src1, $src2}",
7066 (int_x86_sse42_crc32_32_32 GR32:$src1, GR32:$src2))]>;
7067 def CRC32r64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
7068 (ins GR64:$src1, i8mem:$src2),
7069 "crc32{b} \t{$src2, $src1|$src1, $src2}",
7071 (int_x86_sse42_crc32_64_8 GR64:$src1,
7072 (load addr:$src2)))]>,
7074 def CRC32r64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
7075 (ins GR64:$src1, GR8:$src2),
7076 "crc32{b} \t{$src2, $src1|$src1, $src2}",
7078 (int_x86_sse42_crc32_64_8 GR64:$src1, GR8:$src2))]>,
7080 def CRC32r64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
7081 (ins GR64:$src1, i64mem:$src2),
7082 "crc32{q} \t{$src2, $src1|$src1, $src2}",
7084 (int_x86_sse42_crc32_64_64 GR64:$src1,
7085 (load addr:$src2)))]>,
7087 def CRC32r64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
7088 (ins GR64:$src1, GR64:$src2),
7089 "crc32{q} \t{$src2, $src1|$src1, $src2}",
7091 (int_x86_sse42_crc32_64_64 GR64:$src1, GR64:$src2))]>,
7095 //===----------------------------------------------------------------------===//
7096 // AES-NI Instructions
7097 //===----------------------------------------------------------------------===//
7099 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
7100 Intrinsic IntId128, bit Is2Addr = 1> {
7101 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
7102 (ins VR128:$src1, VR128:$src2),
7104 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
7105 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
7106 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
7108 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
7109 (ins VR128:$src1, i128mem:$src2),
7111 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
7112 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}")),
7114 (IntId128 VR128:$src1, (memopv2i64 addr:$src2)))]>, OpSize;
7117 // Perform One Round of an AES Encryption/Decryption Flow
7118 let Predicates = [HasAVX, HasAES] in {
7119 defm VAESENC : AESI_binop_rm_int<0xDC, "vaesenc",
7120 int_x86_aesni_aesenc, 0>, VEX_4V;
7121 defm VAESENCLAST : AESI_binop_rm_int<0xDD, "vaesenclast",
7122 int_x86_aesni_aesenclast, 0>, VEX_4V;
7123 defm VAESDEC : AESI_binop_rm_int<0xDE, "vaesdec",
7124 int_x86_aesni_aesdec, 0>, VEX_4V;
7125 defm VAESDECLAST : AESI_binop_rm_int<0xDF, "vaesdeclast",
7126 int_x86_aesni_aesdeclast, 0>, VEX_4V;
7129 let Constraints = "$src1 = $dst" in {
7130 defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
7131 int_x86_aesni_aesenc>;
7132 defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
7133 int_x86_aesni_aesenclast>;
7134 defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
7135 int_x86_aesni_aesdec>;
7136 defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
7137 int_x86_aesni_aesdeclast>;
7140 // Perform the AES InvMixColumn Transformation
7141 let Predicates = [HasAVX, HasAES] in {
7142 def VAESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
7144 "vaesimc\t{$src1, $dst|$dst, $src1}",
7146 (int_x86_aesni_aesimc VR128:$src1))]>,
7148 def VAESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
7149 (ins i128mem:$src1),
7150 "vaesimc\t{$src1, $dst|$dst, $src1}",
7151 [(set VR128:$dst, (int_x86_aesni_aesimc (memopv2i64 addr:$src1)))]>,
7154 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
7156 "aesimc\t{$src1, $dst|$dst, $src1}",
7158 (int_x86_aesni_aesimc VR128:$src1))]>,
7160 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
7161 (ins i128mem:$src1),
7162 "aesimc\t{$src1, $dst|$dst, $src1}",
7163 [(set VR128:$dst, (int_x86_aesni_aesimc (memopv2i64 addr:$src1)))]>,
7166 // AES Round Key Generation Assist
7167 let Predicates = [HasAVX, HasAES] in {
7168 def VAESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
7169 (ins VR128:$src1, i8imm:$src2),
7170 "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7172 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
7174 def VAESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
7175 (ins i128mem:$src1, i8imm:$src2),
7176 "vaeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7178 (int_x86_aesni_aeskeygenassist (memopv2i64 addr:$src1), imm:$src2))]>,
7181 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
7182 (ins VR128:$src1, i8imm:$src2),
7183 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7185 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
7187 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
7188 (ins i128mem:$src1, i8imm:$src2),
7189 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7191 (int_x86_aesni_aeskeygenassist (memopv2i64 addr:$src1), imm:$src2))]>,
7194 //===----------------------------------------------------------------------===//
7195 // PCLMUL Instructions
7196 //===----------------------------------------------------------------------===//
7198 // AVX carry-less Multiplication instructions
7199 def VPCLMULQDQrr : AVXPCLMULIi8<0x44, MRMSrcReg, (outs VR128:$dst),
7200 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
7201 "vpclmulqdq\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7203 (int_x86_pclmulqdq VR128:$src1, VR128:$src2, imm:$src3))]>;
7205 def VPCLMULQDQrm : AVXPCLMULIi8<0x44, MRMSrcMem, (outs VR128:$dst),
7206 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
7207 "vpclmulqdq\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7208 [(set VR128:$dst, (int_x86_pclmulqdq VR128:$src1,
7209 (memopv2i64 addr:$src2), imm:$src3))]>;
7211 // Carry-less Multiplication instructions
7212 let Constraints = "$src1 = $dst" in {
7213 def PCLMULQDQrr : PCLMULIi8<0x44, MRMSrcReg, (outs VR128:$dst),
7214 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
7215 "pclmulqdq\t{$src3, $src2, $dst|$dst, $src2, $src3}",
7217 (int_x86_pclmulqdq VR128:$src1, VR128:$src2, imm:$src3))]>;
7219 def PCLMULQDQrm : PCLMULIi8<0x44, MRMSrcMem, (outs VR128:$dst),
7220 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
7221 "pclmulqdq\t{$src3, $src2, $dst|$dst, $src2, $src3}",
7222 [(set VR128:$dst, (int_x86_pclmulqdq VR128:$src1,
7223 (memopv2i64 addr:$src2), imm:$src3))]>;
7224 } // Constraints = "$src1 = $dst"
7227 multiclass pclmul_alias<string asm, int immop> {
7228 def : InstAlias<!strconcat("pclmul", asm, "dq {$src, $dst|$dst, $src}"),
7229 (PCLMULQDQrr VR128:$dst, VR128:$src, immop)>;
7231 def : InstAlias<!strconcat("pclmul", asm, "dq {$src, $dst|$dst, $src}"),
7232 (PCLMULQDQrm VR128:$dst, i128mem:$src, immop)>;
7234 def : InstAlias<!strconcat("vpclmul", asm,
7235 "dq {$src2, $src1, $dst|$dst, $src1, $src2}"),
7236 (VPCLMULQDQrr VR128:$dst, VR128:$src1, VR128:$src2, immop)>;
7238 def : InstAlias<!strconcat("vpclmul", asm,
7239 "dq {$src2, $src1, $dst|$dst, $src1, $src2}"),
7240 (VPCLMULQDQrm VR128:$dst, VR128:$src1, i128mem:$src2, immop)>;
7242 defm : pclmul_alias<"hqhq", 0x11>;
7243 defm : pclmul_alias<"hqlq", 0x01>;
7244 defm : pclmul_alias<"lqhq", 0x10>;
7245 defm : pclmul_alias<"lqlq", 0x00>;
7247 //===----------------------------------------------------------------------===//
7248 // SSE4A Instructions
7249 //===----------------------------------------------------------------------===//
7251 let Predicates = [HasSSE4A] in {
7253 let Constraints = "$src = $dst" in {
7254 def EXTRQI : Ii8<0x78, MRM0r, (outs VR128:$dst),
7255 (ins VR128:$src, i8imm:$len, i8imm:$idx),
7256 "extrq\t{$idx, $len, $src|$src, $len, $idx}",
7257 [(set VR128:$dst, (int_x86_sse4a_extrqi VR128:$src, imm:$len,
7258 imm:$idx))]>, TB, OpSize;
7259 def EXTRQ : I<0x79, MRMSrcReg, (outs VR128:$dst),
7260 (ins VR128:$src, VR128:$mask),
7261 "extrq\t{$mask, $src|$src, $mask}",
7262 [(set VR128:$dst, (int_x86_sse4a_extrq VR128:$src,
7263 VR128:$mask))]>, TB, OpSize;
7265 def INSERTQI : Ii8<0x78, MRMSrcReg, (outs VR128:$dst),
7266 (ins VR128:$src, VR128:$src2, i8imm:$len, i8imm:$idx),
7267 "insertq\t{$idx, $len, $src2, $src|$src, $src2, $len, $idx}",
7268 [(set VR128:$dst, (int_x86_sse4a_insertqi VR128:$src,
7269 VR128:$src2, imm:$len, imm:$idx))]>, XD;
7270 def INSERTQ : I<0x79, MRMSrcReg, (outs VR128:$dst),
7271 (ins VR128:$src, VR128:$mask),
7272 "insertq\t{$mask, $src|$src, $mask}",
7273 [(set VR128:$dst, (int_x86_sse4a_insertq VR128:$src,
7274 VR128:$mask))]>, XD;
7277 def MOVNTSS : I<0x2B, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
7278 "movntss\t{$src, $dst|$dst, $src}",
7279 [(int_x86_sse4a_movnt_ss addr:$dst, VR128:$src)]>, XS;
7281 def MOVNTSD : I<0x2B, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
7282 "movntsd\t{$src, $dst|$dst, $src}",
7283 [(int_x86_sse4a_movnt_sd addr:$dst, VR128:$src)]>, XD;
7286 //===----------------------------------------------------------------------===//
7288 //===----------------------------------------------------------------------===//
7290 //===----------------------------------------------------------------------===//
7291 // VBROADCAST - Load from memory and broadcast to all elements of the
7292 // destination operand
7294 class avx_broadcast<bits<8> opc, string OpcodeStr, RegisterClass RC,
7295 X86MemOperand x86memop, Intrinsic Int> :
7296 AVX8I<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
7297 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7298 [(set RC:$dst, (Int addr:$src))]>, VEX;
7300 // AVX2 adds register forms
7301 class avx2_broadcast_reg<bits<8> opc, string OpcodeStr, RegisterClass RC,
7303 AVX28I<opc, MRMSrcReg, (outs RC:$dst), (ins VR128:$src),
7304 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7305 [(set RC:$dst, (Int VR128:$src))]>, VEX;
7307 let ExeDomain = SSEPackedSingle in {
7308 def VBROADCASTSSrm : avx_broadcast<0x18, "vbroadcastss", VR128, f32mem,
7309 int_x86_avx_vbroadcast_ss>;
7310 def VBROADCASTSSYrm : avx_broadcast<0x18, "vbroadcastss", VR256, f32mem,
7311 int_x86_avx_vbroadcast_ss_256>, VEX_L;
7313 let ExeDomain = SSEPackedDouble in
7314 def VBROADCASTSDYrm : avx_broadcast<0x19, "vbroadcastsd", VR256, f64mem,
7315 int_x86_avx_vbroadcast_sd_256>, VEX_L;
7316 def VBROADCASTF128 : avx_broadcast<0x1A, "vbroadcastf128", VR256, f128mem,
7317 int_x86_avx_vbroadcastf128_pd_256>, VEX_L;
7319 let ExeDomain = SSEPackedSingle in {
7320 def VBROADCASTSSrr : avx2_broadcast_reg<0x18, "vbroadcastss", VR128,
7321 int_x86_avx2_vbroadcast_ss_ps>;
7322 def VBROADCASTSSYrr : avx2_broadcast_reg<0x18, "vbroadcastss", VR256,
7323 int_x86_avx2_vbroadcast_ss_ps_256>, VEX_L;
7325 let ExeDomain = SSEPackedDouble in
7326 def VBROADCASTSDYrr : avx2_broadcast_reg<0x19, "vbroadcastsd", VR256,
7327 int_x86_avx2_vbroadcast_sd_pd_256>, VEX_L;
7329 let Predicates = [HasAVX2] in
7330 def VBROADCASTI128 : avx_broadcast<0x5A, "vbroadcasti128", VR256, i128mem,
7331 int_x86_avx2_vbroadcasti128>, VEX_L;
7333 let Predicates = [HasAVX] in
7334 def : Pat<(int_x86_avx_vbroadcastf128_ps_256 addr:$src),
7335 (VBROADCASTF128 addr:$src)>;
7338 //===----------------------------------------------------------------------===//
7339 // VINSERTF128 - Insert packed floating-point values
7341 let neverHasSideEffects = 1, ExeDomain = SSEPackedSingle in {
7342 def VINSERTF128rr : AVXAIi8<0x18, MRMSrcReg, (outs VR256:$dst),
7343 (ins VR256:$src1, VR128:$src2, i8imm:$src3),
7344 "vinsertf128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7347 def VINSERTF128rm : AVXAIi8<0x18, MRMSrcMem, (outs VR256:$dst),
7348 (ins VR256:$src1, f128mem:$src2, i8imm:$src3),
7349 "vinsertf128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7353 let Predicates = [HasAVX] in {
7354 def : Pat<(vinsertf128_insert:$ins (v8f32 VR256:$src1), (v4f32 VR128:$src2),
7356 (VINSERTF128rr VR256:$src1, VR128:$src2,
7357 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7358 def : Pat<(vinsertf128_insert:$ins (v4f64 VR256:$src1), (v2f64 VR128:$src2),
7360 (VINSERTF128rr VR256:$src1, VR128:$src2,
7361 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7363 def : Pat<(vinsertf128_insert:$ins (v8f32 VR256:$src1), (memopv4f32 addr:$src2),
7365 (VINSERTF128rm VR256:$src1, addr:$src2,
7366 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7367 def : Pat<(vinsertf128_insert:$ins (v4f64 VR256:$src1), (memopv2f64 addr:$src2),
7369 (VINSERTF128rm VR256:$src1, addr:$src2,
7370 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7373 let Predicates = [HasAVX1Only] in {
7374 def : Pat<(vinsertf128_insert:$ins (v4i64 VR256:$src1), (v2i64 VR128:$src2),
7376 (VINSERTF128rr VR256:$src1, VR128:$src2,
7377 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7378 def : Pat<(vinsertf128_insert:$ins (v8i32 VR256:$src1), (v4i32 VR128:$src2),
7380 (VINSERTF128rr VR256:$src1, VR128:$src2,
7381 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7382 def : Pat<(vinsertf128_insert:$ins (v32i8 VR256:$src1), (v16i8 VR128:$src2),
7384 (VINSERTF128rr VR256:$src1, VR128:$src2,
7385 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7386 def : Pat<(vinsertf128_insert:$ins (v16i16 VR256:$src1), (v8i16 VR128:$src2),
7388 (VINSERTF128rr VR256:$src1, VR128:$src2,
7389 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7391 def : Pat<(vinsertf128_insert:$ins (v4i64 VR256:$src1), (memopv2i64 addr:$src2),
7393 (VINSERTF128rm VR256:$src1, addr:$src2,
7394 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7395 def : Pat<(vinsertf128_insert:$ins (v8i32 VR256:$src1),
7396 (bc_v4i32 (memopv2i64 addr:$src2)),
7398 (VINSERTF128rm VR256:$src1, addr:$src2,
7399 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7400 def : Pat<(vinsertf128_insert:$ins (v32i8 VR256:$src1),
7401 (bc_v16i8 (memopv2i64 addr:$src2)),
7403 (VINSERTF128rm VR256:$src1, addr:$src2,
7404 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7405 def : Pat<(vinsertf128_insert:$ins (v16i16 VR256:$src1),
7406 (bc_v8i16 (memopv2i64 addr:$src2)),
7408 (VINSERTF128rm VR256:$src1, addr:$src2,
7409 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7412 //===----------------------------------------------------------------------===//
7413 // VEXTRACTF128 - Extract packed floating-point values
7415 let neverHasSideEffects = 1, ExeDomain = SSEPackedSingle in {
7416 def VEXTRACTF128rr : AVXAIi8<0x19, MRMDestReg, (outs VR128:$dst),
7417 (ins VR256:$src1, i8imm:$src2),
7418 "vextractf128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7421 def VEXTRACTF128mr : AVXAIi8<0x19, MRMDestMem, (outs),
7422 (ins f128mem:$dst, VR256:$src1, i8imm:$src2),
7423 "vextractf128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7428 let Predicates = [HasAVX] in {
7429 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
7430 (v4f32 (VEXTRACTF128rr
7431 (v8f32 VR256:$src1),
7432 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7433 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
7434 (v2f64 (VEXTRACTF128rr
7435 (v4f64 VR256:$src1),
7436 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7438 def : Pat<(alignedstore (v4f32 (vextractf128_extract:$ext (v8f32 VR256:$src1),
7439 (iPTR imm))), addr:$dst),
7440 (VEXTRACTF128mr addr:$dst, VR256:$src1,
7441 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
7442 def : Pat<(alignedstore (v2f64 (vextractf128_extract:$ext (v4f64 VR256:$src1),
7443 (iPTR imm))), addr:$dst),
7444 (VEXTRACTF128mr addr:$dst, VR256:$src1,
7445 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
7448 let Predicates = [HasAVX1Only] in {
7449 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
7450 (v2i64 (VEXTRACTF128rr
7451 (v4i64 VR256:$src1),
7452 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7453 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
7454 (v4i32 (VEXTRACTF128rr
7455 (v8i32 VR256:$src1),
7456 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7457 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
7458 (v8i16 (VEXTRACTF128rr
7459 (v16i16 VR256:$src1),
7460 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7461 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
7462 (v16i8 (VEXTRACTF128rr
7463 (v32i8 VR256:$src1),
7464 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
7466 def : Pat<(alignedstore (v2i64 (vextractf128_extract:$ext (v4i64 VR256:$src1),
7467 (iPTR imm))), addr:$dst),
7468 (VEXTRACTF128mr addr:$dst, VR256:$src1,
7469 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
7470 def : Pat<(alignedstore (v4i32 (vextractf128_extract:$ext (v8i32 VR256:$src1),
7471 (iPTR imm))), addr:$dst),
7472 (VEXTRACTF128mr addr:$dst, VR256:$src1,
7473 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
7474 def : Pat<(alignedstore (v8i16 (vextractf128_extract:$ext (v16i16 VR256:$src1),
7475 (iPTR imm))), addr:$dst),
7476 (VEXTRACTF128mr addr:$dst, VR256:$src1,
7477 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
7478 def : Pat<(alignedstore (v16i8 (vextractf128_extract:$ext (v32i8 VR256:$src1),
7479 (iPTR imm))), addr:$dst),
7480 (VEXTRACTF128mr addr:$dst, VR256:$src1,
7481 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
7484 //===----------------------------------------------------------------------===//
7485 // VMASKMOV - Conditional SIMD Packed Loads and Stores
7487 multiclass avx_movmask_rm<bits<8> opc_rm, bits<8> opc_mr, string OpcodeStr,
7488 Intrinsic IntLd, Intrinsic IntLd256,
7489 Intrinsic IntSt, Intrinsic IntSt256> {
7490 def rm : AVX8I<opc_rm, MRMSrcMem, (outs VR128:$dst),
7491 (ins VR128:$src1, f128mem:$src2),
7492 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7493 [(set VR128:$dst, (IntLd addr:$src2, VR128:$src1))]>,
7495 def Yrm : AVX8I<opc_rm, MRMSrcMem, (outs VR256:$dst),
7496 (ins VR256:$src1, f256mem:$src2),
7497 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7498 [(set VR256:$dst, (IntLd256 addr:$src2, VR256:$src1))]>,
7500 def mr : AVX8I<opc_mr, MRMDestMem, (outs),
7501 (ins f128mem:$dst, VR128:$src1, VR128:$src2),
7502 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7503 [(IntSt addr:$dst, VR128:$src1, VR128:$src2)]>, VEX_4V;
7504 def Ymr : AVX8I<opc_mr, MRMDestMem, (outs),
7505 (ins f256mem:$dst, VR256:$src1, VR256:$src2),
7506 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7507 [(IntSt256 addr:$dst, VR256:$src1, VR256:$src2)]>, VEX_4V, VEX_L;
7510 let ExeDomain = SSEPackedSingle in
7511 defm VMASKMOVPS : avx_movmask_rm<0x2C, 0x2E, "vmaskmovps",
7512 int_x86_avx_maskload_ps,
7513 int_x86_avx_maskload_ps_256,
7514 int_x86_avx_maskstore_ps,
7515 int_x86_avx_maskstore_ps_256>;
7516 let ExeDomain = SSEPackedDouble in
7517 defm VMASKMOVPD : avx_movmask_rm<0x2D, 0x2F, "vmaskmovpd",
7518 int_x86_avx_maskload_pd,
7519 int_x86_avx_maskload_pd_256,
7520 int_x86_avx_maskstore_pd,
7521 int_x86_avx_maskstore_pd_256>;
7523 //===----------------------------------------------------------------------===//
7524 // VPERMIL - Permute Single and Double Floating-Point Values
7526 multiclass avx_permil<bits<8> opc_rm, bits<8> opc_rmi, string OpcodeStr,
7527 RegisterClass RC, X86MemOperand x86memop_f,
7528 X86MemOperand x86memop_i, PatFrag i_frag,
7529 Intrinsic IntVar, ValueType vt> {
7530 def rr : AVX8I<opc_rm, MRMSrcReg, (outs RC:$dst),
7531 (ins RC:$src1, RC:$src2),
7532 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7533 [(set RC:$dst, (IntVar RC:$src1, RC:$src2))]>, VEX_4V;
7534 def rm : AVX8I<opc_rm, MRMSrcMem, (outs RC:$dst),
7535 (ins RC:$src1, x86memop_i:$src2),
7536 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7537 [(set RC:$dst, (IntVar RC:$src1,
7538 (bitconvert (i_frag addr:$src2))))]>, VEX_4V;
7540 def ri : AVXAIi8<opc_rmi, MRMSrcReg, (outs RC:$dst),
7541 (ins RC:$src1, i8imm:$src2),
7542 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7543 [(set RC:$dst, (vt (X86VPermilp RC:$src1, (i8 imm:$src2))))]>, VEX;
7544 def mi : AVXAIi8<opc_rmi, MRMSrcMem, (outs RC:$dst),
7545 (ins x86memop_f:$src1, i8imm:$src2),
7546 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7548 (vt (X86VPermilp (memop addr:$src1), (i8 imm:$src2))))]>, VEX;
7551 let ExeDomain = SSEPackedSingle in {
7552 defm VPERMILPS : avx_permil<0x0C, 0x04, "vpermilps", VR128, f128mem, i128mem,
7553 memopv2i64, int_x86_avx_vpermilvar_ps, v4f32>;
7554 defm VPERMILPSY : avx_permil<0x0C, 0x04, "vpermilps", VR256, f256mem, i256mem,
7555 memopv4i64, int_x86_avx_vpermilvar_ps_256, v8f32>, VEX_L;
7557 let ExeDomain = SSEPackedDouble in {
7558 defm VPERMILPD : avx_permil<0x0D, 0x05, "vpermilpd", VR128, f128mem, i128mem,
7559 memopv2i64, int_x86_avx_vpermilvar_pd, v2f64>;
7560 defm VPERMILPDY : avx_permil<0x0D, 0x05, "vpermilpd", VR256, f256mem, i256mem,
7561 memopv4i64, int_x86_avx_vpermilvar_pd_256, v4f64>, VEX_L;
7564 let Predicates = [HasAVX] in {
7565 def : Pat<(v8i32 (X86VPermilp VR256:$src1, (i8 imm:$imm))),
7566 (VPERMILPSYri VR256:$src1, imm:$imm)>;
7567 def : Pat<(v4i64 (X86VPermilp VR256:$src1, (i8 imm:$imm))),
7568 (VPERMILPDYri VR256:$src1, imm:$imm)>;
7569 def : Pat<(v8i32 (X86VPermilp (bc_v8i32 (memopv4i64 addr:$src1)),
7571 (VPERMILPSYmi addr:$src1, imm:$imm)>;
7572 def : Pat<(v4i64 (X86VPermilp (memopv4i64 addr:$src1), (i8 imm:$imm))),
7573 (VPERMILPDYmi addr:$src1, imm:$imm)>;
7575 def : Pat<(v2i64 (X86VPermilp VR128:$src1, (i8 imm:$imm))),
7576 (VPERMILPDri VR128:$src1, imm:$imm)>;
7577 def : Pat<(v2i64 (X86VPermilp (memopv2i64 addr:$src1), (i8 imm:$imm))),
7578 (VPERMILPDmi addr:$src1, imm:$imm)>;
7581 //===----------------------------------------------------------------------===//
7582 // VPERM2F128 - Permute Floating-Point Values in 128-bit chunks
7584 let ExeDomain = SSEPackedSingle in {
7585 def VPERM2F128rr : AVXAIi8<0x06, MRMSrcReg, (outs VR256:$dst),
7586 (ins VR256:$src1, VR256:$src2, i8imm:$src3),
7587 "vperm2f128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7588 [(set VR256:$dst, (v8f32 (X86VPerm2x128 VR256:$src1, VR256:$src2,
7589 (i8 imm:$src3))))]>, VEX_4V, VEX_L;
7590 def VPERM2F128rm : AVXAIi8<0x06, MRMSrcMem, (outs VR256:$dst),
7591 (ins VR256:$src1, f256mem:$src2, i8imm:$src3),
7592 "vperm2f128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7593 [(set VR256:$dst, (X86VPerm2x128 VR256:$src1, (memopv8f32 addr:$src2),
7594 (i8 imm:$src3)))]>, VEX_4V, VEX_L;
7597 let Predicates = [HasAVX] in {
7598 def : Pat<(v4f64 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7599 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7600 def : Pat<(v4f64 (X86VPerm2x128 VR256:$src1,
7601 (memopv4f64 addr:$src2), (i8 imm:$imm))),
7602 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7605 let Predicates = [HasAVX1Only] in {
7606 def : Pat<(v8i32 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7607 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7608 def : Pat<(v4i64 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7609 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7610 def : Pat<(v32i8 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7611 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7612 def : Pat<(v16i16 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7613 (VPERM2F128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7615 def : Pat<(v8i32 (X86VPerm2x128 VR256:$src1,
7616 (bc_v8i32 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
7617 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7618 def : Pat<(v4i64 (X86VPerm2x128 VR256:$src1,
7619 (memopv4i64 addr:$src2), (i8 imm:$imm))),
7620 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7621 def : Pat<(v32i8 (X86VPerm2x128 VR256:$src1,
7622 (bc_v32i8 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
7623 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7624 def : Pat<(v16i16 (X86VPerm2x128 VR256:$src1,
7625 (bc_v16i16 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
7626 (VPERM2F128rm VR256:$src1, addr:$src2, imm:$imm)>;
7629 //===----------------------------------------------------------------------===//
7630 // VZERO - Zero YMM registers
7632 let Defs = [YMM0, YMM1, YMM2, YMM3, YMM4, YMM5, YMM6, YMM7,
7633 YMM8, YMM9, YMM10, YMM11, YMM12, YMM13, YMM14, YMM15] in {
7634 // Zero All YMM registers
7635 def VZEROALL : I<0x77, RawFrm, (outs), (ins), "vzeroall",
7636 [(int_x86_avx_vzeroall)]>, TB, VEX, VEX_L, Requires<[HasAVX]>;
7638 // Zero Upper bits of YMM registers
7639 def VZEROUPPER : I<0x77, RawFrm, (outs), (ins), "vzeroupper",
7640 [(int_x86_avx_vzeroupper)]>, TB, VEX, Requires<[HasAVX]>;
7643 //===----------------------------------------------------------------------===//
7644 // Half precision conversion instructions
7645 //===----------------------------------------------------------------------===//
7646 multiclass f16c_ph2ps<RegisterClass RC, X86MemOperand x86memop, Intrinsic Int> {
7647 def rr : I<0x13, MRMSrcReg, (outs RC:$dst), (ins VR128:$src),
7648 "vcvtph2ps\t{$src, $dst|$dst, $src}",
7649 [(set RC:$dst, (Int VR128:$src))]>,
7651 let neverHasSideEffects = 1, mayLoad = 1 in
7652 def rm : I<0x13, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
7653 "vcvtph2ps\t{$src, $dst|$dst, $src}", []>, T8, OpSize, VEX;
7656 multiclass f16c_ps2ph<RegisterClass RC, X86MemOperand x86memop, Intrinsic Int> {
7657 def rr : Ii8<0x1D, MRMDestReg, (outs VR128:$dst),
7658 (ins RC:$src1, i32i8imm:$src2),
7659 "vcvtps2ph\t{$src2, $src1, $dst|$dst, $src1, $src2}",
7660 [(set VR128:$dst, (Int RC:$src1, imm:$src2))]>,
7662 let neverHasSideEffects = 1, mayStore = 1 in
7663 def mr : Ii8<0x1D, MRMDestMem, (outs),
7664 (ins x86memop:$dst, RC:$src1, i32i8imm:$src2),
7665 "vcvtps2ph\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
7669 let Predicates = [HasAVX, HasF16C] in {
7670 defm VCVTPH2PS : f16c_ph2ps<VR128, f64mem, int_x86_vcvtph2ps_128>;
7671 defm VCVTPH2PSY : f16c_ph2ps<VR256, f128mem, int_x86_vcvtph2ps_256>, VEX_L;
7672 defm VCVTPS2PH : f16c_ps2ph<VR128, f64mem, int_x86_vcvtps2ph_128>;
7673 defm VCVTPS2PHY : f16c_ps2ph<VR256, f128mem, int_x86_vcvtps2ph_256>, VEX_L;
7676 //===----------------------------------------------------------------------===//
7677 // AVX2 Instructions
7678 //===----------------------------------------------------------------------===//
7680 /// AVX2_binop_rmi_int - AVX2 binary operator with 8-bit immediate
7681 multiclass AVX2_binop_rmi_int<bits<8> opc, string OpcodeStr,
7682 Intrinsic IntId, RegisterClass RC, PatFrag memop_frag,
7683 X86MemOperand x86memop> {
7684 let isCommutable = 1 in
7685 def rri : AVX2AIi8<opc, MRMSrcReg, (outs RC:$dst),
7686 (ins RC:$src1, RC:$src2, u32u8imm:$src3),
7687 !strconcat(OpcodeStr,
7688 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
7689 [(set RC:$dst, (IntId RC:$src1, RC:$src2, imm:$src3))]>,
7691 def rmi : AVX2AIi8<opc, MRMSrcMem, (outs RC:$dst),
7692 (ins RC:$src1, x86memop:$src2, u32u8imm:$src3),
7693 !strconcat(OpcodeStr,
7694 "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
7697 (bitconvert (memop_frag addr:$src2)), imm:$src3))]>,
7701 let isCommutable = 0 in {
7702 defm VPBLENDD : AVX2_binop_rmi_int<0x02, "vpblendd", int_x86_avx2_pblendd_128,
7703 VR128, memopv2i64, i128mem>;
7704 defm VPBLENDDY : AVX2_binop_rmi_int<0x02, "vpblendd", int_x86_avx2_pblendd_256,
7705 VR256, memopv4i64, i256mem>, VEX_L;
7708 def : Pat<(v4i32 (X86Blendi (v4i32 VR128:$src1), (v4i32 VR128:$src2),
7710 (VPBLENDDrri VR128:$src1, VR128:$src2, imm:$mask)>;
7711 def : Pat<(v8i32 (X86Blendi (v8i32 VR256:$src1), (v8i32 VR256:$src2),
7713 (VPBLENDDYrri VR256:$src1, VR256:$src2, imm:$mask)>;
7715 //===----------------------------------------------------------------------===//
7716 // VPBROADCAST - Load from memory and broadcast to all elements of the
7717 // destination operand
7719 multiclass avx2_broadcast<bits<8> opc, string OpcodeStr,
7720 X86MemOperand x86memop, PatFrag ld_frag,
7721 Intrinsic Int128, Intrinsic Int256> {
7722 def rr : AVX28I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
7723 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7724 [(set VR128:$dst, (Int128 VR128:$src))]>, VEX;
7725 def rm : AVX28I<opc, MRMSrcMem, (outs VR128:$dst), (ins x86memop:$src),
7726 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7728 (Int128 (scalar_to_vector (ld_frag addr:$src))))]>, VEX;
7729 def Yrr : AVX28I<opc, MRMSrcReg, (outs VR256:$dst), (ins VR128:$src),
7730 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7731 [(set VR256:$dst, (Int256 VR128:$src))]>, VEX, VEX_L;
7732 def Yrm : AVX28I<opc, MRMSrcMem, (outs VR256:$dst), (ins x86memop:$src),
7733 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
7735 (Int256 (scalar_to_vector (ld_frag addr:$src))))]>,
7739 defm VPBROADCASTB : avx2_broadcast<0x78, "vpbroadcastb", i8mem, loadi8,
7740 int_x86_avx2_pbroadcastb_128,
7741 int_x86_avx2_pbroadcastb_256>;
7742 defm VPBROADCASTW : avx2_broadcast<0x79, "vpbroadcastw", i16mem, loadi16,
7743 int_x86_avx2_pbroadcastw_128,
7744 int_x86_avx2_pbroadcastw_256>;
7745 defm VPBROADCASTD : avx2_broadcast<0x58, "vpbroadcastd", i32mem, loadi32,
7746 int_x86_avx2_pbroadcastd_128,
7747 int_x86_avx2_pbroadcastd_256>;
7748 defm VPBROADCASTQ : avx2_broadcast<0x59, "vpbroadcastq", i64mem, loadi64,
7749 int_x86_avx2_pbroadcastq_128,
7750 int_x86_avx2_pbroadcastq_256>;
7752 let Predicates = [HasAVX2] in {
7753 def : Pat<(v16i8 (X86VBroadcast (loadi8 addr:$src))),
7754 (VPBROADCASTBrm addr:$src)>;
7755 def : Pat<(v32i8 (X86VBroadcast (loadi8 addr:$src))),
7756 (VPBROADCASTBYrm addr:$src)>;
7757 def : Pat<(v8i16 (X86VBroadcast (loadi16 addr:$src))),
7758 (VPBROADCASTWrm addr:$src)>;
7759 def : Pat<(v16i16 (X86VBroadcast (loadi16 addr:$src))),
7760 (VPBROADCASTWYrm addr:$src)>;
7761 def : Pat<(v4i32 (X86VBroadcast (loadi32 addr:$src))),
7762 (VPBROADCASTDrm addr:$src)>;
7763 def : Pat<(v8i32 (X86VBroadcast (loadi32 addr:$src))),
7764 (VPBROADCASTDYrm addr:$src)>;
7765 def : Pat<(v2i64 (X86VBroadcast (loadi64 addr:$src))),
7766 (VPBROADCASTQrm addr:$src)>;
7767 def : Pat<(v4i64 (X86VBroadcast (loadi64 addr:$src))),
7768 (VPBROADCASTQYrm addr:$src)>;
7770 def : Pat<(v16i8 (X86VBroadcast (v16i8 VR128:$src))),
7771 (VPBROADCASTBrr VR128:$src)>;
7772 def : Pat<(v32i8 (X86VBroadcast (v16i8 VR128:$src))),
7773 (VPBROADCASTBYrr VR128:$src)>;
7774 def : Pat<(v8i16 (X86VBroadcast (v8i16 VR128:$src))),
7775 (VPBROADCASTWrr VR128:$src)>;
7776 def : Pat<(v16i16 (X86VBroadcast (v8i16 VR128:$src))),
7777 (VPBROADCASTWYrr VR128:$src)>;
7778 def : Pat<(v4i32 (X86VBroadcast (v4i32 VR128:$src))),
7779 (VPBROADCASTDrr VR128:$src)>;
7780 def : Pat<(v8i32 (X86VBroadcast (v4i32 VR128:$src))),
7781 (VPBROADCASTDYrr VR128:$src)>;
7782 def : Pat<(v2i64 (X86VBroadcast (v2i64 VR128:$src))),
7783 (VPBROADCASTQrr VR128:$src)>;
7784 def : Pat<(v4i64 (X86VBroadcast (v2i64 VR128:$src))),
7785 (VPBROADCASTQYrr VR128:$src)>;
7786 def : Pat<(v4f32 (X86VBroadcast (v4f32 VR128:$src))),
7787 (VBROADCASTSSrr VR128:$src)>;
7788 def : Pat<(v8f32 (X86VBroadcast (v4f32 VR128:$src))),
7789 (VBROADCASTSSYrr VR128:$src)>;
7790 def : Pat<(v2f64 (X86VBroadcast (v2f64 VR128:$src))),
7791 (VPBROADCASTQrr VR128:$src)>;
7792 def : Pat<(v4f64 (X86VBroadcast (v2f64 VR128:$src))),
7793 (VBROADCASTSDYrr VR128:$src)>;
7795 // Provide fallback in case the load node that is used in the patterns above
7796 // is used by additional users, which prevents the pattern selection.
7797 let AddedComplexity = 20 in {
7798 def : Pat<(v4f32 (X86VBroadcast FR32:$src)),
7799 (VBROADCASTSSrr (COPY_TO_REGCLASS FR32:$src, VR128))>;
7800 def : Pat<(v8f32 (X86VBroadcast FR32:$src)),
7801 (VBROADCASTSSYrr (COPY_TO_REGCLASS FR32:$src, VR128))>;
7802 def : Pat<(v4f64 (X86VBroadcast FR64:$src)),
7803 (VBROADCASTSDYrr (COPY_TO_REGCLASS FR64:$src, VR128))>;
7805 def : Pat<(v4i32 (X86VBroadcast GR32:$src)),
7806 (VBROADCASTSSrr (COPY_TO_REGCLASS GR32:$src, VR128))>;
7807 def : Pat<(v8i32 (X86VBroadcast GR32:$src)),
7808 (VBROADCASTSSYrr (COPY_TO_REGCLASS GR32:$src, VR128))>;
7809 def : Pat<(v4i64 (X86VBroadcast GR64:$src)),
7810 (VBROADCASTSDYrr (COPY_TO_REGCLASS GR64:$src, VR128))>;
7814 // AVX1 broadcast patterns
7815 let Predicates = [HasAVX1Only] in {
7816 def : Pat<(v8i32 (X86VBroadcast (loadi32 addr:$src))),
7817 (VBROADCASTSSYrm addr:$src)>;
7818 def : Pat<(v4i64 (X86VBroadcast (loadi64 addr:$src))),
7819 (VBROADCASTSDYrm addr:$src)>;
7820 def : Pat<(v4i32 (X86VBroadcast (loadi32 addr:$src))),
7821 (VBROADCASTSSrm addr:$src)>;
7824 let Predicates = [HasAVX] in {
7825 def : Pat<(v8f32 (X86VBroadcast (loadf32 addr:$src))),
7826 (VBROADCASTSSYrm addr:$src)>;
7827 def : Pat<(v4f64 (X86VBroadcast (loadf64 addr:$src))),
7828 (VBROADCASTSDYrm addr:$src)>;
7829 def : Pat<(v4f32 (X86VBroadcast (loadf32 addr:$src))),
7830 (VBROADCASTSSrm addr:$src)>;
7832 // Provide fallback in case the load node that is used in the patterns above
7833 // is used by additional users, which prevents the pattern selection.
7834 let AddedComplexity = 20 in {
7835 // 128bit broadcasts:
7836 def : Pat<(v4f32 (X86VBroadcast FR32:$src)),
7837 (VPSHUFDri (COPY_TO_REGCLASS FR32:$src, VR128), 0)>;
7838 def : Pat<(v8f32 (X86VBroadcast FR32:$src)),
7839 (VINSERTF128rr (INSERT_SUBREG (v8f32 (IMPLICIT_DEF)),
7840 (VPSHUFDri (COPY_TO_REGCLASS FR32:$src, VR128), 0), sub_xmm),
7841 (VPSHUFDri (COPY_TO_REGCLASS FR32:$src, VR128), 0), 1)>;
7842 def : Pat<(v4f64 (X86VBroadcast FR64:$src)),
7843 (VINSERTF128rr (INSERT_SUBREG (v4f64 (IMPLICIT_DEF)),
7844 (VPSHUFDri (COPY_TO_REGCLASS FR64:$src, VR128), 0x44), sub_xmm),
7845 (VPSHUFDri (COPY_TO_REGCLASS FR64:$src, VR128), 0x44), 1)>;
7847 def : Pat<(v4i32 (X86VBroadcast GR32:$src)),
7848 (VPSHUFDri (COPY_TO_REGCLASS GR32:$src, VR128), 0)>;
7849 def : Pat<(v8i32 (X86VBroadcast GR32:$src)),
7850 (VINSERTF128rr (INSERT_SUBREG (v8i32 (IMPLICIT_DEF)),
7851 (VPSHUFDri (COPY_TO_REGCLASS GR32:$src, VR128), 0), sub_xmm),
7852 (VPSHUFDri (COPY_TO_REGCLASS GR32:$src, VR128), 0), 1)>;
7853 def : Pat<(v4i64 (X86VBroadcast GR64:$src)),
7854 (VINSERTF128rr (INSERT_SUBREG (v4i64 (IMPLICIT_DEF)),
7855 (VPSHUFDri (COPY_TO_REGCLASS GR64:$src, VR128), 0x44), sub_xmm),
7856 (VPSHUFDri (COPY_TO_REGCLASS GR64:$src, VR128), 0x44), 1)>;
7860 //===----------------------------------------------------------------------===//
7861 // VPERM - Permute instructions
7864 multiclass avx2_perm<bits<8> opc, string OpcodeStr, PatFrag mem_frag,
7866 def Yrr : AVX28I<opc, MRMSrcReg, (outs VR256:$dst),
7867 (ins VR256:$src1, VR256:$src2),
7868 !strconcat(OpcodeStr,
7869 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7871 (OpVT (X86VPermv VR256:$src1, VR256:$src2)))]>,
7873 def Yrm : AVX28I<opc, MRMSrcMem, (outs VR256:$dst),
7874 (ins VR256:$src1, i256mem:$src2),
7875 !strconcat(OpcodeStr,
7876 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7878 (OpVT (X86VPermv VR256:$src1,
7879 (bitconvert (mem_frag addr:$src2)))))]>,
7883 defm VPERMD : avx2_perm<0x36, "vpermd", memopv4i64, v8i32>;
7884 let ExeDomain = SSEPackedSingle in
7885 defm VPERMPS : avx2_perm<0x16, "vpermps", memopv8f32, v8f32>;
7887 multiclass avx2_perm_imm<bits<8> opc, string OpcodeStr, PatFrag mem_frag,
7889 def Yri : AVX2AIi8<opc, MRMSrcReg, (outs VR256:$dst),
7890 (ins VR256:$src1, i8imm:$src2),
7891 !strconcat(OpcodeStr,
7892 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7894 (OpVT (X86VPermi VR256:$src1, (i8 imm:$src2))))]>,
7896 def Ymi : AVX2AIi8<opc, MRMSrcMem, (outs VR256:$dst),
7897 (ins i256mem:$src1, i8imm:$src2),
7898 !strconcat(OpcodeStr,
7899 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
7901 (OpVT (X86VPermi (mem_frag addr:$src1),
7902 (i8 imm:$src2))))]>, VEX, VEX_L;
7905 defm VPERMQ : avx2_perm_imm<0x00, "vpermq", memopv4i64, v4i64>, VEX_W;
7906 let ExeDomain = SSEPackedDouble in
7907 defm VPERMPD : avx2_perm_imm<0x01, "vpermpd", memopv4f64, v4f64>, VEX_W;
7909 //===----------------------------------------------------------------------===//
7910 // VPERM2I128 - Permute Floating-Point Values in 128-bit chunks
7912 def VPERM2I128rr : AVX2AIi8<0x46, MRMSrcReg, (outs VR256:$dst),
7913 (ins VR256:$src1, VR256:$src2, i8imm:$src3),
7914 "vperm2i128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7915 [(set VR256:$dst, (v4i64 (X86VPerm2x128 VR256:$src1, VR256:$src2,
7916 (i8 imm:$src3))))]>, VEX_4V, VEX_L;
7917 def VPERM2I128rm : AVX2AIi8<0x46, MRMSrcMem, (outs VR256:$dst),
7918 (ins VR256:$src1, f256mem:$src2, i8imm:$src3),
7919 "vperm2i128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7920 [(set VR256:$dst, (X86VPerm2x128 VR256:$src1, (memopv4i64 addr:$src2),
7921 (i8 imm:$src3)))]>, VEX_4V, VEX_L;
7923 let Predicates = [HasAVX2] in {
7924 def : Pat<(v8i32 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7925 (VPERM2I128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7926 def : Pat<(v32i8 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7927 (VPERM2I128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7928 def : Pat<(v16i16 (X86VPerm2x128 VR256:$src1, VR256:$src2, (i8 imm:$imm))),
7929 (VPERM2I128rr VR256:$src1, VR256:$src2, imm:$imm)>;
7931 def : Pat<(v32i8 (X86VPerm2x128 VR256:$src1, (bc_v32i8 (memopv4i64 addr:$src2)),
7933 (VPERM2I128rm VR256:$src1, addr:$src2, imm:$imm)>;
7934 def : Pat<(v16i16 (X86VPerm2x128 VR256:$src1,
7935 (bc_v16i16 (memopv4i64 addr:$src2)), (i8 imm:$imm))),
7936 (VPERM2I128rm VR256:$src1, addr:$src2, imm:$imm)>;
7937 def : Pat<(v8i32 (X86VPerm2x128 VR256:$src1, (bc_v8i32 (memopv4i64 addr:$src2)),
7939 (VPERM2I128rm VR256:$src1, addr:$src2, imm:$imm)>;
7943 //===----------------------------------------------------------------------===//
7944 // VINSERTI128 - Insert packed integer values
7946 let neverHasSideEffects = 1 in {
7947 def VINSERTI128rr : AVX2AIi8<0x38, MRMSrcReg, (outs VR256:$dst),
7948 (ins VR256:$src1, VR128:$src2, i8imm:$src3),
7949 "vinserti128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7952 def VINSERTI128rm : AVX2AIi8<0x38, MRMSrcMem, (outs VR256:$dst),
7953 (ins VR256:$src1, i128mem:$src2, i8imm:$src3),
7954 "vinserti128\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
7958 let Predicates = [HasAVX2] in {
7959 def : Pat<(vinsertf128_insert:$ins (v4i64 VR256:$src1), (v2i64 VR128:$src2),
7961 (VINSERTI128rr VR256:$src1, VR128:$src2,
7962 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7963 def : Pat<(vinsertf128_insert:$ins (v8i32 VR256:$src1), (v4i32 VR128:$src2),
7965 (VINSERTI128rr VR256:$src1, VR128:$src2,
7966 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7967 def : Pat<(vinsertf128_insert:$ins (v32i8 VR256:$src1), (v16i8 VR128:$src2),
7969 (VINSERTI128rr VR256:$src1, VR128:$src2,
7970 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7971 def : Pat<(vinsertf128_insert:$ins (v16i16 VR256:$src1), (v8i16 VR128:$src2),
7973 (VINSERTI128rr VR256:$src1, VR128:$src2,
7974 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7976 def : Pat<(vinsertf128_insert:$ins (v4i64 VR256:$src1), (memopv2i64 addr:$src2),
7978 (VINSERTI128rm VR256:$src1, addr:$src2,
7979 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7980 def : Pat<(vinsertf128_insert:$ins (v8i32 VR256:$src1),
7981 (bc_v4i32 (memopv2i64 addr:$src2)),
7983 (VINSERTI128rm VR256:$src1, addr:$src2,
7984 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7985 def : Pat<(vinsertf128_insert:$ins (v32i8 VR256:$src1),
7986 (bc_v16i8 (memopv2i64 addr:$src2)),
7988 (VINSERTI128rm VR256:$src1, addr:$src2,
7989 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7990 def : Pat<(vinsertf128_insert:$ins (v16i16 VR256:$src1),
7991 (bc_v8i16 (memopv2i64 addr:$src2)),
7993 (VINSERTI128rm VR256:$src1, addr:$src2,
7994 (INSERT_get_vinsertf128_imm VR256:$ins))>;
7997 //===----------------------------------------------------------------------===//
7998 // VEXTRACTI128 - Extract packed integer values
8000 def VEXTRACTI128rr : AVX2AIi8<0x39, MRMDestReg, (outs VR128:$dst),
8001 (ins VR256:$src1, i8imm:$src2),
8002 "vextracti128\t{$src2, $src1, $dst|$dst, $src1, $src2}",
8004 (int_x86_avx2_vextracti128 VR256:$src1, imm:$src2))]>,
8006 let neverHasSideEffects = 1, mayStore = 1 in
8007 def VEXTRACTI128mr : AVX2AIi8<0x39, MRMDestMem, (outs),
8008 (ins i128mem:$dst, VR256:$src1, i8imm:$src2),
8009 "vextracti128\t{$src2, $src1, $dst|$dst, $src1, $src2}", []>,
8012 let Predicates = [HasAVX2] in {
8013 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
8014 (v2i64 (VEXTRACTI128rr
8015 (v4i64 VR256:$src1),
8016 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
8017 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
8018 (v4i32 (VEXTRACTI128rr
8019 (v8i32 VR256:$src1),
8020 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
8021 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
8022 (v8i16 (VEXTRACTI128rr
8023 (v16i16 VR256:$src1),
8024 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
8025 def : Pat<(vextractf128_extract:$ext VR256:$src1, (iPTR imm)),
8026 (v16i8 (VEXTRACTI128rr
8027 (v32i8 VR256:$src1),
8028 (EXTRACT_get_vextractf128_imm VR128:$ext)))>;
8030 def : Pat<(alignedstore (v2i64 (vextractf128_extract:$ext (v4i64 VR256:$src1),
8031 (iPTR imm))), addr:$dst),
8032 (VEXTRACTI128mr addr:$dst, VR256:$src1,
8033 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
8034 def : Pat<(alignedstore (v4i32 (vextractf128_extract:$ext (v8i32 VR256:$src1),
8035 (iPTR imm))), addr:$dst),
8036 (VEXTRACTI128mr addr:$dst, VR256:$src1,
8037 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
8038 def : Pat<(alignedstore (v8i16 (vextractf128_extract:$ext (v16i16 VR256:$src1),
8039 (iPTR imm))), addr:$dst),
8040 (VEXTRACTI128mr addr:$dst, VR256:$src1,
8041 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
8042 def : Pat<(alignedstore (v16i8 (vextractf128_extract:$ext (v32i8 VR256:$src1),
8043 (iPTR imm))), addr:$dst),
8044 (VEXTRACTI128mr addr:$dst, VR256:$src1,
8045 (EXTRACT_get_vextractf128_imm VR128:$ext))>;
8048 //===----------------------------------------------------------------------===//
8049 // VPMASKMOV - Conditional SIMD Integer Packed Loads and Stores
8051 multiclass avx2_pmovmask<string OpcodeStr,
8052 Intrinsic IntLd128, Intrinsic IntLd256,
8053 Intrinsic IntSt128, Intrinsic IntSt256> {
8054 def rm : AVX28I<0x8c, MRMSrcMem, (outs VR128:$dst),
8055 (ins VR128:$src1, i128mem:$src2),
8056 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8057 [(set VR128:$dst, (IntLd128 addr:$src2, VR128:$src1))]>, VEX_4V;
8058 def Yrm : AVX28I<0x8c, MRMSrcMem, (outs VR256:$dst),
8059 (ins VR256:$src1, i256mem:$src2),
8060 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8061 [(set VR256:$dst, (IntLd256 addr:$src2, VR256:$src1))]>,
8063 def mr : AVX28I<0x8e, MRMDestMem, (outs),
8064 (ins i128mem:$dst, VR128:$src1, VR128:$src2),
8065 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8066 [(IntSt128 addr:$dst, VR128:$src1, VR128:$src2)]>, VEX_4V;
8067 def Ymr : AVX28I<0x8e, MRMDestMem, (outs),
8068 (ins i256mem:$dst, VR256:$src1, VR256:$src2),
8069 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8070 [(IntSt256 addr:$dst, VR256:$src1, VR256:$src2)]>, VEX_4V, VEX_L;
8073 defm VPMASKMOVD : avx2_pmovmask<"vpmaskmovd",
8074 int_x86_avx2_maskload_d,
8075 int_x86_avx2_maskload_d_256,
8076 int_x86_avx2_maskstore_d,
8077 int_x86_avx2_maskstore_d_256>;
8078 defm VPMASKMOVQ : avx2_pmovmask<"vpmaskmovq",
8079 int_x86_avx2_maskload_q,
8080 int_x86_avx2_maskload_q_256,
8081 int_x86_avx2_maskstore_q,
8082 int_x86_avx2_maskstore_q_256>, VEX_W;
8085 //===----------------------------------------------------------------------===//
8086 // Variable Bit Shifts
8088 multiclass avx2_var_shift<bits<8> opc, string OpcodeStr, SDNode OpNode,
8089 ValueType vt128, ValueType vt256> {
8090 def rr : AVX28I<opc, MRMSrcReg, (outs VR128:$dst),
8091 (ins VR128:$src1, VR128:$src2),
8092 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8094 (vt128 (OpNode VR128:$src1, (vt128 VR128:$src2))))]>,
8096 def rm : AVX28I<opc, MRMSrcMem, (outs VR128:$dst),
8097 (ins VR128:$src1, i128mem:$src2),
8098 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8100 (vt128 (OpNode VR128:$src1,
8101 (vt128 (bitconvert (memopv2i64 addr:$src2))))))]>,
8103 def Yrr : AVX28I<opc, MRMSrcReg, (outs VR256:$dst),
8104 (ins VR256:$src1, VR256:$src2),
8105 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8107 (vt256 (OpNode VR256:$src1, (vt256 VR256:$src2))))]>,
8109 def Yrm : AVX28I<opc, MRMSrcMem, (outs VR256:$dst),
8110 (ins VR256:$src1, i256mem:$src2),
8111 !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
8113 (vt256 (OpNode VR256:$src1,
8114 (vt256 (bitconvert (memopv4i64 addr:$src2))))))]>,
8118 defm VPSLLVD : avx2_var_shift<0x47, "vpsllvd", shl, v4i32, v8i32>;
8119 defm VPSLLVQ : avx2_var_shift<0x47, "vpsllvq", shl, v2i64, v4i64>, VEX_W;
8120 defm VPSRLVD : avx2_var_shift<0x45, "vpsrlvd", srl, v4i32, v8i32>;
8121 defm VPSRLVQ : avx2_var_shift<0x45, "vpsrlvq", srl, v2i64, v4i64>, VEX_W;
8122 defm VPSRAVD : avx2_var_shift<0x46, "vpsravd", sra, v4i32, v8i32>;
8124 //===----------------------------------------------------------------------===//
8125 // VGATHER - GATHER Operations
8126 multiclass avx2_gather<bits<8> opc, string OpcodeStr, RegisterClass RC256,
8127 X86MemOperand memop128, X86MemOperand memop256> {
8128 def rm : AVX28I<opc, MRMSrcMem, (outs VR128:$dst, VR128:$mask_wb),
8129 (ins VR128:$src1, memop128:$src2, VR128:$mask),
8130 !strconcat(OpcodeStr,
8131 "\t{$mask, $src2, $dst|$dst, $src2, $mask}"),
8133 def Yrm : AVX28I<opc, MRMSrcMem, (outs RC256:$dst, RC256:$mask_wb),
8134 (ins RC256:$src1, memop256:$src2, RC256:$mask),
8135 !strconcat(OpcodeStr,
8136 "\t{$mask, $src2, $dst|$dst, $src2, $mask}"),
8137 []>, VEX_4VOp3, VEX_L;
8140 let mayLoad = 1, Constraints = "$src1 = $dst, $mask = $mask_wb" in {
8141 defm VGATHERDPD : avx2_gather<0x92, "vgatherdpd", VR256, vx64mem, vx64mem>, VEX_W;
8142 defm VGATHERQPD : avx2_gather<0x93, "vgatherqpd", VR256, vx64mem, vy64mem>, VEX_W;
8143 defm VGATHERDPS : avx2_gather<0x92, "vgatherdps", VR256, vx32mem, vy32mem>;
8144 defm VGATHERQPS : avx2_gather<0x93, "vgatherqps", VR128, vx32mem, vy32mem>;
8145 defm VPGATHERDQ : avx2_gather<0x90, "vpgatherdq", VR256, vx64mem, vx64mem>, VEX_W;
8146 defm VPGATHERQQ : avx2_gather<0x91, "vpgatherqq", VR256, vx64mem, vy64mem>, VEX_W;
8147 defm VPGATHERDD : avx2_gather<0x90, "vpgatherdd", VR256, vx32mem, vy32mem>;
8148 defm VPGATHERQD : avx2_gather<0x91, "vpgatherqd", VR128, vx32mem, vy32mem>;