1 //====- X86InstrSSE.td - Describe the X86 Instruction Set --*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the X86 SSE instruction set, defining the instructions,
11 // and properties of the instructions which are needed for code generation,
12 // machine code emission, and analysis.
14 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
18 // SSE specific DAG Nodes.
19 //===----------------------------------------------------------------------===//
21 def SDTX86FPShiftOp : SDTypeProfile<1, 2, [ SDTCisSameAs<0, 1>,
22 SDTCisFP<0>, SDTCisInt<2> ]>;
23 def SDTX86VFCMP : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<1, 2>,
24 SDTCisFP<1>, SDTCisVT<3, i8>]>;
26 def X86fmin : SDNode<"X86ISD::FMIN", SDTFPBinOp>;
27 def X86fmax : SDNode<"X86ISD::FMAX", SDTFPBinOp>;
28 def X86fand : SDNode<"X86ISD::FAND", SDTFPBinOp,
29 [SDNPCommutative, SDNPAssociative]>;
30 def X86for : SDNode<"X86ISD::FOR", SDTFPBinOp,
31 [SDNPCommutative, SDNPAssociative]>;
32 def X86fxor : SDNode<"X86ISD::FXOR", SDTFPBinOp,
33 [SDNPCommutative, SDNPAssociative]>;
34 def X86frsqrt : SDNode<"X86ISD::FRSQRT", SDTFPUnaryOp>;
35 def X86frcp : SDNode<"X86ISD::FRCP", SDTFPUnaryOp>;
36 def X86fsrl : SDNode<"X86ISD::FSRL", SDTX86FPShiftOp>;
37 def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest>;
38 def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest>;
39 def X86pshufb : SDNode<"X86ISD::PSHUFB",
40 SDTypeProfile<1, 2, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
42 def X86pextrb : SDNode<"X86ISD::PEXTRB",
43 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
44 def X86pextrw : SDNode<"X86ISD::PEXTRW",
45 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
46 def X86pinsrb : SDNode<"X86ISD::PINSRB",
47 SDTypeProfile<1, 3, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
48 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
49 def X86pinsrw : SDNode<"X86ISD::PINSRW",
50 SDTypeProfile<1, 3, [SDTCisVT<0, v8i16>, SDTCisSameAs<0,1>,
51 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
52 def X86insrtps : SDNode<"X86ISD::INSERTPS",
53 SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisSameAs<0,1>,
54 SDTCisVT<2, v4f32>, SDTCisPtrTy<3>]>>;
55 def X86vzmovl : SDNode<"X86ISD::VZEXT_MOVL",
56 SDTypeProfile<1, 1, [SDTCisSameAs<0,1>]>>;
57 def X86vzload : SDNode<"X86ISD::VZEXT_LOAD", SDTLoad,
58 [SDNPHasChain, SDNPMayLoad]>;
59 def X86vshl : SDNode<"X86ISD::VSHL", SDTIntShiftOp>;
60 def X86vshr : SDNode<"X86ISD::VSRL", SDTIntShiftOp>;
61 def X86cmpps : SDNode<"X86ISD::CMPPS", SDTX86VFCMP>;
62 def X86cmppd : SDNode<"X86ISD::CMPPD", SDTX86VFCMP>;
63 def X86pcmpeqb : SDNode<"X86ISD::PCMPEQB", SDTIntBinOp, [SDNPCommutative]>;
64 def X86pcmpeqw : SDNode<"X86ISD::PCMPEQW", SDTIntBinOp, [SDNPCommutative]>;
65 def X86pcmpeqd : SDNode<"X86ISD::PCMPEQD", SDTIntBinOp, [SDNPCommutative]>;
66 def X86pcmpeqq : SDNode<"X86ISD::PCMPEQQ", SDTIntBinOp, [SDNPCommutative]>;
67 def X86pcmpgtb : SDNode<"X86ISD::PCMPGTB", SDTIntBinOp>;
68 def X86pcmpgtw : SDNode<"X86ISD::PCMPGTW", SDTIntBinOp>;
69 def X86pcmpgtd : SDNode<"X86ISD::PCMPGTD", SDTIntBinOp>;
70 def X86pcmpgtq : SDNode<"X86ISD::PCMPGTQ", SDTIntBinOp>;
72 def SDTX86CmpPTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>,
75 def X86ptest : SDNode<"X86ISD::PTEST", SDTX86CmpPTest>;
77 //===----------------------------------------------------------------------===//
78 // SSE Complex Patterns
79 //===----------------------------------------------------------------------===//
81 // These are 'extloads' from a scalar to the low element of a vector, zeroing
82 // the top elements. These are used for the SSE 'ss' and 'sd' instruction
84 def sse_load_f32 : ComplexPattern<v4f32, 5, "SelectScalarSSELoad", [],
85 [SDNPHasChain, SDNPMayLoad]>;
86 def sse_load_f64 : ComplexPattern<v2f64, 5, "SelectScalarSSELoad", [],
87 [SDNPHasChain, SDNPMayLoad]>;
89 def ssmem : Operand<v4f32> {
90 let PrintMethod = "printf32mem";
91 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
92 let ParserMatchClass = X86MemAsmOperand;
94 def sdmem : Operand<v2f64> {
95 let PrintMethod = "printf64mem";
96 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
97 let ParserMatchClass = X86MemAsmOperand;
100 //===----------------------------------------------------------------------===//
101 // SSE pattern fragments
102 //===----------------------------------------------------------------------===//
104 def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
105 def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
106 def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
107 def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
109 // Like 'store', but always requires vector alignment.
110 def alignedstore : PatFrag<(ops node:$val, node:$ptr),
111 (store node:$val, node:$ptr), [{
112 return cast<StoreSDNode>(N)->getAlignment() >= 16;
115 // Like 'load', but always requires vector alignment.
116 def alignedload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
117 return cast<LoadSDNode>(N)->getAlignment() >= 16;
120 def alignedloadfsf32 : PatFrag<(ops node:$ptr),
121 (f32 (alignedload node:$ptr))>;
122 def alignedloadfsf64 : PatFrag<(ops node:$ptr),
123 (f64 (alignedload node:$ptr))>;
124 def alignedloadv4f32 : PatFrag<(ops node:$ptr),
125 (v4f32 (alignedload node:$ptr))>;
126 def alignedloadv2f64 : PatFrag<(ops node:$ptr),
127 (v2f64 (alignedload node:$ptr))>;
128 def alignedloadv4i32 : PatFrag<(ops node:$ptr),
129 (v4i32 (alignedload node:$ptr))>;
130 def alignedloadv2i64 : PatFrag<(ops node:$ptr),
131 (v2i64 (alignedload node:$ptr))>;
133 // Like 'load', but uses special alignment checks suitable for use in
134 // memory operands in most SSE instructions, which are required to
135 // be naturally aligned on some targets but not on others. If the subtarget
136 // allows unaligned accesses, match any load, though this may require
137 // setting a feature bit in the processor (on startup, for example).
138 // Opteron 10h and later implement such a feature.
139 def memop : PatFrag<(ops node:$ptr), (load node:$ptr), [{
140 return Subtarget->hasVectorUAMem()
141 || cast<LoadSDNode>(N)->getAlignment() >= 16;
144 def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
145 def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
146 def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
147 def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
148 def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
149 def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
150 def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
152 // SSSE3 uses MMX registers for some instructions. They aren't aligned on a
154 // FIXME: 8 byte alignment for mmx reads is not required
155 def memop64 : PatFrag<(ops node:$ptr), (load node:$ptr), [{
156 return cast<LoadSDNode>(N)->getAlignment() >= 8;
159 def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
160 def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
161 def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
162 def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
165 // Like 'store', but requires the non-temporal bit to be set
166 def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
167 (st node:$val, node:$ptr), [{
168 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
169 return ST->isNonTemporal();
173 def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
174 (st node:$val, node:$ptr), [{
175 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
176 return ST->isNonTemporal() && !ST->isTruncatingStore() &&
177 ST->getAddressingMode() == ISD::UNINDEXED &&
178 ST->getAlignment() >= 16;
182 def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
183 (st node:$val, node:$ptr), [{
184 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
185 return ST->isNonTemporal() &&
186 ST->getAlignment() < 16;
190 def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
191 def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
192 def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
193 def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
194 def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
195 def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
197 def vzmovl_v2i64 : PatFrag<(ops node:$src),
198 (bitconvert (v2i64 (X86vzmovl
199 (v2i64 (scalar_to_vector (loadi64 node:$src))))))>;
200 def vzmovl_v4i32 : PatFrag<(ops node:$src),
201 (bitconvert (v4i32 (X86vzmovl
202 (v4i32 (scalar_to_vector (loadi32 node:$src))))))>;
204 def vzload_v2i64 : PatFrag<(ops node:$src),
205 (bitconvert (v2i64 (X86vzload node:$src)))>;
208 def fp32imm0 : PatLeaf<(f32 fpimm), [{
209 return N->isExactlyValue(+0.0);
212 // BYTE_imm - Transform bit immediates into byte immediates.
213 def BYTE_imm : SDNodeXForm<imm, [{
214 // Transformation function: imm >> 3
215 return getI32Imm(N->getZExtValue() >> 3);
218 // SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
220 def SHUFFLE_get_shuf_imm : SDNodeXForm<vector_shuffle, [{
221 return getI8Imm(X86::getShuffleSHUFImmediate(N));
224 // SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
226 def SHUFFLE_get_pshufhw_imm : SDNodeXForm<vector_shuffle, [{
227 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
230 // SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
232 def SHUFFLE_get_pshuflw_imm : SDNodeXForm<vector_shuffle, [{
233 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
236 // SHUFFLE_get_palign_imm xform function: convert vector_shuffle mask to
238 def SHUFFLE_get_palign_imm : SDNodeXForm<vector_shuffle, [{
239 return getI8Imm(X86::getShufflePALIGNRImmediate(N));
242 def splat_lo : PatFrag<(ops node:$lhs, node:$rhs),
243 (vector_shuffle node:$lhs, node:$rhs), [{
244 ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N);
245 return SVOp->isSplat() && SVOp->getSplatIndex() == 0;
248 def movddup : PatFrag<(ops node:$lhs, node:$rhs),
249 (vector_shuffle node:$lhs, node:$rhs), [{
250 return X86::isMOVDDUPMask(cast<ShuffleVectorSDNode>(N));
253 def movhlps : PatFrag<(ops node:$lhs, node:$rhs),
254 (vector_shuffle node:$lhs, node:$rhs), [{
255 return X86::isMOVHLPSMask(cast<ShuffleVectorSDNode>(N));
258 def movhlps_undef : PatFrag<(ops node:$lhs, node:$rhs),
259 (vector_shuffle node:$lhs, node:$rhs), [{
260 return X86::isMOVHLPS_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
263 def movlhps : PatFrag<(ops node:$lhs, node:$rhs),
264 (vector_shuffle node:$lhs, node:$rhs), [{
265 return X86::isMOVLHPSMask(cast<ShuffleVectorSDNode>(N));
268 def movlp : PatFrag<(ops node:$lhs, node:$rhs),
269 (vector_shuffle node:$lhs, node:$rhs), [{
270 return X86::isMOVLPMask(cast<ShuffleVectorSDNode>(N));
273 def movl : PatFrag<(ops node:$lhs, node:$rhs),
274 (vector_shuffle node:$lhs, node:$rhs), [{
275 return X86::isMOVLMask(cast<ShuffleVectorSDNode>(N));
278 def movshdup : PatFrag<(ops node:$lhs, node:$rhs),
279 (vector_shuffle node:$lhs, node:$rhs), [{
280 return X86::isMOVSHDUPMask(cast<ShuffleVectorSDNode>(N));
283 def movsldup : PatFrag<(ops node:$lhs, node:$rhs),
284 (vector_shuffle node:$lhs, node:$rhs), [{
285 return X86::isMOVSLDUPMask(cast<ShuffleVectorSDNode>(N));
288 def unpckl : PatFrag<(ops node:$lhs, node:$rhs),
289 (vector_shuffle node:$lhs, node:$rhs), [{
290 return X86::isUNPCKLMask(cast<ShuffleVectorSDNode>(N));
293 def unpckh : PatFrag<(ops node:$lhs, node:$rhs),
294 (vector_shuffle node:$lhs, node:$rhs), [{
295 return X86::isUNPCKHMask(cast<ShuffleVectorSDNode>(N));
298 def unpckl_undef : PatFrag<(ops node:$lhs, node:$rhs),
299 (vector_shuffle node:$lhs, node:$rhs), [{
300 return X86::isUNPCKL_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
303 def unpckh_undef : PatFrag<(ops node:$lhs, node:$rhs),
304 (vector_shuffle node:$lhs, node:$rhs), [{
305 return X86::isUNPCKH_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
308 def pshufd : PatFrag<(ops node:$lhs, node:$rhs),
309 (vector_shuffle node:$lhs, node:$rhs), [{
310 return X86::isPSHUFDMask(cast<ShuffleVectorSDNode>(N));
311 }], SHUFFLE_get_shuf_imm>;
313 def shufp : PatFrag<(ops node:$lhs, node:$rhs),
314 (vector_shuffle node:$lhs, node:$rhs), [{
315 return X86::isSHUFPMask(cast<ShuffleVectorSDNode>(N));
316 }], SHUFFLE_get_shuf_imm>;
318 def pshufhw : PatFrag<(ops node:$lhs, node:$rhs),
319 (vector_shuffle node:$lhs, node:$rhs), [{
320 return X86::isPSHUFHWMask(cast<ShuffleVectorSDNode>(N));
321 }], SHUFFLE_get_pshufhw_imm>;
323 def pshuflw : PatFrag<(ops node:$lhs, node:$rhs),
324 (vector_shuffle node:$lhs, node:$rhs), [{
325 return X86::isPSHUFLWMask(cast<ShuffleVectorSDNode>(N));
326 }], SHUFFLE_get_pshuflw_imm>;
328 def palign : PatFrag<(ops node:$lhs, node:$rhs),
329 (vector_shuffle node:$lhs, node:$rhs), [{
330 return X86::isPALIGNRMask(cast<ShuffleVectorSDNode>(N));
331 }], SHUFFLE_get_palign_imm>;
333 //===----------------------------------------------------------------------===//
334 // SSE scalar FP Instructions
335 //===----------------------------------------------------------------------===//
337 // CMOV* - Used to implement the SSE SELECT DAG operation. Expanded after
338 // instruction selection into a branch sequence.
339 let Uses = [EFLAGS], usesCustomInserter = 1 in {
340 def CMOV_FR32 : I<0, Pseudo,
341 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
342 "#CMOV_FR32 PSEUDO!",
343 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
345 def CMOV_FR64 : I<0, Pseudo,
346 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
347 "#CMOV_FR64 PSEUDO!",
348 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
350 def CMOV_V4F32 : I<0, Pseudo,
351 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
352 "#CMOV_V4F32 PSEUDO!",
354 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
356 def CMOV_V2F64 : I<0, Pseudo,
357 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
358 "#CMOV_V2F64 PSEUDO!",
360 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
362 def CMOV_V2I64 : I<0, Pseudo,
363 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
364 "#CMOV_V2I64 PSEUDO!",
366 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
370 //===----------------------------------------------------------------------===//
371 // SSE 1 & 2 Instructions Classes
372 //===----------------------------------------------------------------------===//
374 /// sse12_fp_scalar - SSE 1 & 2 scalar instructions class
375 multiclass sse12_fp_scalar<bits<8> opc, string OpcodeStr, SDNode OpNode,
376 RegisterClass RC, X86MemOperand x86memop> {
377 let isCommutable = 1 in {
378 def rr : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
379 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1, RC:$src2))]>;
381 def rm : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
382 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1, (load addr:$src2)))]>;
385 /// sse12_fp_scalar_int - SSE 1 & 2 scalar instructions intrinsics class
386 multiclass sse12_fp_scalar_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
387 string asm, string SSEVer, string FPSizeStr,
388 Operand memopr, ComplexPattern mem_cpat> {
389 def rr_Int : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
390 asm, [(set RC:$dst, (
391 !nameconcat<Intrinsic>("int_x86_sse",
392 !strconcat(SSEVer, !strconcat("_",
393 !strconcat(OpcodeStr, FPSizeStr))))
394 RC:$src1, RC:$src2))]>;
395 def rm_Int : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, memopr:$src2),
396 asm, [(set RC:$dst, (
397 !nameconcat<Intrinsic>("int_x86_sse",
398 !strconcat(SSEVer, !strconcat("_",
399 !strconcat(OpcodeStr, FPSizeStr))))
400 RC:$src1, mem_cpat:$src2))]>;
403 /// sse12_fp_packed - SSE 1 & 2 packed instructions class
404 multiclass sse12_fp_packed<bits<8> opc, string OpcodeStr, SDNode OpNode,
405 RegisterClass RC, ValueType vt,
406 X86MemOperand x86memop, PatFrag mem_frag,
407 Domain d, bit MayLoad = 0> {
408 let isCommutable = 1 in
409 def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
410 OpcodeStr, [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))],d>;
411 let mayLoad = MayLoad in
412 def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
413 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1,
414 (mem_frag addr:$src2)))],d>;
417 /// sse12_fp_packed_logical_rm - SSE 1 & 2 packed instructions class
418 multiclass sse12_fp_packed_logical_rm<bits<8> opc, RegisterClass RC, Domain d,
419 string OpcodeStr, X86MemOperand x86memop,
420 list<dag> pat_rr, list<dag> pat_rm> {
421 let isCommutable = 1 in
422 def rr : PI<opc, MRMSrcReg, (outs RC:$dst),
423 (ins RC:$src1, RC:$src2), OpcodeStr, pat_rr, d>;
424 def rm : PI<opc, MRMSrcMem, (outs RC:$dst),
425 (ins RC:$src1, x86memop:$src2), OpcodeStr, pat_rm, d>;
428 /// sse12_fp_packed_int - SSE 1 & 2 packed instructions intrinsics class
429 multiclass sse12_fp_packed_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
430 string asm, string SSEVer, string FPSizeStr,
431 X86MemOperand x86memop, PatFrag mem_frag,
433 def rr_Int : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
434 asm, [(set RC:$dst, (
435 !nameconcat<Intrinsic>("int_x86_sse",
436 !strconcat(SSEVer, !strconcat("_",
437 !strconcat(OpcodeStr, FPSizeStr))))
438 RC:$src1, RC:$src2))], d>;
439 def rm_Int : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
440 asm, [(set RC:$dst, (
441 !nameconcat<Intrinsic>("int_x86_sse",
442 !strconcat(SSEVer, !strconcat("_",
443 !strconcat(OpcodeStr, FPSizeStr))))
444 RC:$src1, (mem_frag addr:$src2)))], d>;
447 //===----------------------------------------------------------------------===//
449 //===----------------------------------------------------------------------===//
451 // Conversion Instructions
453 // Match intrinsics which expect XMM operand(s).
454 def CVTSS2SIrr: SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
455 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
456 def CVTSS2SIrm: SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
457 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
459 def CVTDQ2PSrr : PSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
460 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
461 def CVTDQ2PSrm : PSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
462 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
464 // Aliases for intrinsics
465 def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
466 "cvttss2si\t{$src, $dst|$dst, $src}",
468 (int_x86_sse_cvttss2si VR128:$src))]>;
469 def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
470 "cvttss2si\t{$src, $dst|$dst, $src}",
472 (int_x86_sse_cvttss2si(load addr:$src)))]>;
474 let Constraints = "$src1 = $dst" in {
475 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
476 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
477 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
478 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
480 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
481 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
482 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
483 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
484 (loadi32 addr:$src2)))]>;
487 //===----------------------------------------------------------------------===//
488 // SSE 1 & 2 - Move Instructions
489 //===----------------------------------------------------------------------===//
491 class sse12_move_rr<RegisterClass RC, ValueType vt, string asm> :
492 SI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, RC:$src2), asm,
493 [(set (vt VR128:$dst), (movl VR128:$src1, (scalar_to_vector RC:$src2)))]>;
495 // Loading from memory automatically zeroing upper bits.
496 class sse12_move_rm<RegisterClass RC, X86MemOperand x86memop,
497 PatFrag mem_pat, string OpcodeStr> :
498 SI<0x10, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
499 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
500 [(set RC:$dst, (mem_pat addr:$src))]>;
502 // Move Instructions. Register-to-register movss/movsd is not used for FR32/64
503 // register copies because it's a partial register update; FsMOVAPSrr/FsMOVAPDrr
504 // is used instead. Register-to-register movss/movsd is not modeled as an
505 // INSERT_SUBREG because INSERT_SUBREG requires that the insert be implementable
506 // in terms of a copy, and just mentioned, we don't use movss/movsd for copies.
507 let isAsmParserOnly = 1 in {
508 def VMOVSSrr : sse12_move_rr<FR32, v4f32,
509 "movss\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XS, VEX_4V;
510 def VMOVSDrr : sse12_move_rr<FR64, v2f64,
511 "movsd\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XD, VEX_4V;
513 let canFoldAsLoad = 1, isReMaterializable = 1 in {
514 def VMOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS, VEX;
516 let AddedComplexity = 20 in
517 def VMOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD, VEX;
521 let Constraints = "$src1 = $dst" in {
522 def MOVSSrr : sse12_move_rr<FR32, v4f32,
523 "movss\t{$src2, $dst|$dst, $src2}">, XS;
524 def MOVSDrr : sse12_move_rr<FR64, v2f64,
525 "movsd\t{$src2, $dst|$dst, $src2}">, XD;
528 let canFoldAsLoad = 1, isReMaterializable = 1 in {
529 def MOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS;
531 let AddedComplexity = 20 in
532 def MOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD;
535 let AddedComplexity = 15 in {
536 // Extract the low 32-bit value from one vector and insert it into another.
537 def : Pat<(v4f32 (movl VR128:$src1, VR128:$src2)),
538 (MOVSSrr (v4f32 VR128:$src1),
539 (EXTRACT_SUBREG (v4f32 VR128:$src2), sub_ss))>;
540 // Extract the low 64-bit value from one vector and insert it into another.
541 def : Pat<(v2f64 (movl VR128:$src1, VR128:$src2)),
542 (MOVSDrr (v2f64 VR128:$src1),
543 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
546 // Implicitly promote a 32-bit scalar to a vector.
547 def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
548 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss)>;
549 // Implicitly promote a 64-bit scalar to a vector.
550 def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
551 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
553 let AddedComplexity = 20 in {
554 // MOVSSrm zeros the high parts of the register; represent this
555 // with SUBREG_TO_REG.
556 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
557 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
558 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
559 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
560 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
561 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
562 // MOVSDrm zeros the high parts of the register; represent this
563 // with SUBREG_TO_REG.
564 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
565 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
566 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
567 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
568 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
569 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
570 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
571 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
572 def : Pat<(v2f64 (X86vzload addr:$src)),
573 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
576 // Store scalar value to memory.
577 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
578 "movss\t{$src, $dst|$dst, $src}",
579 [(store FR32:$src, addr:$dst)]>;
580 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
581 "movsd\t{$src, $dst|$dst, $src}",
582 [(store FR64:$src, addr:$dst)]>;
584 let isAsmParserOnly = 1 in {
585 def VMOVSSmr : SI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
586 "movss\t{$src, $dst|$dst, $src}",
587 [(store FR32:$src, addr:$dst)]>, XS, VEX_4V;
588 def VMOVSDmr : SI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
589 "movsd\t{$src, $dst|$dst, $src}",
590 [(store FR64:$src, addr:$dst)]>, XD, VEX_4V;
593 // Extract and store.
594 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
597 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
598 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
601 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
603 //===----------------------------------------------------------------------===//
604 // SSE 1 & 2 - Conversion Instructions
605 //===----------------------------------------------------------------------===//
607 // Conversion instructions
608 def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
609 "cvttss2si\t{$src, $dst|$dst, $src}",
610 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
611 def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
612 "cvttss2si\t{$src, $dst|$dst, $src}",
613 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
614 def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
615 "cvttsd2si\t{$src, $dst|$dst, $src}",
616 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
617 def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
618 "cvttsd2si\t{$src, $dst|$dst, $src}",
619 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
621 def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
622 "cvtsi2ss\t{$src, $dst|$dst, $src}",
623 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
624 def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
625 "cvtsi2ss\t{$src, $dst|$dst, $src}",
626 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
627 def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
628 "cvtsi2sd\t{$src, $dst|$dst, $src}",
629 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
630 def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
631 "cvtsi2sd\t{$src, $dst|$dst, $src}",
632 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
634 // Match intrinsics which expect XMM operand(s).
635 def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
636 "cvtss2si\t{$src, $dst|$dst, $src}",
637 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
638 def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
639 "cvtss2si\t{$src, $dst|$dst, $src}",
640 [(set GR32:$dst, (int_x86_sse_cvtss2si
641 (load addr:$src)))]>;
642 def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
643 "cvtsd2si\t{$src, $dst|$dst, $src}",
644 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
645 def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
646 "cvtsd2si\t{$src, $dst|$dst, $src}",
647 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
648 (load addr:$src)))]>;
650 // Match intrinsics which expect MM and XMM operand(s).
651 def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
652 "cvtps2pi\t{$src, $dst|$dst, $src}",
653 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
654 def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
655 "cvtps2pi\t{$src, $dst|$dst, $src}",
656 [(set VR64:$dst, (int_x86_sse_cvtps2pi
657 (load addr:$src)))]>;
658 def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
659 "cvtpd2pi\t{$src, $dst|$dst, $src}",
660 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
661 def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
662 "cvtpd2pi\t{$src, $dst|$dst, $src}",
663 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
664 (memop addr:$src)))]>;
666 // Match intrinsics which expect MM and XMM operand(s).
667 def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
668 "cvttps2pi\t{$src, $dst|$dst, $src}",
669 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
670 def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
671 "cvttps2pi\t{$src, $dst|$dst, $src}",
672 [(set VR64:$dst, (int_x86_sse_cvttps2pi
673 (load addr:$src)))]>;
674 def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
675 "cvttpd2pi\t{$src, $dst|$dst, $src}",
676 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
677 def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
678 "cvttpd2pi\t{$src, $dst|$dst, $src}",
679 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
680 (memop addr:$src)))]>;
682 let Constraints = "$src1 = $dst" in {
683 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
684 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
685 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
686 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
688 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
689 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
690 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
691 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
692 (load addr:$src2)))]>;
695 //===----------------------------------------------------------------------===//
696 // SSE 1 & 2 - Compare Instructions
697 //===----------------------------------------------------------------------===//
699 // sse12_cmp_scalar - sse 1 & 2 compare scalar instructions
700 multiclass sse12_cmp_scalar<RegisterClass RC, X86MemOperand x86memop,
701 string asm, string asm_alt> {
702 def rr : SIi8<0xC2, MRMSrcReg,
703 (outs RC:$dst), (ins RC:$src1, RC:$src, SSECC:$cc),
706 def rm : SIi8<0xC2, MRMSrcMem,
707 (outs RC:$dst), (ins RC:$src1, x86memop:$src, SSECC:$cc),
709 // Accept explicit immediate argument form instead of comparison code.
710 let isAsmParserOnly = 1 in {
711 def rr_alt : SIi8<0xC2, MRMSrcReg,
712 (outs RC:$dst), (ins RC:$src1, RC:$src, i8imm:$src2),
715 def rm_alt : SIi8<0xC2, MRMSrcMem,
716 (outs RC:$dst), (ins RC:$src1, x86memop:$src, i8imm:$src2),
721 let neverHasSideEffects = 1, isAsmParserOnly = 1 in {
722 defm VCMPSS : sse12_cmp_scalar<FR32, f32mem,
723 "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}",
724 "cmpss\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}">,
726 defm VCMPSD : sse12_cmp_scalar<FR64, f64mem,
727 "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}",
728 "cmpsd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}">,
732 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
733 defm CMPSS : sse12_cmp_scalar<FR32, f32mem,
734 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
735 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}">, XS;
736 defm CMPSD : sse12_cmp_scalar<FR64, f64mem,
737 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
738 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}">, XD;
741 multiclass sse12_cmp_scalar_int<RegisterClass RC, X86MemOperand x86memop,
742 Intrinsic Int, string asm> {
743 def rr : SIi8<0xC2, MRMSrcReg, (outs VR128:$dst),
744 (ins VR128:$src1, VR128:$src, SSECC:$cc), asm,
745 [(set VR128:$dst, (Int VR128:$src1,
746 VR128:$src, imm:$cc))]>;
747 def rm : SIi8<0xC2, MRMSrcMem, (outs VR128:$dst),
748 (ins VR128:$src1, f32mem:$src, SSECC:$cc), asm,
749 [(set VR128:$dst, (Int VR128:$src1,
750 (load addr:$src), imm:$cc))]>;
753 // Aliases to match intrinsics which expect XMM operand(s).
754 let isAsmParserOnly = 1 in {
755 defm Int_VCMPSS : sse12_cmp_scalar_int<VR128, f32mem, int_x86_sse_cmp_ss,
756 "cmp${cc}ss\t{$src, $src1, $dst|$dst, $src1, $src}">,
758 defm Int_VCMPSD : sse12_cmp_scalar_int<VR128, f64mem, int_x86_sse2_cmp_sd,
759 "cmp${cc}sd\t{$src, $src1, $dst|$dst, $src1, $src}">,
762 let Constraints = "$src1 = $dst" in {
763 defm Int_CMPSS : sse12_cmp_scalar_int<VR128, f32mem, int_x86_sse_cmp_ss,
764 "cmp${cc}ss\t{$src, $dst|$dst, $src}">, XS;
765 defm Int_CMPSD : sse12_cmp_scalar_int<VR128, f64mem, int_x86_sse2_cmp_sd,
766 "cmp${cc}sd\t{$src, $dst|$dst, $src}">, XD;
770 // sse12_ord_cmp - Unordered/Ordered scalar fp compare and set EFLAGS
771 multiclass sse12_ord_cmp<bits<8> opc, RegisterClass RC, SDNode OpNode,
772 ValueType vt, X86MemOperand x86memop,
773 PatFrag ld_frag, string OpcodeStr, Domain d> {
774 def rr: PI<opc, MRMSrcReg, (outs), (ins RC:$src1, RC:$src2),
775 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
776 [(set EFLAGS, (OpNode (vt RC:$src1), RC:$src2))], d>;
777 def rm: PI<opc, MRMSrcMem, (outs), (ins RC:$src1, x86memop:$src2),
778 !strconcat(OpcodeStr, "\t{$src2, $src1|$src1, $src2}"),
779 [(set EFLAGS, (OpNode (vt RC:$src1),
780 (ld_frag addr:$src2)))], d>;
783 let Defs = [EFLAGS] in {
784 let isAsmParserOnly = 1 in {
785 defm VUCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
786 "ucomiss", SSEPackedSingle>, VEX;
787 defm VUCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
788 "ucomisd", SSEPackedDouble>, OpSize, VEX;
789 let Pattern = []<dag> in {
790 defm VCOMISS : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
791 "comiss", SSEPackedSingle>, VEX;
792 defm VCOMISD : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
793 "comisd", SSEPackedDouble>, OpSize, VEX;
796 defm Int_VUCOMISS : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
797 load, "ucomiss", SSEPackedSingle>, VEX;
798 defm Int_VUCOMISD : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
799 load, "ucomisd", SSEPackedDouble>, OpSize, VEX;
801 defm Int_VCOMISS : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem,
802 load, "comiss", SSEPackedSingle>, VEX;
803 defm Int_VCOMISD : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem,
804 load, "comisd", SSEPackedDouble>, OpSize, VEX;
806 defm UCOMISS : sse12_ord_cmp<0x2E, FR32, X86cmp, f32, f32mem, loadf32,
807 "ucomiss", SSEPackedSingle>, TB;
808 defm UCOMISD : sse12_ord_cmp<0x2E, FR64, X86cmp, f64, f64mem, loadf64,
809 "ucomisd", SSEPackedDouble>, TB, OpSize;
811 let Pattern = []<dag> in {
812 defm COMISS : sse12_ord_cmp<0x2F, VR128, undef, v4f32, f128mem, load,
813 "comiss", SSEPackedSingle>, TB;
814 defm COMISD : sse12_ord_cmp<0x2F, VR128, undef, v2f64, f128mem, load,
815 "comisd", SSEPackedDouble>, TB, OpSize;
818 defm Int_UCOMISS : sse12_ord_cmp<0x2E, VR128, X86ucomi, v4f32, f128mem,
819 load, "ucomiss", SSEPackedSingle>, TB;
820 defm Int_UCOMISD : sse12_ord_cmp<0x2E, VR128, X86ucomi, v2f64, f128mem,
821 load, "ucomisd", SSEPackedDouble>, TB, OpSize;
823 defm Int_COMISS : sse12_ord_cmp<0x2F, VR128, X86comi, v4f32, f128mem, load,
824 "comiss", SSEPackedSingle>, TB;
825 defm Int_COMISD : sse12_ord_cmp<0x2F, VR128, X86comi, v2f64, f128mem, load,
826 "comisd", SSEPackedDouble>, TB, OpSize;
829 // sse12_cmp_packed - sse 1 & 2 compared packed instructions
830 multiclass sse12_cmp_packed<RegisterClass RC, X86MemOperand x86memop,
831 Intrinsic Int, string asm, string asm_alt,
833 def rri : PIi8<0xC2, MRMSrcReg,
834 (outs RC:$dst), (ins RC:$src1, RC:$src, SSECC:$cc), asm,
835 [(set RC:$dst, (Int RC:$src1, RC:$src, imm:$cc))], d>;
836 def rmi : PIi8<0xC2, MRMSrcMem,
837 (outs RC:$dst), (ins RC:$src1, f128mem:$src, SSECC:$cc), asm,
838 [(set RC:$dst, (Int RC:$src1, (memop addr:$src), imm:$cc))], d>;
839 // Accept explicit immediate argument form instead of comparison code.
840 let isAsmParserOnly = 1 in {
841 def rri_alt : PIi8<0xC2, MRMSrcReg,
842 (outs RC:$dst), (ins RC:$src1, RC:$src, i8imm:$src2),
844 def rmi_alt : PIi8<0xC2, MRMSrcMem,
845 (outs RC:$dst), (ins RC:$src1, f128mem:$src, i8imm:$src2),
850 let isAsmParserOnly = 1 in {
851 defm VCMPPS : sse12_cmp_packed<VR128, f128mem, int_x86_sse_cmp_ps,
852 "cmp${cc}ps\t{$src, $src1, $dst|$dst, $src1, $src}",
853 "cmpps\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
854 SSEPackedSingle>, VEX_4V;
855 defm VCMPPD : sse12_cmp_packed<VR128, f128mem, int_x86_sse2_cmp_pd,
856 "cmp${cc}pd\t{$src, $src1, $dst|$dst, $src1, $src}",
857 "cmppd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
858 SSEPackedDouble>, OpSize, VEX_4V;
860 let Constraints = "$src1 = $dst" in {
861 defm CMPPS : sse12_cmp_packed<VR128, f128mem, int_x86_sse_cmp_ps,
862 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
863 "cmpps\t{$src2, $src, $dst|$dst, $src, $src2}",
864 SSEPackedSingle>, TB;
865 defm CMPPD : sse12_cmp_packed<VR128, f128mem, int_x86_sse2_cmp_pd,
866 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
867 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}",
868 SSEPackedDouble>, TB, OpSize;
871 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
872 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
873 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
874 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
875 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
876 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
877 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
878 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
880 //===----------------------------------------------------------------------===//
881 // SSE 1 & 2 - Shuffle Instructions
882 //===----------------------------------------------------------------------===//
884 /// sse12_shuffle - sse 1 & 2 shuffle instructions
885 multiclass sse12_shuffle<RegisterClass RC, X86MemOperand x86memop,
886 ValueType vt, string asm, PatFrag mem_frag,
887 Domain d, bit IsConvertibleToThreeAddress = 0> {
888 def rmi : PIi8<0xC6, MRMSrcMem, (outs VR128:$dst),
889 (ins VR128:$src1, f128mem:$src2, i8imm:$src3), asm,
890 [(set VR128:$dst, (vt (shufp:$src3
891 VR128:$src1, (mem_frag addr:$src2))))], d>;
892 let isConvertibleToThreeAddress = IsConvertibleToThreeAddress in
893 def rri : PIi8<0xC6, MRMSrcReg, (outs VR128:$dst),
894 (ins VR128:$src1, VR128:$src2, i8imm:$src3), asm,
896 (vt (shufp:$src3 VR128:$src1, VR128:$src2)))], d>;
899 let isAsmParserOnly = 1 in {
900 defm VSHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
901 "shufps\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}",
902 memopv4f32, SSEPackedSingle>, VEX_4V;
903 defm VSHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
904 "shufpd\t{$src3, $src2, $src1, $dst|$dst, $src2, $src2, $src3}",
905 memopv2f64, SSEPackedDouble>, OpSize, VEX_4V;
908 let Constraints = "$src1 = $dst" in {
909 defm SHUFPS : sse12_shuffle<VR128, f128mem, v4f32,
910 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
911 memopv4f32, SSEPackedSingle, 1 /* cvt to pshufd */>,
913 defm SHUFPD : sse12_shuffle<VR128, f128mem, v2f64,
914 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
915 memopv2f64, SSEPackedDouble>, TB, OpSize;
918 //===----------------------------------------------------------------------===//
919 // SSE 1 & 2 - Unpack Instructions
920 //===----------------------------------------------------------------------===//
922 /// sse12_unpack_interleave - sse 1 & 2 unpack and interleave
923 multiclass sse12_unpack_interleave<bits<8> opc, PatFrag OpNode, ValueType vt,
924 PatFrag mem_frag, RegisterClass RC,
925 X86MemOperand x86memop, string asm,
927 def rr : PI<opc, MRMSrcReg,
928 (outs RC:$dst), (ins RC:$src1, RC:$src2),
930 (vt (OpNode RC:$src1, RC:$src2)))], d>;
931 def rm : PI<opc, MRMSrcMem,
932 (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
934 (vt (OpNode RC:$src1,
935 (mem_frag addr:$src2))))], d>;
938 let AddedComplexity = 10 in {
939 let isAsmParserOnly = 1 in {
940 defm VUNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
941 VR128, f128mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
942 SSEPackedSingle>, VEX_4V;
943 defm VUNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
944 VR128, f128mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
945 SSEPackedDouble>, OpSize, VEX_4V;
946 defm VUNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
947 VR128, f128mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
948 SSEPackedSingle>, VEX_4V;
949 defm VUNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
950 VR128, f128mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
951 SSEPackedDouble>, OpSize, VEX_4V;
954 let Constraints = "$src1 = $dst" in {
955 defm UNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
956 VR128, f128mem, "unpckhps\t{$src2, $dst|$dst, $src2}",
957 SSEPackedSingle>, TB;
958 defm UNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
959 VR128, f128mem, "unpckhpd\t{$src2, $dst|$dst, $src2}",
960 SSEPackedDouble>, TB, OpSize;
961 defm UNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
962 VR128, f128mem, "unpcklps\t{$src2, $dst|$dst, $src2}",
963 SSEPackedSingle>, TB;
964 defm UNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
965 VR128, f128mem, "unpcklpd\t{$src2, $dst|$dst, $src2}",
966 SSEPackedDouble>, TB, OpSize;
967 } // Constraints = "$src1 = $dst"
970 //===----------------------------------------------------------------------===//
971 // SSE 1 & 2 - Extract Floating-Point Sign mask
972 //===----------------------------------------------------------------------===//
974 /// sse12_extr_sign_mask - sse 1 & 2 unpack and interleave
975 multiclass sse12_extr_sign_mask<RegisterClass RC, Intrinsic Int, string asm,
977 def rr : PI<0x50, MRMSrcReg, (outs GR32:$dst), (ins RC:$src),
978 !strconcat(asm, "\t{$src, $dst|$dst, $src}"),
979 [(set GR32:$dst, (Int RC:$src))], d>;
983 defm MOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps, "movmskps",
984 SSEPackedSingle>, TB;
985 defm MOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd, "movmskpd",
986 SSEPackedDouble>, TB, OpSize;
988 let isAsmParserOnly = 1 in {
989 defm VMOVMSKPS : sse12_extr_sign_mask<VR128, int_x86_sse_movmsk_ps,
990 "movmskps", SSEPackedSingle>, VEX;
991 defm VMOVMSKPD : sse12_extr_sign_mask<VR128, int_x86_sse2_movmsk_pd,
992 "movmskpd", SSEPackedDouble>, OpSize,
996 //===----------------------------------------------------------------------===//
997 // SSE 1 & 2 - Misc aliasing of packed SSE 1 & 2 instructions
998 //===----------------------------------------------------------------------===//
1000 // Aliases of packed SSE1 & SSE2 instructions for scalar use. These all have
1001 // names that start with 'Fs'.
1003 // Alias instructions that map fld0 to pxor for sse.
1004 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
1005 canFoldAsLoad = 1 in {
1006 // FIXME: Set encoding to pseudo!
1007 def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins), "",
1008 [(set FR32:$dst, fp32imm0)]>,
1009 Requires<[HasSSE1]>, TB, OpSize;
1010 def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
1011 [(set FR64:$dst, fpimm0)]>,
1012 Requires<[HasSSE2]>, TB, OpSize;
1015 // Alias instruction to do FR32 or FR64 reg-to-reg copy using movaps. Upper
1016 // bits are disregarded.
1017 let neverHasSideEffects = 1 in {
1018 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1019 "movaps\t{$src, $dst|$dst, $src}", []>;
1020 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1021 "movapd\t{$src, $dst|$dst, $src}", []>;
1024 // Alias instruction to load FR32 or FR64 from f128mem using movaps. Upper
1025 // bits are disregarded.
1026 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1027 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
1028 "movaps\t{$src, $dst|$dst, $src}",
1029 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
1030 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1031 "movapd\t{$src, $dst|$dst, $src}",
1032 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
1035 //===----------------------------------------------------------------------===//
1036 // SSE 1 & 2 - Logical Instructions
1037 //===----------------------------------------------------------------------===//
1039 /// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
1041 multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
1042 SDNode OpNode, bit MayLoad = 0> {
1043 let isAsmParserOnly = 1 in {
1044 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1045 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR32,
1046 f32, f128mem, memopfsf32, SSEPackedSingle, MayLoad>, VEX_4V;
1048 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1049 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR64,
1050 f64, f128mem, memopfsf64, SSEPackedDouble, MayLoad>, OpSize,
1054 let Constraints = "$src1 = $dst" in {
1055 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1056 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, FR32, f32,
1057 f128mem, memopfsf32, SSEPackedSingle, MayLoad>, TB;
1059 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1060 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, FR64, f64,
1061 f128mem, memopfsf64, SSEPackedDouble, MayLoad>, TB, OpSize;
1065 // Alias bitwise logical operations using SSE logical ops on packed FP values.
1066 defm FsAND : sse12_fp_alias_pack_logical<0x54, "and", X86fand>;
1067 defm FsOR : sse12_fp_alias_pack_logical<0x56, "or", X86for>;
1068 defm FsXOR : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor>;
1070 let neverHasSideEffects = 1, Pattern = []<dag>, isCommutable = 0 in
1071 defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef, 1>;
1073 /// sse12_fp_packed_logical - SSE 1 & 2 packed FP logical ops
1075 multiclass sse12_fp_packed_logical<bits<8> opc, string OpcodeStr,
1076 SDNode OpNode, int HasPat = 0,
1077 list<list<dag>> Pattern = []> {
1078 let isAsmParserOnly = 1 in {
1079 defm V#NAME#PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1080 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1082 !if(HasPat, Pattern[0], // rr
1083 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1085 !if(HasPat, Pattern[2], // rm
1086 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1087 (memopv2i64 addr:$src2)))])>,
1090 defm V#NAME#PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1091 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1093 !if(HasPat, Pattern[1], // rr
1094 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1097 !if(HasPat, Pattern[3], // rm
1098 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1099 (memopv2i64 addr:$src2)))])>,
1102 let Constraints = "$src1 = $dst" in {
1103 defm PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1104 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"), f128mem,
1105 !if(HasPat, Pattern[0], // rr
1106 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1108 !if(HasPat, Pattern[2], // rm
1109 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1110 (memopv2i64 addr:$src2)))])>, TB;
1112 defm PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1113 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"), f128mem,
1114 !if(HasPat, Pattern[1], // rr
1115 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1118 !if(HasPat, Pattern[3], // rm
1119 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1120 (memopv2i64 addr:$src2)))])>,
1125 defm AND : sse12_fp_packed_logical<0x54, "and", and>;
1126 defm OR : sse12_fp_packed_logical<0x56, "or", or>;
1127 defm XOR : sse12_fp_packed_logical<0x57, "xor", xor>;
1128 let isCommutable = 0 in
1129 defm ANDN : sse12_fp_packed_logical<0x55, "andn", undef /* dummy */, 1, [
1131 [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
1132 (bc_v2i64 (v4i32 immAllOnesV))),
1135 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1136 (bc_v2i64 (v2f64 VR128:$src2))))],
1138 [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1139 (bc_v2i64 (v4i32 immAllOnesV))),
1140 (memopv2i64 addr:$src2))))],
1142 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1143 (memopv2i64 addr:$src2)))]]>;
1145 //===----------------------------------------------------------------------===//
1146 // SSE 1 & 2 - Arithmetic Instructions
1147 //===----------------------------------------------------------------------===//
1149 /// basic_sse12_fp_binop_rm - SSE 1 & 2 binops come in both scalar and
1152 /// In addition, we also have a special variant of the scalar form here to
1153 /// represent the associated intrinsic operation. This form is unlike the
1154 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
1155 /// and leaves the top elements unmodified (therefore these cannot be commuted).
1157 /// These three forms can each be reg+reg or reg+mem.
1159 multiclass basic_sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
1162 let isAsmParserOnly = 1 in {
1163 defm V#NAME#SS : sse12_fp_scalar<opc,
1164 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1165 OpNode, FR32, f32mem>, XS, VEX_4V;
1167 defm V#NAME#SD : sse12_fp_scalar<opc,
1168 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1169 OpNode, FR64, f64mem>, XD, VEX_4V;
1171 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1172 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1173 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
1176 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1177 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1178 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
1181 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1182 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1183 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
1185 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1186 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1187 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
1190 let Constraints = "$src1 = $dst" in {
1191 defm SS : sse12_fp_scalar<opc,
1192 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1193 OpNode, FR32, f32mem>, XS;
1195 defm SD : sse12_fp_scalar<opc,
1196 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1197 OpNode, FR64, f64mem>, XD;
1199 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1200 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
1201 f128mem, memopv4f32, SSEPackedSingle>, TB;
1203 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1204 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
1205 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1207 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1208 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1209 "", "_ss", ssmem, sse_load_f32>, XS;
1211 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1212 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1213 "2", "_sd", sdmem, sse_load_f64>, XD;
1217 // Arithmetic instructions
1218 defm ADD : basic_sse12_fp_binop_rm<0x58, "add", fadd>;
1219 defm MUL : basic_sse12_fp_binop_rm<0x59, "mul", fmul>;
1221 let isCommutable = 0 in {
1222 defm SUB : basic_sse12_fp_binop_rm<0x5C, "sub", fsub>;
1223 defm DIV : basic_sse12_fp_binop_rm<0x5E, "div", fdiv>;
1226 /// sse12_fp_binop_rm - Other SSE 1 & 2 binops
1228 /// This multiclass is like basic_sse12_fp_binop_rm, with the addition of
1229 /// instructions for a full-vector intrinsic form. Operations that map
1230 /// onto C operators don't use this form since they just use the plain
1231 /// vector form instead of having a separate vector intrinsic form.
1233 multiclass sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
1236 let isAsmParserOnly = 1 in {
1237 // Scalar operation, reg+reg.
1238 defm V#NAME#SS : sse12_fp_scalar<opc,
1239 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1240 OpNode, FR32, f32mem>, XS, VEX_4V;
1242 defm V#NAME#SD : sse12_fp_scalar<opc,
1243 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1244 OpNode, FR64, f64mem>, XD, VEX_4V;
1246 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1247 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1248 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
1251 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1252 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1253 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
1256 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1257 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1258 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
1260 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1261 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1262 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
1264 defm V#NAME#PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1265 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1266 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, VEX_4V;
1268 defm V#NAME#PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1269 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1270 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, OpSize,
1274 let Constraints = "$src1 = $dst" in {
1275 // Scalar operation, reg+reg.
1276 defm SS : sse12_fp_scalar<opc,
1277 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1278 OpNode, FR32, f32mem>, XS;
1279 defm SD : sse12_fp_scalar<opc,
1280 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1281 OpNode, FR64, f64mem>, XD;
1282 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1283 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
1284 f128mem, memopv4f32, SSEPackedSingle>, TB;
1286 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1287 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
1288 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1290 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1291 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1292 "", "_ss", ssmem, sse_load_f32>, XS;
1294 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1295 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1296 "2", "_sd", sdmem, sse_load_f64>, XD;
1298 defm PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1299 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1300 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, TB;
1302 defm PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1303 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1304 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1308 let isCommutable = 0 in {
1309 defm MAX : sse12_fp_binop_rm<0x5F, "max", X86fmax>;
1310 defm MIN : sse12_fp_binop_rm<0x5D, "min", X86fmin>;
1313 //===----------------------------------------------------------------------===//
1314 // SSE packed FP Instructions
1316 // Move Instructions
1317 let neverHasSideEffects = 1 in
1318 def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1319 "movaps\t{$src, $dst|$dst, $src}", []>;
1320 let canFoldAsLoad = 1, isReMaterializable = 1 in
1321 def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1322 "movaps\t{$src, $dst|$dst, $src}",
1323 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
1325 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1326 "movaps\t{$src, $dst|$dst, $src}",
1327 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
1329 let neverHasSideEffects = 1 in
1330 def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1331 "movups\t{$src, $dst|$dst, $src}", []>;
1332 let canFoldAsLoad = 1, isReMaterializable = 1 in
1333 def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1334 "movups\t{$src, $dst|$dst, $src}",
1335 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
1336 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1337 "movups\t{$src, $dst|$dst, $src}",
1338 [(store (v4f32 VR128:$src), addr:$dst)]>;
1340 // Intrinsic forms of MOVUPS load and store
1341 let canFoldAsLoad = 1, isReMaterializable = 1 in
1342 def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1343 "movups\t{$src, $dst|$dst, $src}",
1344 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
1345 def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1346 "movups\t{$src, $dst|$dst, $src}",
1347 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
1349 let Constraints = "$src1 = $dst" in {
1350 let AddedComplexity = 20 in {
1351 def MOVLPSrm : PSI<0x12, MRMSrcMem,
1352 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1353 "movlps\t{$src2, $dst|$dst, $src2}",
1356 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
1357 def MOVHPSrm : PSI<0x16, MRMSrcMem,
1358 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1359 "movhps\t{$src2, $dst|$dst, $src2}",
1361 (movlhps VR128:$src1,
1362 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
1363 } // AddedComplexity
1364 } // Constraints = "$src1 = $dst"
1367 def : Pat<(movlhps VR128:$src1, (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
1368 (MOVHPSrm (v4i32 VR128:$src1), addr:$src2)>;
1370 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1371 "movlps\t{$src, $dst|$dst, $src}",
1372 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
1373 (iPTR 0))), addr:$dst)]>;
1375 // v2f64 extract element 1 is always custom lowered to unpack high to low
1376 // and extract element 0 so the non-store version isn't too horrible.
1377 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1378 "movhps\t{$src, $dst|$dst, $src}",
1379 [(store (f64 (vector_extract
1380 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
1381 (undef)), (iPTR 0))), addr:$dst)]>;
1383 let Constraints = "$src1 = $dst" in {
1384 let AddedComplexity = 20 in {
1385 def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
1386 (ins VR128:$src1, VR128:$src2),
1387 "movlhps\t{$src2, $dst|$dst, $src2}",
1389 (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
1391 def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
1392 (ins VR128:$src1, VR128:$src2),
1393 "movhlps\t{$src2, $dst|$dst, $src2}",
1395 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
1396 } // AddedComplexity
1397 } // Constraints = "$src1 = $dst"
1399 let AddedComplexity = 20 in {
1400 def : Pat<(v4f32 (movddup VR128:$src, (undef))),
1401 (MOVLHPSrr (v4f32 VR128:$src), (v4f32 VR128:$src))>;
1402 def : Pat<(v2i64 (movddup VR128:$src, (undef))),
1403 (MOVLHPSrr (v2i64 VR128:$src), (v2i64 VR128:$src))>;
1410 /// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
1412 /// In addition, we also have a special variant of the scalar form here to
1413 /// represent the associated intrinsic operation. This form is unlike the
1414 /// plain scalar form, in that it takes an entire vector (instead of a
1415 /// scalar) and leaves the top elements undefined.
1417 /// And, we have a special variant form for a full-vector intrinsic form.
1419 /// These four forms can each have a reg or a mem operand, so there are a
1420 /// total of eight "instructions".
1422 multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
1426 bit Commutable = 0> {
1427 // Scalar operation, reg.
1428 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1429 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1430 [(set FR32:$dst, (OpNode FR32:$src))]> {
1431 let isCommutable = Commutable;
1434 // Scalar operation, mem.
1435 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
1436 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1437 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
1438 Requires<[HasSSE1, OptForSize]>;
1440 // Vector operation, reg.
1441 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1442 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1443 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
1444 let isCommutable = Commutable;
1447 // Vector operation, mem.
1448 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1449 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1450 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
1452 // Intrinsic operation, reg.
1453 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1454 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1455 [(set VR128:$dst, (F32Int VR128:$src))]> {
1456 let isCommutable = Commutable;
1459 // Intrinsic operation, mem.
1460 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
1461 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1462 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1464 // Vector intrinsic operation, reg
1465 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1466 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1467 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
1468 let isCommutable = Commutable;
1471 // Vector intrinsic operation, mem
1472 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1473 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1474 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
1478 defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
1479 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
1481 // Reciprocal approximations. Note that these typically require refinement
1482 // in order to obtain suitable precision.
1483 defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
1484 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
1485 defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
1486 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
1488 // Prefetch intrinsic.
1489 def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
1490 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
1491 def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
1492 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
1493 def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
1494 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
1495 def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
1496 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
1498 // Non-temporal stores
1499 def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1500 "movntps\t{$src, $dst|$dst, $src}",
1501 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
1503 let AddedComplexity = 400 in { // Prefer non-temporal versions
1504 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1505 "movntps\t{$src, $dst|$dst, $src}",
1506 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1508 def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1509 "movntdq\t{$src, $dst|$dst, $src}",
1510 [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
1512 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1513 "movnti\t{$src, $dst|$dst, $src}",
1514 [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
1515 TB, Requires<[HasSSE2]>;
1517 def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1518 "movnti\t{$src, $dst|$dst, $src}",
1519 [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
1520 TB, Requires<[HasSSE2]>;
1523 // Load, store, and memory fence
1524 def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
1525 TB, Requires<[HasSSE1]>;
1528 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
1529 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
1530 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
1531 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
1533 // Alias instructions that map zero vector to pxor / xorp* for sse.
1534 // We set canFoldAsLoad because this can be converted to a constant-pool
1535 // load of an all-zeros value if folding it would be beneficial.
1536 // FIXME: Change encoding to pseudo!
1537 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
1538 isCodeGenOnly = 1 in {
1539 def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1540 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
1541 def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1542 [(set VR128:$dst, (v2f64 immAllZerosV))]>;
1543 let ExeDomain = SSEPackedInt in
1544 def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
1545 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
1548 def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
1549 def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
1550 def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
1552 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
1553 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1555 //===---------------------------------------------------------------------===//
1556 // SSE2 Instructions
1557 //===---------------------------------------------------------------------===//
1559 // Conversion instructions
1560 def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
1561 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1562 [(set FR32:$dst, (fround FR64:$src))]>;
1563 def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
1564 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1565 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
1566 Requires<[HasSSE2, OptForSize]>;
1568 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1569 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1570 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1571 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1573 // SSE2 instructions with XS prefix
1574 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
1575 "cvtss2sd\t{$src, $dst|$dst, $src}",
1576 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1577 Requires<[HasSSE2]>;
1578 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
1579 "cvtss2sd\t{$src, $dst|$dst, $src}",
1580 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1581 Requires<[HasSSE2, OptForSize]>;
1583 def : Pat<(extloadf32 addr:$src),
1584 (CVTSS2SDrr (MOVSSrm addr:$src))>,
1585 Requires<[HasSSE2, OptForSpeed]>;
1587 // Match intrinsics which expect MM and XMM operand(s).
1588 def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1589 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1590 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1591 def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1592 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1593 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
1594 (load addr:$src)))]>;
1596 // Aliases for intrinsics
1597 def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1598 "cvttsd2si\t{$src, $dst|$dst, $src}",
1600 (int_x86_sse2_cvttsd2si VR128:$src))]>;
1601 def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
1602 "cvttsd2si\t{$src, $dst|$dst, $src}",
1603 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1604 (load addr:$src)))]>;
1606 //===---------------------------------------------------------------------===//
1607 // SSE packed FP Instructions
1609 // Move Instructions
1610 let neverHasSideEffects = 1 in
1611 def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1612 "movapd\t{$src, $dst|$dst, $src}", []>;
1613 let canFoldAsLoad = 1, isReMaterializable = 1 in
1614 def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1615 "movapd\t{$src, $dst|$dst, $src}",
1616 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
1618 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1619 "movapd\t{$src, $dst|$dst, $src}",
1620 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
1622 let neverHasSideEffects = 1 in
1623 def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1624 "movupd\t{$src, $dst|$dst, $src}", []>;
1625 let canFoldAsLoad = 1 in
1626 def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1627 "movupd\t{$src, $dst|$dst, $src}",
1628 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
1629 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1630 "movupd\t{$src, $dst|$dst, $src}",
1631 [(store (v2f64 VR128:$src), addr:$dst)]>;
1633 // Intrinsic forms of MOVUPD load and store
1634 def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1635 "movupd\t{$src, $dst|$dst, $src}",
1636 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
1637 def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1638 "movupd\t{$src, $dst|$dst, $src}",
1639 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
1641 let Constraints = "$src1 = $dst" in {
1642 let AddedComplexity = 20 in {
1643 def MOVLPDrm : PDI<0x12, MRMSrcMem,
1644 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1645 "movlpd\t{$src2, $dst|$dst, $src2}",
1647 (v2f64 (movlp VR128:$src1,
1648 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1649 def MOVHPDrm : PDI<0x16, MRMSrcMem,
1650 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1651 "movhpd\t{$src2, $dst|$dst, $src2}",
1653 (v2f64 (movlhps VR128:$src1,
1654 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1655 } // AddedComplexity
1656 } // Constraints = "$src1 = $dst"
1658 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1659 "movlpd\t{$src, $dst|$dst, $src}",
1660 [(store (f64 (vector_extract (v2f64 VR128:$src),
1661 (iPTR 0))), addr:$dst)]>;
1663 // v2f64 extract element 1 is always custom lowered to unpack high to low
1664 // and extract element 0 so the non-store version isn't too horrible.
1665 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1666 "movhpd\t{$src, $dst|$dst, $src}",
1667 [(store (f64 (vector_extract
1668 (v2f64 (unpckh VR128:$src, (undef))),
1669 (iPTR 0))), addr:$dst)]>;
1671 // SSE2 instructions without OpSize prefix
1672 def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1673 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1674 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1675 TB, Requires<[HasSSE2]>;
1676 def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1677 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1678 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1679 (bitconvert (memopv2i64 addr:$src))))]>,
1680 TB, Requires<[HasSSE2]>;
1682 // SSE2 instructions with XS prefix
1683 def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1684 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1685 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1686 XS, Requires<[HasSSE2]>;
1687 def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1688 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1689 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1690 (bitconvert (memopv2i64 addr:$src))))]>,
1691 XS, Requires<[HasSSE2]>;
1693 def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1694 "cvtps2dq\t{$src, $dst|$dst, $src}",
1695 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
1696 def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1697 "cvtps2dq\t{$src, $dst|$dst, $src}",
1698 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1699 (memop addr:$src)))]>;
1700 // SSE2 packed instructions with XS prefix
1701 def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1702 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1703 def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1704 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1706 def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1707 "cvttps2dq\t{$src, $dst|$dst, $src}",
1709 (int_x86_sse2_cvttps2dq VR128:$src))]>,
1710 XS, Requires<[HasSSE2]>;
1711 def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1712 "cvttps2dq\t{$src, $dst|$dst, $src}",
1713 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1714 (memop addr:$src)))]>,
1715 XS, Requires<[HasSSE2]>;
1717 // SSE2 packed instructions with XD prefix
1718 def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1719 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1720 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1721 XD, Requires<[HasSSE2]>;
1722 def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1723 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1724 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1725 (memop addr:$src)))]>,
1726 XD, Requires<[HasSSE2]>;
1728 def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1729 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1730 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
1731 def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
1732 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1733 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1734 (memop addr:$src)))]>;
1736 // SSE2 instructions without OpSize prefix
1737 def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1738 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1739 def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1740 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1742 def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1743 "cvtps2pd\t{$src, $dst|$dst, $src}",
1744 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1745 TB, Requires<[HasSSE2]>;
1746 def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1747 "cvtps2pd\t{$src, $dst|$dst, $src}",
1748 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1749 (load addr:$src)))]>,
1750 TB, Requires<[HasSSE2]>;
1752 def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1753 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1754 def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1755 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1758 def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1759 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1760 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
1761 def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1762 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1763 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1764 (memop addr:$src)))]>;
1766 // Match intrinsics which expect XMM operand(s).
1767 // Aliases for intrinsics
1768 let Constraints = "$src1 = $dst" in {
1769 def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
1770 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
1771 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1772 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1774 def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
1775 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
1776 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1777 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1778 (loadi32 addr:$src2)))]>;
1779 def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
1780 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1781 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1782 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1784 def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
1785 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1786 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1787 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1788 (load addr:$src2)))]>;
1789 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
1790 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1791 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1792 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1793 VR128:$src2))]>, XS,
1794 Requires<[HasSSE2]>;
1795 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
1796 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
1797 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1798 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1799 (load addr:$src2)))]>, XS,
1800 Requires<[HasSSE2]>;
1805 /// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1807 /// In addition, we also have a special variant of the scalar form here to
1808 /// represent the associated intrinsic operation. This form is unlike the
1809 /// plain scalar form, in that it takes an entire vector (instead of a
1810 /// scalar) and leaves the top elements undefined.
1812 /// And, we have a special variant form for a full-vector intrinsic form.
1814 /// These four forms can each have a reg or a mem operand, so there are a
1815 /// total of eight "instructions".
1817 multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1821 bit Commutable = 0> {
1822 // Scalar operation, reg.
1823 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1824 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1825 [(set FR64:$dst, (OpNode FR64:$src))]> {
1826 let isCommutable = Commutable;
1829 // Scalar operation, mem.
1830 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1831 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1832 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1834 // Vector operation, reg.
1835 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1836 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1837 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1838 let isCommutable = Commutable;
1841 // Vector operation, mem.
1842 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1843 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1844 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
1846 // Intrinsic operation, reg.
1847 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1848 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1849 [(set VR128:$dst, (F64Int VR128:$src))]> {
1850 let isCommutable = Commutable;
1853 // Intrinsic operation, mem.
1854 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1855 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1856 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1858 // Vector intrinsic operation, reg
1859 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1860 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1861 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1862 let isCommutable = Commutable;
1865 // Vector intrinsic operation, mem
1866 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1867 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1868 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
1872 defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1873 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1875 // There is no f64 version of the reciprocal approximation instructions.
1877 //===---------------------------------------------------------------------===//
1878 // SSE integer instructions
1879 let ExeDomain = SSEPackedInt in {
1881 // Move Instructions
1882 let neverHasSideEffects = 1 in
1883 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1884 "movdqa\t{$src, $dst|$dst, $src}", []>;
1885 let canFoldAsLoad = 1, mayLoad = 1 in
1886 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1887 "movdqa\t{$src, $dst|$dst, $src}",
1888 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
1890 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1891 "movdqa\t{$src, $dst|$dst, $src}",
1892 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
1893 let canFoldAsLoad = 1, mayLoad = 1 in
1894 def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1895 "movdqu\t{$src, $dst|$dst, $src}",
1896 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
1897 XS, Requires<[HasSSE2]>;
1899 def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1900 "movdqu\t{$src, $dst|$dst, $src}",
1901 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
1902 XS, Requires<[HasSSE2]>;
1904 // Intrinsic forms of MOVDQU load and store
1905 let canFoldAsLoad = 1 in
1906 def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1907 "movdqu\t{$src, $dst|$dst, $src}",
1908 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1909 XS, Requires<[HasSSE2]>;
1910 def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1911 "movdqu\t{$src, $dst|$dst, $src}",
1912 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1913 XS, Requires<[HasSSE2]>;
1915 let Constraints = "$src1 = $dst" in {
1917 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1918 bit Commutable = 0> {
1919 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1920 (ins VR128:$src1, VR128:$src2),
1921 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1922 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1923 let isCommutable = Commutable;
1925 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1926 (ins VR128:$src1, i128mem:$src2),
1927 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1928 [(set VR128:$dst, (IntId VR128:$src1,
1929 (bitconvert (memopv2i64
1933 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1935 Intrinsic IntId, Intrinsic IntId2> {
1936 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1937 (ins VR128:$src1, VR128:$src2),
1938 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1939 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
1940 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1941 (ins VR128:$src1, i128mem:$src2),
1942 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1943 [(set VR128:$dst, (IntId VR128:$src1,
1944 (bitconvert (memopv2i64 addr:$src2))))]>;
1945 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
1946 (ins VR128:$src1, i32i8imm:$src2),
1947 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1948 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1951 /// PDI_binop_rm - Simple SSE2 binary operator.
1952 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1953 ValueType OpVT, bit Commutable = 0> {
1954 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1955 (ins VR128:$src1, VR128:$src2),
1956 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1957 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1958 let isCommutable = Commutable;
1960 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1961 (ins VR128:$src1, i128mem:$src2),
1962 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1963 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
1964 (bitconvert (memopv2i64 addr:$src2)))))]>;
1967 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1969 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1970 /// to collapse (bitconvert VT to VT) into its operand.
1972 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1973 bit Commutable = 0> {
1974 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1975 (ins VR128:$src1, VR128:$src2),
1976 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1977 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1978 let isCommutable = Commutable;
1980 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1981 (ins VR128:$src1, i128mem:$src2),
1982 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1983 [(set VR128:$dst, (OpNode VR128:$src1,
1984 (memopv2i64 addr:$src2)))]>;
1987 } // Constraints = "$src1 = $dst"
1988 } // ExeDomain = SSEPackedInt
1990 // 128-bit Integer Arithmetic
1992 defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1993 defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1994 defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1995 defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1997 defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1998 defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1999 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
2000 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
2002 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
2003 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
2004 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
2005 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
2007 defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
2008 defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
2009 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
2010 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
2012 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
2014 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
2015 defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
2016 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
2018 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
2020 defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
2021 defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
2024 defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
2025 defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
2026 defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
2027 defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
2028 defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
2031 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
2032 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
2033 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
2034 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
2035 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2036 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
2038 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2039 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2040 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2041 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
2042 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
2043 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
2045 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2046 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
2047 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
2048 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
2050 // 128-bit logical shifts.
2051 let Constraints = "$src1 = $dst", neverHasSideEffects = 1,
2052 ExeDomain = SSEPackedInt in {
2053 def PSLLDQri : PDIi8<0x73, MRM7r,
2054 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2055 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
2056 def PSRLDQri : PDIi8<0x73, MRM3r,
2057 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2058 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
2059 // PSRADQri doesn't exist in SSE[1-3].
2062 let Predicates = [HasSSE2] in {
2063 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
2064 (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2065 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2066 (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2067 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2068 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2069 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2070 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
2071 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2072 (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2074 // Shift up / down and insert zero's.
2075 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
2076 (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2077 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
2078 (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2082 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2083 defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
2084 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2086 let Constraints = "$src1 = $dst", ExeDomain = SSEPackedInt in {
2087 def PANDNrr : PDI<0xDF, MRMSrcReg,
2088 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2089 "pandn\t{$src2, $dst|$dst, $src2}",
2090 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2093 def PANDNrm : PDI<0xDF, MRMSrcMem,
2094 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2095 "pandn\t{$src2, $dst|$dst, $src2}",
2096 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2097 (memopv2i64 addr:$src2))))]>;
2100 // SSE2 Integer comparison
2101 defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2102 defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2103 defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2104 defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2105 defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2106 defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2108 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
2109 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
2110 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
2111 (PCMPEQBrm VR128:$src1, addr:$src2)>;
2112 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
2113 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
2114 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
2115 (PCMPEQWrm VR128:$src1, addr:$src2)>;
2116 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
2117 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
2118 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
2119 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2121 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
2122 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
2123 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
2124 (PCMPGTBrm VR128:$src1, addr:$src2)>;
2125 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
2126 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
2127 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
2128 (PCMPGTWrm VR128:$src1, addr:$src2)>;
2129 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
2130 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
2131 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
2132 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2135 // Pack instructions
2136 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2137 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2138 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2140 let ExeDomain = SSEPackedInt in {
2142 // Shuffle and unpack instructions
2143 let AddedComplexity = 5 in {
2144 def PSHUFDri : PDIi8<0x70, MRMSrcReg,
2145 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2146 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2147 [(set VR128:$dst, (v4i32 (pshufd:$src2
2148 VR128:$src1, (undef))))]>;
2149 def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
2150 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2151 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2152 [(set VR128:$dst, (v4i32 (pshufd:$src2
2153 (bc_v4i32 (memopv2i64 addr:$src1)),
2157 // SSE2 with ImmT == Imm8 and XS prefix.
2158 def PSHUFHWri : Ii8<0x70, MRMSrcReg,
2159 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2160 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2161 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2163 XS, Requires<[HasSSE2]>;
2164 def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
2165 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2166 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2167 [(set VR128:$dst, (v8i16 (pshufhw:$src2
2168 (bc_v8i16 (memopv2i64 addr:$src1)),
2170 XS, Requires<[HasSSE2]>;
2172 // SSE2 with ImmT == Imm8 and XD prefix.
2173 def PSHUFLWri : Ii8<0x70, MRMSrcReg,
2174 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2175 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2176 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2178 XD, Requires<[HasSSE2]>;
2179 def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
2180 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2181 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2182 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2183 (bc_v8i16 (memopv2i64 addr:$src1)),
2185 XD, Requires<[HasSSE2]>;
2187 // Unpack instructions
2188 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2189 PatFrag unp_frag, PatFrag bc_frag> {
2190 def rr : PDI<opc, MRMSrcReg,
2191 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2192 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2193 [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2194 def rm : PDI<opc, MRMSrcMem,
2195 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2196 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2197 [(set VR128:$dst, (unp_frag VR128:$src1,
2198 (bc_frag (memopv2i64
2202 let Constraints = "$src1 = $dst" in {
2203 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2204 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2205 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2207 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2208 /// knew to collapse (bitconvert VT to VT) into its operand.
2209 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2210 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2211 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2213 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
2214 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2215 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2216 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2218 (v2i64 (unpckl VR128:$src1,
2219 (memopv2i64 addr:$src2))))]>;
2221 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2222 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2223 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2225 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2226 /// knew to collapse (bitconvert VT to VT) into its operand.
2227 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2228 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2229 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2231 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
2232 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2233 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2234 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2236 (v2i64 (unpckh VR128:$src1,
2237 (memopv2i64 addr:$src2))))]>;
2241 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
2242 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2243 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2244 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2246 let Constraints = "$src1 = $dst" in {
2247 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
2248 (outs VR128:$dst), (ins VR128:$src1,
2249 GR32:$src2, i32i8imm:$src3),
2250 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2252 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
2253 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
2254 (outs VR128:$dst), (ins VR128:$src1,
2255 i16mem:$src2, i32i8imm:$src3),
2256 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2258 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2263 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2264 "pmovmskb\t{$src, $dst|$dst, $src}",
2265 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2267 // Conditional store
2269 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2270 "maskmovdqu\t{$mask, $src|$src, $mask}",
2271 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
2274 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2275 "maskmovdqu\t{$mask, $src|$src, $mask}",
2276 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2278 } // ExeDomain = SSEPackedInt
2280 // Non-temporal stores
2281 def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2282 "movntpd\t{$src, $dst|$dst, $src}",
2283 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
2284 let ExeDomain = SSEPackedInt in
2285 def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2286 "movntdq\t{$src, $dst|$dst, $src}",
2287 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2288 def MOVNTImr_Int : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2289 "movnti\t{$src, $dst|$dst, $src}",
2290 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2291 TB, Requires<[HasSSE2]>;
2293 let AddedComplexity = 400 in { // Prefer non-temporal versions
2294 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2295 "movntpd\t{$src, $dst|$dst, $src}",
2296 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
2298 let ExeDomain = SSEPackedInt in
2299 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2300 "movntdq\t{$src, $dst|$dst, $src}",
2301 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
2305 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
2306 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
2307 TB, Requires<[HasSSE2]>;
2309 // Load, store, and memory fence
2310 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
2311 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
2312 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
2313 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2315 // Pause. This "instruction" is encoded as "rep; nop", so even though it
2316 // was introduced with SSE2, it's backward compatible.
2317 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
2319 //TODO: custom lower this so as to never even generate the noop
2320 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2322 def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2323 def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
2324 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2327 // Alias instructions that map zero vector to pxor / xorp* for sse.
2328 // We set canFoldAsLoad because this can be converted to a constant-pool
2329 // load of an all-ones value if folding it would be beneficial.
2330 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
2331 isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
2332 // FIXME: Change encoding to pseudo.
2333 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
2334 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
2336 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2337 "movd\t{$src, $dst|$dst, $src}",
2339 (v4i32 (scalar_to_vector GR32:$src)))]>;
2340 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2341 "movd\t{$src, $dst|$dst, $src}",
2343 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2345 def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2346 "movd\t{$src, $dst|$dst, $src}",
2347 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2349 def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2350 "movd\t{$src, $dst|$dst, $src}",
2351 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2353 // SSE2 instructions with XS prefix
2354 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2355 "movq\t{$src, $dst|$dst, $src}",
2357 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2358 Requires<[HasSSE2]>;
2359 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2360 "movq\t{$src, $dst|$dst, $src}",
2361 [(store (i64 (vector_extract (v2i64 VR128:$src),
2362 (iPTR 0))), addr:$dst)]>;
2364 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
2365 (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
2367 def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2368 "movd\t{$src, $dst|$dst, $src}",
2369 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2371 def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
2372 "movd\t{$src, $dst|$dst, $src}",
2373 [(store (i32 (vector_extract (v4i32 VR128:$src),
2374 (iPTR 0))), addr:$dst)]>;
2376 def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2377 "movd\t{$src, $dst|$dst, $src}",
2378 [(set GR32:$dst, (bitconvert FR32:$src))]>;
2379 def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2380 "movd\t{$src, $dst|$dst, $src}",
2381 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2383 // Store / copy lower 64-bits of a XMM register.
2384 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2385 "movq\t{$src, $dst|$dst, $src}",
2386 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2388 // movd / movq to XMM register zero-extends
2389 let AddedComplexity = 15 in {
2390 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2391 "movd\t{$src, $dst|$dst, $src}",
2392 [(set VR128:$dst, (v4i32 (X86vzmovl
2393 (v4i32 (scalar_to_vector GR32:$src)))))]>;
2394 // This is X86-64 only.
2395 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2396 "mov{d|q}\t{$src, $dst|$dst, $src}",
2397 [(set VR128:$dst, (v2i64 (X86vzmovl
2398 (v2i64 (scalar_to_vector GR64:$src)))))]>;
2401 let AddedComplexity = 20 in {
2402 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2403 "movd\t{$src, $dst|$dst, $src}",
2405 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2406 (loadi32 addr:$src))))))]>;
2408 def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2409 (MOVZDI2PDIrm addr:$src)>;
2410 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2411 (MOVZDI2PDIrm addr:$src)>;
2412 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2413 (MOVZDI2PDIrm addr:$src)>;
2415 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2416 "movq\t{$src, $dst|$dst, $src}",
2418 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2419 (loadi64 addr:$src))))))]>, XS,
2420 Requires<[HasSSE2]>;
2422 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2423 (MOVZQI2PQIrm addr:$src)>;
2424 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2425 (MOVZQI2PQIrm addr:$src)>;
2426 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
2429 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2430 // IA32 document. movq xmm1, xmm2 does clear the high bits.
2431 let AddedComplexity = 15 in
2432 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2433 "movq\t{$src, $dst|$dst, $src}",
2434 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2435 XS, Requires<[HasSSE2]>;
2437 let AddedComplexity = 20 in {
2438 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2439 "movq\t{$src, $dst|$dst, $src}",
2440 [(set VR128:$dst, (v2i64 (X86vzmovl
2441 (loadv2i64 addr:$src))))]>,
2442 XS, Requires<[HasSSE2]>;
2444 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2445 (MOVZPQILo2PQIrm addr:$src)>;
2448 // Instructions for the disassembler
2449 // xr = XMM register
2452 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2453 "movq\t{$src, $dst|$dst, $src}", []>, XS;
2455 //===---------------------------------------------------------------------===//
2456 // SSE3 Instructions
2457 //===---------------------------------------------------------------------===//
2459 // Conversion Instructions
2460 def CVTPD2DQrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2461 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2462 def CVTPD2DQrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2463 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2464 def CVTDQ2PDrm : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2465 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2466 def CVTDQ2PDrr : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2467 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2469 // Move Instructions
2470 def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2471 "movshdup\t{$src, $dst|$dst, $src}",
2472 [(set VR128:$dst, (v4f32 (movshdup
2473 VR128:$src, (undef))))]>;
2474 def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2475 "movshdup\t{$src, $dst|$dst, $src}",
2476 [(set VR128:$dst, (movshdup
2477 (memopv4f32 addr:$src), (undef)))]>;
2479 def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2480 "movsldup\t{$src, $dst|$dst, $src}",
2481 [(set VR128:$dst, (v4f32 (movsldup
2482 VR128:$src, (undef))))]>;
2483 def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2484 "movsldup\t{$src, $dst|$dst, $src}",
2485 [(set VR128:$dst, (movsldup
2486 (memopv4f32 addr:$src), (undef)))]>;
2488 def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2489 "movddup\t{$src, $dst|$dst, $src}",
2490 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
2491 def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2492 "movddup\t{$src, $dst|$dst, $src}",
2494 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2497 def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2499 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2501 let AddedComplexity = 5 in {
2502 def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
2503 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2504 def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2505 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2506 def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2507 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2508 def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2509 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2513 let Constraints = "$src1 = $dst" in {
2514 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
2515 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2516 "addsubps\t{$src2, $dst|$dst, $src2}",
2517 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2519 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
2520 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2521 "addsubps\t{$src2, $dst|$dst, $src2}",
2522 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2523 (memop addr:$src2)))]>;
2524 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
2525 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2526 "addsubpd\t{$src2, $dst|$dst, $src2}",
2527 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2529 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
2530 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2531 "addsubpd\t{$src2, $dst|$dst, $src2}",
2532 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2533 (memop addr:$src2)))]>;
2536 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2537 "lddqu\t{$src, $dst|$dst, $src}",
2538 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2541 class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2542 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2543 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2544 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2545 class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2546 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2547 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2548 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
2549 class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2550 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2551 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2552 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2553 class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2554 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2555 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2556 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
2558 let Constraints = "$src1 = $dst" in {
2559 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2560 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2561 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2562 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2563 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2564 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2565 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2566 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2569 // Thread synchronization
2570 def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
2571 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
2572 def MWAIT : I<0x01, MRM_C9, (outs), (ins), "mwait",
2573 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2575 // vector_shuffle v1, <undef> <1, 1, 3, 3>
2576 let AddedComplexity = 15 in
2577 def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
2578 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2579 let AddedComplexity = 20 in
2580 def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2581 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2583 // vector_shuffle v1, <undef> <0, 0, 2, 2>
2584 let AddedComplexity = 15 in
2585 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
2586 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2587 let AddedComplexity = 20 in
2588 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2589 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2591 //===---------------------------------------------------------------------===//
2592 // SSSE3 Instructions
2593 //===---------------------------------------------------------------------===//
2595 /// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
2596 multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2597 Intrinsic IntId64, Intrinsic IntId128> {
2598 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2599 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2600 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2602 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2603 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2605 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2607 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2609 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2610 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2613 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2615 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2618 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
2621 /// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
2622 multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2623 Intrinsic IntId64, Intrinsic IntId128> {
2624 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2626 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2627 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2629 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2631 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2634 (bitconvert (memopv4i16 addr:$src))))]>;
2636 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2638 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2639 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2642 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2644 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2647 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
2650 /// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
2651 multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2652 Intrinsic IntId64, Intrinsic IntId128> {
2653 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2655 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2656 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2658 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2660 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2663 (bitconvert (memopv2i32 addr:$src))))]>;
2665 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2667 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2668 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2671 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2673 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2676 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
2679 defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2680 int_x86_ssse3_pabs_b,
2681 int_x86_ssse3_pabs_b_128>;
2682 defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2683 int_x86_ssse3_pabs_w,
2684 int_x86_ssse3_pabs_w_128>;
2685 defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2686 int_x86_ssse3_pabs_d,
2687 int_x86_ssse3_pabs_d_128>;
2689 /// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
2690 let Constraints = "$src1 = $dst" in {
2691 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2692 Intrinsic IntId64, Intrinsic IntId128,
2693 bit Commutable = 0> {
2694 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2695 (ins VR64:$src1, VR64:$src2),
2696 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2697 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2698 let isCommutable = Commutable;
2700 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2701 (ins VR64:$src1, i64mem:$src2),
2702 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2704 (IntId64 VR64:$src1,
2705 (bitconvert (memopv8i8 addr:$src2))))]>;
2707 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2708 (ins VR128:$src1, VR128:$src2),
2709 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2710 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2712 let isCommutable = Commutable;
2714 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2715 (ins VR128:$src1, i128mem:$src2),
2716 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2718 (IntId128 VR128:$src1,
2719 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2723 /// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
2724 let Constraints = "$src1 = $dst" in {
2725 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2726 Intrinsic IntId64, Intrinsic IntId128,
2727 bit Commutable = 0> {
2728 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2729 (ins VR64:$src1, VR64:$src2),
2730 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2731 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2732 let isCommutable = Commutable;
2734 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2735 (ins VR64:$src1, i64mem:$src2),
2736 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2738 (IntId64 VR64:$src1,
2739 (bitconvert (memopv4i16 addr:$src2))))]>;
2741 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2742 (ins VR128:$src1, VR128:$src2),
2743 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2744 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2746 let isCommutable = Commutable;
2748 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2749 (ins VR128:$src1, i128mem:$src2),
2750 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2752 (IntId128 VR128:$src1,
2753 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2757 /// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
2758 let Constraints = "$src1 = $dst" in {
2759 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2760 Intrinsic IntId64, Intrinsic IntId128,
2761 bit Commutable = 0> {
2762 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2763 (ins VR64:$src1, VR64:$src2),
2764 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2765 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2766 let isCommutable = Commutable;
2768 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2769 (ins VR64:$src1, i64mem:$src2),
2770 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2772 (IntId64 VR64:$src1,
2773 (bitconvert (memopv2i32 addr:$src2))))]>;
2775 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2776 (ins VR128:$src1, VR128:$src2),
2777 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2778 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2780 let isCommutable = Commutable;
2782 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2783 (ins VR128:$src1, i128mem:$src2),
2784 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2786 (IntId128 VR128:$src1,
2787 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2791 let ImmT = NoImm in { // None of these have i8 immediate fields.
2792 defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2793 int_x86_ssse3_phadd_w,
2794 int_x86_ssse3_phadd_w_128>;
2795 defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2796 int_x86_ssse3_phadd_d,
2797 int_x86_ssse3_phadd_d_128>;
2798 defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2799 int_x86_ssse3_phadd_sw,
2800 int_x86_ssse3_phadd_sw_128>;
2801 defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2802 int_x86_ssse3_phsub_w,
2803 int_x86_ssse3_phsub_w_128>;
2804 defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2805 int_x86_ssse3_phsub_d,
2806 int_x86_ssse3_phsub_d_128>;
2807 defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2808 int_x86_ssse3_phsub_sw,
2809 int_x86_ssse3_phsub_sw_128>;
2810 defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2811 int_x86_ssse3_pmadd_ub_sw,
2812 int_x86_ssse3_pmadd_ub_sw_128>;
2813 defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2814 int_x86_ssse3_pmul_hr_sw,
2815 int_x86_ssse3_pmul_hr_sw_128, 1>;
2817 defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2818 int_x86_ssse3_pshuf_b,
2819 int_x86_ssse3_pshuf_b_128>;
2820 defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2821 int_x86_ssse3_psign_b,
2822 int_x86_ssse3_psign_b_128>;
2823 defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2824 int_x86_ssse3_psign_w,
2825 int_x86_ssse3_psign_w_128>;
2826 defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
2827 int_x86_ssse3_psign_d,
2828 int_x86_ssse3_psign_d_128>;
2831 // palignr patterns.
2832 let Constraints = "$src1 = $dst" in {
2833 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2834 (ins VR64:$src1, VR64:$src2, i8imm:$src3),
2835 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2837 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
2838 (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
2839 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2842 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2843 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
2844 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2846 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
2847 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
2848 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2852 let AddedComplexity = 5 in {
2854 def : Pat<(v1i64 (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<(v2i32 (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<(v2f32 (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<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
2867 (PALIGNR64rr VR64:$src2, VR64:$src1,
2868 (SHUFFLE_get_palign_imm VR64:$src3))>,
2869 Requires<[HasSSSE3]>;
2870 def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
2871 (PALIGNR64rr VR64:$src2, VR64:$src1,
2872 (SHUFFLE_get_palign_imm VR64:$src3))>,
2873 Requires<[HasSSSE3]>;
2875 def : Pat<(v4i32 (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<(v4f32 (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<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
2884 (PALIGNR128rr VR128:$src2, VR128:$src1,
2885 (SHUFFLE_get_palign_imm VR128:$src3))>,
2886 Requires<[HasSSSE3]>;
2887 def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
2888 (PALIGNR128rr VR128:$src2, VR128:$src1,
2889 (SHUFFLE_get_palign_imm VR128:$src3))>,
2890 Requires<[HasSSSE3]>;
2893 def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2894 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2895 def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2896 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2898 //===---------------------------------------------------------------------===//
2899 // Non-Instruction Patterns
2900 //===---------------------------------------------------------------------===//
2902 // extload f32 -> f64. This matches load+fextend because we have a hack in
2903 // the isel (PreprocessForFPConvert) that can introduce loads after dag
2905 // Since these loads aren't folded into the fextend, we have to match it
2907 let Predicates = [HasSSE2] in
2908 def : Pat<(fextend (loadf32 addr:$src)),
2909 (CVTSS2SDrm addr:$src)>;
2912 let Predicates = [HasSSE2] in {
2913 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2914 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2915 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2916 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2917 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2918 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2919 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2920 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2921 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2922 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2923 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2924 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2925 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2926 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2927 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2928 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2929 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2930 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2931 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2932 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2933 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2934 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2935 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2936 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2937 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2938 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2939 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2940 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2941 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2942 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2945 // Move scalar to XMM zero-extended
2946 // movd to XMM register zero-extends
2947 let AddedComplexity = 15 in {
2948 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
2949 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
2950 (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
2951 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
2952 (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
2953 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
2954 (MOVSSrr (v4f32 (V_SET0PS)),
2955 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
2956 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
2957 (MOVSSrr (v4i32 (V_SET0PI)),
2958 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
2961 // Splat v2f64 / v2i64
2962 let AddedComplexity = 10 in {
2963 def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
2964 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2965 def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
2966 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2967 def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
2968 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2969 def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
2970 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2973 // Special unary SHUFPSrri case.
2974 def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2975 (SHUFPSrri VR128:$src1, VR128:$src1,
2976 (SHUFFLE_get_shuf_imm VR128:$src3))>;
2977 let AddedComplexity = 5 in
2978 def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2979 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2980 Requires<[HasSSE2]>;
2981 // Special unary SHUFPDrri case.
2982 def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
2983 (SHUFPDrri VR128:$src1, VR128:$src1,
2984 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2985 Requires<[HasSSE2]>;
2986 // Special unary SHUFPDrri case.
2987 def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
2988 (SHUFPDrri VR128:$src1, VR128:$src1,
2989 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2990 Requires<[HasSSE2]>;
2991 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
2992 def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2993 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2994 Requires<[HasSSE2]>;
2996 // Special binary v4i32 shuffle cases with SHUFPS.
2997 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
2998 (SHUFPSrri VR128:$src1, VR128:$src2,
2999 (SHUFFLE_get_shuf_imm VR128:$src3))>,
3000 Requires<[HasSSE2]>;
3001 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
3002 (SHUFPSrmi VR128:$src1, addr:$src2,
3003 (SHUFFLE_get_shuf_imm VR128:$src3))>,
3004 Requires<[HasSSE2]>;
3005 // Special binary v2i64 shuffle cases using SHUFPDrri.
3006 def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
3007 (SHUFPDrri VR128:$src1, VR128:$src2,
3008 (SHUFFLE_get_shuf_imm VR128:$src3))>,
3009 Requires<[HasSSE2]>;
3011 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
3012 let AddedComplexity = 15 in {
3013 def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
3014 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3015 Requires<[OptForSpeed, HasSSE2]>;
3016 def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
3017 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3018 Requires<[OptForSpeed, HasSSE2]>;
3020 let AddedComplexity = 10 in {
3021 def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
3022 (UNPCKLPSrr VR128:$src, VR128:$src)>;
3023 def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
3024 (PUNPCKLBWrr VR128:$src, VR128:$src)>;
3025 def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
3026 (PUNPCKLWDrr VR128:$src, VR128:$src)>;
3027 def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
3028 (PUNPCKLDQrr VR128:$src, VR128:$src)>;
3031 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
3032 let AddedComplexity = 15 in {
3033 def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
3034 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3035 Requires<[OptForSpeed, HasSSE2]>;
3036 def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
3037 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3038 Requires<[OptForSpeed, HasSSE2]>;
3040 let AddedComplexity = 10 in {
3041 def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
3042 (UNPCKHPSrr VR128:$src, VR128:$src)>;
3043 def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
3044 (PUNPCKHBWrr VR128:$src, VR128:$src)>;
3045 def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
3046 (PUNPCKHWDrr VR128:$src, VR128:$src)>;
3047 def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
3048 (PUNPCKHDQrr VR128:$src, VR128:$src)>;
3051 let AddedComplexity = 20 in {
3052 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
3053 def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
3054 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
3056 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
3057 def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
3058 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
3060 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
3061 def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
3062 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3063 def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
3064 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3067 let AddedComplexity = 20 in {
3068 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
3069 def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
3070 (MOVLPSrm VR128:$src1, addr:$src2)>;
3071 def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
3072 (MOVLPDrm VR128:$src1, addr:$src2)>;
3073 def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
3074 (MOVLPSrm VR128:$src1, addr:$src2)>;
3075 def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
3076 (MOVLPDrm VR128:$src1, addr:$src2)>;
3079 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3080 def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3081 (MOVLPSmr addr:$src1, VR128:$src2)>;
3082 def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3083 (MOVLPDmr addr:$src1, VR128:$src2)>;
3084 def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3086 (MOVLPSmr addr:$src1, VR128:$src2)>;
3087 def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3088 (MOVLPDmr addr:$src1, VR128:$src2)>;
3090 let AddedComplexity = 15 in {
3091 // Setting the lowest element in the vector.
3092 def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
3093 (MOVSSrr (v4i32 VR128:$src1),
3094 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
3095 def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
3096 (MOVSDrr (v2i64 VR128:$src1),
3097 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
3099 // vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
3100 def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
3101 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3102 Requires<[HasSSE2]>;
3103 def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
3104 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3105 Requires<[HasSSE2]>;
3108 // vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3109 // fall back to this for SSE1)
3110 def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
3111 (SHUFPSrri VR128:$src2, VR128:$src1,
3112 (SHUFFLE_get_shuf_imm VR128:$src3))>;
3114 // Set lowest element and zero upper elements.
3115 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
3116 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3118 // Some special case pandn patterns.
3119 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3121 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3122 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3124 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3125 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3127 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3129 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3130 (memop addr:$src2))),
3131 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3132 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3133 (memop addr:$src2))),
3134 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3135 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3136 (memop addr:$src2))),
3137 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3139 // vector -> vector casts
3140 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3141 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3142 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3143 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3144 def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3145 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3146 def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3147 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
3149 // Use movaps / movups for SSE integer load / store (one byte shorter).
3150 def : Pat<(alignedloadv4i32 addr:$src),
3151 (MOVAPSrm addr:$src)>;
3152 def : Pat<(loadv4i32 addr:$src),
3153 (MOVUPSrm addr:$src)>;
3154 def : Pat<(alignedloadv2i64 addr:$src),
3155 (MOVAPSrm addr:$src)>;
3156 def : Pat<(loadv2i64 addr:$src),
3157 (MOVUPSrm addr:$src)>;
3159 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3160 (MOVAPSmr addr:$dst, VR128:$src)>;
3161 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3162 (MOVAPSmr addr:$dst, VR128:$src)>;
3163 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3164 (MOVAPSmr addr:$dst, VR128:$src)>;
3165 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3166 (MOVAPSmr addr:$dst, VR128:$src)>;
3167 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3168 (MOVUPSmr addr:$dst, VR128:$src)>;
3169 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3170 (MOVUPSmr addr:$dst, VR128:$src)>;
3171 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3172 (MOVUPSmr addr:$dst, VR128:$src)>;
3173 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3174 (MOVUPSmr addr:$dst, VR128:$src)>;
3176 //===----------------------------------------------------------------------===//
3177 // SSE4.1 Instructions
3178 //===----------------------------------------------------------------------===//
3180 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
3183 Intrinsic V2F64Int> {
3184 // Intrinsic operation, reg.
3185 // Vector intrinsic operation, reg
3186 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
3187 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3188 !strconcat(OpcodeStr,
3189 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3190 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3193 // Vector intrinsic operation, mem
3194 def PSm_Int : Ii8<opcps, MRMSrcMem,
3195 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3196 !strconcat(OpcodeStr,
3197 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3199 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
3201 Requires<[HasSSE41]>;
3203 // Vector intrinsic operation, reg
3204 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
3205 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3206 !strconcat(OpcodeStr,
3207 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3208 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3211 // Vector intrinsic operation, mem
3212 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
3213 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3214 !strconcat(OpcodeStr,
3215 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3217 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
3221 let Constraints = "$src1 = $dst" in {
3222 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3226 // Intrinsic operation, reg.
3227 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
3229 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3230 !strconcat(OpcodeStr,
3231 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3233 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3236 // Intrinsic operation, mem.
3237 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3239 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
3240 !strconcat(OpcodeStr,
3241 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3243 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3246 // Intrinsic operation, reg.
3247 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
3249 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3250 !strconcat(OpcodeStr,
3251 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3253 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3256 // Intrinsic operation, mem.
3257 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
3259 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3260 !strconcat(OpcodeStr,
3261 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3263 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3268 // FP round - roundss, roundps, roundsd, roundpd
3269 defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3270 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3271 defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3272 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
3274 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3275 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3276 Intrinsic IntId128> {
3277 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3279 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3280 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3281 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3283 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3286 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3289 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3290 int_x86_sse41_phminposuw>;
3292 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3293 let Constraints = "$src1 = $dst" in {
3294 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3295 Intrinsic IntId128, bit Commutable = 0> {
3296 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3297 (ins VR128:$src1, VR128:$src2),
3298 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3299 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3301 let isCommutable = Commutable;
3303 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3304 (ins VR128:$src1, i128mem:$src2),
3305 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3307 (IntId128 VR128:$src1,
3308 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3312 defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3313 int_x86_sse41_pcmpeqq, 1>;
3314 defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3315 int_x86_sse41_packusdw, 0>;
3316 defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3317 int_x86_sse41_pminsb, 1>;
3318 defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3319 int_x86_sse41_pminsd, 1>;
3320 defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3321 int_x86_sse41_pminud, 1>;
3322 defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3323 int_x86_sse41_pminuw, 1>;
3324 defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3325 int_x86_sse41_pmaxsb, 1>;
3326 defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3327 int_x86_sse41_pmaxsd, 1>;
3328 defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3329 int_x86_sse41_pmaxud, 1>;
3330 defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3331 int_x86_sse41_pmaxuw, 1>;
3333 defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3335 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3336 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3337 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3338 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3340 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3341 let Constraints = "$src1 = $dst" in {
3342 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3343 SDNode OpNode, Intrinsic IntId128,
3344 bit Commutable = 0> {
3345 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3346 (ins VR128:$src1, VR128:$src2),
3347 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3348 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3349 VR128:$src2))]>, OpSize {
3350 let isCommutable = Commutable;
3352 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3353 (ins VR128:$src1, VR128:$src2),
3354 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3355 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3357 let isCommutable = Commutable;
3359 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3360 (ins VR128:$src1, i128mem:$src2),
3361 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3363 (OpVT (OpNode VR128:$src1, (memop addr:$src2))))]>, OpSize;
3364 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3365 (ins VR128:$src1, i128mem:$src2),
3366 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3368 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
3373 /// SS48I_binop_rm - Simple SSE41 binary operator.
3374 let Constraints = "$src1 = $dst" in {
3375 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
3376 ValueType OpVT, bit Commutable = 0> {
3377 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3378 (ins VR128:$src1, VR128:$src2),
3379 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3380 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
3382 let isCommutable = Commutable;
3384 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3385 (ins VR128:$src1, i128mem:$src2),
3386 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3387 [(set VR128:$dst, (OpNode VR128:$src1,
3388 (bc_v4i32 (memopv2i64 addr:$src2))))]>,
3393 defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, 1>;
3395 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
3396 let Constraints = "$src1 = $dst" in {
3397 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3398 Intrinsic IntId128, bit Commutable = 0> {
3399 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3400 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3401 !strconcat(OpcodeStr,
3402 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3404 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3406 let isCommutable = Commutable;
3408 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3409 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3410 !strconcat(OpcodeStr,
3411 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3413 (IntId128 VR128:$src1,
3414 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3419 defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3420 int_x86_sse41_blendps, 0>;
3421 defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3422 int_x86_sse41_blendpd, 0>;
3423 defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3424 int_x86_sse41_pblendw, 0>;
3425 defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3426 int_x86_sse41_dpps, 1>;
3427 defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3428 int_x86_sse41_dppd, 1>;
3429 defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
3430 int_x86_sse41_mpsadbw, 0>;
3433 /// SS41I_ternary_int - SSE 4.1 ternary operator
3434 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
3435 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3436 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3437 (ins VR128:$src1, VR128:$src2),
3438 !strconcat(OpcodeStr,
3439 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3440 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3443 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3444 (ins VR128:$src1, i128mem:$src2),
3445 !strconcat(OpcodeStr,
3446 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3449 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3453 defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3454 defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3455 defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3458 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3459 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3460 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3461 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3463 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3464 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3466 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3470 defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3471 defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3472 defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3473 defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3474 defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3475 defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3477 // Common patterns involving scalar load.
3478 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3479 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3480 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3481 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3483 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3484 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3485 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3486 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3488 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3489 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3490 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3491 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3493 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3494 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3495 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3496 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3498 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3499 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3500 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3501 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3503 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3504 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3505 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3506 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3509 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3510 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3511 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3512 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3514 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3515 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3517 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3521 defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3522 defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3523 defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3524 defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3526 // Common patterns involving scalar load
3527 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
3528 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
3529 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
3530 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
3532 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
3533 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
3534 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
3535 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
3538 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3539 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3540 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3541 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3543 // Expecting a i16 load any extended to i32 value.
3544 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3545 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3546 [(set VR128:$dst, (IntId (bitconvert
3547 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3551 defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3552 defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
3554 // Common patterns involving scalar load
3555 def : Pat<(int_x86_sse41_pmovsxbq
3556 (bitconvert (v4i32 (X86vzmovl
3557 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3558 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
3560 def : Pat<(int_x86_sse41_pmovzxbq
3561 (bitconvert (v4i32 (X86vzmovl
3562 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3563 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
3566 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3567 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
3568 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3569 (ins VR128:$src1, i32i8imm:$src2),
3570 !strconcat(OpcodeStr,
3571 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3572 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3574 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3575 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
3576 !strconcat(OpcodeStr,
3577 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3580 // There's an AssertZext in the way of writing the store pattern
3581 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3584 defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
3587 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3588 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
3589 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3590 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
3591 !strconcat(OpcodeStr,
3592 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3595 // There's an AssertZext in the way of writing the store pattern
3596 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3599 defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3602 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3603 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
3604 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3605 (ins VR128:$src1, i32i8imm:$src2),
3606 !strconcat(OpcodeStr,
3607 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3609 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
3610 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3611 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
3612 !strconcat(OpcodeStr,
3613 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3614 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3615 addr:$dst)]>, OpSize;
3618 defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
3621 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3623 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
3624 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3625 (ins VR128:$src1, i32i8imm:$src2),
3626 !strconcat(OpcodeStr,
3627 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3629 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
3631 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3632 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
3633 !strconcat(OpcodeStr,
3634 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3635 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
3636 addr:$dst)]>, OpSize;
3639 defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
3641 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3642 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3645 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3646 Requires<[HasSSE41]>;
3648 let Constraints = "$src1 = $dst" in {
3649 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
3650 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3651 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3652 !strconcat(OpcodeStr,
3653 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3655 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
3656 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3657 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3658 !strconcat(OpcodeStr,
3659 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3661 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3662 imm:$src3))]>, OpSize;
3666 defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3668 let Constraints = "$src1 = $dst" in {
3669 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
3670 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3671 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3672 !strconcat(OpcodeStr,
3673 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3675 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3677 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3678 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3679 !strconcat(OpcodeStr,
3680 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3682 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3683 imm:$src3)))]>, OpSize;
3687 defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3689 // insertps has a few different modes, there's the first two here below which
3690 // are optimized inserts that won't zero arbitrary elements in the destination
3691 // vector. The next one matches the intrinsic and could zero arbitrary elements
3692 // in the target vector.
3693 let Constraints = "$src1 = $dst" in {
3694 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
3695 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3696 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3697 !strconcat(OpcodeStr,
3698 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3700 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
3702 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3703 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3704 !strconcat(OpcodeStr,
3705 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3707 (X86insrtps VR128:$src1,
3708 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
3709 imm:$src3))]>, OpSize;
3713 defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
3715 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3716 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3718 // ptest instruction we'll lower to this in X86ISelLowering primarily from
3719 // the intel intrinsic that corresponds to this.
3720 let Defs = [EFLAGS] in {
3721 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
3722 "ptest \t{$src2, $src1|$src1, $src2}",
3723 [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
3725 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
3726 "ptest \t{$src2, $src1|$src1, $src2}",
3727 [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
3731 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3732 "movntdqa\t{$src, $dst|$dst, $src}",
3733 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
3737 //===----------------------------------------------------------------------===//
3738 // SSE4.2 Instructions
3739 //===----------------------------------------------------------------------===//
3741 /// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3742 let Constraints = "$src1 = $dst" in {
3743 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3744 Intrinsic IntId128, bit Commutable = 0> {
3745 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3746 (ins VR128:$src1, VR128:$src2),
3747 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3748 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3750 let isCommutable = Commutable;
3752 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3753 (ins VR128:$src1, i128mem:$src2),
3754 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3756 (IntId128 VR128:$src1,
3757 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3761 defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
3763 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3764 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3765 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3766 (PCMPGTQrm VR128:$src1, addr:$src2)>;
3768 // crc intrinsic instruction
3769 // This set of instructions are only rm, the only difference is the size
3771 let Constraints = "$src1 = $dst" in {
3772 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
3773 (ins GR32:$src1, i8mem:$src2),
3774 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3776 (int_x86_sse42_crc32_8 GR32:$src1,
3777 (load addr:$src2)))]>;
3778 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
3779 (ins GR32:$src1, GR8:$src2),
3780 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3782 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
3783 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3784 (ins GR32:$src1, i16mem:$src2),
3785 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3787 (int_x86_sse42_crc32_16 GR32:$src1,
3788 (load addr:$src2)))]>,
3790 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3791 (ins GR32:$src1, GR16:$src2),
3792 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3794 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
3796 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3797 (ins GR32:$src1, i32mem:$src2),
3798 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3800 (int_x86_sse42_crc32_32 GR32:$src1,
3801 (load addr:$src2)))]>;
3802 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3803 (ins GR32:$src1, GR32:$src2),
3804 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3806 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
3807 def CRC64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3808 (ins GR64:$src1, i8mem:$src2),
3809 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3811 (int_x86_sse42_crc64_8 GR64:$src1,
3812 (load addr:$src2)))]>,
3814 def CRC64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3815 (ins GR64:$src1, GR8:$src2),
3816 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3818 (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
3820 def CRC64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
3821 (ins GR64:$src1, i64mem:$src2),
3822 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3824 (int_x86_sse42_crc64_64 GR64:$src1,
3825 (load addr:$src2)))]>,
3827 def CRC64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
3828 (ins GR64:$src1, GR64:$src2),
3829 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3831 (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
3835 // String/text processing instructions.
3836 let Defs = [EFLAGS], usesCustomInserter = 1 in {
3837 def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3838 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3839 "#PCMPISTRM128rr PSEUDO!",
3840 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
3841 imm:$src3))]>, OpSize;
3842 def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3843 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3844 "#PCMPISTRM128rm PSEUDO!",
3845 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, (load addr:$src2),
3846 imm:$src3))]>, OpSize;
3849 let Defs = [XMM0, EFLAGS] in {
3850 def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
3851 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3852 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3853 def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
3854 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3855 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3858 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
3859 def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3860 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3861 "#PCMPESTRM128rr PSEUDO!",
3863 (int_x86_sse42_pcmpestrm128
3864 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
3866 def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3867 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3868 "#PCMPESTRM128rm PSEUDO!",
3869 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
3870 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
3874 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
3875 def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
3876 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3877 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3878 def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
3879 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3880 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3883 let Defs = [ECX, EFLAGS] in {
3884 multiclass SS42AI_pcmpistri<Intrinsic IntId128> {
3885 def rr : SS42AI<0x63, MRMSrcReg, (outs),
3886 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3887 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3888 [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
3889 (implicit EFLAGS)]>, OpSize;
3890 def rm : SS42AI<0x63, MRMSrcMem, (outs),
3891 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3892 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3893 [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
3894 (implicit EFLAGS)]>, OpSize;
3898 defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
3899 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
3900 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
3901 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
3902 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
3903 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
3905 let Defs = [ECX, EFLAGS] in {
3906 let Uses = [EAX, EDX] in {
3907 multiclass SS42AI_pcmpestri<Intrinsic IntId128> {
3908 def rr : SS42AI<0x61, MRMSrcReg, (outs),
3909 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3910 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3911 [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
3912 (implicit EFLAGS)]>, OpSize;
3913 def rm : SS42AI<0x61, MRMSrcMem, (outs),
3914 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3915 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3917 (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
3918 (implicit EFLAGS)]>, OpSize;
3923 defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
3924 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
3925 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
3926 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
3927 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
3928 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
3930 //===----------------------------------------------------------------------===//
3931 // AES-NI Instructions
3932 //===----------------------------------------------------------------------===//
3934 let Constraints = "$src1 = $dst" in {
3935 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
3936 Intrinsic IntId128, bit Commutable = 0> {
3937 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
3938 (ins VR128:$src1, VR128:$src2),
3939 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3940 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3942 let isCommutable = Commutable;
3944 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
3945 (ins VR128:$src1, i128mem:$src2),
3946 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3948 (IntId128 VR128:$src1,
3949 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3953 defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
3954 int_x86_aesni_aesenc>;
3955 defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
3956 int_x86_aesni_aesenclast>;
3957 defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
3958 int_x86_aesni_aesdec>;
3959 defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
3960 int_x86_aesni_aesdeclast>;
3962 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
3963 (AESENCrr VR128:$src1, VR128:$src2)>;
3964 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
3965 (AESENCrm VR128:$src1, addr:$src2)>;
3966 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
3967 (AESENCLASTrr VR128:$src1, VR128:$src2)>;
3968 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
3969 (AESENCLASTrm VR128:$src1, addr:$src2)>;
3970 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
3971 (AESDECrr VR128:$src1, VR128:$src2)>;
3972 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
3973 (AESDECrm VR128:$src1, addr:$src2)>;
3974 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
3975 (AESDECLASTrr VR128:$src1, VR128:$src2)>;
3976 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
3977 (AESDECLASTrm VR128:$src1, addr:$src2)>;
3979 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
3981 "aesimc\t{$src1, $dst|$dst, $src1}",
3983 (int_x86_aesni_aesimc VR128:$src1))]>,
3986 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
3987 (ins i128mem:$src1),
3988 "aesimc\t{$src1, $dst|$dst, $src1}",
3990 (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
3993 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
3994 (ins VR128:$src1, i8imm:$src2),
3995 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3997 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
3999 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
4000 (ins i128mem:$src1, i8imm:$src2),
4001 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
4003 (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),