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 //===----------------------------------------------------------------------===//
448 // SSE 1 & 2 - Move Instructions
449 //===----------------------------------------------------------------------===//
451 class sse12_move_rr<RegisterClass RC, ValueType vt, string asm> :
452 SI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, RC:$src2), asm,
453 [(set (vt VR128:$dst), (movl VR128:$src1, (scalar_to_vector RC:$src2)))]>;
455 // Loading from memory automatically zeroing upper bits.
456 class sse12_move_rm<RegisterClass RC, X86MemOperand x86memop,
457 PatFrag mem_pat, string OpcodeStr> :
458 SI<0x10, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
459 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
460 [(set RC:$dst, (mem_pat addr:$src))]>;
462 // Move Instructions. Register-to-register movss/movsd is not used for FR32/64
463 // register copies because it's a partial register update; FsMOVAPSrr/FsMOVAPDrr
464 // is used instead. Register-to-register movss/movsd is not modeled as an
465 // INSERT_SUBREG because INSERT_SUBREG requires that the insert be implementable
466 // in terms of a copy, and just mentioned, we don't use movss/movsd for copies.
467 let isAsmParserOnly = 1 in {
468 def VMOVSSrr : sse12_move_rr<FR32, v4f32,
469 "movss\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XS, VEX_4V;
470 def VMOVSDrr : sse12_move_rr<FR64, v2f64,
471 "movsd\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XD, VEX_4V;
473 let canFoldAsLoad = 1, isReMaterializable = 1 in {
474 def VMOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS, VEX;
476 let AddedComplexity = 20 in
477 def VMOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD, VEX;
481 let Constraints = "$src1 = $dst" in {
482 def MOVSSrr : sse12_move_rr<FR32, v4f32,
483 "movss\t{$src2, $dst|$dst, $src2}">, XS;
484 def MOVSDrr : sse12_move_rr<FR64, v2f64,
485 "movsd\t{$src2, $dst|$dst, $src2}">, XD;
488 let canFoldAsLoad = 1, isReMaterializable = 1 in {
489 def MOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS;
491 let AddedComplexity = 20 in
492 def MOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD;
495 let AddedComplexity = 15 in {
496 // Extract the low 32-bit value from one vector and insert it into another.
497 def : Pat<(v4f32 (movl VR128:$src1, VR128:$src2)),
498 (MOVSSrr (v4f32 VR128:$src1),
499 (EXTRACT_SUBREG (v4f32 VR128:$src2), sub_ss))>;
500 // Extract the low 64-bit value from one vector and insert it into another.
501 def : Pat<(v2f64 (movl VR128:$src1, VR128:$src2)),
502 (MOVSDrr (v2f64 VR128:$src1),
503 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
506 // Implicitly promote a 32-bit scalar to a vector.
507 def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
508 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss)>;
509 // Implicitly promote a 64-bit scalar to a vector.
510 def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
511 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
513 let AddedComplexity = 20 in {
514 // MOVSSrm zeros the high parts of the register; represent this
515 // with SUBREG_TO_REG.
516 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
517 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
518 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
519 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
520 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
521 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
522 // MOVSDrm zeros the high parts of the register; represent this
523 // with SUBREG_TO_REG.
524 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
525 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
526 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
527 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
528 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
529 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
530 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
531 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
532 def : Pat<(v2f64 (X86vzload addr:$src)),
533 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
536 // Store scalar value to memory.
537 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
538 "movss\t{$src, $dst|$dst, $src}",
539 [(store FR32:$src, addr:$dst)]>;
540 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
541 "movsd\t{$src, $dst|$dst, $src}",
542 [(store FR64:$src, addr:$dst)]>;
544 let isAsmParserOnly = 1 in {
545 def VMOVSSmr : SI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
546 "movss\t{$src, $dst|$dst, $src}",
547 [(store FR32:$src, addr:$dst)]>, XS, VEX_4V;
548 def VMOVSDmr : SI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
549 "movsd\t{$src, $dst|$dst, $src}",
550 [(store FR64:$src, addr:$dst)]>, XD, VEX_4V;
553 // Extract and store.
554 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
557 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
558 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
561 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
563 //===----------------------------------------------------------------------===//
564 // SSE 1 & 2 - Conversion Instructions
565 //===----------------------------------------------------------------------===//
567 multiclass sse12_cvt_s<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
568 SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
570 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
571 [(set DstRC:$dst, (OpNode SrcRC:$src))]>;
572 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
573 [(set DstRC:$dst, (OpNode (ld_frag addr:$src)))]>;
576 multiclass sse12_cvt_p<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
577 SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
578 string asm, Domain d> {
579 def rr : PI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
580 [(set DstRC:$dst, (OpNode SrcRC:$src))], d>;
581 def rm : PI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
582 [(set DstRC:$dst, (OpNode (ld_frag addr:$src)))], d>;
585 multiclass sse12_vcvt_avx<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
586 SDNode OpNode, X86MemOperand x86memop, PatFrag ld_frag,
588 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src),
590 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
591 (ins DstRC:$src1, x86memop:$src), asm, []>;
594 let isAsmParserOnly = 1 in {
595 defm VCVTTSS2SI : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
596 "cvttss2si\t{$src, $dst|$dst, $src}">, XS, VEX;
597 defm VCVTTSD2SI : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
598 "cvttsd2si\t{$src, $dst|$dst, $src}">, XD, VEX;
599 defm VCVTSI2SS : sse12_vcvt_avx<0x2A, GR32, FR32, sint_to_fp, i32mem, loadi32,
600 "cvtsi2ss\t{$src, $src1, $dst|$dst, $src1, $src}">, XS,
602 defm VCVTSI2SD : sse12_vcvt_avx<0x2A, GR32, FR64, sint_to_fp, i32mem, loadi32,
603 "cvtsi2sd\t{$src, $src1, $dst|$dst, $src1, $src}">, XD,
607 defm CVTTSS2SI : sse12_cvt_s<0x2C, FR32, GR32, fp_to_sint, f32mem, loadf32,
608 "cvttss2si\t{$src, $dst|$dst, $src}">, XS;
609 defm CVTTSD2SI : sse12_cvt_s<0x2C, FR64, GR32, fp_to_sint, f64mem, loadf64,
610 "cvttsd2si\t{$src, $dst|$dst, $src}">, XD;
611 defm CVTSI2SS : sse12_cvt_s<0x2A, GR32, FR32, sint_to_fp, i32mem, loadi32,
612 "cvtsi2ss\t{$src, $dst|$dst, $src}">, XS;
613 defm CVTSI2SD : sse12_cvt_s<0x2A, GR32, FR64, sint_to_fp, i32mem, loadi32,
614 "cvtsi2sd\t{$src, $dst|$dst, $src}">, XD;
616 // Conversion Instructions Intrinsics - Match intrinsics which expect MM
617 // and/or XMM operand(s).
618 multiclass sse12_cvt_pint<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
619 Intrinsic Int, X86MemOperand x86memop, PatFrag ld_frag,
620 string asm, Domain d> {
621 def rr : PI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
622 [(set DstRC:$dst, (Int SrcRC:$src))], d>;
623 def rm : PI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
624 [(set DstRC:$dst, (Int (ld_frag addr:$src)))], d>;
627 multiclass sse12_cvt_sint<bits<8> opc, RegisterClass SrcRC, RegisterClass DstRC,
628 Intrinsic Int, X86MemOperand x86memop, PatFrag ld_frag,
630 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins SrcRC:$src), asm,
631 [(set DstRC:$dst, (Int SrcRC:$src))]>;
632 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst), (ins x86memop:$src), asm,
633 [(set DstRC:$dst, (Int (ld_frag addr:$src)))]>;
636 multiclass sse12_cvt_pint_3addr<bits<8> opc, RegisterClass SrcRC,
637 RegisterClass DstRC, Intrinsic Int, X86MemOperand x86memop,
638 PatFrag ld_frag, string asm, Domain d> {
639 def rr : PI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src2),
640 asm, [(set DstRC:$dst, (Int DstRC:$src1, SrcRC:$src2))], d>;
641 def rm : PI<opc, MRMSrcMem, (outs DstRC:$dst),
642 (ins DstRC:$src1, x86memop:$src2), asm,
643 [(set DstRC:$dst, (Int DstRC:$src1, (ld_frag addr:$src2)))], d>;
646 multiclass sse12_cvt_sint_3addr<bits<8> opc, RegisterClass SrcRC,
647 RegisterClass DstRC, Intrinsic Int, X86MemOperand x86memop,
648 PatFrag ld_frag, string asm> {
649 def rr : SI<opc, MRMSrcReg, (outs DstRC:$dst), (ins DstRC:$src1, SrcRC:$src2),
650 asm, [(set DstRC:$dst, (Int DstRC:$src1, SrcRC:$src2))]>;
651 def rm : SI<opc, MRMSrcMem, (outs DstRC:$dst),
652 (ins DstRC:$src1, x86memop:$src2), asm,
653 [(set DstRC:$dst, (Int DstRC:$src1, (ld_frag addr:$src2)))]>;
656 let isAsmParserOnly = 1 in {
657 defm Int_VCVTSS2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse_cvtss2si,
658 f32mem, load, "cvtss2si\t{$src, $dst|$dst, $src}">, XS,
660 defm Int_VCVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse2_cvtsd2si,
661 f128mem, load, "cvtsd2si\t{$src, $dst|$dst, $src}">, XD,
664 defm Int_CVTSS2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse_cvtss2si,
665 f32mem, load, "cvtss2si\t{$src, $dst|$dst, $src}">, XS;
666 defm Int_CVTSD2SI : sse12_cvt_sint<0x2D, VR128, GR32, int_x86_sse2_cvtsd2si,
667 f128mem, load, "cvtsd2si\t{$src, $dst|$dst, $src}">, XD;
670 let Constraints = "$src1 = $dst" in {
671 defm Int_CVTSI2SS : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
672 int_x86_sse_cvtsi2ss, i32mem, loadi32,
673 "cvtsi2ss\t{$src2, $dst|$dst, $src2}">, XS;
674 defm Int_CVTSI2SD : sse12_cvt_sint_3addr<0x2A, GR32, VR128,
675 int_x86_sse2_cvtsi2sd, i32mem, loadi32,
676 "cvtsi2ss\t{$src2, $dst|$dst, $src2}">, XD;
679 // Instructions below don't have an AVX form.
680 defm Int_CVTPS2PI : sse12_cvt_pint<0x2D, VR128, VR64, int_x86_sse_cvtps2pi,
681 f64mem, load, "cvtps2pi\t{$src, $dst|$dst, $src}",
682 SSEPackedSingle>, TB;
683 defm Int_CVTPD2PI : sse12_cvt_pint<0x2D, VR128, VR64, int_x86_sse_cvtpd2pi,
684 f128mem, memop, "cvtpd2pi\t{$src, $dst|$dst, $src}",
685 SSEPackedDouble>, TB, OpSize;
686 defm Int_CVTTPS2PI : sse12_cvt_pint<0x2C, VR128, VR64, int_x86_sse_cvttps2pi,
687 f64mem, load, "cvttps2pi\t{$src, $dst|$dst, $src}",
688 SSEPackedSingle>, TB;
689 defm Int_CVTTPD2PI : sse12_cvt_pint<0x2C, VR128, VR64, int_x86_sse_cvttpd2pi,
690 f128mem, memop, "cvttpd2pi\t{$src, $dst|$dst, $src}",
691 SSEPackedDouble>, TB, OpSize;
692 defm Int_CVTPI2PD : sse12_cvt_pint<0x2A, VR64, VR128, int_x86_sse_cvtpi2pd,
693 i64mem, load, "cvtpi2pd\t{$src, $dst|$dst, $src}",
694 SSEPackedDouble>, TB, OpSize;
695 let Constraints = "$src1 = $dst" in {
696 defm Int_CVTPI2PS : sse12_cvt_pint_3addr<0x2A, VR64, VR128,
697 int_x86_sse_cvtpi2ps,
698 i64mem, load, "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
699 SSEPackedSingle>, TB;
704 // Aliases for intrinsics
705 defm Int_CVTTSS2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse_cvttss2si,
706 f32mem, load, "cvttss2si\t{$src, $dst|$dst, $src}">,
708 defm Int_CVTTSD2SI : sse12_cvt_sint<0x2C, VR128, GR32, int_x86_sse2_cvttsd2si,
709 f128mem, load, "cvttss2si\t{$src, $dst|$dst, $src}">,
712 let Pattern = []<dag> in {
713 defm CVTSS2SI : sse12_cvt_s<0x2D, FR32, GR32, undef, f32mem, load /*dummy*/,
714 "cvtss2si{l}\t{$src, $dst|$dst, $src}">, XS;
715 defm CVTDQ2PS : sse12_cvt_p<0x5B, VR128, VR128, undef, f128mem, load /*dummy*/,
716 "cvtdq2ps\t{$src, $dst|$dst, $src}",
717 SSEPackedSingle>, TB; /* PD SSE3 form is avaiable */
720 //===----------------------------------------------------------------------===//
721 // SSE 1 & 2 - Compare Instructions
722 //===----------------------------------------------------------------------===//
724 // sse12_cmp_scalar - sse 1 & 2 compare scalar instructions
725 multiclass sse12_cmp_scalar<RegisterClass RC, X86MemOperand x86memop,
726 string asm, string asm_alt> {
727 def rr : SIi8<0xC2, MRMSrcReg,
728 (outs RC:$dst), (ins RC:$src1, RC:$src, SSECC:$cc),
731 def rm : SIi8<0xC2, MRMSrcMem,
732 (outs RC:$dst), (ins RC:$src1, x86memop:$src, SSECC:$cc),
734 // Accept explicit immediate argument form instead of comparison code.
735 let isAsmParserOnly = 1 in {
736 def rr_alt : SIi8<0xC2, MRMSrcReg,
737 (outs RC:$dst), (ins RC:$src1, RC:$src, i8imm:$src2),
740 def rm_alt : SIi8<0xC2, MRMSrcMem,
741 (outs RC:$dst), (ins RC:$src1, x86memop:$src, i8imm:$src2),
746 let neverHasSideEffects = 1, isAsmParserOnly = 1 in {
747 defm VCMPSS : sse12_cmp_scalar<FR32, f32mem,
748 "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}",
749 "cmpss\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}">,
751 defm VCMPSD : sse12_cmp_scalar<FR64, f64mem,
752 "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}",
753 "cmpsd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}">,
757 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
758 defm CMPSS : sse12_cmp_scalar<FR32, f32mem,
759 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
760 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}">, XS;
761 defm CMPSD : sse12_cmp_scalar<FR64, f64mem,
762 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
763 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}">, XD;
766 multiclass sse12_cmp_scalar_int<RegisterClass RC, X86MemOperand x86memop,
767 Intrinsic Int, string asm> {
768 def rr : SIi8<0xC2, MRMSrcReg, (outs VR128:$dst),
769 (ins VR128:$src1, VR128:$src, SSECC:$cc), asm,
770 [(set VR128:$dst, (Int VR128:$src1,
771 VR128:$src, imm:$cc))]>;
772 def rm : SIi8<0xC2, MRMSrcMem, (outs VR128:$dst),
773 (ins VR128:$src1, f32mem:$src, SSECC:$cc), asm,
774 [(set VR128:$dst, (Int VR128:$src1,
775 (load addr:$src), imm:$cc))]>;
778 // Aliases to match intrinsics which expect XMM operand(s).
779 let isAsmParserOnly = 1 in {
780 defm Int_VCMPSS : sse12_cmp_scalar_int<VR128, f32mem, int_x86_sse_cmp_ss,
781 "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}">,
783 defm Int_VCMPSD : sse12_cmp_scalar_int<VR128, f64mem, int_x86_sse2_cmp_sd,
784 "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}">,
787 let Constraints = "$src1 = $dst" in {
788 defm Int_CMPSS : sse12_cmp_scalar_int<VR128, f32mem, int_x86_sse_cmp_ss,
789 "cmp${cc}ss\t{$src, $dst|$dst, $src}">, XS;
790 defm Int_CMPSD : sse12_cmp_scalar_int<VR128, f64mem, int_x86_sse2_cmp_sd,
791 "cmp${cc}sd\t{$src, $dst|$dst, $src}">, XD;
795 // sse12_ord_cmp - Unordered/Ordered scalar fp compare and set EFLAGS
796 multiclass sse12_ord_cmp<bits<8> opc, RegisterClass RC, SDNode OpNode,
797 ValueType vt, X86MemOperand x86memop,
798 PatFrag ld_frag, string OpcodeStr, Domain d> {
799 def rr: PI<opc, MRMSrcReg, (outs), (ins RC:$src1, RC:$src2),
800 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
801 [(set EFLAGS, (OpNode (vt RC:$src1), RC:$src2))], d>;
802 def rm: PI<opc, MRMSrcMem, (outs), (ins RC:$src1, x86memop:$src2),
803 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
804 [(set EFLAGS, (OpNode (vt RC:$src1),
805 (ld_frag addr:$src2)))], d>;
808 let Defs = [EFLAGS] in {
809 let isAsmParserOnly = 1 in {
810 defm VUCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
811 "ucomiss", SSEPackedSingle>, VEX;
812 defm VUCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
813 "ucomisd", SSEPackedDouble>, OpSize, VEX;
814 let Pattern = []<dag> in {
815 defm VCOMISS : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
816 "comiss", SSEPackedSingle>, VEX;
817 defm VCOMISD : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
818 "comisd", SSEPackedDouble>, OpSize, VEX;
821 defm Int_VUCOMISS : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
822 load, "ucomiss", SSEPackedSingle>, VEX;
823 defm Int_VUCOMISD : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
824 load, "ucomisd", SSEPackedDouble>, OpSize, VEX;
826 defm Int_VCOMISS : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem,
827 load, "comiss", SSEPackedSingle>, VEX;
828 defm Int_VCOMISD : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem,
829 load, "comisd", SSEPackedDouble>, OpSize, VEX;
831 defm UCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
832 "ucomiss", SSEPackedSingle>, TB;
833 defm UCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
834 "ucomisd", SSEPackedDouble>, TB, OpSize;
836 let Pattern = []<dag> in {
837 defm COMISS : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
838 "comiss", SSEPackedSingle>, TB;
839 defm COMISD : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
840 "comisd", SSEPackedDouble>, TB, OpSize;
843 defm Int_UCOMISS : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
844 load, "ucomiss", SSEPackedSingle>, TB;
845 defm Int_UCOMISD : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
846 load, "ucomisd", SSEPackedDouble>, TB, OpSize;
848 defm Int_COMISS : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem, load,
849 "comiss", SSEPackedSingle>, TB;
850 defm Int_COMISD : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem, load,
851 "comisd", SSEPackedDouble>, TB, OpSize;
854 // sse12_cmp_packed - sse 1 & 2 compared packed instructions
855 multiclass sse12_cmp_packed<RegisterClass RC, X86MemOperand x86memop,
856 Intrinsic Int, string asm, string asm_alt,
858 def rri : PIi8<0xC2, MRMSrcReg,
859 (outs RC:$dst), (ins RC:$src1, RC:$src, SSECC:$cc), asm,
860 [(set RC:$dst, (Int RC:$src1, RC:$src, imm:$cc))], d>;
861 def rmi : PIi8<0xC2, MRMSrcMem,
862 (outs RC:$dst), (ins RC:$src1, f128mem:$src, SSECC:$cc), asm,
863 [(set RC:$dst, (Int RC:$src1, (memop addr:$src), imm:$cc))], d>;
864 // Accept explicit immediate argument form instead of comparison code.
865 let isAsmParserOnly = 1 in {
866 def rri_alt : PIi8<0xC2, MRMSrcReg,
867 (outs RC:$dst), (ins RC:$src1, RC:$src, i8imm:$src2),
869 def rmi_alt : PIi8<0xC2, MRMSrcMem,
870 (outs RC:$dst), (ins RC:$src1, f128mem:$src, i8imm:$src2),
875 let isAsmParserOnly = 1 in {
876 defm VCMPPS : sse12_cmp_packed<VR128, f128mem, int_x86_sse_cmp_ps,
877 "cmp${cc}ps\t{$src, $src1, $dst|$dst, $src1, $src}",
878 "cmpps\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
879 SSEPackedSingle>, VEX_4V;
880 defm VCMPPD : sse12_cmp_packed<VR128, f128mem, int_x86_sse2_cmp_pd,
881 "cmp${cc}pd\t{$src, $src1, $dst|$dst, $src1, $src}",
882 "cmppd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
883 SSEPackedDouble>, OpSize, VEX_4V;
885 let Constraints = "$src1 = $dst" in {
886 defm CMPPS : sse12_cmp_packed<VR128, f128mem, int_x86_sse_cmp_ps,
887 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
888 "cmpps\t{$src2, $src, $dst|$dst, $src, $src2}",
889 SSEPackedSingle>, TB;
890 defm CMPPD : sse12_cmp_packed<VR128, f128mem, int_x86_sse2_cmp_pd,
891 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
892 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}",
893 SSEPackedDouble>, TB, OpSize;
896 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
897 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
898 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
899 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
900 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
901 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
902 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
903 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
905 //===----------------------------------------------------------------------===//
906 // SSE 1 & 2 - Shuffle Instructions
907 //===----------------------------------------------------------------------===//
909 /// sse12_shuffle - sse 1 & 2 shuffle instructions
910 multiclass sse12_shuffle<RegisterClass RC, X86MemOperand x86memop,
911 ValueType vt, string asm, PatFrag mem_frag,
912 Domain d, bit IsConvertibleToThreeAddress = 0> {
913 def rmi : PIi8<0xC6, MRMSrcMem, (outs VR128:$dst),
914 (ins VR128:$src1, f128mem:$src2, i8imm:$src3), asm,
915 [(set VR128:$dst, (vt (shufp:$src3
916 VR128:$src1, (mem_frag addr:$src2))))], d>;
917 let isConvertibleToThreeAddress = IsConvertibleToThreeAddress in
918 def rri : PIi8<0xC6, MRMSrcReg, (outs VR128:$dst),
919 (ins VR128:$src1, VR128:$src2, i8imm:$src3), asm,
921 (vt (shufp:$src3 VR128:$src1, VR128:$src2)))], d>;
924 let isAsmParserOnly = 1 in {
925 defm VSHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
926 "shufps\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
927 memopv4f32, SSEPackedSingle>, VEX_4V;
928 defm VSHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
929 "shufpd\t{$src3, $src2, $src1, $dst|$dst, $src2, $src2, $src3}",
930 memopv2f64, SSEPackedDouble>, OpSize, VEX_4V;
933 let Constraints = "$src1 = $dst" in {
934 defm SHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
935 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
936 memopv4f32, SSEPackedSingle, 1 /* cvt to pshufd */>,
938 defm SHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
939 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
940 memopv2f64, SSEPackedDouble>, TB, OpSize;
943 //===----------------------------------------------------------------------===//
944 // SSE 1 & 2 - Unpack Instructions
945 //===----------------------------------------------------------------------===//
947 /// sse12_unpack_interleave - sse 1 & 2 unpack and interleave
948 multiclass sse12_unpack_interleave<bits<8> opc, PatFrag OpNode, ValueType vt,
949 PatFrag mem_frag, RegisterClass RC,
950 X86MemOperand x86memop, string asm,
952 def rr : PI<opc, MRMSrcReg,
953 (outs RC:$dst), (ins RC:$src1, RC:$src2),
955 (vt (OpNode RC:$src1, RC:$src2)))], d>;
956 def rm : PI<opc, MRMSrcMem,
957 (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
959 (vt (OpNode RC:$src1,
960 (mem_frag addr:$src2))))], d>;
963 let AddedComplexity = 10 in {
964 let isAsmParserOnly = 1 in {
965 defm VUNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
966 VR128, f128mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
967 SSEPackedSingle>, VEX_4V;
968 defm VUNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
969 VR128, f128mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
970 SSEPackedDouble>, OpSize, VEX_4V;
971 defm VUNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
972 VR128, f128mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
973 SSEPackedSingle>, VEX_4V;
974 defm VUNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
975 VR128, f128mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
976 SSEPackedDouble>, OpSize, VEX_4V;
979 let Constraints = "$src1 = $dst" in {
980 defm UNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
981 VR128, f128mem, "unpckhps\t{$src2, $dst|$dst, $src2}",
982 SSEPackedSingle>, TB;
983 defm UNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
984 VR128, f128mem, "unpckhpd\t{$src2, $dst|$dst, $src2}",
985 SSEPackedDouble>, TB, OpSize;
986 defm UNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
987 VR128, f128mem, "unpcklps\t{$src2, $dst|$dst, $src2}",
988 SSEPackedSingle>, TB;
989 defm UNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
990 VR128, f128mem, "unpcklpd\t{$src2, $dst|$dst, $src2}",
991 SSEPackedDouble>, TB, OpSize;
992 } // Constraints = "$src1 = $dst"
995 //===----------------------------------------------------------------------===//
996 // SSE 1 & 2 - Extract Floating-Point Sign mask
997 //===----------------------------------------------------------------------===//
999 /// sse12_extr_sign_mask - sse 1 & 2 unpack and interleave
1000 multiclass sse12_extr_sign_mask<RegisterClass RC, Intrinsic Int, string asm,
1002 def rr : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins RC:$src),
1003 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
1004 [(set GR32:$dst, (Int RC:$src))], d>;
1008 defm MOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps, "movmskps",
1009 SSEPackedSingle>, TB;
1010 defm MOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd, "movmskpd",
1011 SSEPackedDouble>, TB, OpSize;
1013 let isAsmParserOnly = 1 in {
1014 defm VMOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps,
1015 "movmskps", SSEPackedSingle>, VEX;
1016 defm VMOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd,
1017 "movmskpd", SSEPackedDouble>, OpSize,
1021 //===----------------------------------------------------------------------===//
1022 // SSE 1 & 2 - Misc aliasing of packed SSE 1 & 2 instructions
1023 //===----------------------------------------------------------------------===//
1025 // Aliases of packed SSE1 & SSE2 instructions for scalar use. These all have
1026 // names that start with 'Fs'.
1028 // Alias instructions that map fld0 to pxor for sse.
1029 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
1030 canFoldAsLoad = 1 in {
1031 // FIXME: Set encoding to pseudo!
1032 def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins), "",
1033 [(set FR32:$dst, fp32imm0)]>,
1034 Requires<[HasSSE1]>, TB, OpSize;
1035 def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
1036 [(set FR64:$dst, fpimm0)]>,
1037 Requires<[HasSSE2]>, TB, OpSize;
1040 // Alias instruction to do FR32 or FR64 reg-to-reg copy using movaps. Upper
1041 // bits are disregarded.
1042 let neverHasSideEffects = 1 in {
1043 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1044 "movaps\t{$src, $dst|$dst, $src}", []>;
1045 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1046 "movapd\t{$src, $dst|$dst, $src}", []>;
1049 // Alias instruction to load FR32 or FR64 from f128mem using movaps. Upper
1050 // bits are disregarded.
1051 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1052 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
1053 "movaps\t{$src, $dst|$dst, $src}",
1054 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
1055 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1056 "movapd\t{$src, $dst|$dst, $src}",
1057 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
1060 //===----------------------------------------------------------------------===//
1061 // SSE 1 & 2 - Logical Instructions
1062 //===----------------------------------------------------------------------===//
1064 /// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
1066 multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
1067 SDNode OpNode, bit MayLoad = 0> {
1068 let isAsmParserOnly = 1 in {
1069 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1070 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR32,
1071 f32, f128mem, memopfsf32, SSEPackedSingle, MayLoad>, VEX_4V;
1073 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1074 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR64,
1075 f64, f128mem, memopfsf64, SSEPackedDouble, MayLoad>, OpSize,
1079 let Constraints = "$src1 = $dst" in {
1080 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1081 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, FR32, f32,
1082 f128mem, memopfsf32, SSEPackedSingle, MayLoad>, TB;
1084 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1085 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, FR64, f64,
1086 f128mem, memopfsf64, SSEPackedDouble, MayLoad>, TB, OpSize;
1090 // Alias bitwise logical operations using SSE logical ops on packed FP values.
1091 defm FsAND : sse12_fp_alias_pack_logical<0x54, "and", X86fand>;
1092 defm FsOR : sse12_fp_alias_pack_logical<0x56, "or", X86for>;
1093 defm FsXOR : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor>;
1095 let neverHasSideEffects = 1, Pattern = []<dag>, isCommutable = 0 in
1096 defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef, 1>;
1098 /// sse12_fp_packed_logical - SSE 1 & 2 packed FP logical ops
1100 multiclass sse12_fp_packed_logical<bits<8> opc, string OpcodeStr,
1101 SDNode OpNode, int HasPat = 0,
1102 list<list<dag>> Pattern = []> {
1103 let isAsmParserOnly = 1 in {
1104 defm V#NAME#PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1105 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1107 !if(HasPat, Pattern[0], // rr
1108 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1110 !if(HasPat, Pattern[2], // rm
1111 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1112 (memopv2i64 addr:$src2)))])>,
1115 defm V#NAME#PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1116 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1118 !if(HasPat, Pattern[1], // rr
1119 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1122 !if(HasPat, Pattern[3], // rm
1123 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1124 (memopv2i64 addr:$src2)))])>,
1127 let Constraints = "$src1 = $dst" in {
1128 defm PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1129 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"), f128mem,
1130 !if(HasPat, Pattern[0], // rr
1131 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1133 !if(HasPat, Pattern[2], // rm
1134 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1135 (memopv2i64 addr:$src2)))])>, TB;
1137 defm PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1138 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"), f128mem,
1139 !if(HasPat, Pattern[1], // rr
1140 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1143 !if(HasPat, Pattern[3], // rm
1144 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1145 (memopv2i64 addr:$src2)))])>,
1150 defm AND : sse12_fp_packed_logical<0x54, "and", and>;
1151 defm OR : sse12_fp_packed_logical<0x56, "or", or>;
1152 defm XOR : sse12_fp_packed_logical<0x57, "xor", xor>;
1153 let isCommutable = 0 in
1154 defm ANDN : sse12_fp_packed_logical<0x55, "andn", undef /* dummy */, 1, [
1156 [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
1157 (bc_v2i64 (v4i32 immAllOnesV))),
1160 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1161 (bc_v2i64 (v2f64 VR128:$src2))))],
1163 [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1164 (bc_v2i64 (v4i32 immAllOnesV))),
1165 (memopv2i64 addr:$src2))))],
1167 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1168 (memopv2i64 addr:$src2)))]]>;
1170 //===----------------------------------------------------------------------===//
1171 // SSE 1 & 2 - Arithmetic Instructions
1172 //===----------------------------------------------------------------------===//
1174 /// basic_sse12_fp_binop_rm - SSE 1 & 2 binops come in both scalar and
1177 /// In addition, we also have a special variant of the scalar form here to
1178 /// represent the associated intrinsic operation. This form is unlike the
1179 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
1180 /// and leaves the top elements unmodified (therefore these cannot be commuted).
1182 /// These three forms can each be reg+reg or reg+mem.
1184 multiclass basic_sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
1187 let isAsmParserOnly = 1 in {
1188 defm V#NAME#SS : sse12_fp_scalar<opc,
1189 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1190 OpNode, FR32, f32mem>, XS, VEX_4V;
1192 defm V#NAME#SD : sse12_fp_scalar<opc,
1193 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1194 OpNode, FR64, f64mem>, XD, VEX_4V;
1196 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1197 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1198 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
1201 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1202 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1203 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
1206 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1207 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1208 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
1210 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1211 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1212 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
1215 let Constraints = "$src1 = $dst" in {
1216 defm SS : sse12_fp_scalar<opc,
1217 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1218 OpNode, FR32, f32mem>, XS;
1220 defm SD : sse12_fp_scalar<opc,
1221 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1222 OpNode, FR64, f64mem>, XD;
1224 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1225 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
1226 f128mem, memopv4f32, SSEPackedSingle>, TB;
1228 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1229 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
1230 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1232 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1233 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1234 "", "_ss", ssmem, sse_load_f32>, XS;
1236 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1237 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1238 "2", "_sd", sdmem, sse_load_f64>, XD;
1242 // Arithmetic instructions
1243 defm ADD : basic_sse12_fp_binop_rm<0x58, "add", fadd>;
1244 defm MUL : basic_sse12_fp_binop_rm<0x59, "mul", fmul>;
1246 let isCommutable = 0 in {
1247 defm SUB : basic_sse12_fp_binop_rm<0x5C, "sub", fsub>;
1248 defm DIV : basic_sse12_fp_binop_rm<0x5E, "div", fdiv>;
1251 /// sse12_fp_binop_rm - Other SSE 1 & 2 binops
1253 /// This multiclass is like basic_sse12_fp_binop_rm, with the addition of
1254 /// instructions for a full-vector intrinsic form. Operations that map
1255 /// onto C operators don't use this form since they just use the plain
1256 /// vector form instead of having a separate vector intrinsic form.
1258 multiclass sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
1261 let isAsmParserOnly = 1 in {
1262 // Scalar operation, reg+reg.
1263 defm V#NAME#SS : sse12_fp_scalar<opc,
1264 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1265 OpNode, FR32, f32mem>, XS, VEX_4V;
1267 defm V#NAME#SD : sse12_fp_scalar<opc,
1268 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1269 OpNode, FR64, f64mem>, XD, VEX_4V;
1271 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1272 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1273 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
1276 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1277 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1278 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
1281 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1282 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1283 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
1285 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1286 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1287 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
1289 defm V#NAME#PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1290 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1291 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, VEX_4V;
1293 defm V#NAME#PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1294 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1295 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, OpSize,
1299 let Constraints = "$src1 = $dst" in {
1300 // Scalar operation, reg+reg.
1301 defm SS : sse12_fp_scalar<opc,
1302 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1303 OpNode, FR32, f32mem>, XS;
1304 defm SD : sse12_fp_scalar<opc,
1305 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1306 OpNode, FR64, f64mem>, XD;
1307 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1308 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
1309 f128mem, memopv4f32, SSEPackedSingle>, TB;
1311 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1312 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
1313 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1315 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1316 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1317 "", "_ss", ssmem, sse_load_f32>, XS;
1319 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1320 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1321 "2", "_sd", sdmem, sse_load_f64>, XD;
1323 defm PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1324 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1325 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, TB;
1327 defm PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1328 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1329 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1333 let isCommutable = 0 in {
1334 defm MAX : sse12_fp_binop_rm<0x5F, "max", X86fmax>;
1335 defm MIN : sse12_fp_binop_rm<0x5D, "min", X86fmin>;
1338 //===----------------------------------------------------------------------===//
1339 // SSE packed FP Instructions
1341 // Move Instructions
1342 let neverHasSideEffects = 1 in
1343 def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1344 "movaps\t{$src, $dst|$dst, $src}", []>;
1345 let canFoldAsLoad = 1, isReMaterializable = 1 in
1346 def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1347 "movaps\t{$src, $dst|$dst, $src}",
1348 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
1350 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1351 "movaps\t{$src, $dst|$dst, $src}",
1352 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
1354 let neverHasSideEffects = 1 in
1355 def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1356 "movups\t{$src, $dst|$dst, $src}", []>;
1357 let canFoldAsLoad = 1, isReMaterializable = 1 in
1358 def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1359 "movups\t{$src, $dst|$dst, $src}",
1360 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
1361 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1362 "movups\t{$src, $dst|$dst, $src}",
1363 [(store (v4f32 VR128:$src), addr:$dst)]>;
1365 // Intrinsic forms of MOVUPS load and store
1366 let canFoldAsLoad = 1, isReMaterializable = 1 in
1367 def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1368 "movups\t{$src, $dst|$dst, $src}",
1369 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
1370 def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1371 "movups\t{$src, $dst|$dst, $src}",
1372 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
1374 let Constraints = "$src1 = $dst" in {
1375 let AddedComplexity = 20 in {
1376 def MOVLPSrm : PSI<0x12, MRMSrcMem,
1377 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1378 "movlps\t{$src2, $dst|$dst, $src2}",
1381 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
1382 def MOVHPSrm : PSI<0x16, MRMSrcMem,
1383 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1384 "movhps\t{$src2, $dst|$dst, $src2}",
1386 (movlhps VR128:$src1,
1387 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
1388 } // AddedComplexity
1389 } // Constraints = "$src1 = $dst"
1392 def : Pat<(movlhps VR128:$src1, (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
1393 (MOVHPSrm (v4i32 VR128:$src1), addr:$src2)>;
1395 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1396 "movlps\t{$src, $dst|$dst, $src}",
1397 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
1398 (iPTR 0))), addr:$dst)]>;
1400 // v2f64 extract element 1 is always custom lowered to unpack high to low
1401 // and extract element 0 so the non-store version isn't too horrible.
1402 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1403 "movhps\t{$src, $dst|$dst, $src}",
1404 [(store (f64 (vector_extract
1405 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
1406 (undef)), (iPTR 0))), addr:$dst)]>;
1408 let Constraints = "$src1 = $dst" in {
1409 let AddedComplexity = 20 in {
1410 def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
1411 (ins VR128:$src1, VR128:$src2),
1412 "movlhps\t{$src2, $dst|$dst, $src2}",
1414 (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
1416 def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
1417 (ins VR128:$src1, VR128:$src2),
1418 "movhlps\t{$src2, $dst|$dst, $src2}",
1420 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
1421 } // AddedComplexity
1422 } // Constraints = "$src1 = $dst"
1424 let AddedComplexity = 20 in {
1425 def : Pat<(v4f32 (movddup VR128:$src, (undef))),
1426 (MOVLHPSrr (v4f32 VR128:$src), (v4f32 VR128:$src))>;
1427 def : Pat<(v2i64 (movddup VR128:$src, (undef))),
1428 (MOVLHPSrr (v2i64 VR128:$src), (v2i64 VR128:$src))>;
1435 /// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
1437 /// In addition, we also have a special variant of the scalar form here to
1438 /// represent the associated intrinsic operation. This form is unlike the
1439 /// plain scalar form, in that it takes an entire vector (instead of a
1440 /// scalar) and leaves the top elements undefined.
1442 /// And, we have a special variant form for a full-vector intrinsic form.
1444 /// These four forms can each have a reg or a mem operand, so there are a
1445 /// total of eight "instructions".
1447 multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
1451 bit Commutable = 0> {
1452 // Scalar operation, reg.
1453 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1454 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1455 [(set FR32:$dst, (OpNode FR32:$src))]> {
1456 let isCommutable = Commutable;
1459 // Scalar operation, mem.
1460 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
1461 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1462 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
1463 Requires<[HasSSE1, OptForSize]>;
1465 // Vector operation, reg.
1466 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1467 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1468 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
1469 let isCommutable = Commutable;
1472 // Vector operation, mem.
1473 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1474 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1475 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
1477 // Intrinsic operation, reg.
1478 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1479 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1480 [(set VR128:$dst, (F32Int VR128:$src))]> {
1481 let isCommutable = Commutable;
1484 // Intrinsic operation, mem.
1485 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
1486 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1487 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1489 // Vector intrinsic operation, reg
1490 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1491 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1492 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
1493 let isCommutable = Commutable;
1496 // Vector intrinsic operation, mem
1497 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1498 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1499 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
1503 defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
1504 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
1506 // Reciprocal approximations. Note that these typically require refinement
1507 // in order to obtain suitable precision.
1508 defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
1509 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
1510 defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
1511 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
1513 // Prefetch intrinsic.
1514 def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
1515 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
1516 def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
1517 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
1518 def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
1519 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
1520 def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
1521 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
1523 // Non-temporal stores
1524 def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1525 "movntps\t{$src, $dst|$dst, $src}",
1526 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
1528 let AddedComplexity = 400 in { // Prefer non-temporal versions
1529 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1530 "movntps\t{$src, $dst|$dst, $src}",
1531 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1533 def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1534 "movntdq\t{$src, $dst|$dst, $src}",
1535 [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
1537 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1538 "movnti\t{$src, $dst|$dst, $src}",
1539 [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
1540 TB, Requires<[HasSSE2]>;
1542 def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1543 "movnti\t{$src, $dst|$dst, $src}",
1544 [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
1545 TB, Requires<[HasSSE2]>;
1548 // Load, store, and memory fence
1549 def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
1550 TB, Requires<[HasSSE1]>;
1553 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
1554 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
1555 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
1556 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
1558 // Alias instructions that map zero vector to pxor / xorp* for sse.
1559 // We set canFoldAsLoad because this can be converted to a constant-pool
1560 // load of an all-zeros value if folding it would be beneficial.
1561 // FIXME: Change encoding to pseudo!
1562 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
1563 isCodeGenOnly = 1 in {
1564 def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1565 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
1566 def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1567 [(set VR128:$dst, (v2f64 immAllZerosV))]>;
1568 let ExeDomain = SSEPackedInt in
1569 def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
1570 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
1573 def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
1574 def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
1575 def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
1577 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
1578 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1580 //===---------------------------------------------------------------------===//
1581 // SSE2 Instructions
1582 //===---------------------------------------------------------------------===//
1584 // Conversion instructions
1585 def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
1586 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1587 [(set FR32:$dst, (fround FR64:$src))]>;
1588 def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
1589 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1590 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
1591 Requires<[HasSSE2, OptForSize]>;
1593 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1594 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1595 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1596 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1598 // SSE2 instructions with XS prefix
1599 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
1600 "cvtss2sd\t{$src, $dst|$dst, $src}",
1601 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1602 Requires<[HasSSE2]>;
1603 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
1604 "cvtss2sd\t{$src, $dst|$dst, $src}",
1605 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1606 Requires<[HasSSE2, OptForSize]>;
1608 def : Pat<(extloadf32 addr:$src),
1609 (CVTSS2SDrr (MOVSSrm addr:$src))>,
1610 Requires<[HasSSE2, OptForSpeed]>;
1612 //===---------------------------------------------------------------------===//
1613 // SSE packed FP Instructions
1615 // Move Instructions
1616 let neverHasSideEffects = 1 in
1617 def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1618 "movapd\t{$src, $dst|$dst, $src}", []>;
1619 let canFoldAsLoad = 1, isReMaterializable = 1 in
1620 def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1621 "movapd\t{$src, $dst|$dst, $src}",
1622 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
1624 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1625 "movapd\t{$src, $dst|$dst, $src}",
1626 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
1628 let neverHasSideEffects = 1 in
1629 def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1630 "movupd\t{$src, $dst|$dst, $src}", []>;
1631 let canFoldAsLoad = 1 in
1632 def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1633 "movupd\t{$src, $dst|$dst, $src}",
1634 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
1635 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1636 "movupd\t{$src, $dst|$dst, $src}",
1637 [(store (v2f64 VR128:$src), addr:$dst)]>;
1639 // Intrinsic forms of MOVUPD load and store
1640 def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1641 "movupd\t{$src, $dst|$dst, $src}",
1642 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
1643 def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1644 "movupd\t{$src, $dst|$dst, $src}",
1645 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
1647 let Constraints = "$src1 = $dst" in {
1648 let AddedComplexity = 20 in {
1649 def MOVLPDrm : PDI<0x12, MRMSrcMem,
1650 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1651 "movlpd\t{$src2, $dst|$dst, $src2}",
1653 (v2f64 (movlp VR128:$src1,
1654 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1655 def MOVHPDrm : PDI<0x16, MRMSrcMem,
1656 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1657 "movhpd\t{$src2, $dst|$dst, $src2}",
1659 (v2f64 (movlhps VR128:$src1,
1660 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1661 } // AddedComplexity
1662 } // Constraints = "$src1 = $dst"
1664 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1665 "movlpd\t{$src, $dst|$dst, $src}",
1666 [(store (f64 (vector_extract (v2f64 VR128:$src),
1667 (iPTR 0))), addr:$dst)]>;
1669 // v2f64 extract element 1 is always custom lowered to unpack high to low
1670 // and extract element 0 so the non-store version isn't too horrible.
1671 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1672 "movhpd\t{$src, $dst|$dst, $src}",
1673 [(store (f64 (vector_extract
1674 (v2f64 (unpckh VR128:$src, (undef))),
1675 (iPTR 0))), addr:$dst)]>;
1677 // SSE2 instructions without OpSize prefix
1678 def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1679 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1680 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1681 TB, Requires<[HasSSE2]>;
1682 def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1683 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1684 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1685 (bitconvert (memopv2i64 addr:$src))))]>,
1686 TB, Requires<[HasSSE2]>;
1688 // SSE2 instructions with XS prefix
1689 def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1690 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1691 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1692 XS, Requires<[HasSSE2]>;
1693 def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1694 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1695 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1696 (bitconvert (memopv2i64 addr:$src))))]>,
1697 XS, Requires<[HasSSE2]>;
1699 def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1700 "cvtps2dq\t{$src, $dst|$dst, $src}",
1701 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
1702 def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1703 "cvtps2dq\t{$src, $dst|$dst, $src}",
1704 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1705 (memop addr:$src)))]>;
1706 // SSE2 packed instructions with XS prefix
1707 def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1708 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1709 def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1710 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1712 def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1713 "cvttps2dq\t{$src, $dst|$dst, $src}",
1715 (int_x86_sse2_cvttps2dq VR128:$src))]>,
1716 XS, Requires<[HasSSE2]>;
1717 def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1718 "cvttps2dq\t{$src, $dst|$dst, $src}",
1719 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1720 (memop addr:$src)))]>,
1721 XS, Requires<[HasSSE2]>;
1723 // SSE2 packed instructions with XD prefix
1724 def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1725 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1726 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1727 XD, Requires<[HasSSE2]>;
1728 def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1729 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1730 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1731 (memop addr:$src)))]>,
1732 XD, Requires<[HasSSE2]>;
1734 def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1735 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1736 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
1737 def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
1738 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1739 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1740 (memop addr:$src)))]>;
1742 // SSE2 instructions without OpSize prefix
1743 def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1744 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1745 def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1746 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1748 def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1749 "cvtps2pd\t{$src, $dst|$dst, $src}",
1750 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1751 TB, Requires<[HasSSE2]>;
1752 def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1753 "cvtps2pd\t{$src, $dst|$dst, $src}",
1754 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1755 (load addr:$src)))]>,
1756 TB, Requires<[HasSSE2]>;
1758 def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1759 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1760 def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1761 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1764 def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1765 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1766 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
1767 def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1768 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1769 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1770 (memop addr:$src)))]>;
1772 // Match intrinsics which expect XMM operand(s).
1773 // Aliases for intrinsics
1774 let Constraints = "$src1 = $dst" in {
1775 def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
1776 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1777 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1778 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1780 def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
1781 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1782 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1783 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1784 (load addr:$src2)))]>;
1785 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
1786 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1787 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1788 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1789 VR128:$src2))]>, XS,
1790 Requires<[HasSSE2]>;
1791 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
1792 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
1793 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1794 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1795 (load addr:$src2)))]>, XS,
1796 Requires<[HasSSE2]>;
1801 /// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1803 /// In addition, we also have a special variant of the scalar form here to
1804 /// represent the associated intrinsic operation. This form is unlike the
1805 /// plain scalar form, in that it takes an entire vector (instead of a
1806 /// scalar) and leaves the top elements undefined.
1808 /// And, we have a special variant form for a full-vector intrinsic form.
1810 /// These four forms can each have a reg or a mem operand, so there are a
1811 /// total of eight "instructions".
1813 multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1817 bit Commutable = 0> {
1818 // Scalar operation, reg.
1819 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1820 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1821 [(set FR64:$dst, (OpNode FR64:$src))]> {
1822 let isCommutable = Commutable;
1825 // Scalar operation, mem.
1826 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1827 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1828 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1830 // Vector operation, reg.
1831 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1832 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1833 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1834 let isCommutable = Commutable;
1837 // Vector operation, mem.
1838 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1839 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1840 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
1842 // Intrinsic operation, reg.
1843 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1844 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1845 [(set VR128:$dst, (F64Int VR128:$src))]> {
1846 let isCommutable = Commutable;
1849 // Intrinsic operation, mem.
1850 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1851 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1852 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1854 // Vector intrinsic operation, reg
1855 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1856 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1857 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1858 let isCommutable = Commutable;
1861 // Vector intrinsic operation, mem
1862 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1863 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1864 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
1868 defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1869 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1871 // There is no f64 version of the reciprocal approximation instructions.
1873 //===---------------------------------------------------------------------===//
1874 // SSE integer instructions
1875 let ExeDomain = SSEPackedInt in {
1877 // Move Instructions
1878 let neverHasSideEffects = 1 in
1879 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1880 "movdqa\t{$src, $dst|$dst, $src}", []>;
1881 let canFoldAsLoad = 1, mayLoad = 1 in
1882 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1883 "movdqa\t{$src, $dst|$dst, $src}",
1884 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
1886 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1887 "movdqa\t{$src, $dst|$dst, $src}",
1888 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
1889 let canFoldAsLoad = 1, mayLoad = 1 in
1890 def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1891 "movdqu\t{$src, $dst|$dst, $src}",
1892 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
1893 XS, Requires<[HasSSE2]>;
1895 def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1896 "movdqu\t{$src, $dst|$dst, $src}",
1897 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
1898 XS, Requires<[HasSSE2]>;
1900 // Intrinsic forms of MOVDQU load and store
1901 let canFoldAsLoad = 1 in
1902 def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1903 "movdqu\t{$src, $dst|$dst, $src}",
1904 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1905 XS, Requires<[HasSSE2]>;
1906 def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1907 "movdqu\t{$src, $dst|$dst, $src}",
1908 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1909 XS, Requires<[HasSSE2]>;
1911 let Constraints = "$src1 = $dst" in {
1913 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1914 bit Commutable = 0> {
1915 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1916 (ins VR128:$src1, VR128:$src2),
1917 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1918 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1919 let isCommutable = Commutable;
1921 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1922 (ins VR128:$src1, i128mem:$src2),
1923 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1924 [(set VR128:$dst, (IntId VR128:$src1,
1925 (bitconvert (memopv2i64
1929 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1931 Intrinsic IntId, Intrinsic IntId2> {
1932 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1933 (ins VR128:$src1, VR128:$src2),
1934 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1935 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
1936 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1937 (ins VR128:$src1, i128mem:$src2),
1938 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1939 [(set VR128:$dst, (IntId VR128:$src1,
1940 (bitconvert (memopv2i64 addr:$src2))))]>;
1941 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
1942 (ins VR128:$src1, i32i8imm:$src2),
1943 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1944 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1947 /// PDI_binop_rm - Simple SSE2 binary operator.
1948 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1949 ValueType OpVT, bit Commutable = 0> {
1950 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1951 (ins VR128:$src1, VR128:$src2),
1952 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1953 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1954 let isCommutable = Commutable;
1956 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1957 (ins VR128:$src1, i128mem:$src2),
1958 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1959 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
1960 (bitconvert (memopv2i64 addr:$src2)))))]>;
1963 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1965 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1966 /// to collapse (bitconvert VT to VT) into its operand.
1968 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1969 bit Commutable = 0> {
1970 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1971 (ins VR128:$src1, VR128:$src2),
1972 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1973 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1974 let isCommutable = Commutable;
1976 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1977 (ins VR128:$src1, i128mem:$src2),
1978 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1979 [(set VR128:$dst, (OpNode VR128:$src1,
1980 (memopv2i64 addr:$src2)))]>;
1983 } // Constraints = "$src1 = $dst"
1984 } // ExeDomain = SSEPackedInt
1986 // 128-bit Integer Arithmetic
1988 defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1989 defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1990 defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1991 defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1993 defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1994 defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1995 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1996 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1998 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1999 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
2000 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
2001 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
2003 defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
2004 defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
2005 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
2006 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
2008 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
2010 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
2011 defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
2012 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
2014 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
2016 defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
2017 defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
2020 defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
2021 defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
2022 defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
2023 defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
2024 defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
2027 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
2028 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
2029 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
2030 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
2031 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2032 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
2034 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2035 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2036 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2037 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
2038 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
2039 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
2041 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2042 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
2043 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
2044 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
2046 // 128-bit logical shifts.
2047 let Constraints = "$src1 = $dst", neverHasSideEffects = 1,
2048 ExeDomain = SSEPackedInt in {
2049 def PSLLDQri : PDIi8<0x73, MRM7r,
2050 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2051 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
2052 def PSRLDQri : PDIi8<0x73, MRM3r,
2053 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2054 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
2055 // PSRADQri doesn't exist in SSE[1-3].
2058 let Predicates = [HasSSE2] in {
2059 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
2060 (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2061 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2062 (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2063 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2064 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2065 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2066 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
2067 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2068 (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2070 // Shift up / down and insert zero's.
2071 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
2072 (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2073 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
2074 (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2078 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2079 defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
2080 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2082 let Constraints = "$src1 = $dst", ExeDomain = SSEPackedInt in {
2083 def PANDNrr : PDI<0xDF, MRMSrcReg,
2084 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2085 "pandn\t{$src2, $dst|$dst, $src2}",
2086 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2089 def PANDNrm : PDI<0xDF, MRMSrcMem,
2090 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2091 "pandn\t{$src2, $dst|$dst, $src2}",
2092 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2093 (memopv2i64 addr:$src2))))]>;
2096 // SSE2 Integer comparison
2097 defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2098 defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2099 defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2100 defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2101 defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2102 defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2104 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
2105 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
2106 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
2107 (PCMPEQBrm VR128:$src1, addr:$src2)>;
2108 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
2109 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
2110 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
2111 (PCMPEQWrm VR128:$src1, addr:$src2)>;
2112 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
2113 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
2114 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
2115 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2117 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
2118 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
2119 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
2120 (PCMPGTBrm VR128:$src1, addr:$src2)>;
2121 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
2122 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
2123 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
2124 (PCMPGTWrm VR128:$src1, addr:$src2)>;
2125 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
2126 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
2127 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
2128 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2131 // Pack instructions
2132 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2133 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2134 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2136 let ExeDomain = SSEPackedInt in {
2138 // Shuffle and unpack instructions
2139 let AddedComplexity = 5 in {
2140 def PSHUFDri : PDIi8<0x70, MRMSrcReg,
2141 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2142 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2143 [(set VR128:$dst, (v4i32 (pshufd:$src2
2144 VR128:$src1, (undef))))]>;
2145 def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
2146 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2147 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2148 [(set VR128:$dst, (v4i32 (pshufd:$src2
2149 (bc_v4i32 (memopv2i64 addr:$src1)),
2153 // SSE2 with ImmT == Imm8 and XS prefix.
2154 def PSHUFHWri : Ii8<0x70, MRMSrcReg,
2155 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2156 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2157 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2159 XS, Requires<[HasSSE2]>;
2160 def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
2161 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2162 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2163 [(set VR128:$dst, (v8i16 (pshufhw:$src2
2164 (bc_v8i16 (memopv2i64 addr:$src1)),
2166 XS, Requires<[HasSSE2]>;
2168 // SSE2 with ImmT == Imm8 and XD prefix.
2169 def PSHUFLWri : Ii8<0x70, MRMSrcReg,
2170 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2171 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2172 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2174 XD, Requires<[HasSSE2]>;
2175 def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
2176 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2177 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2178 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2179 (bc_v8i16 (memopv2i64 addr:$src1)),
2181 XD, Requires<[HasSSE2]>;
2183 // Unpack instructions
2184 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2185 PatFrag unp_frag, PatFrag bc_frag> {
2186 def rr : PDI<opc, MRMSrcReg,
2187 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2188 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2189 [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2190 def rm : PDI<opc, MRMSrcMem,
2191 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2192 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2193 [(set VR128:$dst, (unp_frag VR128:$src1,
2194 (bc_frag (memopv2i64
2198 let Constraints = "$src1 = $dst" in {
2199 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2200 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2201 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2203 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2204 /// knew to collapse (bitconvert VT to VT) into its operand.
2205 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2206 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2207 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2209 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
2210 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2211 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2212 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2214 (v2i64 (unpckl VR128:$src1,
2215 (memopv2i64 addr:$src2))))]>;
2217 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2218 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2219 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2221 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2222 /// knew to collapse (bitconvert VT to VT) into its operand.
2223 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2224 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2225 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2227 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
2228 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2229 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2230 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2232 (v2i64 (unpckh VR128:$src1,
2233 (memopv2i64 addr:$src2))))]>;
2237 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
2238 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2239 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2240 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2242 let Constraints = "$src1 = $dst" in {
2243 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
2244 (outs VR128:$dst), (ins VR128:$src1,
2245 GR32:$src2, i32i8imm:$src3),
2246 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2248 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
2249 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
2250 (outs VR128:$dst), (ins VR128:$src1,
2251 i16mem:$src2, i32i8imm:$src3),
2252 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2254 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2259 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2260 "pmovmskb\t{$src, $dst|$dst, $src}",
2261 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2263 // Conditional store
2265 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2266 "maskmovdqu\t{$mask, $src|$src, $mask}",
2267 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
2270 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2271 "maskmovdqu\t{$mask, $src|$src, $mask}",
2272 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2274 } // ExeDomain = SSEPackedInt
2276 // Non-temporal stores
2277 def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2278 "movntpd\t{$src, $dst|$dst, $src}",
2279 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
2280 let ExeDomain = SSEPackedInt in
2281 def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2282 "movntdq\t{$src, $dst|$dst, $src}",
2283 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2284 def MOVNTImr_Int : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2285 "movnti\t{$src, $dst|$dst, $src}",
2286 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2287 TB, Requires<[HasSSE2]>;
2289 let AddedComplexity = 400 in { // Prefer non-temporal versions
2290 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2291 "movntpd\t{$src, $dst|$dst, $src}",
2292 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
2294 let ExeDomain = SSEPackedInt in
2295 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2296 "movntdq\t{$src, $dst|$dst, $src}",
2297 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
2301 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
2302 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
2303 TB, Requires<[HasSSE2]>;
2305 // Load, store, and memory fence
2306 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
2307 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
2308 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
2309 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2311 // Pause. This "instruction" is encoded as "rep; nop", so even though it
2312 // was introduced with SSE2, it's backward compatible.
2313 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
2315 //TODO: custom lower this so as to never even generate the noop
2316 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2318 def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2319 def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
2320 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2323 // Alias instructions that map zero vector to pxor / xorp* for sse.
2324 // We set canFoldAsLoad because this can be converted to a constant-pool
2325 // load of an all-ones value if folding it would be beneficial.
2326 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
2327 isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
2328 // FIXME: Change encoding to pseudo.
2329 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
2330 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
2332 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2333 "movd\t{$src, $dst|$dst, $src}",
2335 (v4i32 (scalar_to_vector GR32:$src)))]>;
2336 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2337 "movd\t{$src, $dst|$dst, $src}",
2339 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2341 def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2342 "movd\t{$src, $dst|$dst, $src}",
2343 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2345 def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2346 "movd\t{$src, $dst|$dst, $src}",
2347 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2349 // SSE2 instructions with XS prefix
2350 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2351 "movq\t{$src, $dst|$dst, $src}",
2353 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2354 Requires<[HasSSE2]>;
2355 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2356 "movq\t{$src, $dst|$dst, $src}",
2357 [(store (i64 (vector_extract (v2i64 VR128:$src),
2358 (iPTR 0))), addr:$dst)]>;
2360 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
2361 (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
2363 def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2364 "movd\t{$src, $dst|$dst, $src}",
2365 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2367 def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
2368 "movd\t{$src, $dst|$dst, $src}",
2369 [(store (i32 (vector_extract (v4i32 VR128:$src),
2370 (iPTR 0))), addr:$dst)]>;
2372 def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2373 "movd\t{$src, $dst|$dst, $src}",
2374 [(set GR32:$dst, (bitconvert FR32:$src))]>;
2375 def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2376 "movd\t{$src, $dst|$dst, $src}",
2377 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2379 // Store / copy lower 64-bits of a XMM register.
2380 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2381 "movq\t{$src, $dst|$dst, $src}",
2382 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2384 // movd / movq to XMM register zero-extends
2385 let AddedComplexity = 15 in {
2386 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2387 "movd\t{$src, $dst|$dst, $src}",
2388 [(set VR128:$dst, (v4i32 (X86vzmovl
2389 (v4i32 (scalar_to_vector GR32:$src)))))]>;
2390 // This is X86-64 only.
2391 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2392 "mov{d|q}\t{$src, $dst|$dst, $src}",
2393 [(set VR128:$dst, (v2i64 (X86vzmovl
2394 (v2i64 (scalar_to_vector GR64:$src)))))]>;
2397 let AddedComplexity = 20 in {
2398 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2399 "movd\t{$src, $dst|$dst, $src}",
2401 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2402 (loadi32 addr:$src))))))]>;
2404 def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2405 (MOVZDI2PDIrm addr:$src)>;
2406 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2407 (MOVZDI2PDIrm addr:$src)>;
2408 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2409 (MOVZDI2PDIrm addr:$src)>;
2411 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2412 "movq\t{$src, $dst|$dst, $src}",
2414 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2415 (loadi64 addr:$src))))))]>, XS,
2416 Requires<[HasSSE2]>;
2418 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2419 (MOVZQI2PQIrm addr:$src)>;
2420 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2421 (MOVZQI2PQIrm addr:$src)>;
2422 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
2425 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2426 // IA32 document. movq xmm1, xmm2 does clear the high bits.
2427 let AddedComplexity = 15 in
2428 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2429 "movq\t{$src, $dst|$dst, $src}",
2430 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2431 XS, Requires<[HasSSE2]>;
2433 let AddedComplexity = 20 in {
2434 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2435 "movq\t{$src, $dst|$dst, $src}",
2436 [(set VR128:$dst, (v2i64 (X86vzmovl
2437 (loadv2i64 addr:$src))))]>,
2438 XS, Requires<[HasSSE2]>;
2440 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2441 (MOVZPQILo2PQIrm addr:$src)>;
2444 // Instructions for the disassembler
2445 // xr = XMM register
2448 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2449 "movq\t{$src, $dst|$dst, $src}", []>, XS;
2451 //===---------------------------------------------------------------------===//
2452 // SSE3 Instructions
2453 //===---------------------------------------------------------------------===//
2455 // Conversion Instructions
2456 def CVTPD2DQrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2457 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2458 def CVTPD2DQrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2459 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2460 def CVTDQ2PDrm : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2461 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2462 def CVTDQ2PDrr : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2463 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2465 // Move Instructions
2466 def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2467 "movshdup\t{$src, $dst|$dst, $src}",
2468 [(set VR128:$dst, (v4f32 (movshdup
2469 VR128:$src, (undef))))]>;
2470 def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2471 "movshdup\t{$src, $dst|$dst, $src}",
2472 [(set VR128:$dst, (movshdup
2473 (memopv4f32 addr:$src), (undef)))]>;
2475 def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2476 "movsldup\t{$src, $dst|$dst, $src}",
2477 [(set VR128:$dst, (v4f32 (movsldup
2478 VR128:$src, (undef))))]>;
2479 def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2480 "movsldup\t{$src, $dst|$dst, $src}",
2481 [(set VR128:$dst, (movsldup
2482 (memopv4f32 addr:$src), (undef)))]>;
2484 def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2485 "movddup\t{$src, $dst|$dst, $src}",
2486 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
2487 def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2488 "movddup\t{$src, $dst|$dst, $src}",
2490 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2493 def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2495 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2497 let AddedComplexity = 5 in {
2498 def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
2499 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2500 def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2501 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2502 def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2503 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2504 def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2505 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2509 let Constraints = "$src1 = $dst" in {
2510 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
2511 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2512 "addsubps\t{$src2, $dst|$dst, $src2}",
2513 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2515 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
2516 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2517 "addsubps\t{$src2, $dst|$dst, $src2}",
2518 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2519 (memop addr:$src2)))]>;
2520 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
2521 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2522 "addsubpd\t{$src2, $dst|$dst, $src2}",
2523 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2525 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
2526 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2527 "addsubpd\t{$src2, $dst|$dst, $src2}",
2528 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2529 (memop addr:$src2)))]>;
2532 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2533 "lddqu\t{$src, $dst|$dst, $src}",
2534 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2537 class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2538 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2539 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2540 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2541 class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2542 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2543 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2544 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
2545 class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2546 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2547 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2548 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2549 class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2550 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2551 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2552 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
2554 let Constraints = "$src1 = $dst" in {
2555 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2556 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2557 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2558 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2559 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2560 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2561 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2562 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2565 // Thread synchronization
2566 def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
2567 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
2568 def MWAIT : I<0x01, MRM_C9, (outs), (ins), "mwait",
2569 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2571 // vector_shuffle v1, <undef> <1, 1, 3, 3>
2572 let AddedComplexity = 15 in
2573 def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
2574 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2575 let AddedComplexity = 20 in
2576 def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2577 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2579 // vector_shuffle v1, <undef> <0, 0, 2, 2>
2580 let AddedComplexity = 15 in
2581 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
2582 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2583 let AddedComplexity = 20 in
2584 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2585 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2587 //===---------------------------------------------------------------------===//
2588 // SSSE3 Instructions
2589 //===---------------------------------------------------------------------===//
2591 /// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
2592 multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2593 Intrinsic IntId64, Intrinsic IntId128> {
2594 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2595 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2596 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2598 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2599 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2601 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2603 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2605 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2606 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2609 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2611 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2614 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
2617 /// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
2618 multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2619 Intrinsic IntId64, Intrinsic IntId128> {
2620 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2622 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2623 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2625 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2627 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2630 (bitconvert (memopv4i16 addr:$src))))]>;
2632 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2634 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2635 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2638 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2640 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2643 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
2646 /// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
2647 multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2648 Intrinsic IntId64, Intrinsic IntId128> {
2649 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2651 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2652 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2654 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2656 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2659 (bitconvert (memopv2i32 addr:$src))))]>;
2661 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2663 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2664 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2667 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2669 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2672 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
2675 defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2676 int_x86_ssse3_pabs_b,
2677 int_x86_ssse3_pabs_b_128>;
2678 defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2679 int_x86_ssse3_pabs_w,
2680 int_x86_ssse3_pabs_w_128>;
2681 defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2682 int_x86_ssse3_pabs_d,
2683 int_x86_ssse3_pabs_d_128>;
2685 /// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
2686 let Constraints = "$src1 = $dst" in {
2687 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2688 Intrinsic IntId64, Intrinsic IntId128,
2689 bit Commutable = 0> {
2690 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2691 (ins VR64:$src1, VR64:$src2),
2692 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2693 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2694 let isCommutable = Commutable;
2696 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2697 (ins VR64:$src1, i64mem:$src2),
2698 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2700 (IntId64 VR64:$src1,
2701 (bitconvert (memopv8i8 addr:$src2))))]>;
2703 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2704 (ins VR128:$src1, VR128:$src2),
2705 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2706 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2708 let isCommutable = Commutable;
2710 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2711 (ins VR128:$src1, i128mem:$src2),
2712 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2714 (IntId128 VR128:$src1,
2715 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2719 /// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
2720 let Constraints = "$src1 = $dst" in {
2721 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2722 Intrinsic IntId64, Intrinsic IntId128,
2723 bit Commutable = 0> {
2724 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2725 (ins VR64:$src1, VR64:$src2),
2726 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2727 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2728 let isCommutable = Commutable;
2730 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2731 (ins VR64:$src1, i64mem:$src2),
2732 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2734 (IntId64 VR64:$src1,
2735 (bitconvert (memopv4i16 addr:$src2))))]>;
2737 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2738 (ins VR128:$src1, VR128:$src2),
2739 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2740 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2742 let isCommutable = Commutable;
2744 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2745 (ins VR128:$src1, i128mem:$src2),
2746 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2748 (IntId128 VR128:$src1,
2749 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2753 /// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
2754 let Constraints = "$src1 = $dst" in {
2755 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2756 Intrinsic IntId64, Intrinsic IntId128,
2757 bit Commutable = 0> {
2758 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2759 (ins VR64:$src1, VR64:$src2),
2760 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2761 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2762 let isCommutable = Commutable;
2764 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2765 (ins VR64:$src1, i64mem:$src2),
2766 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2768 (IntId64 VR64:$src1,
2769 (bitconvert (memopv2i32 addr:$src2))))]>;
2771 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2772 (ins VR128:$src1, VR128:$src2),
2773 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2774 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2776 let isCommutable = Commutable;
2778 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2779 (ins VR128:$src1, i128mem:$src2),
2780 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2782 (IntId128 VR128:$src1,
2783 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2787 let ImmT = NoImm in { // None of these have i8 immediate fields.
2788 defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2789 int_x86_ssse3_phadd_w,
2790 int_x86_ssse3_phadd_w_128>;
2791 defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2792 int_x86_ssse3_phadd_d,
2793 int_x86_ssse3_phadd_d_128>;
2794 defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2795 int_x86_ssse3_phadd_sw,
2796 int_x86_ssse3_phadd_sw_128>;
2797 defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2798 int_x86_ssse3_phsub_w,
2799 int_x86_ssse3_phsub_w_128>;
2800 defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2801 int_x86_ssse3_phsub_d,
2802 int_x86_ssse3_phsub_d_128>;
2803 defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2804 int_x86_ssse3_phsub_sw,
2805 int_x86_ssse3_phsub_sw_128>;
2806 defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2807 int_x86_ssse3_pmadd_ub_sw,
2808 int_x86_ssse3_pmadd_ub_sw_128>;
2809 defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2810 int_x86_ssse3_pmul_hr_sw,
2811 int_x86_ssse3_pmul_hr_sw_128, 1>;
2813 defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2814 int_x86_ssse3_pshuf_b,
2815 int_x86_ssse3_pshuf_b_128>;
2816 defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2817 int_x86_ssse3_psign_b,
2818 int_x86_ssse3_psign_b_128>;
2819 defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2820 int_x86_ssse3_psign_w,
2821 int_x86_ssse3_psign_w_128>;
2822 defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
2823 int_x86_ssse3_psign_d,
2824 int_x86_ssse3_psign_d_128>;
2827 // palignr patterns.
2828 let Constraints = "$src1 = $dst" in {
2829 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2830 (ins VR64:$src1, VR64:$src2, i8imm:$src3),
2831 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2833 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
2834 (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
2835 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2838 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2839 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
2840 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2842 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
2843 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
2844 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2848 let AddedComplexity = 5 in {
2850 def : Pat<(v1i64 (palign:$src3 VR64:$src1, VR64:$src2)),
2851 (PALIGNR64rr VR64:$src2, VR64:$src1,
2852 (SHUFFLE_get_palign_imm VR64:$src3))>,
2853 Requires<[HasSSSE3]>;
2854 def : Pat<(v2i32 (palign:$src3 VR64:$src1, VR64:$src2)),
2855 (PALIGNR64rr VR64:$src2, VR64:$src1,
2856 (SHUFFLE_get_palign_imm VR64:$src3))>,
2857 Requires<[HasSSSE3]>;
2858 def : Pat<(v2f32 (palign:$src3 VR64:$src1, VR64:$src2)),
2859 (PALIGNR64rr VR64:$src2, VR64:$src1,
2860 (SHUFFLE_get_palign_imm VR64:$src3))>,
2861 Requires<[HasSSSE3]>;
2862 def : Pat<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
2863 (PALIGNR64rr VR64:$src2, VR64:$src1,
2864 (SHUFFLE_get_palign_imm VR64:$src3))>,
2865 Requires<[HasSSSE3]>;
2866 def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
2867 (PALIGNR64rr VR64:$src2, VR64:$src1,
2868 (SHUFFLE_get_palign_imm VR64:$src3))>,
2869 Requires<[HasSSSE3]>;
2871 def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
2872 (PALIGNR128rr VR128:$src2, VR128:$src1,
2873 (SHUFFLE_get_palign_imm VR128:$src3))>,
2874 Requires<[HasSSSE3]>;
2875 def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
2876 (PALIGNR128rr VR128:$src2, VR128:$src1,
2877 (SHUFFLE_get_palign_imm VR128:$src3))>,
2878 Requires<[HasSSSE3]>;
2879 def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
2880 (PALIGNR128rr VR128:$src2, VR128:$src1,
2881 (SHUFFLE_get_palign_imm VR128:$src3))>,
2882 Requires<[HasSSSE3]>;
2883 def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
2884 (PALIGNR128rr VR128:$src2, VR128:$src1,
2885 (SHUFFLE_get_palign_imm VR128:$src3))>,
2886 Requires<[HasSSSE3]>;
2889 def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2890 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2891 def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2892 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2894 //===---------------------------------------------------------------------===//
2895 // Non-Instruction Patterns
2896 //===---------------------------------------------------------------------===//
2898 // extload f32 -> f64. This matches load+fextend because we have a hack in
2899 // the isel (PreprocessForFPConvert) that can introduce loads after dag
2901 // Since these loads aren't folded into the fextend, we have to match it
2903 let Predicates = [HasSSE2] in
2904 def : Pat<(fextend (loadf32 addr:$src)),
2905 (CVTSS2SDrm addr:$src)>;
2908 let Predicates = [HasSSE2] in {
2909 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2910 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2911 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2912 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2913 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2914 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2915 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2916 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2917 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2918 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2919 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2920 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2921 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2922 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2923 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2924 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2925 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2926 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2927 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2928 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2929 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2930 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2931 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2932 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2933 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2934 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2935 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2936 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2937 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2938 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2941 // Move scalar to XMM zero-extended
2942 // movd to XMM register zero-extends
2943 let AddedComplexity = 15 in {
2944 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
2945 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
2946 (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
2947 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
2948 (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
2949 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
2950 (MOVSSrr (v4f32 (V_SET0PS)),
2951 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
2952 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
2953 (MOVSSrr (v4i32 (V_SET0PI)),
2954 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
2957 // Splat v2f64 / v2i64
2958 let AddedComplexity = 10 in {
2959 def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
2960 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2961 def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
2962 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2963 def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
2964 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2965 def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
2966 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2969 // Special unary SHUFPSrri case.
2970 def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2971 (SHUFPSrri VR128:$src1, VR128:$src1,
2972 (SHUFFLE_get_shuf_imm VR128:$src3))>;
2973 let AddedComplexity = 5 in
2974 def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2975 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2976 Requires<[HasSSE2]>;
2977 // Special unary SHUFPDrri case.
2978 def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
2979 (SHUFPDrri VR128:$src1, VR128:$src1,
2980 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2981 Requires<[HasSSE2]>;
2982 // Special unary SHUFPDrri case.
2983 def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
2984 (SHUFPDrri VR128:$src1, VR128:$src1,
2985 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2986 Requires<[HasSSE2]>;
2987 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
2988 def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2989 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2990 Requires<[HasSSE2]>;
2992 // Special binary v4i32 shuffle cases with SHUFPS.
2993 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
2994 (SHUFPSrri VR128:$src1, VR128:$src2,
2995 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2996 Requires<[HasSSE2]>;
2997 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
2998 (SHUFPSrmi VR128:$src1, addr:$src2,
2999 (SHUFFLE_get_shuf_imm VR128:$src3))>,
3000 Requires<[HasSSE2]>;
3001 // Special binary v2i64 shuffle cases using SHUFPDrri.
3002 def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
3003 (SHUFPDrri VR128:$src1, VR128:$src2,
3004 (SHUFFLE_get_shuf_imm VR128:$src3))>,
3005 Requires<[HasSSE2]>;
3007 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
3008 let AddedComplexity = 15 in {
3009 def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
3010 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3011 Requires<[OptForSpeed, HasSSE2]>;
3012 def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
3013 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3014 Requires<[OptForSpeed, HasSSE2]>;
3016 let AddedComplexity = 10 in {
3017 def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
3018 (UNPCKLPSrr VR128:$src, VR128:$src)>;
3019 def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
3020 (PUNPCKLBWrr VR128:$src, VR128:$src)>;
3021 def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
3022 (PUNPCKLWDrr VR128:$src, VR128:$src)>;
3023 def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
3024 (PUNPCKLDQrr VR128:$src, VR128:$src)>;
3027 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
3028 let AddedComplexity = 15 in {
3029 def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
3030 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3031 Requires<[OptForSpeed, HasSSE2]>;
3032 def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
3033 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3034 Requires<[OptForSpeed, HasSSE2]>;
3036 let AddedComplexity = 10 in {
3037 def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
3038 (UNPCKHPSrr VR128:$src, VR128:$src)>;
3039 def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
3040 (PUNPCKHBWrr VR128:$src, VR128:$src)>;
3041 def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
3042 (PUNPCKHWDrr VR128:$src, VR128:$src)>;
3043 def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
3044 (PUNPCKHDQrr VR128:$src, VR128:$src)>;
3047 let AddedComplexity = 20 in {
3048 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
3049 def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
3050 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
3052 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
3053 def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
3054 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
3056 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
3057 def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
3058 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3059 def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
3060 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3063 let AddedComplexity = 20 in {
3064 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
3065 def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
3066 (MOVLPSrm VR128:$src1, addr:$src2)>;
3067 def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
3068 (MOVLPDrm VR128:$src1, addr:$src2)>;
3069 def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
3070 (MOVLPSrm VR128:$src1, addr:$src2)>;
3071 def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
3072 (MOVLPDrm VR128:$src1, addr:$src2)>;
3075 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3076 def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3077 (MOVLPSmr addr:$src1, VR128:$src2)>;
3078 def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3079 (MOVLPDmr addr:$src1, VR128:$src2)>;
3080 def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3082 (MOVLPSmr addr:$src1, VR128:$src2)>;
3083 def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3084 (MOVLPDmr addr:$src1, VR128:$src2)>;
3086 let AddedComplexity = 15 in {
3087 // Setting the lowest element in the vector.
3088 def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
3089 (MOVSSrr (v4i32 VR128:$src1),
3090 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
3091 def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
3092 (MOVSDrr (v2i64 VR128:$src1),
3093 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
3095 // vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
3096 def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
3097 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3098 Requires<[HasSSE2]>;
3099 def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
3100 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3101 Requires<[HasSSE2]>;
3104 // vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3105 // fall back to this for SSE1)
3106 def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
3107 (SHUFPSrri VR128:$src2, VR128:$src1,
3108 (SHUFFLE_get_shuf_imm VR128:$src3))>;
3110 // Set lowest element and zero upper elements.
3111 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
3112 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3114 // Some special case pandn patterns.
3115 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3117 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3118 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3120 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3121 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3123 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3125 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3126 (memop addr:$src2))),
3127 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3128 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3129 (memop addr:$src2))),
3130 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3131 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3132 (memop addr:$src2))),
3133 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3135 // vector -> vector casts
3136 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3137 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3138 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3139 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3140 def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3141 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3142 def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3143 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
3145 // Use movaps / movups for SSE integer load / store (one byte shorter).
3146 def : Pat<(alignedloadv4i32 addr:$src),
3147 (MOVAPSrm addr:$src)>;
3148 def : Pat<(loadv4i32 addr:$src),
3149 (MOVUPSrm addr:$src)>;
3150 def : Pat<(alignedloadv2i64 addr:$src),
3151 (MOVAPSrm addr:$src)>;
3152 def : Pat<(loadv2i64 addr:$src),
3153 (MOVUPSrm addr:$src)>;
3155 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3156 (MOVAPSmr addr:$dst, VR128:$src)>;
3157 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3158 (MOVAPSmr addr:$dst, VR128:$src)>;
3159 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3160 (MOVAPSmr addr:$dst, VR128:$src)>;
3161 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3162 (MOVAPSmr addr:$dst, VR128:$src)>;
3163 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3164 (MOVUPSmr addr:$dst, VR128:$src)>;
3165 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3166 (MOVUPSmr addr:$dst, VR128:$src)>;
3167 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3168 (MOVUPSmr addr:$dst, VR128:$src)>;
3169 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3170 (MOVUPSmr addr:$dst, VR128:$src)>;
3172 //===----------------------------------------------------------------------===//
3173 // SSE4.1 Instructions
3174 //===----------------------------------------------------------------------===//
3176 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
3179 Intrinsic V2F64Int> {
3180 // Intrinsic operation, reg.
3181 // Vector intrinsic operation, reg
3182 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
3183 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3184 !strconcat(OpcodeStr,
3185 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3186 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3189 // Vector intrinsic operation, mem
3190 def PSm_Int : Ii8<opcps, MRMSrcMem,
3191 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3192 !strconcat(OpcodeStr,
3193 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3195 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
3197 Requires<[HasSSE41]>;
3199 // Vector intrinsic operation, reg
3200 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
3201 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3202 !strconcat(OpcodeStr,
3203 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3204 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3207 // Vector intrinsic operation, mem
3208 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
3209 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3210 !strconcat(OpcodeStr,
3211 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3213 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
3217 let Constraints = "$src1 = $dst" in {
3218 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3222 // Intrinsic operation, reg.
3223 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
3225 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3226 !strconcat(OpcodeStr,
3227 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3229 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3232 // Intrinsic operation, mem.
3233 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3235 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
3236 !strconcat(OpcodeStr,
3237 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3239 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3242 // Intrinsic operation, reg.
3243 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
3245 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3246 !strconcat(OpcodeStr,
3247 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3249 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3252 // Intrinsic operation, mem.
3253 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
3255 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3256 !strconcat(OpcodeStr,
3257 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3259 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3264 // FP round - roundss, roundps, roundsd, roundpd
3265 defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3266 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3267 defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3268 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
3270 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3271 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3272 Intrinsic IntId128> {
3273 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3275 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3276 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3277 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3279 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3282 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3285 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3286 int_x86_sse41_phminposuw>;
3288 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3289 let Constraints = "$src1 = $dst" in {
3290 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3291 Intrinsic IntId128, bit Commutable = 0> {
3292 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3293 (ins VR128:$src1, VR128:$src2),
3294 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3295 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3297 let isCommutable = Commutable;
3299 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3300 (ins VR128:$src1, i128mem:$src2),
3301 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3303 (IntId128 VR128:$src1,
3304 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3308 defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3309 int_x86_sse41_pcmpeqq, 1>;
3310 defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3311 int_x86_sse41_packusdw, 0>;
3312 defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3313 int_x86_sse41_pminsb, 1>;
3314 defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3315 int_x86_sse41_pminsd, 1>;
3316 defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3317 int_x86_sse41_pminud, 1>;
3318 defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3319 int_x86_sse41_pminuw, 1>;
3320 defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3321 int_x86_sse41_pmaxsb, 1>;
3322 defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3323 int_x86_sse41_pmaxsd, 1>;
3324 defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3325 int_x86_sse41_pmaxud, 1>;
3326 defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3327 int_x86_sse41_pmaxuw, 1>;
3329 defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3331 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3332 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3333 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3334 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3336 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3337 let Constraints = "$src1 = $dst" in {
3338 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3339 SDNode OpNode, Intrinsic IntId128,
3340 bit Commutable = 0> {
3341 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3342 (ins VR128:$src1, VR128:$src2),
3343 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3344 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3345 VR128:$src2))]>, OpSize {
3346 let isCommutable = Commutable;
3348 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3349 (ins VR128:$src1, VR128:$src2),
3350 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3351 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3353 let isCommutable = Commutable;
3355 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3356 (ins VR128:$src1, i128mem:$src2),
3357 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3359 (OpVT (OpNode VR128:$src1, (memop addr:$src2))))]>, OpSize;
3360 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3361 (ins VR128:$src1, i128mem:$src2),
3362 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3364 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
3369 /// SS48I_binop_rm - Simple SSE41 binary operator.
3370 let Constraints = "$src1 = $dst" in {
3371 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
3372 ValueType OpVT, bit Commutable = 0> {
3373 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3374 (ins VR128:$src1, VR128:$src2),
3375 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3376 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
3378 let isCommutable = Commutable;
3380 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3381 (ins VR128:$src1, i128mem:$src2),
3382 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3383 [(set VR128:$dst, (OpNode VR128:$src1,
3384 (bc_v4i32 (memopv2i64 addr:$src2))))]>,
3389 defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, 1>;
3391 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
3392 let Constraints = "$src1 = $dst" in {
3393 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3394 Intrinsic IntId128, bit Commutable = 0> {
3395 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3396 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3397 !strconcat(OpcodeStr,
3398 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3400 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3402 let isCommutable = Commutable;
3404 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3405 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3406 !strconcat(OpcodeStr,
3407 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3409 (IntId128 VR128:$src1,
3410 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3415 defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3416 int_x86_sse41_blendps, 0>;
3417 defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3418 int_x86_sse41_blendpd, 0>;
3419 defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3420 int_x86_sse41_pblendw, 0>;
3421 defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3422 int_x86_sse41_dpps, 1>;
3423 defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3424 int_x86_sse41_dppd, 1>;
3425 defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
3426 int_x86_sse41_mpsadbw, 0>;
3429 /// SS41I_ternary_int - SSE 4.1 ternary operator
3430 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
3431 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3432 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3433 (ins VR128:$src1, VR128:$src2),
3434 !strconcat(OpcodeStr,
3435 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3436 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3439 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3440 (ins VR128:$src1, i128mem:$src2),
3441 !strconcat(OpcodeStr,
3442 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3445 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3449 defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3450 defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3451 defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3454 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3455 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3456 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3457 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3459 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3460 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3462 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3466 defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3467 defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3468 defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3469 defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3470 defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3471 defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3473 // Common patterns involving scalar load.
3474 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3475 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3476 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3477 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3479 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3480 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3481 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3482 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3484 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3485 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3486 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3487 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3489 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3490 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3491 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3492 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3494 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3495 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3496 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3497 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3499 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3500 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3501 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3502 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3505 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3506 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3507 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3508 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3510 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3511 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3513 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3517 defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3518 defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3519 defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3520 defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3522 // Common patterns involving scalar load
3523 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
3524 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
3525 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
3526 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
3528 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
3529 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
3530 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
3531 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
3534 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3535 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3536 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3537 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3539 // Expecting a i16 load any extended to i32 value.
3540 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3541 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3542 [(set VR128:$dst, (IntId (bitconvert
3543 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3547 defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3548 defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
3550 // Common patterns involving scalar load
3551 def : Pat<(int_x86_sse41_pmovsxbq
3552 (bitconvert (v4i32 (X86vzmovl
3553 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3554 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
3556 def : Pat<(int_x86_sse41_pmovzxbq
3557 (bitconvert (v4i32 (X86vzmovl
3558 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3559 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
3562 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3563 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
3564 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3565 (ins VR128:$src1, i32i8imm:$src2),
3566 !strconcat(OpcodeStr,
3567 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3568 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3570 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3571 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
3572 !strconcat(OpcodeStr,
3573 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3576 // There's an AssertZext in the way of writing the store pattern
3577 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3580 defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
3583 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3584 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
3585 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3586 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
3587 !strconcat(OpcodeStr,
3588 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3591 // There's an AssertZext in the way of writing the store pattern
3592 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3595 defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3598 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3599 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
3600 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3601 (ins VR128:$src1, i32i8imm:$src2),
3602 !strconcat(OpcodeStr,
3603 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3605 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
3606 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3607 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
3608 !strconcat(OpcodeStr,
3609 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3610 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3611 addr:$dst)]>, OpSize;
3614 defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
3617 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3619 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
3620 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3621 (ins VR128:$src1, i32i8imm:$src2),
3622 !strconcat(OpcodeStr,
3623 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3625 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
3627 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3628 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
3629 !strconcat(OpcodeStr,
3630 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3631 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
3632 addr:$dst)]>, OpSize;
3635 defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
3637 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3638 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3641 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3642 Requires<[HasSSE41]>;
3644 let Constraints = "$src1 = $dst" in {
3645 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
3646 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3647 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3648 !strconcat(OpcodeStr,
3649 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3651 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
3652 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3653 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3654 !strconcat(OpcodeStr,
3655 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3657 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3658 imm:$src3))]>, OpSize;
3662 defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3664 let Constraints = "$src1 = $dst" in {
3665 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
3666 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3667 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3668 !strconcat(OpcodeStr,
3669 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3671 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3673 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3674 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3675 !strconcat(OpcodeStr,
3676 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3678 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3679 imm:$src3)))]>, OpSize;
3683 defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3685 // insertps has a few different modes, there's the first two here below which
3686 // are optimized inserts that won't zero arbitrary elements in the destination
3687 // vector. The next one matches the intrinsic and could zero arbitrary elements
3688 // in the target vector.
3689 let Constraints = "$src1 = $dst" in {
3690 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
3691 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3692 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3693 !strconcat(OpcodeStr,
3694 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3696 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
3698 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3699 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3700 !strconcat(OpcodeStr,
3701 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3703 (X86insrtps VR128:$src1,
3704 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
3705 imm:$src3))]>, OpSize;
3709 defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
3711 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3712 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3714 // ptest instruction we'll lower to this in X86ISelLowering primarily from
3715 // the intel intrinsic that corresponds to this.
3716 let Defs = [EFLAGS] in {
3717 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
3718 "ptest \t{$src2, $src1|$src1, $src2}",
3719 [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
3721 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
3722 "ptest \t{$src2, $src1|$src1, $src2}",
3723 [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
3727 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3728 "movntdqa\t{$src, $dst|$dst, $src}",
3729 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
3733 //===----------------------------------------------------------------------===//
3734 // SSE4.2 Instructions
3735 //===----------------------------------------------------------------------===//
3737 /// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3738 let Constraints = "$src1 = $dst" in {
3739 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3740 Intrinsic IntId128, bit Commutable = 0> {
3741 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3742 (ins VR128:$src1, VR128:$src2),
3743 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3744 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3746 let isCommutable = Commutable;
3748 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3749 (ins VR128:$src1, i128mem:$src2),
3750 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3752 (IntId128 VR128:$src1,
3753 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3757 defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
3759 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3760 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3761 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3762 (PCMPGTQrm VR128:$src1, addr:$src2)>;
3764 // crc intrinsic instruction
3765 // This set of instructions are only rm, the only difference is the size
3767 let Constraints = "$src1 = $dst" in {
3768 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
3769 (ins GR32:$src1, i8mem:$src2),
3770 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3772 (int_x86_sse42_crc32_8 GR32:$src1,
3773 (load addr:$src2)))]>;
3774 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
3775 (ins GR32:$src1, GR8:$src2),
3776 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3778 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
3779 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3780 (ins GR32:$src1, i16mem:$src2),
3781 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3783 (int_x86_sse42_crc32_16 GR32:$src1,
3784 (load addr:$src2)))]>,
3786 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3787 (ins GR32:$src1, GR16:$src2),
3788 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3790 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
3792 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3793 (ins GR32:$src1, i32mem:$src2),
3794 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3796 (int_x86_sse42_crc32_32 GR32:$src1,
3797 (load addr:$src2)))]>;
3798 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3799 (ins GR32:$src1, GR32:$src2),
3800 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3802 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
3803 def CRC64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3804 (ins GR64:$src1, i8mem:$src2),
3805 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3807 (int_x86_sse42_crc64_8 GR64:$src1,
3808 (load addr:$src2)))]>,
3810 def CRC64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3811 (ins GR64:$src1, GR8:$src2),
3812 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3814 (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
3816 def CRC64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
3817 (ins GR64:$src1, i64mem:$src2),
3818 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3820 (int_x86_sse42_crc64_64 GR64:$src1,
3821 (load addr:$src2)))]>,
3823 def CRC64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
3824 (ins GR64:$src1, GR64:$src2),
3825 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3827 (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
3831 // String/text processing instructions.
3832 let Defs = [EFLAGS], usesCustomInserter = 1 in {
3833 def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3834 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3835 "#PCMPISTRM128rr PSEUDO!",
3836 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
3837 imm:$src3))]>, OpSize;
3838 def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3839 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3840 "#PCMPISTRM128rm PSEUDO!",
3841 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, (load addr:$src2),
3842 imm:$src3))]>, OpSize;
3845 let Defs = [XMM0, EFLAGS] in {
3846 def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
3847 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3848 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3849 def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
3850 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3851 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3854 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
3855 def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3856 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3857 "#PCMPESTRM128rr PSEUDO!",
3859 (int_x86_sse42_pcmpestrm128
3860 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
3862 def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3863 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3864 "#PCMPESTRM128rm PSEUDO!",
3865 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
3866 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
3870 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
3871 def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
3872 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3873 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3874 def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
3875 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3876 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3879 let Defs = [ECX, EFLAGS] in {
3880 multiclass SS42AI_pcmpistri<Intrinsic IntId128> {
3881 def rr : SS42AI<0x63, MRMSrcReg, (outs),
3882 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3883 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3884 [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
3885 (implicit EFLAGS)]>, OpSize;
3886 def rm : SS42AI<0x63, MRMSrcMem, (outs),
3887 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3888 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3889 [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
3890 (implicit EFLAGS)]>, OpSize;
3894 defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
3895 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
3896 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
3897 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
3898 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
3899 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
3901 let Defs = [ECX, EFLAGS] in {
3902 let Uses = [EAX, EDX] in {
3903 multiclass SS42AI_pcmpestri<Intrinsic IntId128> {
3904 def rr : SS42AI<0x61, MRMSrcReg, (outs),
3905 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3906 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3907 [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
3908 (implicit EFLAGS)]>, OpSize;
3909 def rm : SS42AI<0x61, MRMSrcMem, (outs),
3910 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3911 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3913 (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
3914 (implicit EFLAGS)]>, OpSize;
3919 defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
3920 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
3921 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
3922 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
3923 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
3924 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
3926 //===----------------------------------------------------------------------===//
3927 // AES-NI Instructions
3928 //===----------------------------------------------------------------------===//
3930 let Constraints = "$src1 = $dst" in {
3931 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
3932 Intrinsic IntId128, bit Commutable = 0> {
3933 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
3934 (ins VR128:$src1, VR128:$src2),
3935 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3936 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3938 let isCommutable = Commutable;
3940 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
3941 (ins VR128:$src1, i128mem:$src2),
3942 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3944 (IntId128 VR128:$src1,
3945 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3949 defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
3950 int_x86_aesni_aesenc>;
3951 defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
3952 int_x86_aesni_aesenclast>;
3953 defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
3954 int_x86_aesni_aesdec>;
3955 defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
3956 int_x86_aesni_aesdeclast>;
3958 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
3959 (AESENCrr VR128:$src1, VR128:$src2)>;
3960 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
3961 (AESENCrm VR128:$src1, addr:$src2)>;
3962 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
3963 (AESENCLASTrr VR128:$src1, VR128:$src2)>;
3964 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
3965 (AESENCLASTrm VR128:$src1, addr:$src2)>;
3966 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
3967 (AESDECrr VR128:$src1, VR128:$src2)>;
3968 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
3969 (AESDECrm VR128:$src1, addr:$src2)>;
3970 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
3971 (AESDECLASTrr VR128:$src1, VR128:$src2)>;
3972 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
3973 (AESDECLASTrm VR128:$src1, addr:$src2)>;
3975 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
3977 "aesimc\t{$src1, $dst|$dst, $src1}",
3979 (int_x86_aesni_aesimc VR128:$src1))]>,
3982 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
3983 (ins i128mem:$src1),
3984 "aesimc\t{$src1, $dst|$dst, $src1}",
3986 (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
3989 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
3990 (ins VR128:$src1, i8imm:$src2),
3991 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3993 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
3995 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
3996 (ins i128mem:$src1, i8imm:$src2),
3997 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3999 (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),