1 //====- X86InstrSSE.td - Describe the X86 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 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
18 // SSE specific DAG Nodes.
19 //===----------------------------------------------------------------------===//
21 def SDTX86FPShiftOp : SDTypeProfile<1, 2, [ SDTCisSameAs<0, 1>,
22 SDTCisFP<0>, SDTCisInt<2> ]>;
23 def SDTX86VFCMP : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<1, 2>,
24 SDTCisFP<1>, SDTCisVT<3, i8>]>;
26 def X86fmin : SDNode<"X86ISD::FMIN", SDTFPBinOp>;
27 def X86fmax : SDNode<"X86ISD::FMAX", SDTFPBinOp>;
28 def X86fand : SDNode<"X86ISD::FAND", SDTFPBinOp,
29 [SDNPCommutative, SDNPAssociative]>;
30 def X86for : SDNode<"X86ISD::FOR", SDTFPBinOp,
31 [SDNPCommutative, SDNPAssociative]>;
32 def X86fxor : SDNode<"X86ISD::FXOR", SDTFPBinOp,
33 [SDNPCommutative, SDNPAssociative]>;
34 def X86frsqrt : SDNode<"X86ISD::FRSQRT", SDTFPUnaryOp>;
35 def X86frcp : SDNode<"X86ISD::FRCP", SDTFPUnaryOp>;
36 def X86fsrl : SDNode<"X86ISD::FSRL", SDTX86FPShiftOp>;
37 def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest>;
38 def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest>;
39 def X86pshufb : SDNode<"X86ISD::PSHUFB",
40 SDTypeProfile<1, 2, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
42 def X86pextrb : SDNode<"X86ISD::PEXTRB",
43 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
44 def X86pextrw : SDNode<"X86ISD::PEXTRW",
45 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
46 def X86pinsrb : SDNode<"X86ISD::PINSRB",
47 SDTypeProfile<1, 3, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
48 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
49 def X86pinsrw : SDNode<"X86ISD::PINSRW",
50 SDTypeProfile<1, 3, [SDTCisVT<0, v8i16>, SDTCisSameAs<0,1>,
51 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
52 def X86insrtps : SDNode<"X86ISD::INSERTPS",
53 SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisSameAs<0,1>,
54 SDTCisVT<2, v4f32>, SDTCisPtrTy<3>]>>;
55 def X86vzmovl : SDNode<"X86ISD::VZEXT_MOVL",
56 SDTypeProfile<1, 1, [SDTCisSameAs<0,1>]>>;
57 def X86vzload : SDNode<"X86ISD::VZEXT_LOAD", SDTLoad,
58 [SDNPHasChain, SDNPMayLoad]>;
59 def X86vshl : SDNode<"X86ISD::VSHL", SDTIntShiftOp>;
60 def X86vshr : SDNode<"X86ISD::VSRL", SDTIntShiftOp>;
61 def X86cmpps : SDNode<"X86ISD::CMPPS", SDTX86VFCMP>;
62 def X86cmppd : SDNode<"X86ISD::CMPPD", SDTX86VFCMP>;
63 def X86pcmpeqb : SDNode<"X86ISD::PCMPEQB", SDTIntBinOp, [SDNPCommutative]>;
64 def X86pcmpeqw : SDNode<"X86ISD::PCMPEQW", SDTIntBinOp, [SDNPCommutative]>;
65 def X86pcmpeqd : SDNode<"X86ISD::PCMPEQD", SDTIntBinOp, [SDNPCommutative]>;
66 def X86pcmpeqq : SDNode<"X86ISD::PCMPEQQ", SDTIntBinOp, [SDNPCommutative]>;
67 def X86pcmpgtb : SDNode<"X86ISD::PCMPGTB", SDTIntBinOp>;
68 def X86pcmpgtw : SDNode<"X86ISD::PCMPGTW", SDTIntBinOp>;
69 def X86pcmpgtd : SDNode<"X86ISD::PCMPGTD", SDTIntBinOp>;
70 def X86pcmpgtq : SDNode<"X86ISD::PCMPGTQ", SDTIntBinOp>;
72 def SDTX86CmpPTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>,
75 def X86ptest : SDNode<"X86ISD::PTEST", SDTX86CmpPTest>;
77 //===----------------------------------------------------------------------===//
78 // SSE Complex Patterns
79 //===----------------------------------------------------------------------===//
81 // These are 'extloads' from a scalar to the low element of a vector, zeroing
82 // the top elements. These are used for the SSE 'ss' and 'sd' instruction
84 def sse_load_f32 : ComplexPattern<v4f32, 5, "SelectScalarSSELoad", [],
85 [SDNPHasChain, SDNPMayLoad]>;
86 def sse_load_f64 : ComplexPattern<v2f64, 5, "SelectScalarSSELoad", [],
87 [SDNPHasChain, SDNPMayLoad]>;
89 def ssmem : Operand<v4f32> {
90 let PrintMethod = "printf32mem";
91 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
92 let ParserMatchClass = X86MemAsmOperand;
94 def sdmem : Operand<v2f64> {
95 let PrintMethod = "printf64mem";
96 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
97 let ParserMatchClass = X86MemAsmOperand;
100 //===----------------------------------------------------------------------===//
101 // SSE pattern fragments
102 //===----------------------------------------------------------------------===//
104 def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
105 def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
106 def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
107 def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
109 // Like 'store', but always requires vector alignment.
110 def alignedstore : PatFrag<(ops node:$val, node:$ptr),
111 (store node:$val, node:$ptr), [{
112 return cast<StoreSDNode>(N)->getAlignment() >= 16;
115 // Like 'load', but always requires vector alignment.
116 def alignedload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
117 return cast<LoadSDNode>(N)->getAlignment() >= 16;
120 def alignedloadfsf32 : PatFrag<(ops node:$ptr),
121 (f32 (alignedload node:$ptr))>;
122 def alignedloadfsf64 : PatFrag<(ops node:$ptr),
123 (f64 (alignedload node:$ptr))>;
124 def alignedloadv4f32 : PatFrag<(ops node:$ptr),
125 (v4f32 (alignedload node:$ptr))>;
126 def alignedloadv2f64 : PatFrag<(ops node:$ptr),
127 (v2f64 (alignedload node:$ptr))>;
128 def alignedloadv4i32 : PatFrag<(ops node:$ptr),
129 (v4i32 (alignedload node:$ptr))>;
130 def alignedloadv2i64 : PatFrag<(ops node:$ptr),
131 (v2i64 (alignedload node:$ptr))>;
133 // Like 'load', but uses special alignment checks suitable for use in
134 // memory operands in most SSE instructions, which are required to
135 // be naturally aligned on some targets but not on others. If the subtarget
136 // allows unaligned accesses, match any load, though this may require
137 // setting a feature bit in the processor (on startup, for example).
138 // Opteron 10h and later implement such a feature.
139 def memop : PatFrag<(ops node:$ptr), (load node:$ptr), [{
140 return Subtarget->hasVectorUAMem()
141 || cast<LoadSDNode>(N)->getAlignment() >= 16;
144 def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
145 def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
146 def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
147 def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
148 def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
149 def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
150 def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
152 // SSSE3 uses MMX registers for some instructions. They aren't aligned on a
154 // FIXME: 8 byte alignment for mmx reads is not required
155 def memop64 : PatFrag<(ops node:$ptr), (load node:$ptr), [{
156 return cast<LoadSDNode>(N)->getAlignment() >= 8;
159 def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
160 def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
161 def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
162 def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
165 // Like 'store', but requires the non-temporal bit to be set
166 def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
167 (st node:$val, node:$ptr), [{
168 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
169 return ST->isNonTemporal();
173 def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
174 (st node:$val, node:$ptr), [{
175 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
176 return ST->isNonTemporal() && !ST->isTruncatingStore() &&
177 ST->getAddressingMode() == ISD::UNINDEXED &&
178 ST->getAlignment() >= 16;
182 def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
183 (st node:$val, node:$ptr), [{
184 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
185 return ST->isNonTemporal() &&
186 ST->getAlignment() < 16;
190 def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
191 def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
192 def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
193 def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
194 def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
195 def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
197 def vzmovl_v2i64 : PatFrag<(ops node:$src),
198 (bitconvert (v2i64 (X86vzmovl
199 (v2i64 (scalar_to_vector (loadi64 node:$src))))))>;
200 def vzmovl_v4i32 : PatFrag<(ops node:$src),
201 (bitconvert (v4i32 (X86vzmovl
202 (v4i32 (scalar_to_vector (loadi32 node:$src))))))>;
204 def vzload_v2i64 : PatFrag<(ops node:$src),
205 (bitconvert (v2i64 (X86vzload node:$src)))>;
208 def fp32imm0 : PatLeaf<(f32 fpimm), [{
209 return N->isExactlyValue(+0.0);
212 // BYTE_imm - Transform bit immediates into byte immediates.
213 def BYTE_imm : SDNodeXForm<imm, [{
214 // Transformation function: imm >> 3
215 return getI32Imm(N->getZExtValue() >> 3);
218 // SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
220 def SHUFFLE_get_shuf_imm : SDNodeXForm<vector_shuffle, [{
221 return getI8Imm(X86::getShuffleSHUFImmediate(N));
224 // SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
226 def SHUFFLE_get_pshufhw_imm : SDNodeXForm<vector_shuffle, [{
227 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
230 // SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
232 def SHUFFLE_get_pshuflw_imm : SDNodeXForm<vector_shuffle, [{
233 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
236 // SHUFFLE_get_palign_imm xform function: convert vector_shuffle mask to
238 def SHUFFLE_get_palign_imm : SDNodeXForm<vector_shuffle, [{
239 return getI8Imm(X86::getShufflePALIGNRImmediate(N));
242 def splat_lo : PatFrag<(ops node:$lhs, node:$rhs),
243 (vector_shuffle node:$lhs, node:$rhs), [{
244 ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N);
245 return SVOp->isSplat() && SVOp->getSplatIndex() == 0;
248 def movddup : PatFrag<(ops node:$lhs, node:$rhs),
249 (vector_shuffle node:$lhs, node:$rhs), [{
250 return X86::isMOVDDUPMask(cast<ShuffleVectorSDNode>(N));
253 def movhlps : PatFrag<(ops node:$lhs, node:$rhs),
254 (vector_shuffle node:$lhs, node:$rhs), [{
255 return X86::isMOVHLPSMask(cast<ShuffleVectorSDNode>(N));
258 def movhlps_undef : PatFrag<(ops node:$lhs, node:$rhs),
259 (vector_shuffle node:$lhs, node:$rhs), [{
260 return X86::isMOVHLPS_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
263 def movlhps : PatFrag<(ops node:$lhs, node:$rhs),
264 (vector_shuffle node:$lhs, node:$rhs), [{
265 return X86::isMOVLHPSMask(cast<ShuffleVectorSDNode>(N));
268 def movlp : PatFrag<(ops node:$lhs, node:$rhs),
269 (vector_shuffle node:$lhs, node:$rhs), [{
270 return X86::isMOVLPMask(cast<ShuffleVectorSDNode>(N));
273 def movl : PatFrag<(ops node:$lhs, node:$rhs),
274 (vector_shuffle node:$lhs, node:$rhs), [{
275 return X86::isMOVLMask(cast<ShuffleVectorSDNode>(N));
278 def movshdup : PatFrag<(ops node:$lhs, node:$rhs),
279 (vector_shuffle node:$lhs, node:$rhs), [{
280 return X86::isMOVSHDUPMask(cast<ShuffleVectorSDNode>(N));
283 def movsldup : PatFrag<(ops node:$lhs, node:$rhs),
284 (vector_shuffle node:$lhs, node:$rhs), [{
285 return X86::isMOVSLDUPMask(cast<ShuffleVectorSDNode>(N));
288 def unpckl : PatFrag<(ops node:$lhs, node:$rhs),
289 (vector_shuffle node:$lhs, node:$rhs), [{
290 return X86::isUNPCKLMask(cast<ShuffleVectorSDNode>(N));
293 def unpckh : PatFrag<(ops node:$lhs, node:$rhs),
294 (vector_shuffle node:$lhs, node:$rhs), [{
295 return X86::isUNPCKHMask(cast<ShuffleVectorSDNode>(N));
298 def unpckl_undef : PatFrag<(ops node:$lhs, node:$rhs),
299 (vector_shuffle node:$lhs, node:$rhs), [{
300 return X86::isUNPCKL_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
303 def unpckh_undef : PatFrag<(ops node:$lhs, node:$rhs),
304 (vector_shuffle node:$lhs, node:$rhs), [{
305 return X86::isUNPCKH_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
308 def pshufd : PatFrag<(ops node:$lhs, node:$rhs),
309 (vector_shuffle node:$lhs, node:$rhs), [{
310 return X86::isPSHUFDMask(cast<ShuffleVectorSDNode>(N));
311 }], SHUFFLE_get_shuf_imm>;
313 def shufp : PatFrag<(ops node:$lhs, node:$rhs),
314 (vector_shuffle node:$lhs, node:$rhs), [{
315 return X86::isSHUFPMask(cast<ShuffleVectorSDNode>(N));
316 }], SHUFFLE_get_shuf_imm>;
318 def pshufhw : PatFrag<(ops node:$lhs, node:$rhs),
319 (vector_shuffle node:$lhs, node:$rhs), [{
320 return X86::isPSHUFHWMask(cast<ShuffleVectorSDNode>(N));
321 }], SHUFFLE_get_pshufhw_imm>;
323 def pshuflw : PatFrag<(ops node:$lhs, node:$rhs),
324 (vector_shuffle node:$lhs, node:$rhs), [{
325 return X86::isPSHUFLWMask(cast<ShuffleVectorSDNode>(N));
326 }], SHUFFLE_get_pshuflw_imm>;
328 def palign : PatFrag<(ops node:$lhs, node:$rhs),
329 (vector_shuffle node:$lhs, node:$rhs), [{
330 return X86::isPALIGNRMask(cast<ShuffleVectorSDNode>(N));
331 }], SHUFFLE_get_palign_imm>;
333 //===----------------------------------------------------------------------===//
334 // SSE scalar FP Instructions
335 //===----------------------------------------------------------------------===//
337 // CMOV* - Used to implement the SSE SELECT DAG operation. Expanded after
338 // instruction selection into a branch sequence.
339 let Uses = [EFLAGS], usesCustomInserter = 1 in {
340 def CMOV_FR32 : I<0, Pseudo,
341 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
342 "#CMOV_FR32 PSEUDO!",
343 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
345 def CMOV_FR64 : I<0, Pseudo,
346 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
347 "#CMOV_FR64 PSEUDO!",
348 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
350 def CMOV_V4F32 : I<0, Pseudo,
351 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
352 "#CMOV_V4F32 PSEUDO!",
354 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
356 def CMOV_V2F64 : I<0, Pseudo,
357 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
358 "#CMOV_V2F64 PSEUDO!",
360 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
362 def CMOV_V2I64 : I<0, Pseudo,
363 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
364 "#CMOV_V2I64 PSEUDO!",
366 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
370 //===----------------------------------------------------------------------===//
371 // SSE 1 & 2 Instructions Classes
372 //===----------------------------------------------------------------------===//
374 /// sse12_fp_scalar - SSE 1 & 2 scalar instructions class
375 multiclass sse12_fp_scalar<bits<8> opc, string OpcodeStr, SDNode OpNode,
376 RegisterClass RC, X86MemOperand x86memop> {
377 let isCommutable = 1 in {
378 def rr : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
379 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1, RC:$src2))]>;
381 def rm : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
382 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1, (load addr:$src2)))]>;
385 /// sse12_fp_scalar_int - SSE 1 & 2 scalar instructions intrinsics class
386 multiclass sse12_fp_scalar_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
387 string asm, string SSEVer, string FPSizeStr,
388 Operand memopr, ComplexPattern mem_cpat> {
389 def rr_Int : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
390 asm, [(set RC:$dst, (
391 !nameconcat<Intrinsic>("int_x86_sse",
392 !strconcat(SSEVer, !strconcat("_",
393 !strconcat(OpcodeStr, FPSizeStr))))
394 RC:$src1, RC:$src2))]>;
395 def rm_Int : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, memopr:$src2),
396 asm, [(set RC:$dst, (
397 !nameconcat<Intrinsic>("int_x86_sse",
398 !strconcat(SSEVer, !strconcat("_",
399 !strconcat(OpcodeStr, FPSizeStr))))
400 RC:$src1, mem_cpat:$src2))]>;
403 /// sse12_fp_packed - SSE 1 & 2 packed instructions class
404 multiclass sse12_fp_packed<bits<8> opc, string OpcodeStr, SDNode OpNode,
405 RegisterClass RC, ValueType vt,
406 X86MemOperand x86memop, PatFrag mem_frag,
407 Domain d, bit MayLoad = 0> {
408 let isCommutable = 1 in
409 def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
410 OpcodeStr, [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))],d>;
411 let mayLoad = MayLoad in
412 def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
413 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1,
414 (mem_frag addr:$src2)))],d>;
417 /// sse12_fp_packed_logical_rm - SSE 1 & 2 packed instructions class
418 multiclass sse12_fp_packed_logical_rm<bits<8> opc, RegisterClass RC, Domain d,
419 string OpcodeStr, X86MemOperand x86memop,
420 list<dag> pat_rr, list<dag> pat_rm> {
421 let isCommutable = 1 in
422 def rr : PI<opc, MRMSrcReg, (outs RC:$dst),
423 (ins RC:$src1, RC:$src2), OpcodeStr, pat_rr, d>;
424 def rm : PI<opc, MRMSrcMem, (outs RC:$dst),
425 (ins RC:$src1, x86memop:$src2), OpcodeStr, pat_rm, d>;
428 /// sse12_fp_packed_int - SSE 1 & 2 packed instructions intrinsics class
429 multiclass sse12_fp_packed_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
430 string asm, string SSEVer, string FPSizeStr,
431 X86MemOperand x86memop, PatFrag mem_frag,
433 def rr_Int : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
434 asm, [(set RC:$dst, (
435 !nameconcat<Intrinsic>("int_x86_sse",
436 !strconcat(SSEVer, !strconcat("_",
437 !strconcat(OpcodeStr, FPSizeStr))))
438 RC:$src1, RC:$src2))], d>;
439 def rm_Int : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
440 asm, [(set RC:$dst, (
441 !nameconcat<Intrinsic>("int_x86_sse",
442 !strconcat(SSEVer, !strconcat("_",
443 !strconcat(OpcodeStr, FPSizeStr))))
444 RC:$src1, (mem_frag addr:$src2)))], d>;
447 //===----------------------------------------------------------------------===//
449 //===----------------------------------------------------------------------===//
451 // Conversion Instructions
453 // Match intrinsics which expect XMM operand(s).
454 def CVTSS2SIrr: SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
455 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
456 def CVTSS2SIrm: SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
457 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
459 def CVTDQ2PSrr : PSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
460 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
461 def CVTDQ2PSrm : PSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
462 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
464 // Aliases for intrinsics
465 def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
466 "cvttss2si\t{$src, $dst|$dst, $src}",
468 (int_x86_sse_cvttss2si VR128:$src))]>;
469 def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
470 "cvttss2si\t{$src, $dst|$dst, $src}",
472 (int_x86_sse_cvttss2si(load addr:$src)))]>;
474 let Constraints = "$src1 = $dst" in {
475 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
476 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
477 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
478 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
480 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
481 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
482 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
483 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
484 (loadi32 addr:$src2)))]>;
487 // Compare Instructions
488 let Defs = [EFLAGS] in {
489 def COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
490 "comiss\t{$src2, $src1|$src1, $src2}", []>;
491 def COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
492 "comiss\t{$src2, $src1|$src1, $src2}", []>;
495 //===----------------------------------------------------------------------===//
496 // SSE 1 & 2 - Move Instructions
497 //===----------------------------------------------------------------------===//
499 // Move Instructions. Register-to-register movss/movsd is not used for FR32/64
500 // register copies because it's a partial register update; FsMOVAPSrr/FsMOVAPDrr
501 // is used instead. Register-to-register movss/movsd is not modeled as an
502 // INSERT_SUBREG because INSERT_SUBREG requires that the insert be implementable
503 // in terms of a copy, and just mentioned, we don't use movss/movsd for copies.
504 let Constraints = "$src1 = $dst" in {
505 def MOVSSrr : SSI<0x10, MRMSrcReg,
506 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
507 "movss\t{$src2, $dst|$dst, $src2}",
508 [(set (v4f32 VR128:$dst),
509 (movl VR128:$src1, (scalar_to_vector FR32:$src2)))]>;
510 def MOVSDrr : SDI<0x10, MRMSrcReg,
511 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
512 "movsd\t{$src2, $dst|$dst, $src2}",
513 [(set (v2f64 VR128:$dst),
514 (movl VR128:$src1, (scalar_to_vector FR64:$src2)))]>;
517 // Loading from memory automatically zeroing upper bits.
518 let canFoldAsLoad = 1, isReMaterializable = 1 in {
519 def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
520 "movss\t{$src, $dst|$dst, $src}",
521 [(set FR32:$dst, (loadf32 addr:$src))]>;
522 let AddedComplexity = 20 in
523 def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
524 "movsd\t{$src, $dst|$dst, $src}",
525 [(set FR64:$dst, (loadf64 addr:$src))]>;
528 let AddedComplexity = 15 in {
529 // Extract the low 32-bit value from one vector and insert it into another.
530 def : Pat<(v4f32 (movl VR128:$src1, VR128:$src2)),
531 (MOVSSrr (v4f32 VR128:$src1),
532 (EXTRACT_SUBREG (v4f32 VR128:$src2), sub_ss))>;
533 // Extract the low 64-bit value from one vector and insert it into another.
534 def : Pat<(v2f64 (movl VR128:$src1, VR128:$src2)),
535 (MOVSDrr (v2f64 VR128:$src1),
536 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
539 // Implicitly promote a 32-bit scalar to a vector.
540 def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
541 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss)>;
542 // Implicitly promote a 64-bit scalar to a vector.
543 def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
544 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
546 let AddedComplexity = 20 in {
547 // MOVSSrm zeros the high parts of the register; represent this
548 // with SUBREG_TO_REG.
549 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
550 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
551 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
552 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
553 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
554 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
555 // MOVSDrm zeros the high parts of the register; represent this
556 // with SUBREG_TO_REG.
557 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
558 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
559 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
560 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
561 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
562 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
563 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
564 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
565 def : Pat<(v2f64 (X86vzload addr:$src)),
566 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
569 // Store scalar value to memory.
570 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
571 "movss\t{$src, $dst|$dst, $src}",
572 [(store FR32:$src, addr:$dst)]>;
573 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
574 "movsd\t{$src, $dst|$dst, $src}",
575 [(store FR64:$src, addr:$dst)]>;
577 // Extract and store.
578 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
581 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
582 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
585 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
587 //===----------------------------------------------------------------------===//
588 // SSE 1 & 2 - Conversion Instructions
589 //===----------------------------------------------------------------------===//
591 // Conversion instructions
592 def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
593 "cvttss2si\t{$src, $dst|$dst, $src}",
594 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
595 def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
596 "cvttss2si\t{$src, $dst|$dst, $src}",
597 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
598 def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
599 "cvttsd2si\t{$src, $dst|$dst, $src}",
600 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
601 def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
602 "cvttsd2si\t{$src, $dst|$dst, $src}",
603 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
605 def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
606 "cvtsi2ss\t{$src, $dst|$dst, $src}",
607 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
608 def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
609 "cvtsi2ss\t{$src, $dst|$dst, $src}",
610 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
611 def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
612 "cvtsi2sd\t{$src, $dst|$dst, $src}",
613 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
614 def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
615 "cvtsi2sd\t{$src, $dst|$dst, $src}",
616 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
618 // Match intrinsics which expect XMM operand(s).
619 def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
620 "cvtss2si\t{$src, $dst|$dst, $src}",
621 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
622 def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
623 "cvtss2si\t{$src, $dst|$dst, $src}",
624 [(set GR32:$dst, (int_x86_sse_cvtss2si
625 (load addr:$src)))]>;
626 def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
627 "cvtsd2si\t{$src, $dst|$dst, $src}",
628 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
629 def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
630 "cvtsd2si\t{$src, $dst|$dst, $src}",
631 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
632 (load addr:$src)))]>;
634 // Match intrinsics which expect MM and XMM operand(s).
635 def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
636 "cvtps2pi\t{$src, $dst|$dst, $src}",
637 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
638 def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
639 "cvtps2pi\t{$src, $dst|$dst, $src}",
640 [(set VR64:$dst, (int_x86_sse_cvtps2pi
641 (load addr:$src)))]>;
642 def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
643 "cvtpd2pi\t{$src, $dst|$dst, $src}",
644 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
645 def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
646 "cvtpd2pi\t{$src, $dst|$dst, $src}",
647 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
648 (memop addr:$src)))]>;
650 // Match intrinsics which expect MM and XMM operand(s).
651 def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
652 "cvttps2pi\t{$src, $dst|$dst, $src}",
653 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
654 def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
655 "cvttps2pi\t{$src, $dst|$dst, $src}",
656 [(set VR64:$dst, (int_x86_sse_cvttps2pi
657 (load addr:$src)))]>;
658 def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
659 "cvttpd2pi\t{$src, $dst|$dst, $src}",
660 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
661 def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
662 "cvttpd2pi\t{$src, $dst|$dst, $src}",
663 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
664 (memop addr:$src)))]>;
666 let Constraints = "$src1 = $dst" in {
667 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
668 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
669 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
670 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
672 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
673 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
674 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
675 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
676 (load addr:$src2)))]>;
679 //===----------------------------------------------------------------------===//
680 // SSE 1 & 2 - Compare Instructions
681 //===----------------------------------------------------------------------===//
683 // Comparison instructions
684 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
685 def CMPSSrr : SSIi8<0xC2, MRMSrcReg,
686 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
687 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
689 def CMPSSrm : SSIi8<0xC2, MRMSrcMem,
690 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
691 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
693 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
694 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
695 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
697 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
698 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
699 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
701 // Accept explicit immediate argument form instead of comparison code.
702 let isAsmParserOnly = 1 in {
703 def CMPSSrr_alt : SSIi8<0xC2, MRMSrcReg,
704 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, i8imm:$src2),
705 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
707 def CMPSSrm_alt : SSIi8<0xC2, MRMSrcMem,
708 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, i8imm:$src2),
709 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
711 def CMPSDrr_alt : SDIi8<0xC2, MRMSrcReg,
712 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, i8imm:$src2),
713 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
715 def CMPSDrm_alt : SDIi8<0xC2, MRMSrcMem,
716 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, i8imm:$src2),
717 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
721 let Defs = [EFLAGS] in {
722 def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
723 "ucomiss\t{$src2, $src1|$src1, $src2}",
724 [(set EFLAGS, (X86cmp FR32:$src1, FR32:$src2))]>;
725 def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
726 "ucomiss\t{$src2, $src1|$src1, $src2}",
727 [(set EFLAGS, (X86cmp FR32:$src1, (loadf32 addr:$src2)))]>;
728 def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
729 "ucomisd\t{$src2, $src1|$src1, $src2}",
730 [(set EFLAGS, (X86cmp FR64:$src1, FR64:$src2))]>;
731 def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
732 "ucomisd\t{$src2, $src1|$src1, $src2}",
733 [(set EFLAGS, (X86cmp FR64:$src1, (loadf64 addr:$src2)))]>;
736 // Aliases to match intrinsics which expect XMM operand(s).
737 let Constraints = "$src1 = $dst" in {
738 def Int_CMPSSrr : SSIi8<0xC2, MRMSrcReg,
740 (ins VR128:$src1, VR128:$src, SSECC:$cc),
741 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
742 [(set VR128:$dst, (int_x86_sse_cmp_ss
744 VR128:$src, imm:$cc))]>;
745 def Int_CMPSSrm : SSIi8<0xC2, MRMSrcMem,
747 (ins VR128:$src1, f32mem:$src, SSECC:$cc),
748 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
749 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
750 (load addr:$src), imm:$cc))]>;
752 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
754 (ins VR128:$src1, VR128:$src, SSECC:$cc),
755 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
756 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
757 VR128:$src, imm:$cc))]>;
758 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
760 (ins VR128:$src1, f64mem:$src, SSECC:$cc),
761 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
762 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
763 (load addr:$src), imm:$cc))]>;
766 let Defs = [EFLAGS] in {
767 def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
768 "ucomiss\t{$src2, $src1|$src1, $src2}",
769 [(set EFLAGS, (X86ucomi (v4f32 VR128:$src1),
771 def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
772 "ucomiss\t{$src2, $src1|$src1, $src2}",
773 [(set EFLAGS, (X86ucomi (v4f32 VR128:$src1),
774 (load addr:$src2)))]>;
775 def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
776 "ucomisd\t{$src2, $src1|$src1, $src2}",
777 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
779 def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
780 "ucomisd\t{$src2, $src1|$src1, $src2}",
781 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
782 (load addr:$src2)))]>;
784 def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
785 "comiss\t{$src2, $src1|$src1, $src2}",
786 [(set EFLAGS, (X86comi (v4f32 VR128:$src1),
788 def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
789 "comiss\t{$src2, $src1|$src1, $src2}",
790 [(set EFLAGS, (X86comi (v4f32 VR128:$src1),
791 (load addr:$src2)))]>;
792 def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
793 "comisd\t{$src2, $src1|$src1, $src2}",
794 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
796 def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
797 "comisd\t{$src2, $src1|$src1, $src2}",
798 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
799 (load addr:$src2)))]>;
802 // Aliases of packed SSE1 & SSE2 instructions for scalar use. These all have
803 // names that start with 'Fs'.
805 // Alias instructions that map fld0 to pxor for sse.
806 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
807 canFoldAsLoad = 1 in {
808 // FIXME: Set encoding to pseudo!
809 def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins), "",
810 [(set FR32:$dst, fp32imm0)]>,
811 Requires<[HasSSE1]>, TB, OpSize;
812 def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
813 [(set FR64:$dst, fpimm0)]>,
814 Requires<[HasSSE2]>, TB, OpSize;
817 // Alias instruction to do FR32 or FR64 reg-to-reg copy using movaps. Upper
818 // bits are disregarded.
819 let neverHasSideEffects = 1 in {
820 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
821 "movaps\t{$src, $dst|$dst, $src}", []>;
822 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
823 "movapd\t{$src, $dst|$dst, $src}", []>;
826 // Alias instruction to load FR32 or FR64 from f128mem using movaps. Upper
827 // bits are disregarded.
828 let canFoldAsLoad = 1, isReMaterializable = 1 in {
829 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
830 "movaps\t{$src, $dst|$dst, $src}",
831 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
832 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
833 "movapd\t{$src, $dst|$dst, $src}",
834 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
837 /// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
839 multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
840 SDNode OpNode, bit MayLoad = 0> {
841 let isAsmParserOnly = 1 in {
842 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
843 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR32,
844 f32, f128mem, memopfsf32, SSEPackedSingle, MayLoad>, VEX_4V;
846 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
847 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR64,
848 f64, f128mem, memopfsf64, SSEPackedDouble, MayLoad>, OpSize,
852 let Constraints = "$src1 = $dst" in {
853 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
854 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, FR32, f32,
855 f128mem, memopfsf32, SSEPackedSingle, MayLoad>, TB;
857 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
858 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, FR64, f64,
859 f128mem, memopfsf64, SSEPackedDouble, MayLoad>, TB, OpSize;
863 // Alias bitwise logical operations using SSE logical ops on packed FP values.
864 defm FsAND : sse12_fp_alias_pack_logical<0x54, "and", X86fand>;
865 defm FsOR : sse12_fp_alias_pack_logical<0x56, "or", X86for>;
866 defm FsXOR : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor>;
868 let neverHasSideEffects = 1, Pattern = []<dag>, isCommutable = 0 in
869 defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef, 1>;
871 /// basic_sse12_fp_binop_rm - SSE 1 & 2 binops come in both scalar and
874 /// In addition, we also have a special variant of the scalar form here to
875 /// represent the associated intrinsic operation. This form is unlike the
876 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
877 /// and leaves the top elements unmodified (therefore these cannot be commuted).
879 /// These three forms can each be reg+reg or reg+mem, so there are a total of
880 /// six "instructions".
882 multiclass basic_sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
885 let isAsmParserOnly = 1 in {
886 defm V#NAME#SS : sse12_fp_scalar<opc,
887 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
888 OpNode, FR32, f32mem>, XS, VEX_4V;
890 defm V#NAME#SD : sse12_fp_scalar<opc,
891 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
892 OpNode, FR64, f64mem>, XD, VEX_4V;
894 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
895 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
896 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
899 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
900 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
901 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
904 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
905 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
906 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
908 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
909 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
910 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
913 let Constraints = "$src1 = $dst" in {
914 defm SS : sse12_fp_scalar<opc,
915 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
916 OpNode, FR32, f32mem>, XS;
918 defm SD : sse12_fp_scalar<opc,
919 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
920 OpNode, FR64, f64mem>, XD;
922 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
923 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
924 f128mem, memopv4f32, SSEPackedSingle>, TB;
926 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
927 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
928 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
930 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
931 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
932 "", "_ss", ssmem, sse_load_f32>, XS;
934 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
935 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
936 "2", "_sd", sdmem, sse_load_f64>, XD;
940 // Arithmetic instructions
941 defm ADD : basic_sse12_fp_binop_rm<0x58, "add", fadd>;
942 defm MUL : basic_sse12_fp_binop_rm<0x59, "mul", fmul>;
944 let isCommutable = 0 in {
945 defm SUB : basic_sse12_fp_binop_rm<0x5C, "sub", fsub>;
946 defm DIV : basic_sse12_fp_binop_rm<0x5E, "div", fdiv>;
949 /// sse12_fp_binop_rm - Other SSE 1 & 2 binops
951 /// This multiclass is like basic_sse12_fp_binop_rm, with the addition of
952 /// instructions for a full-vector intrinsic form. Operations that map
953 /// onto C operators don't use this form since they just use the plain
954 /// vector form instead of having a separate vector intrinsic form.
956 /// This provides a total of eight "instructions".
958 multiclass sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
961 let isAsmParserOnly = 1 in {
962 // Scalar operation, reg+reg.
963 defm V#NAME#SS : sse12_fp_scalar<opc,
964 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
965 OpNode, FR32, f32mem>, XS, VEX_4V;
967 defm V#NAME#SD : sse12_fp_scalar<opc,
968 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
969 OpNode, FR64, f64mem>, XD, VEX_4V;
971 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
972 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
973 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
976 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
977 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
978 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
981 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
982 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
983 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
985 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
986 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
987 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
989 defm V#NAME#PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
990 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
991 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, VEX_4V;
993 defm V#NAME#PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
994 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
995 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, OpSize,
999 let Constraints = "$src1 = $dst" in {
1000 // Scalar operation, reg+reg.
1001 defm SS : sse12_fp_scalar<opc,
1002 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1003 OpNode, FR32, f32mem>, XS;
1004 defm SD : sse12_fp_scalar<opc,
1005 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1006 OpNode, FR64, f64mem>, XD;
1007 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1008 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
1009 f128mem, memopv4f32, SSEPackedSingle>, TB;
1011 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1012 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
1013 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1015 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1016 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1017 "", "_ss", ssmem, sse_load_f32>, XS;
1019 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1020 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1021 "2", "_sd", sdmem, sse_load_f64>, XD;
1023 defm PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1024 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1025 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, TB;
1027 defm PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1028 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1029 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1033 let isCommutable = 0 in {
1034 defm MAX : sse12_fp_binop_rm<0x5F, "max", X86fmax>;
1035 defm MIN : sse12_fp_binop_rm<0x5D, "min", X86fmin>;
1038 //===----------------------------------------------------------------------===//
1039 // SSE packed FP Instructions
1041 // Move Instructions
1042 let neverHasSideEffects = 1 in
1043 def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1044 "movaps\t{$src, $dst|$dst, $src}", []>;
1045 let canFoldAsLoad = 1, isReMaterializable = 1 in
1046 def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1047 "movaps\t{$src, $dst|$dst, $src}",
1048 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
1050 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1051 "movaps\t{$src, $dst|$dst, $src}",
1052 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
1054 let neverHasSideEffects = 1 in
1055 def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1056 "movups\t{$src, $dst|$dst, $src}", []>;
1057 let canFoldAsLoad = 1, isReMaterializable = 1 in
1058 def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1059 "movups\t{$src, $dst|$dst, $src}",
1060 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
1061 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1062 "movups\t{$src, $dst|$dst, $src}",
1063 [(store (v4f32 VR128:$src), addr:$dst)]>;
1065 // Intrinsic forms of MOVUPS load and store
1066 let canFoldAsLoad = 1, isReMaterializable = 1 in
1067 def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1068 "movups\t{$src, $dst|$dst, $src}",
1069 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
1070 def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1071 "movups\t{$src, $dst|$dst, $src}",
1072 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
1074 let Constraints = "$src1 = $dst" in {
1075 let AddedComplexity = 20 in {
1076 def MOVLPSrm : PSI<0x12, MRMSrcMem,
1077 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1078 "movlps\t{$src2, $dst|$dst, $src2}",
1081 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
1082 def MOVHPSrm : PSI<0x16, MRMSrcMem,
1083 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1084 "movhps\t{$src2, $dst|$dst, $src2}",
1086 (movlhps VR128:$src1,
1087 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
1088 } // AddedComplexity
1089 } // Constraints = "$src1 = $dst"
1092 def : Pat<(movlhps VR128:$src1, (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
1093 (MOVHPSrm (v4i32 VR128:$src1), addr:$src2)>;
1095 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1096 "movlps\t{$src, $dst|$dst, $src}",
1097 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
1098 (iPTR 0))), addr:$dst)]>;
1100 // v2f64 extract element 1 is always custom lowered to unpack high to low
1101 // and extract element 0 so the non-store version isn't too horrible.
1102 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1103 "movhps\t{$src, $dst|$dst, $src}",
1104 [(store (f64 (vector_extract
1105 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
1106 (undef)), (iPTR 0))), addr:$dst)]>;
1108 let Constraints = "$src1 = $dst" in {
1109 let AddedComplexity = 20 in {
1110 def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
1111 (ins VR128:$src1, VR128:$src2),
1112 "movlhps\t{$src2, $dst|$dst, $src2}",
1114 (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
1116 def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
1117 (ins VR128:$src1, VR128:$src2),
1118 "movhlps\t{$src2, $dst|$dst, $src2}",
1120 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
1121 } // AddedComplexity
1122 } // Constraints = "$src1 = $dst"
1124 let AddedComplexity = 20 in {
1125 def : Pat<(v4f32 (movddup VR128:$src, (undef))),
1126 (MOVLHPSrr (v4f32 VR128:$src), (v4f32 VR128:$src))>;
1127 def : Pat<(v2i64 (movddup VR128:$src, (undef))),
1128 (MOVLHPSrr (v2i64 VR128:$src), (v2i64 VR128:$src))>;
1135 /// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
1137 /// In addition, we also have a special variant of the scalar form here to
1138 /// represent the associated intrinsic operation. This form is unlike the
1139 /// plain scalar form, in that it takes an entire vector (instead of a
1140 /// scalar) and leaves the top elements undefined.
1142 /// And, we have a special variant form for a full-vector intrinsic form.
1144 /// These four forms can each have a reg or a mem operand, so there are a
1145 /// total of eight "instructions".
1147 multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
1151 bit Commutable = 0> {
1152 // Scalar operation, reg.
1153 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1154 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1155 [(set FR32:$dst, (OpNode FR32:$src))]> {
1156 let isCommutable = Commutable;
1159 // Scalar operation, mem.
1160 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
1161 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1162 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
1163 Requires<[HasSSE1, OptForSize]>;
1165 // Vector operation, reg.
1166 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1167 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1168 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
1169 let isCommutable = Commutable;
1172 // Vector operation, mem.
1173 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1174 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1175 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
1177 // Intrinsic operation, reg.
1178 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1179 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1180 [(set VR128:$dst, (F32Int VR128:$src))]> {
1181 let isCommutable = Commutable;
1184 // Intrinsic operation, mem.
1185 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
1186 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1187 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1189 // Vector intrinsic operation, reg
1190 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1191 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1192 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
1193 let isCommutable = Commutable;
1196 // Vector intrinsic operation, mem
1197 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1198 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1199 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
1203 defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
1204 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
1206 // Reciprocal approximations. Note that these typically require refinement
1207 // in order to obtain suitable precision.
1208 defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
1209 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
1210 defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
1211 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
1213 /// sse12_fp_packed_logical - SSE 1 & 2 packed FP logical ops
1215 multiclass sse12_fp_packed_logical<bits<8> opc, string OpcodeStr,
1216 SDNode OpNode, int HasPat = 0,
1217 list<list<dag>> Pattern = []> {
1218 let isAsmParserOnly = 1 in {
1219 defm V#NAME#PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1220 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1222 !if(HasPat, Pattern[0], // rr
1223 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1225 !if(HasPat, Pattern[2], // rm
1226 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1227 (memopv2i64 addr:$src2)))])>,
1230 defm V#NAME#PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1231 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1233 !if(HasPat, Pattern[1], // rr
1234 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1237 !if(HasPat, Pattern[3], // rm
1238 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1239 (memopv2i64 addr:$src2)))])>,
1242 let Constraints = "$src1 = $dst" in {
1243 defm PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1244 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"), f128mem,
1245 !if(HasPat, Pattern[0], // rr
1246 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1248 !if(HasPat, Pattern[2], // rm
1249 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1250 (memopv2i64 addr:$src2)))])>, TB;
1252 defm PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1253 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"), f128mem,
1254 !if(HasPat, Pattern[1], // rr
1255 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1258 !if(HasPat, Pattern[3], // rm
1259 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1260 (memopv2i64 addr:$src2)))])>,
1266 defm AND : sse12_fp_packed_logical<0x54, "and", and>;
1267 defm OR : sse12_fp_packed_logical<0x56, "or", or>;
1268 defm XOR : sse12_fp_packed_logical<0x57, "xor", xor>;
1269 let isCommutable = 0 in
1270 defm ANDN : sse12_fp_packed_logical<0x55, "andn", undef /* dummy */, 1, [
1272 [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
1273 (bc_v2i64 (v4i32 immAllOnesV))),
1276 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1277 (bc_v2i64 (v2f64 VR128:$src2))))],
1279 [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1280 (bc_v2i64 (v4i32 immAllOnesV))),
1281 (memopv2i64 addr:$src2))))],
1283 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1284 (memopv2i64 addr:$src2)))]]>;
1286 let Constraints = "$src1 = $dst" in {
1287 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
1288 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1289 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1290 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
1291 VR128:$src, imm:$cc))]>;
1292 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
1293 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1294 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1295 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
1296 (memop addr:$src), imm:$cc))]>;
1297 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
1298 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1299 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1300 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1301 VR128:$src, imm:$cc))]>;
1302 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
1303 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1304 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1305 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1306 (memop addr:$src), imm:$cc))]>;
1308 // Accept explicit immediate argument form instead of comparison code.
1309 let isAsmParserOnly = 1 in {
1310 def CMPPSrri_alt : PSIi8<0xC2, MRMSrcReg,
1311 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1312 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1313 def CMPPSrmi_alt : PSIi8<0xC2, MRMSrcMem,
1314 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1315 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1316 def CMPPDrri_alt : PDIi8<0xC2, MRMSrcReg,
1317 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1318 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1319 def CMPPDrmi_alt : PDIi8<0xC2, MRMSrcMem,
1320 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1321 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1324 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
1325 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
1326 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
1327 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
1328 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
1329 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
1330 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
1331 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
1333 // Shuffle and unpack instructions
1334 let Constraints = "$src1 = $dst" in {
1335 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
1336 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
1337 (outs VR128:$dst), (ins VR128:$src1,
1338 VR128:$src2, i8imm:$src3),
1339 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1341 (v4f32 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
1342 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
1343 (outs VR128:$dst), (ins VR128:$src1,
1344 f128mem:$src2, i8imm:$src3),
1345 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1348 VR128:$src1, (memopv4f32 addr:$src2))))]>;
1349 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
1350 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1351 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1353 (v2f64 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
1354 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
1355 (outs VR128:$dst), (ins VR128:$src1,
1356 f128mem:$src2, i8imm:$src3),
1357 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1360 VR128:$src1, (memopv2f64 addr:$src2))))]>;
1362 let AddedComplexity = 10 in {
1363 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
1364 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1365 "unpckhps\t{$src2, $dst|$dst, $src2}",
1367 (v4f32 (unpckh VR128:$src1, VR128:$src2)))]>;
1368 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
1369 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1370 "unpckhps\t{$src2, $dst|$dst, $src2}",
1372 (v4f32 (unpckh VR128:$src1,
1373 (memopv4f32 addr:$src2))))]>;
1375 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
1376 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1377 "unpcklps\t{$src2, $dst|$dst, $src2}",
1379 (v4f32 (unpckl VR128:$src1, VR128:$src2)))]>;
1380 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
1381 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1382 "unpcklps\t{$src2, $dst|$dst, $src2}",
1384 (unpckl VR128:$src1, (memopv4f32 addr:$src2)))]>;
1385 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
1386 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1387 "unpckhpd\t{$src2, $dst|$dst, $src2}",
1389 (v2f64 (unpckh VR128:$src1, VR128:$src2)))]>;
1390 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
1391 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1392 "unpckhpd\t{$src2, $dst|$dst, $src2}",
1394 (v2f64 (unpckh VR128:$src1,
1395 (memopv2f64 addr:$src2))))]>;
1397 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
1398 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1399 "unpcklpd\t{$src2, $dst|$dst, $src2}",
1401 (v2f64 (unpckl VR128:$src1, VR128:$src2)))]>;
1402 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
1403 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
1404 "unpcklpd\t{$src2, $dst|$dst, $src2}",
1406 (unpckl VR128:$src1, (memopv2f64 addr:$src2)))]>;
1407 } // AddedComplexity
1408 } // Constraints = "$src1 = $dst"
1411 def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1412 "movmskps\t{$src, $dst|$dst, $src}",
1413 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
1414 def MOVMSKPDrr : PDI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1415 "movmskpd\t{$src, $dst|$dst, $src}",
1416 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
1418 // Prefetch intrinsic.
1419 def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
1420 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
1421 def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
1422 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
1423 def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
1424 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
1425 def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
1426 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
1428 // Non-temporal stores
1429 def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1430 "movntps\t{$src, $dst|$dst, $src}",
1431 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
1433 let AddedComplexity = 400 in { // Prefer non-temporal versions
1434 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1435 "movntps\t{$src, $dst|$dst, $src}",
1436 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1438 def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1439 "movntdq\t{$src, $dst|$dst, $src}",
1440 [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
1442 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1443 "movnti\t{$src, $dst|$dst, $src}",
1444 [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
1445 TB, Requires<[HasSSE2]>;
1447 def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1448 "movnti\t{$src, $dst|$dst, $src}",
1449 [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
1450 TB, Requires<[HasSSE2]>;
1453 // Load, store, and memory fence
1454 def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
1455 TB, Requires<[HasSSE1]>;
1458 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
1459 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
1460 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
1461 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
1463 // Alias instructions that map zero vector to pxor / xorp* for sse.
1464 // We set canFoldAsLoad because this can be converted to a constant-pool
1465 // load of an all-zeros value if folding it would be beneficial.
1466 // FIXME: Change encoding to pseudo!
1467 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
1468 isCodeGenOnly = 1 in {
1469 def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1470 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
1471 def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1472 [(set VR128:$dst, (v2f64 immAllZerosV))]>;
1473 let ExeDomain = SSEPackedInt in
1474 def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
1475 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
1478 def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
1479 def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
1480 def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
1482 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
1483 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1485 //===---------------------------------------------------------------------===//
1486 // SSE2 Instructions
1487 //===---------------------------------------------------------------------===//
1489 // Conversion instructions
1490 def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
1491 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1492 [(set FR32:$dst, (fround FR64:$src))]>;
1493 def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
1494 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1495 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
1496 Requires<[HasSSE2, OptForSize]>;
1498 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1499 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1500 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1501 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1502 def COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1503 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1504 def COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1505 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1507 // SSE2 instructions with XS prefix
1508 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
1509 "cvtss2sd\t{$src, $dst|$dst, $src}",
1510 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1511 Requires<[HasSSE2]>;
1512 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
1513 "cvtss2sd\t{$src, $dst|$dst, $src}",
1514 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1515 Requires<[HasSSE2, OptForSize]>;
1517 def : Pat<(extloadf32 addr:$src),
1518 (CVTSS2SDrr (MOVSSrm addr:$src))>,
1519 Requires<[HasSSE2, OptForSpeed]>;
1521 // Match intrinsics which expect MM and XMM operand(s).
1522 def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1523 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1524 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1525 def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1526 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1527 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
1528 (load addr:$src)))]>;
1530 // Aliases for intrinsics
1531 def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1532 "cvttsd2si\t{$src, $dst|$dst, $src}",
1534 (int_x86_sse2_cvttsd2si VR128:$src))]>;
1535 def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
1536 "cvttsd2si\t{$src, $dst|$dst, $src}",
1537 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1538 (load addr:$src)))]>;
1540 //===---------------------------------------------------------------------===//
1541 // SSE packed FP Instructions
1543 // Move Instructions
1544 let neverHasSideEffects = 1 in
1545 def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1546 "movapd\t{$src, $dst|$dst, $src}", []>;
1547 let canFoldAsLoad = 1, isReMaterializable = 1 in
1548 def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1549 "movapd\t{$src, $dst|$dst, $src}",
1550 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
1552 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1553 "movapd\t{$src, $dst|$dst, $src}",
1554 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
1556 let neverHasSideEffects = 1 in
1557 def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1558 "movupd\t{$src, $dst|$dst, $src}", []>;
1559 let canFoldAsLoad = 1 in
1560 def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1561 "movupd\t{$src, $dst|$dst, $src}",
1562 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
1563 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1564 "movupd\t{$src, $dst|$dst, $src}",
1565 [(store (v2f64 VR128:$src), addr:$dst)]>;
1567 // Intrinsic forms of MOVUPD load and store
1568 def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1569 "movupd\t{$src, $dst|$dst, $src}",
1570 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
1571 def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1572 "movupd\t{$src, $dst|$dst, $src}",
1573 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
1575 let Constraints = "$src1 = $dst" in {
1576 let AddedComplexity = 20 in {
1577 def MOVLPDrm : PDI<0x12, MRMSrcMem,
1578 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1579 "movlpd\t{$src2, $dst|$dst, $src2}",
1581 (v2f64 (movlp VR128:$src1,
1582 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1583 def MOVHPDrm : PDI<0x16, MRMSrcMem,
1584 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1585 "movhpd\t{$src2, $dst|$dst, $src2}",
1587 (v2f64 (movlhps VR128:$src1,
1588 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1589 } // AddedComplexity
1590 } // Constraints = "$src1 = $dst"
1592 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1593 "movlpd\t{$src, $dst|$dst, $src}",
1594 [(store (f64 (vector_extract (v2f64 VR128:$src),
1595 (iPTR 0))), addr:$dst)]>;
1597 // v2f64 extract element 1 is always custom lowered to unpack high to low
1598 // and extract element 0 so the non-store version isn't too horrible.
1599 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1600 "movhpd\t{$src, $dst|$dst, $src}",
1601 [(store (f64 (vector_extract
1602 (v2f64 (unpckh VR128:$src, (undef))),
1603 (iPTR 0))), addr:$dst)]>;
1605 // SSE2 instructions without OpSize prefix
1606 def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1607 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1608 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1609 TB, Requires<[HasSSE2]>;
1610 def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1611 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1612 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1613 (bitconvert (memopv2i64 addr:$src))))]>,
1614 TB, Requires<[HasSSE2]>;
1616 // SSE2 instructions with XS prefix
1617 def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1618 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1619 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1620 XS, Requires<[HasSSE2]>;
1621 def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1622 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1623 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1624 (bitconvert (memopv2i64 addr:$src))))]>,
1625 XS, Requires<[HasSSE2]>;
1627 def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1628 "cvtps2dq\t{$src, $dst|$dst, $src}",
1629 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
1630 def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1631 "cvtps2dq\t{$src, $dst|$dst, $src}",
1632 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1633 (memop addr:$src)))]>;
1634 // SSE2 packed instructions with XS prefix
1635 def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1636 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1637 def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1638 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1640 def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1641 "cvttps2dq\t{$src, $dst|$dst, $src}",
1643 (int_x86_sse2_cvttps2dq VR128:$src))]>,
1644 XS, Requires<[HasSSE2]>;
1645 def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1646 "cvttps2dq\t{$src, $dst|$dst, $src}",
1647 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1648 (memop addr:$src)))]>,
1649 XS, Requires<[HasSSE2]>;
1651 // SSE2 packed instructions with XD prefix
1652 def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1653 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1654 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1655 XD, Requires<[HasSSE2]>;
1656 def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1657 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1658 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1659 (memop addr:$src)))]>,
1660 XD, Requires<[HasSSE2]>;
1662 def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1663 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1664 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
1665 def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
1666 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1667 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1668 (memop addr:$src)))]>;
1670 // SSE2 instructions without OpSize prefix
1671 def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1672 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1673 def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1674 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1676 def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1677 "cvtps2pd\t{$src, $dst|$dst, $src}",
1678 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1679 TB, Requires<[HasSSE2]>;
1680 def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1681 "cvtps2pd\t{$src, $dst|$dst, $src}",
1682 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1683 (load addr:$src)))]>,
1684 TB, Requires<[HasSSE2]>;
1686 def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1687 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1688 def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1689 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1692 def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1693 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1694 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
1695 def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1696 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1697 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1698 (memop addr:$src)))]>;
1700 // Match intrinsics which expect XMM operand(s).
1701 // Aliases for intrinsics
1702 let Constraints = "$src1 = $dst" in {
1703 def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
1704 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
1705 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1706 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1708 def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
1709 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
1710 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1711 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1712 (loadi32 addr:$src2)))]>;
1713 def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
1714 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1715 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1716 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1718 def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
1719 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1720 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1721 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1722 (load addr:$src2)))]>;
1723 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
1724 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1725 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1726 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1727 VR128:$src2))]>, XS,
1728 Requires<[HasSSE2]>;
1729 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
1730 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
1731 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1732 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1733 (load addr:$src2)))]>, XS,
1734 Requires<[HasSSE2]>;
1739 /// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1741 /// In addition, we also have a special variant of the scalar form here to
1742 /// represent the associated intrinsic operation. This form is unlike the
1743 /// plain scalar form, in that it takes an entire vector (instead of a
1744 /// scalar) and leaves the top elements undefined.
1746 /// And, we have a special variant form for a full-vector intrinsic form.
1748 /// These four forms can each have a reg or a mem operand, so there are a
1749 /// total of eight "instructions".
1751 multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1755 bit Commutable = 0> {
1756 // Scalar operation, reg.
1757 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1758 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1759 [(set FR64:$dst, (OpNode FR64:$src))]> {
1760 let isCommutable = Commutable;
1763 // Scalar operation, mem.
1764 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1765 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1766 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1768 // Vector operation, reg.
1769 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1770 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1771 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1772 let isCommutable = Commutable;
1775 // Vector operation, mem.
1776 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1777 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1778 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
1780 // Intrinsic operation, reg.
1781 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1782 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1783 [(set VR128:$dst, (F64Int VR128:$src))]> {
1784 let isCommutable = Commutable;
1787 // Intrinsic operation, mem.
1788 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1789 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1790 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1792 // Vector intrinsic operation, reg
1793 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1794 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1795 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1796 let isCommutable = Commutable;
1799 // Vector intrinsic operation, mem
1800 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1801 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1802 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
1806 defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1807 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1809 // There is no f64 version of the reciprocal approximation instructions.
1811 //===---------------------------------------------------------------------===//
1812 // SSE integer instructions
1813 let ExeDomain = SSEPackedInt in {
1815 // Move Instructions
1816 let neverHasSideEffects = 1 in
1817 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1818 "movdqa\t{$src, $dst|$dst, $src}", []>;
1819 let canFoldAsLoad = 1, mayLoad = 1 in
1820 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1821 "movdqa\t{$src, $dst|$dst, $src}",
1822 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
1824 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1825 "movdqa\t{$src, $dst|$dst, $src}",
1826 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
1827 let canFoldAsLoad = 1, mayLoad = 1 in
1828 def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1829 "movdqu\t{$src, $dst|$dst, $src}",
1830 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
1831 XS, Requires<[HasSSE2]>;
1833 def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1834 "movdqu\t{$src, $dst|$dst, $src}",
1835 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
1836 XS, Requires<[HasSSE2]>;
1838 // Intrinsic forms of MOVDQU load and store
1839 let canFoldAsLoad = 1 in
1840 def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1841 "movdqu\t{$src, $dst|$dst, $src}",
1842 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1843 XS, Requires<[HasSSE2]>;
1844 def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1845 "movdqu\t{$src, $dst|$dst, $src}",
1846 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1847 XS, Requires<[HasSSE2]>;
1849 let Constraints = "$src1 = $dst" in {
1851 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1852 bit Commutable = 0> {
1853 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1854 (ins VR128:$src1, VR128:$src2),
1855 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1856 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1857 let isCommutable = Commutable;
1859 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1860 (ins VR128:$src1, i128mem:$src2),
1861 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1862 [(set VR128:$dst, (IntId VR128:$src1,
1863 (bitconvert (memopv2i64
1867 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1869 Intrinsic IntId, Intrinsic IntId2> {
1870 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1871 (ins VR128:$src1, VR128:$src2),
1872 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1873 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
1874 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1875 (ins VR128:$src1, i128mem:$src2),
1876 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1877 [(set VR128:$dst, (IntId VR128:$src1,
1878 (bitconvert (memopv2i64 addr:$src2))))]>;
1879 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
1880 (ins VR128:$src1, i32i8imm:$src2),
1881 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1882 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1885 /// PDI_binop_rm - Simple SSE2 binary operator.
1886 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1887 ValueType OpVT, bit Commutable = 0> {
1888 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1889 (ins VR128:$src1, VR128:$src2),
1890 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1891 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1892 let isCommutable = Commutable;
1894 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1895 (ins VR128:$src1, i128mem:$src2),
1896 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1897 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
1898 (bitconvert (memopv2i64 addr:$src2)))))]>;
1901 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1903 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1904 /// to collapse (bitconvert VT to VT) into its operand.
1906 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1907 bit Commutable = 0> {
1908 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1909 (ins VR128:$src1, VR128:$src2),
1910 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1911 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1912 let isCommutable = Commutable;
1914 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1915 (ins VR128:$src1, i128mem:$src2),
1916 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1917 [(set VR128:$dst, (OpNode VR128:$src1,
1918 (memopv2i64 addr:$src2)))]>;
1921 } // Constraints = "$src1 = $dst"
1922 } // ExeDomain = SSEPackedInt
1924 // 128-bit Integer Arithmetic
1926 defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1927 defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1928 defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1929 defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1931 defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1932 defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1933 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1934 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1936 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1937 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1938 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1939 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1941 defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1942 defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1943 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1944 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1946 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1948 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1949 defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1950 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1952 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1954 defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1955 defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1958 defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1959 defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1960 defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1961 defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
1962 defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
1965 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
1966 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
1967 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
1968 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
1969 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
1970 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
1972 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
1973 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
1974 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
1975 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
1976 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
1977 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
1979 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
1980 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
1981 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
1982 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
1984 // 128-bit logical shifts.
1985 let Constraints = "$src1 = $dst", neverHasSideEffects = 1,
1986 ExeDomain = SSEPackedInt in {
1987 def PSLLDQri : PDIi8<0x73, MRM7r,
1988 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
1989 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
1990 def PSRLDQri : PDIi8<0x73, MRM3r,
1991 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
1992 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
1993 // PSRADQri doesn't exist in SSE[1-3].
1996 let Predicates = [HasSSE2] in {
1997 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
1998 (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
1999 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2000 (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2001 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2002 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2003 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2004 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
2005 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2006 (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2008 // Shift up / down and insert zero's.
2009 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
2010 (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2011 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
2012 (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2016 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2017 defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
2018 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2020 let Constraints = "$src1 = $dst", ExeDomain = SSEPackedInt in {
2021 def PANDNrr : PDI<0xDF, MRMSrcReg,
2022 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2023 "pandn\t{$src2, $dst|$dst, $src2}",
2024 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2027 def PANDNrm : PDI<0xDF, MRMSrcMem,
2028 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2029 "pandn\t{$src2, $dst|$dst, $src2}",
2030 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2031 (memopv2i64 addr:$src2))))]>;
2034 // SSE2 Integer comparison
2035 defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2036 defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2037 defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2038 defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2039 defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2040 defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2042 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
2043 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
2044 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
2045 (PCMPEQBrm VR128:$src1, addr:$src2)>;
2046 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
2047 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
2048 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
2049 (PCMPEQWrm VR128:$src1, addr:$src2)>;
2050 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
2051 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
2052 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
2053 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2055 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
2056 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
2057 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
2058 (PCMPGTBrm VR128:$src1, addr:$src2)>;
2059 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
2060 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
2061 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
2062 (PCMPGTWrm VR128:$src1, addr:$src2)>;
2063 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
2064 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
2065 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
2066 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2069 // Pack instructions
2070 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2071 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2072 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2074 let ExeDomain = SSEPackedInt in {
2076 // Shuffle and unpack instructions
2077 let AddedComplexity = 5 in {
2078 def PSHUFDri : PDIi8<0x70, MRMSrcReg,
2079 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2080 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2081 [(set VR128:$dst, (v4i32 (pshufd:$src2
2082 VR128:$src1, (undef))))]>;
2083 def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
2084 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2085 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2086 [(set VR128:$dst, (v4i32 (pshufd:$src2
2087 (bc_v4i32 (memopv2i64 addr:$src1)),
2091 // SSE2 with ImmT == Imm8 and XS prefix.
2092 def PSHUFHWri : Ii8<0x70, MRMSrcReg,
2093 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2094 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2095 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2097 XS, Requires<[HasSSE2]>;
2098 def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
2099 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2100 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2101 [(set VR128:$dst, (v8i16 (pshufhw:$src2
2102 (bc_v8i16 (memopv2i64 addr:$src1)),
2104 XS, Requires<[HasSSE2]>;
2106 // SSE2 with ImmT == Imm8 and XD prefix.
2107 def PSHUFLWri : Ii8<0x70, MRMSrcReg,
2108 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2109 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2110 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2112 XD, Requires<[HasSSE2]>;
2113 def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
2114 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2115 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2116 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2117 (bc_v8i16 (memopv2i64 addr:$src1)),
2119 XD, Requires<[HasSSE2]>;
2121 // Unpack instructions
2122 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2123 PatFrag unp_frag, PatFrag bc_frag> {
2124 def rr : PDI<opc, MRMSrcReg,
2125 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2126 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2127 [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2128 def rm : PDI<opc, MRMSrcMem,
2129 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2130 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2131 [(set VR128:$dst, (unp_frag VR128:$src1,
2132 (bc_frag (memopv2i64
2136 let Constraints = "$src1 = $dst" in {
2137 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2138 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2139 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2141 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2142 /// knew to collapse (bitconvert VT to VT) into its operand.
2143 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2144 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2145 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2147 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
2148 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2149 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2150 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2152 (v2i64 (unpckl VR128:$src1,
2153 (memopv2i64 addr:$src2))))]>;
2155 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2156 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2157 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2159 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2160 /// knew to collapse (bitconvert VT to VT) into its operand.
2161 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2162 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2163 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2165 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
2166 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2167 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2168 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2170 (v2i64 (unpckh VR128:$src1,
2171 (memopv2i64 addr:$src2))))]>;
2175 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
2176 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2177 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2178 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2180 let Constraints = "$src1 = $dst" in {
2181 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
2182 (outs VR128:$dst), (ins VR128:$src1,
2183 GR32:$src2, i32i8imm:$src3),
2184 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2186 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
2187 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
2188 (outs VR128:$dst), (ins VR128:$src1,
2189 i16mem:$src2, i32i8imm:$src3),
2190 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2192 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2197 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2198 "pmovmskb\t{$src, $dst|$dst, $src}",
2199 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2201 // Conditional store
2203 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2204 "maskmovdqu\t{$mask, $src|$src, $mask}",
2205 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
2208 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2209 "maskmovdqu\t{$mask, $src|$src, $mask}",
2210 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2212 } // ExeDomain = SSEPackedInt
2214 // Non-temporal stores
2215 def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2216 "movntpd\t{$src, $dst|$dst, $src}",
2217 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
2218 let ExeDomain = SSEPackedInt in
2219 def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2220 "movntdq\t{$src, $dst|$dst, $src}",
2221 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2222 def MOVNTImr_Int : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2223 "movnti\t{$src, $dst|$dst, $src}",
2224 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2225 TB, Requires<[HasSSE2]>;
2227 let AddedComplexity = 400 in { // Prefer non-temporal versions
2228 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2229 "movntpd\t{$src, $dst|$dst, $src}",
2230 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
2232 let ExeDomain = SSEPackedInt in
2233 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2234 "movntdq\t{$src, $dst|$dst, $src}",
2235 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
2239 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
2240 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
2241 TB, Requires<[HasSSE2]>;
2243 // Load, store, and memory fence
2244 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
2245 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
2246 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
2247 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2249 // Pause. This "instruction" is encoded as "rep; nop", so even though it
2250 // was introduced with SSE2, it's backward compatible.
2251 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
2253 //TODO: custom lower this so as to never even generate the noop
2254 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2256 def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2257 def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
2258 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2261 // Alias instructions that map zero vector to pxor / xorp* for sse.
2262 // We set canFoldAsLoad because this can be converted to a constant-pool
2263 // load of an all-ones value if folding it would be beneficial.
2264 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
2265 isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
2266 // FIXME: Change encoding to pseudo.
2267 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
2268 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
2270 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2271 "movd\t{$src, $dst|$dst, $src}",
2273 (v4i32 (scalar_to_vector GR32:$src)))]>;
2274 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2275 "movd\t{$src, $dst|$dst, $src}",
2277 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2279 def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2280 "movd\t{$src, $dst|$dst, $src}",
2281 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2283 def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2284 "movd\t{$src, $dst|$dst, $src}",
2285 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2287 // SSE2 instructions with XS prefix
2288 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2289 "movq\t{$src, $dst|$dst, $src}",
2291 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2292 Requires<[HasSSE2]>;
2293 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2294 "movq\t{$src, $dst|$dst, $src}",
2295 [(store (i64 (vector_extract (v2i64 VR128:$src),
2296 (iPTR 0))), addr:$dst)]>;
2298 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
2299 (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
2301 def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2302 "movd\t{$src, $dst|$dst, $src}",
2303 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2305 def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
2306 "movd\t{$src, $dst|$dst, $src}",
2307 [(store (i32 (vector_extract (v4i32 VR128:$src),
2308 (iPTR 0))), addr:$dst)]>;
2310 def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2311 "movd\t{$src, $dst|$dst, $src}",
2312 [(set GR32:$dst, (bitconvert FR32:$src))]>;
2313 def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2314 "movd\t{$src, $dst|$dst, $src}",
2315 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2317 // Store / copy lower 64-bits of a XMM register.
2318 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2319 "movq\t{$src, $dst|$dst, $src}",
2320 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2322 // movd / movq to XMM register zero-extends
2323 let AddedComplexity = 15 in {
2324 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2325 "movd\t{$src, $dst|$dst, $src}",
2326 [(set VR128:$dst, (v4i32 (X86vzmovl
2327 (v4i32 (scalar_to_vector GR32:$src)))))]>;
2328 // This is X86-64 only.
2329 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2330 "mov{d|q}\t{$src, $dst|$dst, $src}",
2331 [(set VR128:$dst, (v2i64 (X86vzmovl
2332 (v2i64 (scalar_to_vector GR64:$src)))))]>;
2335 let AddedComplexity = 20 in {
2336 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2337 "movd\t{$src, $dst|$dst, $src}",
2339 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2340 (loadi32 addr:$src))))))]>;
2342 def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2343 (MOVZDI2PDIrm addr:$src)>;
2344 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2345 (MOVZDI2PDIrm addr:$src)>;
2346 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2347 (MOVZDI2PDIrm addr:$src)>;
2349 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2350 "movq\t{$src, $dst|$dst, $src}",
2352 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2353 (loadi64 addr:$src))))))]>, XS,
2354 Requires<[HasSSE2]>;
2356 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2357 (MOVZQI2PQIrm addr:$src)>;
2358 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2359 (MOVZQI2PQIrm addr:$src)>;
2360 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
2363 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2364 // IA32 document. movq xmm1, xmm2 does clear the high bits.
2365 let AddedComplexity = 15 in
2366 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2367 "movq\t{$src, $dst|$dst, $src}",
2368 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2369 XS, Requires<[HasSSE2]>;
2371 let AddedComplexity = 20 in {
2372 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2373 "movq\t{$src, $dst|$dst, $src}",
2374 [(set VR128:$dst, (v2i64 (X86vzmovl
2375 (loadv2i64 addr:$src))))]>,
2376 XS, Requires<[HasSSE2]>;
2378 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2379 (MOVZPQILo2PQIrm addr:$src)>;
2382 // Instructions for the disassembler
2383 // xr = XMM register
2386 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2387 "movq\t{$src, $dst|$dst, $src}", []>, XS;
2389 //===---------------------------------------------------------------------===//
2390 // SSE3 Instructions
2391 //===---------------------------------------------------------------------===//
2393 // Conversion Instructions
2394 def CVTPD2DQrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2395 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2396 def CVTPD2DQrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2397 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2398 def CVTDQ2PDrm : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2399 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2400 def CVTDQ2PDrr : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2401 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2403 // Move Instructions
2404 def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2405 "movshdup\t{$src, $dst|$dst, $src}",
2406 [(set VR128:$dst, (v4f32 (movshdup
2407 VR128:$src, (undef))))]>;
2408 def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2409 "movshdup\t{$src, $dst|$dst, $src}",
2410 [(set VR128:$dst, (movshdup
2411 (memopv4f32 addr:$src), (undef)))]>;
2413 def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2414 "movsldup\t{$src, $dst|$dst, $src}",
2415 [(set VR128:$dst, (v4f32 (movsldup
2416 VR128:$src, (undef))))]>;
2417 def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2418 "movsldup\t{$src, $dst|$dst, $src}",
2419 [(set VR128:$dst, (movsldup
2420 (memopv4f32 addr:$src), (undef)))]>;
2422 def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2423 "movddup\t{$src, $dst|$dst, $src}",
2424 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
2425 def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2426 "movddup\t{$src, $dst|$dst, $src}",
2428 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2431 def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2433 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2435 let AddedComplexity = 5 in {
2436 def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
2437 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2438 def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2439 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2440 def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2441 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2442 def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2443 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2447 let Constraints = "$src1 = $dst" in {
2448 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
2449 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2450 "addsubps\t{$src2, $dst|$dst, $src2}",
2451 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2453 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
2454 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2455 "addsubps\t{$src2, $dst|$dst, $src2}",
2456 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2457 (memop addr:$src2)))]>;
2458 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
2459 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2460 "addsubpd\t{$src2, $dst|$dst, $src2}",
2461 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2463 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
2464 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2465 "addsubpd\t{$src2, $dst|$dst, $src2}",
2466 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2467 (memop addr:$src2)))]>;
2470 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2471 "lddqu\t{$src, $dst|$dst, $src}",
2472 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2475 class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2476 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2477 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2478 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2479 class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2480 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2481 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2482 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
2483 class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2484 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2485 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2486 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2487 class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2488 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2489 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2490 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
2492 let Constraints = "$src1 = $dst" in {
2493 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2494 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2495 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2496 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2497 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2498 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2499 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2500 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2503 // Thread synchronization
2504 def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
2505 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
2506 def MWAIT : I<0x01, MRM_C9, (outs), (ins), "mwait",
2507 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2509 // vector_shuffle v1, <undef> <1, 1, 3, 3>
2510 let AddedComplexity = 15 in
2511 def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
2512 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2513 let AddedComplexity = 20 in
2514 def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2515 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2517 // vector_shuffle v1, <undef> <0, 0, 2, 2>
2518 let AddedComplexity = 15 in
2519 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
2520 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2521 let AddedComplexity = 20 in
2522 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2523 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2525 //===---------------------------------------------------------------------===//
2526 // SSSE3 Instructions
2527 //===---------------------------------------------------------------------===//
2529 /// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
2530 multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2531 Intrinsic IntId64, Intrinsic IntId128> {
2532 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2533 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2534 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2536 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2537 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2539 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2541 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2543 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2544 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2547 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2549 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2552 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
2555 /// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
2556 multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2557 Intrinsic IntId64, Intrinsic IntId128> {
2558 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2560 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2561 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2563 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2565 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2568 (bitconvert (memopv4i16 addr:$src))))]>;
2570 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2572 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2573 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2576 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2578 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2581 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
2584 /// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
2585 multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2586 Intrinsic IntId64, Intrinsic IntId128> {
2587 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2589 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2590 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2592 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2594 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2597 (bitconvert (memopv2i32 addr:$src))))]>;
2599 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2601 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2602 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2605 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2607 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2610 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
2613 defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2614 int_x86_ssse3_pabs_b,
2615 int_x86_ssse3_pabs_b_128>;
2616 defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2617 int_x86_ssse3_pabs_w,
2618 int_x86_ssse3_pabs_w_128>;
2619 defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2620 int_x86_ssse3_pabs_d,
2621 int_x86_ssse3_pabs_d_128>;
2623 /// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
2624 let Constraints = "$src1 = $dst" in {
2625 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2626 Intrinsic IntId64, Intrinsic IntId128,
2627 bit Commutable = 0> {
2628 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2629 (ins VR64:$src1, VR64:$src2),
2630 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2631 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2632 let isCommutable = Commutable;
2634 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2635 (ins VR64:$src1, i64mem:$src2),
2636 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2638 (IntId64 VR64:$src1,
2639 (bitconvert (memopv8i8 addr:$src2))))]>;
2641 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2642 (ins VR128:$src1, VR128:$src2),
2643 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2644 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2646 let isCommutable = Commutable;
2648 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2649 (ins VR128:$src1, i128mem:$src2),
2650 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2652 (IntId128 VR128:$src1,
2653 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2657 /// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
2658 let Constraints = "$src1 = $dst" in {
2659 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2660 Intrinsic IntId64, Intrinsic IntId128,
2661 bit Commutable = 0> {
2662 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2663 (ins VR64:$src1, VR64:$src2),
2664 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2665 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2666 let isCommutable = Commutable;
2668 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2669 (ins VR64:$src1, i64mem:$src2),
2670 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2672 (IntId64 VR64:$src1,
2673 (bitconvert (memopv4i16 addr:$src2))))]>;
2675 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2676 (ins VR128:$src1, VR128:$src2),
2677 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2678 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2680 let isCommutable = Commutable;
2682 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2683 (ins VR128:$src1, i128mem:$src2),
2684 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2686 (IntId128 VR128:$src1,
2687 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2691 /// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
2692 let Constraints = "$src1 = $dst" in {
2693 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2694 Intrinsic IntId64, Intrinsic IntId128,
2695 bit Commutable = 0> {
2696 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2697 (ins VR64:$src1, VR64:$src2),
2698 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2699 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2700 let isCommutable = Commutable;
2702 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2703 (ins VR64:$src1, i64mem:$src2),
2704 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2706 (IntId64 VR64:$src1,
2707 (bitconvert (memopv2i32 addr:$src2))))]>;
2709 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2710 (ins VR128:$src1, VR128:$src2),
2711 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2712 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2714 let isCommutable = Commutable;
2716 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2717 (ins VR128:$src1, i128mem:$src2),
2718 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2720 (IntId128 VR128:$src1,
2721 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2725 let ImmT = NoImm in { // None of these have i8 immediate fields.
2726 defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2727 int_x86_ssse3_phadd_w,
2728 int_x86_ssse3_phadd_w_128>;
2729 defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2730 int_x86_ssse3_phadd_d,
2731 int_x86_ssse3_phadd_d_128>;
2732 defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2733 int_x86_ssse3_phadd_sw,
2734 int_x86_ssse3_phadd_sw_128>;
2735 defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2736 int_x86_ssse3_phsub_w,
2737 int_x86_ssse3_phsub_w_128>;
2738 defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2739 int_x86_ssse3_phsub_d,
2740 int_x86_ssse3_phsub_d_128>;
2741 defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2742 int_x86_ssse3_phsub_sw,
2743 int_x86_ssse3_phsub_sw_128>;
2744 defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2745 int_x86_ssse3_pmadd_ub_sw,
2746 int_x86_ssse3_pmadd_ub_sw_128>;
2747 defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2748 int_x86_ssse3_pmul_hr_sw,
2749 int_x86_ssse3_pmul_hr_sw_128, 1>;
2751 defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2752 int_x86_ssse3_pshuf_b,
2753 int_x86_ssse3_pshuf_b_128>;
2754 defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2755 int_x86_ssse3_psign_b,
2756 int_x86_ssse3_psign_b_128>;
2757 defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2758 int_x86_ssse3_psign_w,
2759 int_x86_ssse3_psign_w_128>;
2760 defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
2761 int_x86_ssse3_psign_d,
2762 int_x86_ssse3_psign_d_128>;
2765 // palignr patterns.
2766 let Constraints = "$src1 = $dst" in {
2767 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2768 (ins VR64:$src1, VR64:$src2, i8imm:$src3),
2769 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2771 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
2772 (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
2773 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2776 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2777 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
2778 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2780 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
2781 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
2782 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2786 let AddedComplexity = 5 in {
2788 def : Pat<(v1i64 (palign:$src3 VR64:$src1, VR64:$src2)),
2789 (PALIGNR64rr VR64:$src2, VR64:$src1,
2790 (SHUFFLE_get_palign_imm VR64:$src3))>,
2791 Requires<[HasSSSE3]>;
2792 def : Pat<(v2i32 (palign:$src3 VR64:$src1, VR64:$src2)),
2793 (PALIGNR64rr VR64:$src2, VR64:$src1,
2794 (SHUFFLE_get_palign_imm VR64:$src3))>,
2795 Requires<[HasSSSE3]>;
2796 def : Pat<(v2f32 (palign:$src3 VR64:$src1, VR64:$src2)),
2797 (PALIGNR64rr VR64:$src2, VR64:$src1,
2798 (SHUFFLE_get_palign_imm VR64:$src3))>,
2799 Requires<[HasSSSE3]>;
2800 def : Pat<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
2801 (PALIGNR64rr VR64:$src2, VR64:$src1,
2802 (SHUFFLE_get_palign_imm VR64:$src3))>,
2803 Requires<[HasSSSE3]>;
2804 def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
2805 (PALIGNR64rr VR64:$src2, VR64:$src1,
2806 (SHUFFLE_get_palign_imm VR64:$src3))>,
2807 Requires<[HasSSSE3]>;
2809 def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
2810 (PALIGNR128rr VR128:$src2, VR128:$src1,
2811 (SHUFFLE_get_palign_imm VR128:$src3))>,
2812 Requires<[HasSSSE3]>;
2813 def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
2814 (PALIGNR128rr VR128:$src2, VR128:$src1,
2815 (SHUFFLE_get_palign_imm VR128:$src3))>,
2816 Requires<[HasSSSE3]>;
2817 def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
2818 (PALIGNR128rr VR128:$src2, VR128:$src1,
2819 (SHUFFLE_get_palign_imm VR128:$src3))>,
2820 Requires<[HasSSSE3]>;
2821 def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
2822 (PALIGNR128rr VR128:$src2, VR128:$src1,
2823 (SHUFFLE_get_palign_imm VR128:$src3))>,
2824 Requires<[HasSSSE3]>;
2827 def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2828 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2829 def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2830 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2832 //===---------------------------------------------------------------------===//
2833 // Non-Instruction Patterns
2834 //===---------------------------------------------------------------------===//
2836 // extload f32 -> f64. This matches load+fextend because we have a hack in
2837 // the isel (PreprocessForFPConvert) that can introduce loads after dag
2839 // Since these loads aren't folded into the fextend, we have to match it
2841 let Predicates = [HasSSE2] in
2842 def : Pat<(fextend (loadf32 addr:$src)),
2843 (CVTSS2SDrm addr:$src)>;
2846 let Predicates = [HasSSE2] in {
2847 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2848 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2849 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2850 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2851 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2852 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2853 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2854 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2855 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2856 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2857 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2858 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2859 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2860 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2861 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2862 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2863 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2864 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2865 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2866 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2867 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2868 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2869 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2870 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2871 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2872 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2873 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2874 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2875 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2876 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2879 // Move scalar to XMM zero-extended
2880 // movd to XMM register zero-extends
2881 let AddedComplexity = 15 in {
2882 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
2883 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
2884 (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
2885 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
2886 (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
2887 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
2888 (MOVSSrr (v4f32 (V_SET0PS)),
2889 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
2890 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
2891 (MOVSSrr (v4i32 (V_SET0PI)),
2892 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
2895 // Splat v2f64 / v2i64
2896 let AddedComplexity = 10 in {
2897 def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
2898 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2899 def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
2900 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2901 def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
2902 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2903 def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
2904 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2907 // Special unary SHUFPSrri case.
2908 def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2909 (SHUFPSrri VR128:$src1, VR128:$src1,
2910 (SHUFFLE_get_shuf_imm VR128:$src3))>;
2911 let AddedComplexity = 5 in
2912 def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2913 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2914 Requires<[HasSSE2]>;
2915 // Special unary SHUFPDrri case.
2916 def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
2917 (SHUFPDrri VR128:$src1, VR128:$src1,
2918 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2919 Requires<[HasSSE2]>;
2920 // Special unary SHUFPDrri case.
2921 def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
2922 (SHUFPDrri VR128:$src1, VR128:$src1,
2923 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2924 Requires<[HasSSE2]>;
2925 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
2926 def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2927 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2928 Requires<[HasSSE2]>;
2930 // Special binary v4i32 shuffle cases with SHUFPS.
2931 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
2932 (SHUFPSrri VR128:$src1, VR128:$src2,
2933 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2934 Requires<[HasSSE2]>;
2935 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
2936 (SHUFPSrmi VR128:$src1, addr:$src2,
2937 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2938 Requires<[HasSSE2]>;
2939 // Special binary v2i64 shuffle cases using SHUFPDrri.
2940 def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
2941 (SHUFPDrri VR128:$src1, VR128:$src2,
2942 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2943 Requires<[HasSSE2]>;
2945 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
2946 let AddedComplexity = 15 in {
2947 def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
2948 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2949 Requires<[OptForSpeed, HasSSE2]>;
2950 def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
2951 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2952 Requires<[OptForSpeed, HasSSE2]>;
2954 let AddedComplexity = 10 in {
2955 def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
2956 (UNPCKLPSrr VR128:$src, VR128:$src)>;
2957 def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
2958 (PUNPCKLBWrr VR128:$src, VR128:$src)>;
2959 def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
2960 (PUNPCKLWDrr VR128:$src, VR128:$src)>;
2961 def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
2962 (PUNPCKLDQrr VR128:$src, VR128:$src)>;
2965 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
2966 let AddedComplexity = 15 in {
2967 def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
2968 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2969 Requires<[OptForSpeed, HasSSE2]>;
2970 def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
2971 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2972 Requires<[OptForSpeed, HasSSE2]>;
2974 let AddedComplexity = 10 in {
2975 def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
2976 (UNPCKHPSrr VR128:$src, VR128:$src)>;
2977 def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
2978 (PUNPCKHBWrr VR128:$src, VR128:$src)>;
2979 def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
2980 (PUNPCKHWDrr VR128:$src, VR128:$src)>;
2981 def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
2982 (PUNPCKHDQrr VR128:$src, VR128:$src)>;
2985 let AddedComplexity = 20 in {
2986 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
2987 def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
2988 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
2990 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
2991 def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
2992 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
2994 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
2995 def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
2996 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2997 def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
2998 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3001 let AddedComplexity = 20 in {
3002 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
3003 def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
3004 (MOVLPSrm VR128:$src1, addr:$src2)>;
3005 def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
3006 (MOVLPDrm VR128:$src1, addr:$src2)>;
3007 def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
3008 (MOVLPSrm VR128:$src1, addr:$src2)>;
3009 def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
3010 (MOVLPDrm VR128:$src1, addr:$src2)>;
3013 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3014 def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3015 (MOVLPSmr addr:$src1, VR128:$src2)>;
3016 def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3017 (MOVLPDmr addr:$src1, VR128:$src2)>;
3018 def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3020 (MOVLPSmr addr:$src1, VR128:$src2)>;
3021 def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3022 (MOVLPDmr addr:$src1, VR128:$src2)>;
3024 let AddedComplexity = 15 in {
3025 // Setting the lowest element in the vector.
3026 def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
3027 (MOVSSrr (v4i32 VR128:$src1),
3028 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
3029 def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
3030 (MOVSDrr (v2i64 VR128:$src1),
3031 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
3033 // vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
3034 def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
3035 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3036 Requires<[HasSSE2]>;
3037 def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
3038 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3039 Requires<[HasSSE2]>;
3042 // vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3043 // fall back to this for SSE1)
3044 def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
3045 (SHUFPSrri VR128:$src2, VR128:$src1,
3046 (SHUFFLE_get_shuf_imm VR128:$src3))>;
3048 // Set lowest element and zero upper elements.
3049 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
3050 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3052 // Some special case pandn patterns.
3053 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3055 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3056 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3058 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3059 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3061 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3063 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3064 (memop addr:$src2))),
3065 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3066 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3067 (memop addr:$src2))),
3068 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3069 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3070 (memop addr:$src2))),
3071 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3073 // vector -> vector casts
3074 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3075 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3076 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3077 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3078 def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3079 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3080 def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3081 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
3083 // Use movaps / movups for SSE integer load / store (one byte shorter).
3084 def : Pat<(alignedloadv4i32 addr:$src),
3085 (MOVAPSrm addr:$src)>;
3086 def : Pat<(loadv4i32 addr:$src),
3087 (MOVUPSrm addr:$src)>;
3088 def : Pat<(alignedloadv2i64 addr:$src),
3089 (MOVAPSrm addr:$src)>;
3090 def : Pat<(loadv2i64 addr:$src),
3091 (MOVUPSrm addr:$src)>;
3093 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3094 (MOVAPSmr addr:$dst, VR128:$src)>;
3095 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3096 (MOVAPSmr addr:$dst, VR128:$src)>;
3097 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3098 (MOVAPSmr addr:$dst, VR128:$src)>;
3099 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3100 (MOVAPSmr addr:$dst, VR128:$src)>;
3101 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3102 (MOVUPSmr addr:$dst, VR128:$src)>;
3103 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3104 (MOVUPSmr addr:$dst, VR128:$src)>;
3105 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3106 (MOVUPSmr addr:$dst, VR128:$src)>;
3107 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3108 (MOVUPSmr addr:$dst, VR128:$src)>;
3110 //===----------------------------------------------------------------------===//
3111 // SSE4.1 Instructions
3112 //===----------------------------------------------------------------------===//
3114 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
3117 Intrinsic V2F64Int> {
3118 // Intrinsic operation, reg.
3119 // Vector intrinsic operation, reg
3120 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
3121 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3122 !strconcat(OpcodeStr,
3123 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3124 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3127 // Vector intrinsic operation, mem
3128 def PSm_Int : Ii8<opcps, MRMSrcMem,
3129 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3130 !strconcat(OpcodeStr,
3131 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3133 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
3135 Requires<[HasSSE41]>;
3137 // Vector intrinsic operation, reg
3138 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
3139 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3140 !strconcat(OpcodeStr,
3141 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3142 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3145 // Vector intrinsic operation, mem
3146 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
3147 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3148 !strconcat(OpcodeStr,
3149 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3151 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
3155 let Constraints = "$src1 = $dst" in {
3156 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3160 // Intrinsic operation, reg.
3161 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
3163 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3164 !strconcat(OpcodeStr,
3165 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3167 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3170 // Intrinsic operation, mem.
3171 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3173 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
3174 !strconcat(OpcodeStr,
3175 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3177 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3180 // Intrinsic operation, reg.
3181 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
3183 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3184 !strconcat(OpcodeStr,
3185 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3187 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3190 // Intrinsic operation, mem.
3191 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
3193 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3194 !strconcat(OpcodeStr,
3195 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3197 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3202 // FP round - roundss, roundps, roundsd, roundpd
3203 defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3204 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3205 defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3206 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
3208 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3209 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3210 Intrinsic IntId128> {
3211 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3213 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3214 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3215 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3217 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3220 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3223 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3224 int_x86_sse41_phminposuw>;
3226 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3227 let Constraints = "$src1 = $dst" in {
3228 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3229 Intrinsic IntId128, bit Commutable = 0> {
3230 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3231 (ins VR128:$src1, VR128:$src2),
3232 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3233 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3235 let isCommutable = Commutable;
3237 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3238 (ins VR128:$src1, i128mem:$src2),
3239 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3241 (IntId128 VR128:$src1,
3242 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3246 defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3247 int_x86_sse41_pcmpeqq, 1>;
3248 defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3249 int_x86_sse41_packusdw, 0>;
3250 defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3251 int_x86_sse41_pminsb, 1>;
3252 defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3253 int_x86_sse41_pminsd, 1>;
3254 defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3255 int_x86_sse41_pminud, 1>;
3256 defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3257 int_x86_sse41_pminuw, 1>;
3258 defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3259 int_x86_sse41_pmaxsb, 1>;
3260 defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3261 int_x86_sse41_pmaxsd, 1>;
3262 defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3263 int_x86_sse41_pmaxud, 1>;
3264 defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3265 int_x86_sse41_pmaxuw, 1>;
3267 defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3269 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3270 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3271 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3272 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3274 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3275 let Constraints = "$src1 = $dst" in {
3276 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3277 SDNode OpNode, Intrinsic IntId128,
3278 bit Commutable = 0> {
3279 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3280 (ins VR128:$src1, VR128:$src2),
3281 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3282 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3283 VR128:$src2))]>, OpSize {
3284 let isCommutable = Commutable;
3286 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3287 (ins VR128:$src1, VR128:$src2),
3288 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3289 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3291 let isCommutable = Commutable;
3293 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3294 (ins VR128:$src1, i128mem:$src2),
3295 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3297 (OpVT (OpNode VR128:$src1, (memop addr:$src2))))]>, OpSize;
3298 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3299 (ins VR128:$src1, i128mem:$src2),
3300 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3302 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
3307 /// SS48I_binop_rm - Simple SSE41 binary operator.
3308 let Constraints = "$src1 = $dst" in {
3309 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
3310 ValueType OpVT, bit Commutable = 0> {
3311 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3312 (ins VR128:$src1, VR128:$src2),
3313 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3314 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
3316 let isCommutable = Commutable;
3318 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3319 (ins VR128:$src1, i128mem:$src2),
3320 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3321 [(set VR128:$dst, (OpNode VR128:$src1,
3322 (bc_v4i32 (memopv2i64 addr:$src2))))]>,
3327 defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, 1>;
3329 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
3330 let Constraints = "$src1 = $dst" in {
3331 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3332 Intrinsic IntId128, bit Commutable = 0> {
3333 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3334 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3335 !strconcat(OpcodeStr,
3336 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3338 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3340 let isCommutable = Commutable;
3342 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3343 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3344 !strconcat(OpcodeStr,
3345 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3347 (IntId128 VR128:$src1,
3348 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3353 defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3354 int_x86_sse41_blendps, 0>;
3355 defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3356 int_x86_sse41_blendpd, 0>;
3357 defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3358 int_x86_sse41_pblendw, 0>;
3359 defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3360 int_x86_sse41_dpps, 1>;
3361 defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3362 int_x86_sse41_dppd, 1>;
3363 defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
3364 int_x86_sse41_mpsadbw, 0>;
3367 /// SS41I_ternary_int - SSE 4.1 ternary operator
3368 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
3369 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3370 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3371 (ins VR128:$src1, VR128:$src2),
3372 !strconcat(OpcodeStr,
3373 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3374 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3377 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3378 (ins VR128:$src1, i128mem:$src2),
3379 !strconcat(OpcodeStr,
3380 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3383 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3387 defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3388 defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3389 defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3392 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3393 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3394 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3395 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3397 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3398 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3400 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3404 defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3405 defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3406 defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3407 defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3408 defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3409 defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3411 // Common patterns involving scalar load.
3412 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3413 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3414 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3415 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3417 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3418 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3419 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3420 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3422 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3423 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3424 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3425 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3427 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3428 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3429 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3430 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3432 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3433 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3434 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3435 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3437 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3438 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3439 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3440 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3443 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3444 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3445 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3446 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3448 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3449 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3451 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3455 defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3456 defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3457 defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3458 defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3460 // Common patterns involving scalar load
3461 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
3462 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
3463 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
3464 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
3466 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
3467 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
3468 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
3469 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
3472 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3473 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3474 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3475 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3477 // Expecting a i16 load any extended to i32 value.
3478 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3479 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3480 [(set VR128:$dst, (IntId (bitconvert
3481 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3485 defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3486 defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
3488 // Common patterns involving scalar load
3489 def : Pat<(int_x86_sse41_pmovsxbq
3490 (bitconvert (v4i32 (X86vzmovl
3491 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3492 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
3494 def : Pat<(int_x86_sse41_pmovzxbq
3495 (bitconvert (v4i32 (X86vzmovl
3496 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3497 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
3500 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3501 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
3502 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3503 (ins VR128:$src1, i32i8imm:$src2),
3504 !strconcat(OpcodeStr,
3505 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3506 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3508 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3509 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
3510 !strconcat(OpcodeStr,
3511 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3514 // There's an AssertZext in the way of writing the store pattern
3515 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3518 defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
3521 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3522 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
3523 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3524 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
3525 !strconcat(OpcodeStr,
3526 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3529 // There's an AssertZext in the way of writing the store pattern
3530 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3533 defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3536 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3537 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
3538 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3539 (ins VR128:$src1, i32i8imm:$src2),
3540 !strconcat(OpcodeStr,
3541 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3543 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
3544 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3545 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
3546 !strconcat(OpcodeStr,
3547 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3548 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3549 addr:$dst)]>, OpSize;
3552 defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
3555 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3557 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
3558 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3559 (ins VR128:$src1, i32i8imm:$src2),
3560 !strconcat(OpcodeStr,
3561 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3563 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
3565 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3566 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
3567 !strconcat(OpcodeStr,
3568 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3569 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
3570 addr:$dst)]>, OpSize;
3573 defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
3575 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3576 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3579 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3580 Requires<[HasSSE41]>;
3582 let Constraints = "$src1 = $dst" in {
3583 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
3584 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3585 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3586 !strconcat(OpcodeStr,
3587 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3589 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
3590 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3591 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3592 !strconcat(OpcodeStr,
3593 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3595 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3596 imm:$src3))]>, OpSize;
3600 defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3602 let Constraints = "$src1 = $dst" in {
3603 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
3604 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3605 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3606 !strconcat(OpcodeStr,
3607 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3609 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3611 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3612 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3613 !strconcat(OpcodeStr,
3614 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3616 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3617 imm:$src3)))]>, OpSize;
3621 defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3623 // insertps has a few different modes, there's the first two here below which
3624 // are optimized inserts that won't zero arbitrary elements in the destination
3625 // vector. The next one matches the intrinsic and could zero arbitrary elements
3626 // in the target vector.
3627 let Constraints = "$src1 = $dst" in {
3628 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
3629 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3630 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3631 !strconcat(OpcodeStr,
3632 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3634 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
3636 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3637 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3638 !strconcat(OpcodeStr,
3639 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3641 (X86insrtps VR128:$src1,
3642 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
3643 imm:$src3))]>, OpSize;
3647 defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
3649 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3650 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3652 // ptest instruction we'll lower to this in X86ISelLowering primarily from
3653 // the intel intrinsic that corresponds to this.
3654 let Defs = [EFLAGS] in {
3655 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
3656 "ptest \t{$src2, $src1|$src1, $src2}",
3657 [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
3659 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
3660 "ptest \t{$src2, $src1|$src1, $src2}",
3661 [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
3665 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3666 "movntdqa\t{$src, $dst|$dst, $src}",
3667 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
3671 //===----------------------------------------------------------------------===//
3672 // SSE4.2 Instructions
3673 //===----------------------------------------------------------------------===//
3675 /// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3676 let Constraints = "$src1 = $dst" in {
3677 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3678 Intrinsic IntId128, bit Commutable = 0> {
3679 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3680 (ins VR128:$src1, VR128:$src2),
3681 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3682 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3684 let isCommutable = Commutable;
3686 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3687 (ins VR128:$src1, i128mem:$src2),
3688 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3690 (IntId128 VR128:$src1,
3691 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3695 defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
3697 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3698 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3699 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3700 (PCMPGTQrm VR128:$src1, addr:$src2)>;
3702 // crc intrinsic instruction
3703 // This set of instructions are only rm, the only difference is the size
3705 let Constraints = "$src1 = $dst" in {
3706 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
3707 (ins GR32:$src1, i8mem:$src2),
3708 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3710 (int_x86_sse42_crc32_8 GR32:$src1,
3711 (load addr:$src2)))]>;
3712 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
3713 (ins GR32:$src1, GR8:$src2),
3714 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3716 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
3717 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3718 (ins GR32:$src1, i16mem:$src2),
3719 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3721 (int_x86_sse42_crc32_16 GR32:$src1,
3722 (load addr:$src2)))]>,
3724 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3725 (ins GR32:$src1, GR16:$src2),
3726 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3728 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
3730 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3731 (ins GR32:$src1, i32mem:$src2),
3732 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3734 (int_x86_sse42_crc32_32 GR32:$src1,
3735 (load addr:$src2)))]>;
3736 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3737 (ins GR32:$src1, GR32:$src2),
3738 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3740 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
3741 def CRC64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3742 (ins GR64:$src1, i8mem:$src2),
3743 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3745 (int_x86_sse42_crc64_8 GR64:$src1,
3746 (load addr:$src2)))]>,
3748 def CRC64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3749 (ins GR64:$src1, GR8:$src2),
3750 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3752 (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
3754 def CRC64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
3755 (ins GR64:$src1, i64mem:$src2),
3756 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3758 (int_x86_sse42_crc64_64 GR64:$src1,
3759 (load addr:$src2)))]>,
3761 def CRC64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
3762 (ins GR64:$src1, GR64:$src2),
3763 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3765 (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
3769 // String/text processing instructions.
3770 let Defs = [EFLAGS], usesCustomInserter = 1 in {
3771 def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3772 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3773 "#PCMPISTRM128rr PSEUDO!",
3774 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
3775 imm:$src3))]>, OpSize;
3776 def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3777 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3778 "#PCMPISTRM128rm PSEUDO!",
3779 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, (load addr:$src2),
3780 imm:$src3))]>, OpSize;
3783 let Defs = [XMM0, EFLAGS] in {
3784 def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
3785 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3786 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3787 def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
3788 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3789 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3792 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
3793 def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3794 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3795 "#PCMPESTRM128rr PSEUDO!",
3797 (int_x86_sse42_pcmpestrm128
3798 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
3800 def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3801 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3802 "#PCMPESTRM128rm PSEUDO!",
3803 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
3804 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
3808 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
3809 def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
3810 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3811 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3812 def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
3813 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3814 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3817 let Defs = [ECX, EFLAGS] in {
3818 multiclass SS42AI_pcmpistri<Intrinsic IntId128> {
3819 def rr : SS42AI<0x63, MRMSrcReg, (outs),
3820 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3821 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3822 [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
3823 (implicit EFLAGS)]>, OpSize;
3824 def rm : SS42AI<0x63, MRMSrcMem, (outs),
3825 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3826 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3827 [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
3828 (implicit EFLAGS)]>, OpSize;
3832 defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
3833 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
3834 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
3835 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
3836 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
3837 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
3839 let Defs = [ECX, EFLAGS] in {
3840 let Uses = [EAX, EDX] in {
3841 multiclass SS42AI_pcmpestri<Intrinsic IntId128> {
3842 def rr : SS42AI<0x61, MRMSrcReg, (outs),
3843 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3844 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3845 [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
3846 (implicit EFLAGS)]>, OpSize;
3847 def rm : SS42AI<0x61, MRMSrcMem, (outs),
3848 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3849 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3851 (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
3852 (implicit EFLAGS)]>, OpSize;
3857 defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
3858 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
3859 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
3860 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
3861 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
3862 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
3864 //===----------------------------------------------------------------------===//
3865 // AES-NI Instructions
3866 //===----------------------------------------------------------------------===//
3868 let Constraints = "$src1 = $dst" in {
3869 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
3870 Intrinsic IntId128, bit Commutable = 0> {
3871 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
3872 (ins VR128:$src1, VR128:$src2),
3873 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3874 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3876 let isCommutable = Commutable;
3878 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
3879 (ins VR128:$src1, i128mem:$src2),
3880 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3882 (IntId128 VR128:$src1,
3883 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3887 defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
3888 int_x86_aesni_aesenc>;
3889 defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
3890 int_x86_aesni_aesenclast>;
3891 defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
3892 int_x86_aesni_aesdec>;
3893 defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
3894 int_x86_aesni_aesdeclast>;
3896 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
3897 (AESENCrr VR128:$src1, VR128:$src2)>;
3898 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
3899 (AESENCrm VR128:$src1, addr:$src2)>;
3900 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
3901 (AESENCLASTrr VR128:$src1, VR128:$src2)>;
3902 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
3903 (AESENCLASTrm VR128:$src1, addr:$src2)>;
3904 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
3905 (AESDECrr VR128:$src1, VR128:$src2)>;
3906 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
3907 (AESDECrm VR128:$src1, addr:$src2)>;
3908 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
3909 (AESDECLASTrr VR128:$src1, VR128:$src2)>;
3910 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
3911 (AESDECLASTrm VR128:$src1, addr:$src2)>;
3913 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
3915 "aesimc\t{$src1, $dst|$dst, $src1}",
3917 (int_x86_aesni_aesimc VR128:$src1))]>,
3920 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
3921 (ins i128mem:$src1),
3922 "aesimc\t{$src1, $dst|$dst, $src1}",
3924 (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
3927 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
3928 (ins VR128:$src1, i8imm:$src2),
3929 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3931 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
3933 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
3934 (ins i128mem:$src1, i8imm:$src2),
3935 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3937 (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),