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 memop> {
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, memop:$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 memop, 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, memop:$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 memop, 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, memop:$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 /// sse12_unpack_interleave - SSE 1 & 2 unpack and interleave
448 multiclass sse12_unpack_interleave<bits<8> opc, PatFrag OpNode, ValueType vt,
449 PatFrag mem_frag, RegisterClass RC,
450 X86MemOperand x86memop, string asm,
452 def rr : PI<opc, MRMSrcReg,
453 (outs RC:$dst), (ins RC:$src1, RC:$src2),
455 (vt (OpNode RC:$src1, RC:$src2)))], d>;
456 def rm : PI<opc, MRMSrcMem,
457 (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
459 (vt (OpNode RC:$src1,
460 (mem_frag addr:$src2))))], d>;
463 //===----------------------------------------------------------------------===//
465 //===----------------------------------------------------------------------===//
467 // Move Instructions. Register-to-register movss is not used for FR32
468 // register copies because it's a partial register update; FsMOVAPSrr is
469 // used instead. Register-to-register movss is not modeled as an INSERT_SUBREG
470 // because INSERT_SUBREG requires that the insert be implementable in terms of
471 // a copy, and just mentioned, we don't use movss for copies.
472 let Constraints = "$src1 = $dst" in
473 def MOVSSrr : SSI<0x10, MRMSrcReg,
474 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
475 "movss\t{$src2, $dst|$dst, $src2}",
476 [(set (v4f32 VR128:$dst),
477 (movl VR128:$src1, (scalar_to_vector FR32:$src2)))]>;
479 // Extract the low 32-bit value from one vector and insert it into another.
480 let AddedComplexity = 15 in
481 def : Pat<(v4f32 (movl VR128:$src1, VR128:$src2)),
482 (MOVSSrr (v4f32 VR128:$src1),
483 (EXTRACT_SUBREG (v4f32 VR128:$src2), sub_ss))>;
485 // Implicitly promote a 32-bit scalar to a vector.
486 def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
487 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss)>;
489 // Loading from memory automatically zeroing upper bits.
490 let canFoldAsLoad = 1, isReMaterializable = 1 in
491 def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
492 "movss\t{$src, $dst|$dst, $src}",
493 [(set FR32:$dst, (loadf32 addr:$src))]>;
495 // MOVSSrm zeros the high parts of the register; represent this
496 // with SUBREG_TO_REG.
497 let AddedComplexity = 20 in {
498 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
499 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
500 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
501 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
502 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
503 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
506 // Store scalar value to memory.
507 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
508 "movss\t{$src, $dst|$dst, $src}",
509 [(store FR32:$src, addr:$dst)]>;
511 // Extract and store.
512 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
515 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
517 // Conversion instructions
518 def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
519 "cvttss2si\t{$src, $dst|$dst, $src}",
520 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
521 def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
522 "cvttss2si\t{$src, $dst|$dst, $src}",
523 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
524 def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
525 "cvtsi2ss\t{$src, $dst|$dst, $src}",
526 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
527 def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
528 "cvtsi2ss\t{$src, $dst|$dst, $src}",
529 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
531 // Match intrinsics which expect XMM operand(s).
532 def CVTSS2SIrr: SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
533 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
534 def CVTSS2SIrm: SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
535 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
537 def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
538 "cvtss2si\t{$src, $dst|$dst, $src}",
539 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
540 def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
541 "cvtss2si\t{$src, $dst|$dst, $src}",
542 [(set GR32:$dst, (int_x86_sse_cvtss2si
543 (load addr:$src)))]>;
545 // Match intrinsics which expect MM and XMM operand(s).
546 def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
547 "cvtps2pi\t{$src, $dst|$dst, $src}",
548 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
549 def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
550 "cvtps2pi\t{$src, $dst|$dst, $src}",
551 [(set VR64:$dst, (int_x86_sse_cvtps2pi
552 (load addr:$src)))]>;
553 def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
554 "cvttps2pi\t{$src, $dst|$dst, $src}",
555 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
556 def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
557 "cvttps2pi\t{$src, $dst|$dst, $src}",
558 [(set VR64:$dst, (int_x86_sse_cvttps2pi
559 (load addr:$src)))]>;
560 let Constraints = "$src1 = $dst" in {
561 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
562 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
563 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
564 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
566 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
567 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
568 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
569 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
570 (load addr:$src2)))]>;
573 // Aliases for intrinsics
574 def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
575 "cvttss2si\t{$src, $dst|$dst, $src}",
577 (int_x86_sse_cvttss2si VR128:$src))]>;
578 def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
579 "cvttss2si\t{$src, $dst|$dst, $src}",
581 (int_x86_sse_cvttss2si(load addr:$src)))]>;
583 let Constraints = "$src1 = $dst" in {
584 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
585 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
586 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
587 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
589 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
590 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
591 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
592 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
593 (loadi32 addr:$src2)))]>;
596 // Comparison instructions
597 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
598 def CMPSSrr : SSIi8<0xC2, MRMSrcReg,
599 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
600 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
602 def CMPSSrm : SSIi8<0xC2, MRMSrcMem,
603 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
604 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
606 // Accept explicit immediate argument form instead of comparison code.
607 let isAsmParserOnly = 1 in {
608 def CMPSSrr_alt : SSIi8<0xC2, MRMSrcReg,
609 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, i8imm:$src2),
610 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
612 def CMPSSrm_alt : SSIi8<0xC2, MRMSrcMem,
613 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, i8imm:$src2),
614 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
618 let Defs = [EFLAGS] in {
619 def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
620 "ucomiss\t{$src2, $src1|$src1, $src2}",
621 [(set EFLAGS, (X86cmp FR32:$src1, FR32:$src2))]>;
622 def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
623 "ucomiss\t{$src2, $src1|$src1, $src2}",
624 [(set EFLAGS, (X86cmp FR32:$src1, (loadf32 addr:$src2)))]>;
626 def COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
627 "comiss\t{$src2, $src1|$src1, $src2}", []>;
628 def COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
629 "comiss\t{$src2, $src1|$src1, $src2}", []>;
633 // Aliases to match intrinsics which expect XMM operand(s).
634 let Constraints = "$src1 = $dst" in {
635 def Int_CMPSSrr : SSIi8<0xC2, MRMSrcReg,
637 (ins VR128:$src1, VR128:$src, SSECC:$cc),
638 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
639 [(set VR128:$dst, (int_x86_sse_cmp_ss
641 VR128:$src, imm:$cc))]>;
642 def Int_CMPSSrm : SSIi8<0xC2, MRMSrcMem,
644 (ins VR128:$src1, f32mem:$src, SSECC:$cc),
645 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
646 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
647 (load addr:$src), imm:$cc))]>;
650 let Defs = [EFLAGS] in {
651 def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
652 "ucomiss\t{$src2, $src1|$src1, $src2}",
653 [(set EFLAGS, (X86ucomi (v4f32 VR128:$src1),
655 def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
656 "ucomiss\t{$src2, $src1|$src1, $src2}",
657 [(set EFLAGS, (X86ucomi (v4f32 VR128:$src1),
658 (load addr:$src2)))]>;
660 def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
661 "comiss\t{$src2, $src1|$src1, $src2}",
662 [(set EFLAGS, (X86comi (v4f32 VR128:$src1),
664 def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
665 "comiss\t{$src2, $src1|$src1, $src2}",
666 [(set EFLAGS, (X86comi (v4f32 VR128:$src1),
667 (load addr:$src2)))]>;
670 // Aliases of packed SSE1 instructions for scalar use. These all have names
671 // that start with 'Fs'.
673 // Alias instructions that map fld0 to pxor for sse.
674 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
676 // FIXME: Set encoding to pseudo!
677 def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins), "",
678 [(set FR32:$dst, fp32imm0)]>,
679 Requires<[HasSSE1]>, TB, OpSize;
681 // Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
683 let neverHasSideEffects = 1 in
684 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
685 "movaps\t{$src, $dst|$dst, $src}", []>;
687 // Alias instruction to load FR32 from f128mem using movaps. Upper bits are
689 let canFoldAsLoad = 1, isReMaterializable = 1 in
690 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
691 "movaps\t{$src, $dst|$dst, $src}",
692 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
694 /// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
696 multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
697 SDNode OpNode, bit MayLoad = 0> {
698 let isAsmParserOnly = 1 in {
699 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
700 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR32,
701 f32, f128mem, memopfsf32, SSEPackedSingle, MayLoad>, VEX_4V;
703 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
704 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR64,
705 f64, f128mem, memopfsf64, SSEPackedDouble, MayLoad>, OpSize,
709 let Constraints = "$src1 = $dst" in {
710 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
711 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, FR32, f32,
712 f128mem, memopfsf32, SSEPackedSingle, MayLoad>, TB;
714 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
715 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, FR64, f64,
716 f128mem, memopfsf64, SSEPackedDouble, MayLoad>, TB, OpSize;
720 // Alias bitwise logical operations using SSE logical ops on packed FP values.
721 defm FsAND : sse12_fp_alias_pack_logical<0x54, "and", X86fand>;
722 defm FsOR : sse12_fp_alias_pack_logical<0x56, "or", X86for>;
723 defm FsXOR : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor>;
725 let neverHasSideEffects = 1, Pattern = []<dag>, isCommutable = 0 in
726 defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef, 1>;
728 /// basic_sse12_fp_binop_rm - SSE 1 & 2 binops come in both scalar and
731 /// In addition, we also have a special variant of the scalar form here to
732 /// represent the associated intrinsic operation. This form is unlike the
733 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
734 /// and leaves the top elements unmodified (therefore these cannot be commuted).
736 /// These three forms can each be reg+reg or reg+mem, so there are a total of
737 /// six "instructions".
739 multiclass basic_sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
742 let isAsmParserOnly = 1 in {
743 defm V#NAME#SS : sse12_fp_scalar<opc,
744 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
745 OpNode, FR32, f32mem>, XS, VEX_4V;
747 defm V#NAME#SD : sse12_fp_scalar<opc,
748 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
749 OpNode, FR64, f64mem>, XD, VEX_4V;
751 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
752 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
753 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
756 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
757 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
758 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
761 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
762 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
763 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
765 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
766 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
767 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
770 let Constraints = "$src1 = $dst" in {
771 defm SS : sse12_fp_scalar<opc,
772 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
773 OpNode, FR32, f32mem>, XS;
775 defm SD : sse12_fp_scalar<opc,
776 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
777 OpNode, FR64, f64mem>, XD;
779 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
780 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
781 f128mem, memopv4f32, SSEPackedSingle>, TB;
783 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
784 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
785 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
787 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
788 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
789 "", "_ss", ssmem, sse_load_f32>, XS;
791 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
792 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
793 "2", "_sd", sdmem, sse_load_f64>, XD;
797 // Arithmetic instructions
798 defm ADD : basic_sse12_fp_binop_rm<0x58, "add", fadd>;
799 defm MUL : basic_sse12_fp_binop_rm<0x59, "mul", fmul>;
801 let isCommutable = 0 in {
802 defm SUB : basic_sse12_fp_binop_rm<0x5C, "sub", fsub>;
803 defm DIV : basic_sse12_fp_binop_rm<0x5E, "div", fdiv>;
806 /// sse12_fp_binop_rm - Other SSE 1 & 2 binops
808 /// This multiclass is like basic_sse12_fp_binop_rm, with the addition of
809 /// instructions for a full-vector intrinsic form. Operations that map
810 /// onto C operators don't use this form since they just use the plain
811 /// vector form instead of having a separate vector intrinsic form.
813 /// This provides a total of eight "instructions".
815 multiclass sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
818 let isAsmParserOnly = 1 in {
819 // Scalar operation, reg+reg.
820 defm V#NAME#SS : sse12_fp_scalar<opc,
821 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
822 OpNode, FR32, f32mem>, XS, VEX_4V;
824 defm V#NAME#SD : sse12_fp_scalar<opc,
825 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
826 OpNode, FR64, f64mem>, XD, VEX_4V;
828 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
829 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
830 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
833 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
834 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
835 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
838 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
839 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
840 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
842 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
843 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
844 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
846 defm V#NAME#PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
847 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
848 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, VEX_4V;
850 defm V#NAME#PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
851 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
852 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, OpSize,
856 let Constraints = "$src1 = $dst" in {
857 // Scalar operation, reg+reg.
858 defm SS : sse12_fp_scalar<opc,
859 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
860 OpNode, FR32, f32mem>, XS;
861 defm SD : sse12_fp_scalar<opc,
862 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
863 OpNode, FR64, f64mem>, XD;
864 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
865 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
866 f128mem, memopv4f32, SSEPackedSingle>, TB;
868 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
869 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
870 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
872 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
873 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
874 "", "_ss", ssmem, sse_load_f32>, XS;
876 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
877 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
878 "2", "_sd", sdmem, sse_load_f64>, XD;
880 defm PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
881 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
882 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, TB;
884 defm PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
885 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
886 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
890 let isCommutable = 0 in {
891 defm MAX : sse12_fp_binop_rm<0x5F, "max", X86fmax>;
892 defm MIN : sse12_fp_binop_rm<0x5D, "min", X86fmin>;
895 //===----------------------------------------------------------------------===//
896 // SSE packed FP Instructions
899 let neverHasSideEffects = 1 in
900 def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
901 "movaps\t{$src, $dst|$dst, $src}", []>;
902 let canFoldAsLoad = 1, isReMaterializable = 1 in
903 def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
904 "movaps\t{$src, $dst|$dst, $src}",
905 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
907 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
908 "movaps\t{$src, $dst|$dst, $src}",
909 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
911 let neverHasSideEffects = 1 in
912 def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
913 "movups\t{$src, $dst|$dst, $src}", []>;
914 let canFoldAsLoad = 1, isReMaterializable = 1 in
915 def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
916 "movups\t{$src, $dst|$dst, $src}",
917 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
918 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
919 "movups\t{$src, $dst|$dst, $src}",
920 [(store (v4f32 VR128:$src), addr:$dst)]>;
922 // Intrinsic forms of MOVUPS load and store
923 let canFoldAsLoad = 1, isReMaterializable = 1 in
924 def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
925 "movups\t{$src, $dst|$dst, $src}",
926 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
927 def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
928 "movups\t{$src, $dst|$dst, $src}",
929 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
931 let Constraints = "$src1 = $dst" in {
932 let AddedComplexity = 20 in {
933 def MOVLPSrm : PSI<0x12, MRMSrcMem,
934 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
935 "movlps\t{$src2, $dst|$dst, $src2}",
938 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
939 def MOVHPSrm : PSI<0x16, MRMSrcMem,
940 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
941 "movhps\t{$src2, $dst|$dst, $src2}",
943 (movlhps VR128:$src1,
944 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
946 } // Constraints = "$src1 = $dst"
949 def : Pat<(movlhps VR128:$src1, (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
950 (MOVHPSrm (v4i32 VR128:$src1), addr:$src2)>;
952 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
953 "movlps\t{$src, $dst|$dst, $src}",
954 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
955 (iPTR 0))), addr:$dst)]>;
957 // v2f64 extract element 1 is always custom lowered to unpack high to low
958 // and extract element 0 so the non-store version isn't too horrible.
959 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
960 "movhps\t{$src, $dst|$dst, $src}",
961 [(store (f64 (vector_extract
962 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
963 (undef)), (iPTR 0))), addr:$dst)]>;
965 let Constraints = "$src1 = $dst" in {
966 let AddedComplexity = 20 in {
967 def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
968 (ins VR128:$src1, VR128:$src2),
969 "movlhps\t{$src2, $dst|$dst, $src2}",
971 (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
973 def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
974 (ins VR128:$src1, VR128:$src2),
975 "movhlps\t{$src2, $dst|$dst, $src2}",
977 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
979 } // Constraints = "$src1 = $dst"
981 let AddedComplexity = 20 in {
982 def : Pat<(v4f32 (movddup VR128:$src, (undef))),
983 (MOVLHPSrr (v4f32 VR128:$src), (v4f32 VR128:$src))>;
984 def : Pat<(v2i64 (movddup VR128:$src, (undef))),
985 (MOVLHPSrr (v2i64 VR128:$src), (v2i64 VR128:$src))>;
992 /// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
994 /// In addition, we also have a special variant of the scalar form here to
995 /// represent the associated intrinsic operation. This form is unlike the
996 /// plain scalar form, in that it takes an entire vector (instead of a
997 /// scalar) and leaves the top elements undefined.
999 /// And, we have a special variant form for a full-vector intrinsic form.
1001 /// These four forms can each have a reg or a mem operand, so there are a
1002 /// total of eight "instructions".
1004 multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
1008 bit Commutable = 0> {
1009 // Scalar operation, reg.
1010 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1011 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1012 [(set FR32:$dst, (OpNode FR32:$src))]> {
1013 let isCommutable = Commutable;
1016 // Scalar operation, mem.
1017 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
1018 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1019 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
1020 Requires<[HasSSE1, OptForSize]>;
1022 // Vector operation, reg.
1023 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1024 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1025 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
1026 let isCommutable = Commutable;
1029 // Vector operation, mem.
1030 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1031 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1032 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
1034 // Intrinsic operation, reg.
1035 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1036 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1037 [(set VR128:$dst, (F32Int VR128:$src))]> {
1038 let isCommutable = Commutable;
1041 // Intrinsic operation, mem.
1042 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
1043 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1044 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1046 // Vector intrinsic operation, reg
1047 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1048 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1049 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
1050 let isCommutable = Commutable;
1053 // Vector intrinsic operation, mem
1054 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1055 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1056 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
1060 defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
1061 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
1063 // Reciprocal approximations. Note that these typically require refinement
1064 // in order to obtain suitable precision.
1065 defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
1066 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
1067 defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
1068 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
1070 /// sse12_fp_packed_logical - SSE 1 & 2 packed FP logical ops
1072 multiclass sse12_fp_packed_logical<bits<8> opc, string OpcodeStr,
1073 SDNode OpNode, int HasPat = 0,
1074 list<list<dag>> Pattern = []> {
1075 let isAsmParserOnly = 1 in {
1076 defm V#NAME#PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1077 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1079 !if(HasPat, Pattern[0], // rr
1080 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1082 !if(HasPat, Pattern[2], // rm
1083 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1084 (memopv2i64 addr:$src2)))])>,
1087 defm V#NAME#PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1088 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1090 !if(HasPat, Pattern[1], // rr
1091 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1094 !if(HasPat, Pattern[3], // rm
1095 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1096 (memopv2i64 addr:$src2)))])>,
1099 let Constraints = "$src1 = $dst" in {
1100 defm PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
1101 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"), f128mem,
1102 !if(HasPat, Pattern[0], // rr
1103 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1105 !if(HasPat, Pattern[2], // rm
1106 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1107 (memopv2i64 addr:$src2)))])>, TB;
1109 defm PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
1110 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"), f128mem,
1111 !if(HasPat, Pattern[1], // rr
1112 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1115 !if(HasPat, Pattern[3], // rm
1116 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1117 (memopv2i64 addr:$src2)))])>,
1123 defm AND : sse12_fp_packed_logical<0x54, "and", and>;
1124 defm OR : sse12_fp_packed_logical<0x56, "or", or>;
1125 defm XOR : sse12_fp_packed_logical<0x57, "xor", xor>;
1126 let isCommutable = 0 in
1127 defm ANDN : sse12_fp_packed_logical<0x55, "andn", undef /* dummy */, 1, [
1129 [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
1130 (bc_v2i64 (v4i32 immAllOnesV))),
1133 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1134 (bc_v2i64 (v2f64 VR128:$src2))))],
1136 [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1137 (bc_v2i64 (v4i32 immAllOnesV))),
1138 (memopv2i64 addr:$src2))))],
1140 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1141 (memopv2i64 addr:$src2)))]]>;
1143 let Constraints = "$src1 = $dst" in {
1144 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
1145 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1146 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1147 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
1148 VR128:$src, imm:$cc))]>;
1149 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
1150 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1151 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1152 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
1153 (memop addr:$src), imm:$cc))]>;
1154 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
1155 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1156 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1157 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1158 VR128:$src, imm:$cc))]>;
1159 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
1160 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1161 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1162 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1163 (memop addr:$src), imm:$cc))]>;
1165 // Accept explicit immediate argument form instead of comparison code.
1166 let isAsmParserOnly = 1 in {
1167 def CMPPSrri_alt : PSIi8<0xC2, MRMSrcReg,
1168 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1169 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1170 def CMPPSrmi_alt : PSIi8<0xC2, MRMSrcMem,
1171 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1172 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1173 def CMPPDrri_alt : PDIi8<0xC2, MRMSrcReg,
1174 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1175 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1176 def CMPPDrmi_alt : PDIi8<0xC2, MRMSrcMem,
1177 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1178 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1181 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
1182 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
1183 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
1184 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
1185 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
1186 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
1187 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
1188 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
1190 // Shuffle and unpack instructions
1191 let Constraints = "$src1 = $dst" in {
1192 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
1193 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
1194 (outs VR128:$dst), (ins VR128:$src1,
1195 VR128:$src2, i8imm:$src3),
1196 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1198 (v4f32 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
1199 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
1200 (outs VR128:$dst), (ins VR128:$src1,
1201 f128mem:$src2, i8imm:$src3),
1202 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1205 VR128:$src1, (memopv4f32 addr:$src2))))]>;
1206 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
1207 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1208 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1210 (v2f64 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
1211 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
1212 (outs VR128:$dst), (ins VR128:$src1,
1213 f128mem:$src2, i8imm:$src3),
1214 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1217 VR128:$src1, (memopv2f64 addr:$src2))))]>;
1219 let AddedComplexity = 10 in {
1220 let Constraints = "", isAsmParserOnly = 1 in {
1221 defm VUNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
1222 VR128, f128mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1223 SSEPackedSingle>, VEX_4V;
1224 defm VUNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
1225 VR128, f128mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1226 SSEPackedDouble>, OpSize, VEX_4V;
1227 defm VUNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
1228 VR128, f128mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1229 SSEPackedSingle>, VEX_4V;
1230 defm VUNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
1231 VR128, f128mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1232 SSEPackedDouble>, OpSize, VEX_4V;
1234 defm UNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
1235 VR128, f128mem, "unpckhps\t{$src2, $dst|$dst, $src2}",
1236 SSEPackedSingle>, TB;
1237 defm UNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
1238 VR128, f128mem, "unpckhpd\t{$src2, $dst|$dst, $src2}",
1239 SSEPackedDouble>, TB, OpSize;
1240 defm UNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
1241 VR128, f128mem, "unpcklps\t{$src2, $dst|$dst, $src2}",
1242 SSEPackedSingle>, TB;
1243 defm UNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
1244 VR128, f128mem, "unpcklpd\t{$src2, $dst|$dst, $src2}",
1245 SSEPackedDouble>, TB, OpSize;
1246 } // AddedComplexity
1247 } // Constraints = "$src1 = $dst"
1250 def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1251 "movmskps\t{$src, $dst|$dst, $src}",
1252 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
1253 def MOVMSKPDrr : PDI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1254 "movmskpd\t{$src, $dst|$dst, $src}",
1255 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
1257 // Prefetch intrinsic.
1258 def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
1259 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
1260 def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
1261 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
1262 def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
1263 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
1264 def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
1265 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
1267 // Non-temporal stores
1268 def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1269 "movntps\t{$src, $dst|$dst, $src}",
1270 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
1272 let AddedComplexity = 400 in { // Prefer non-temporal versions
1273 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1274 "movntps\t{$src, $dst|$dst, $src}",
1275 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1277 def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1278 "movntdq\t{$src, $dst|$dst, $src}",
1279 [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
1281 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1282 "movnti\t{$src, $dst|$dst, $src}",
1283 [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
1284 TB, Requires<[HasSSE2]>;
1286 def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1287 "movnti\t{$src, $dst|$dst, $src}",
1288 [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
1289 TB, Requires<[HasSSE2]>;
1292 // Load, store, and memory fence
1293 def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
1294 TB, Requires<[HasSSE1]>;
1297 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
1298 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
1299 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
1300 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
1302 // Alias instructions that map zero vector to pxor / xorp* for sse.
1303 // We set canFoldAsLoad because this can be converted to a constant-pool
1304 // load of an all-zeros value if folding it would be beneficial.
1305 // FIXME: Change encoding to pseudo!
1306 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
1307 isCodeGenOnly = 1 in {
1308 def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1309 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
1310 def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1311 [(set VR128:$dst, (v2f64 immAllZerosV))]>;
1312 let ExeDomain = SSEPackedInt in
1313 def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
1314 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
1317 def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
1318 def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
1319 def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
1321 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
1322 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1324 //===---------------------------------------------------------------------===//
1325 // SSE2 Instructions
1326 //===---------------------------------------------------------------------===//
1328 // Move Instructions. Register-to-register movsd is not used for FR64
1329 // register copies because it's a partial register update; FsMOVAPDrr is
1330 // used instead. Register-to-register movsd is not modeled as an INSERT_SUBREG
1331 // because INSERT_SUBREG requires that the insert be implementable in terms of
1332 // a copy, and just mentioned, we don't use movsd for copies.
1333 let Constraints = "$src1 = $dst" in
1334 def MOVSDrr : SDI<0x10, MRMSrcReg,
1335 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
1336 "movsd\t{$src2, $dst|$dst, $src2}",
1337 [(set (v2f64 VR128:$dst),
1338 (movl VR128:$src1, (scalar_to_vector FR64:$src2)))]>;
1340 // Extract the low 64-bit value from one vector and insert it into another.
1341 let AddedComplexity = 15 in
1342 def : Pat<(v2f64 (movl VR128:$src1, VR128:$src2)),
1343 (MOVSDrr (v2f64 VR128:$src1),
1344 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
1346 // Implicitly promote a 64-bit scalar to a vector.
1347 def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
1348 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
1350 // Loading from memory automatically zeroing upper bits.
1351 let canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 20 in
1352 def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1353 "movsd\t{$src, $dst|$dst, $src}",
1354 [(set FR64:$dst, (loadf64 addr:$src))]>;
1356 // MOVSDrm zeros the high parts of the register; represent this
1357 // with SUBREG_TO_REG.
1358 let AddedComplexity = 20 in {
1359 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
1360 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
1361 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
1362 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
1363 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
1364 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
1365 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
1366 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
1367 def : Pat<(v2f64 (X86vzload addr:$src)),
1368 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
1371 // Store scalar value to memory.
1372 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
1373 "movsd\t{$src, $dst|$dst, $src}",
1374 [(store FR64:$src, addr:$dst)]>;
1376 // Extract and store.
1377 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
1380 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
1382 // Conversion instructions
1383 def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
1384 "cvttsd2si\t{$src, $dst|$dst, $src}",
1385 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
1386 def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
1387 "cvttsd2si\t{$src, $dst|$dst, $src}",
1388 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1389 def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
1390 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1391 [(set FR32:$dst, (fround FR64:$src))]>;
1392 def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
1393 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1394 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
1395 Requires<[HasSSE2, OptForSize]>;
1396 def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
1397 "cvtsi2sd\t{$src, $dst|$dst, $src}",
1398 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
1399 def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
1400 "cvtsi2sd\t{$src, $dst|$dst, $src}",
1401 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1403 def CVTPD2DQrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1404 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1405 def CVTPD2DQrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1406 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1407 def CVTDQ2PDrm : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1408 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1409 def CVTDQ2PDrr : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1410 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1411 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1412 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1413 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1414 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1415 def CVTDQ2PSrr : PSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1416 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1417 def CVTDQ2PSrm : PSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1418 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1419 def COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1420 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1421 def COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1422 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1424 // SSE2 instructions with XS prefix
1425 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
1426 "cvtss2sd\t{$src, $dst|$dst, $src}",
1427 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1428 Requires<[HasSSE2]>;
1429 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
1430 "cvtss2sd\t{$src, $dst|$dst, $src}",
1431 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1432 Requires<[HasSSE2, OptForSize]>;
1434 def : Pat<(extloadf32 addr:$src),
1435 (CVTSS2SDrr (MOVSSrm addr:$src))>,
1436 Requires<[HasSSE2, OptForSpeed]>;
1438 // Match intrinsics which expect XMM operand(s).
1439 def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1440 "cvtsd2si\t{$src, $dst|$dst, $src}",
1441 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
1442 def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
1443 "cvtsd2si\t{$src, $dst|$dst, $src}",
1444 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1445 (load addr:$src)))]>;
1447 // Match intrinsics which expect MM and XMM operand(s).
1448 def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1449 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1450 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1451 def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1452 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1453 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
1454 (memop addr:$src)))]>;
1455 def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1456 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1457 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1458 def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1459 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1460 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
1461 (memop addr:$src)))]>;
1462 def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1463 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1464 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1465 def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1466 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1467 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
1468 (load addr:$src)))]>;
1470 // Aliases for intrinsics
1471 def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1472 "cvttsd2si\t{$src, $dst|$dst, $src}",
1474 (int_x86_sse2_cvttsd2si VR128:$src))]>;
1475 def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
1476 "cvttsd2si\t{$src, $dst|$dst, $src}",
1477 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1478 (load addr:$src)))]>;
1480 // Comparison instructions
1481 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
1482 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
1483 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
1484 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
1486 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
1487 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
1488 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
1490 // Accept explicit immediate argument form instead of comparison code.
1491 let isAsmParserOnly = 1 in {
1492 def CMPSDrr_alt : SDIi8<0xC2, MRMSrcReg,
1493 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, i8imm:$src2),
1494 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1496 def CMPSDrm_alt : SDIi8<0xC2, MRMSrcMem,
1497 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, i8imm:$src2),
1498 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1502 let Defs = [EFLAGS] in {
1503 def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
1504 "ucomisd\t{$src2, $src1|$src1, $src2}",
1505 [(set EFLAGS, (X86cmp FR64:$src1, FR64:$src2))]>;
1506 def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
1507 "ucomisd\t{$src2, $src1|$src1, $src2}",
1508 [(set EFLAGS, (X86cmp FR64:$src1, (loadf64 addr:$src2)))]>;
1509 } // Defs = [EFLAGS]
1511 // Aliases to match intrinsics which expect XMM operand(s).
1512 let Constraints = "$src1 = $dst" in {
1513 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
1515 (ins VR128:$src1, VR128:$src, SSECC:$cc),
1516 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
1517 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1518 VR128:$src, imm:$cc))]>;
1519 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
1521 (ins VR128:$src1, f64mem:$src, SSECC:$cc),
1522 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
1523 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1524 (load addr:$src), imm:$cc))]>;
1527 let Defs = [EFLAGS] in {
1528 def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1529 "ucomisd\t{$src2, $src1|$src1, $src2}",
1530 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
1532 def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
1533 "ucomisd\t{$src2, $src1|$src1, $src2}",
1534 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
1535 (load addr:$src2)))]>;
1537 def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1538 "comisd\t{$src2, $src1|$src1, $src2}",
1539 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
1541 def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1542 "comisd\t{$src2, $src1|$src1, $src2}",
1543 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
1544 (load addr:$src2)))]>;
1545 } // Defs = [EFLAGS]
1547 // Aliases of packed SSE2 instructions for scalar use. These all have names
1548 // that start with 'Fs'.
1550 // Alias instructions that map fld0 to pxor for sse.
1551 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
1552 canFoldAsLoad = 1 in
1553 def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
1554 [(set FR64:$dst, fpimm0)]>,
1555 Requires<[HasSSE2]>, TB, OpSize;
1557 // Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
1559 let neverHasSideEffects = 1 in
1560 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1561 "movapd\t{$src, $dst|$dst, $src}", []>;
1563 // Alias instruction to load FR64 from f128mem using movapd. Upper bits are
1565 let canFoldAsLoad = 1, isReMaterializable = 1 in
1566 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
1567 "movapd\t{$src, $dst|$dst, $src}",
1568 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
1570 //===---------------------------------------------------------------------===//
1571 // SSE packed FP Instructions
1573 // Move Instructions
1574 let neverHasSideEffects = 1 in
1575 def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1576 "movapd\t{$src, $dst|$dst, $src}", []>;
1577 let canFoldAsLoad = 1, isReMaterializable = 1 in
1578 def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1579 "movapd\t{$src, $dst|$dst, $src}",
1580 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
1582 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1583 "movapd\t{$src, $dst|$dst, $src}",
1584 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
1586 let neverHasSideEffects = 1 in
1587 def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1588 "movupd\t{$src, $dst|$dst, $src}", []>;
1589 let canFoldAsLoad = 1 in
1590 def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1591 "movupd\t{$src, $dst|$dst, $src}",
1592 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
1593 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1594 "movupd\t{$src, $dst|$dst, $src}",
1595 [(store (v2f64 VR128:$src), addr:$dst)]>;
1597 // Intrinsic forms of MOVUPD load and store
1598 def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1599 "movupd\t{$src, $dst|$dst, $src}",
1600 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
1601 def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1602 "movupd\t{$src, $dst|$dst, $src}",
1603 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
1605 let Constraints = "$src1 = $dst" in {
1606 let AddedComplexity = 20 in {
1607 def MOVLPDrm : PDI<0x12, MRMSrcMem,
1608 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1609 "movlpd\t{$src2, $dst|$dst, $src2}",
1611 (v2f64 (movlp VR128:$src1,
1612 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1613 def MOVHPDrm : PDI<0x16, MRMSrcMem,
1614 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1615 "movhpd\t{$src2, $dst|$dst, $src2}",
1617 (v2f64 (movlhps VR128:$src1,
1618 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1619 } // AddedComplexity
1620 } // Constraints = "$src1 = $dst"
1622 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1623 "movlpd\t{$src, $dst|$dst, $src}",
1624 [(store (f64 (vector_extract (v2f64 VR128:$src),
1625 (iPTR 0))), addr:$dst)]>;
1627 // v2f64 extract element 1 is always custom lowered to unpack high to low
1628 // and extract element 0 so the non-store version isn't too horrible.
1629 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1630 "movhpd\t{$src, $dst|$dst, $src}",
1631 [(store (f64 (vector_extract
1632 (v2f64 (unpckh VR128:$src, (undef))),
1633 (iPTR 0))), addr:$dst)]>;
1635 // SSE2 instructions without OpSize prefix
1636 def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1637 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1638 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1639 TB, Requires<[HasSSE2]>;
1640 def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1641 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1642 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1643 (bitconvert (memopv2i64 addr:$src))))]>,
1644 TB, Requires<[HasSSE2]>;
1646 // SSE2 instructions with XS prefix
1647 def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1648 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1649 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1650 XS, Requires<[HasSSE2]>;
1651 def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1652 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1653 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1654 (bitconvert (memopv2i64 addr:$src))))]>,
1655 XS, Requires<[HasSSE2]>;
1657 def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1658 "cvtps2dq\t{$src, $dst|$dst, $src}",
1659 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
1660 def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1661 "cvtps2dq\t{$src, $dst|$dst, $src}",
1662 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1663 (memop addr:$src)))]>;
1664 // SSE2 packed instructions with XS prefix
1665 def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1666 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1667 def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1668 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1670 def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1671 "cvttps2dq\t{$src, $dst|$dst, $src}",
1673 (int_x86_sse2_cvttps2dq VR128:$src))]>,
1674 XS, Requires<[HasSSE2]>;
1675 def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1676 "cvttps2dq\t{$src, $dst|$dst, $src}",
1677 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1678 (memop addr:$src)))]>,
1679 XS, Requires<[HasSSE2]>;
1681 // SSE2 packed instructions with XD prefix
1682 def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1683 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1684 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1685 XD, Requires<[HasSSE2]>;
1686 def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1687 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1688 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1689 (memop addr:$src)))]>,
1690 XD, Requires<[HasSSE2]>;
1692 def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1693 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1694 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
1695 def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
1696 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1697 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1698 (memop addr:$src)))]>;
1700 // SSE2 instructions without OpSize prefix
1701 def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1702 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1703 def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1704 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1706 def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1707 "cvtps2pd\t{$src, $dst|$dst, $src}",
1708 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1709 TB, Requires<[HasSSE2]>;
1710 def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1711 "cvtps2pd\t{$src, $dst|$dst, $src}",
1712 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1713 (load addr:$src)))]>,
1714 TB, Requires<[HasSSE2]>;
1716 def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1717 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1718 def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1719 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1722 def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1723 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1724 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
1725 def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1726 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1727 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1728 (memop addr:$src)))]>;
1730 // Match intrinsics which expect XMM operand(s).
1731 // Aliases for intrinsics
1732 let Constraints = "$src1 = $dst" in {
1733 def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
1734 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
1735 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1736 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1738 def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
1739 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
1740 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1741 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1742 (loadi32 addr:$src2)))]>;
1743 def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
1744 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1745 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1746 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1748 def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
1749 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1750 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1751 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1752 (load addr:$src2)))]>;
1753 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
1754 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1755 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1756 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1757 VR128:$src2))]>, XS,
1758 Requires<[HasSSE2]>;
1759 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
1760 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
1761 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1762 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1763 (load addr:$src2)))]>, XS,
1764 Requires<[HasSSE2]>;
1769 /// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1771 /// In addition, we also have a special variant of the scalar form here to
1772 /// represent the associated intrinsic operation. This form is unlike the
1773 /// plain scalar form, in that it takes an entire vector (instead of a
1774 /// scalar) and leaves the top elements undefined.
1776 /// And, we have a special variant form for a full-vector intrinsic form.
1778 /// These four forms can each have a reg or a mem operand, so there are a
1779 /// total of eight "instructions".
1781 multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1785 bit Commutable = 0> {
1786 // Scalar operation, reg.
1787 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1788 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1789 [(set FR64:$dst, (OpNode FR64:$src))]> {
1790 let isCommutable = Commutable;
1793 // Scalar operation, mem.
1794 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1795 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1796 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1798 // Vector operation, reg.
1799 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1800 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1801 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1802 let isCommutable = Commutable;
1805 // Vector operation, mem.
1806 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1807 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1808 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
1810 // Intrinsic operation, reg.
1811 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1812 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1813 [(set VR128:$dst, (F64Int VR128:$src))]> {
1814 let isCommutable = Commutable;
1817 // Intrinsic operation, mem.
1818 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1819 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1820 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1822 // Vector intrinsic operation, reg
1823 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1824 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1825 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1826 let isCommutable = Commutable;
1829 // Vector intrinsic operation, mem
1830 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1831 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1832 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
1836 defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1837 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1839 // There is no f64 version of the reciprocal approximation instructions.
1841 //===---------------------------------------------------------------------===//
1842 // SSE integer instructions
1843 let ExeDomain = SSEPackedInt in {
1845 // Move Instructions
1846 let neverHasSideEffects = 1 in
1847 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1848 "movdqa\t{$src, $dst|$dst, $src}", []>;
1849 let canFoldAsLoad = 1, mayLoad = 1 in
1850 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1851 "movdqa\t{$src, $dst|$dst, $src}",
1852 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
1854 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1855 "movdqa\t{$src, $dst|$dst, $src}",
1856 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
1857 let canFoldAsLoad = 1, mayLoad = 1 in
1858 def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1859 "movdqu\t{$src, $dst|$dst, $src}",
1860 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
1861 XS, Requires<[HasSSE2]>;
1863 def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1864 "movdqu\t{$src, $dst|$dst, $src}",
1865 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
1866 XS, Requires<[HasSSE2]>;
1868 // Intrinsic forms of MOVDQU load and store
1869 let canFoldAsLoad = 1 in
1870 def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1871 "movdqu\t{$src, $dst|$dst, $src}",
1872 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1873 XS, Requires<[HasSSE2]>;
1874 def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1875 "movdqu\t{$src, $dst|$dst, $src}",
1876 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1877 XS, Requires<[HasSSE2]>;
1879 let Constraints = "$src1 = $dst" in {
1881 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1882 bit Commutable = 0> {
1883 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1884 (ins VR128:$src1, VR128:$src2),
1885 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1886 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1887 let isCommutable = Commutable;
1889 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1890 (ins VR128:$src1, i128mem:$src2),
1891 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1892 [(set VR128:$dst, (IntId VR128:$src1,
1893 (bitconvert (memopv2i64
1897 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1899 Intrinsic IntId, Intrinsic IntId2> {
1900 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1901 (ins VR128:$src1, VR128:$src2),
1902 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1903 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
1904 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1905 (ins VR128:$src1, i128mem:$src2),
1906 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1907 [(set VR128:$dst, (IntId VR128:$src1,
1908 (bitconvert (memopv2i64 addr:$src2))))]>;
1909 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
1910 (ins VR128:$src1, i32i8imm:$src2),
1911 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1912 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1915 /// PDI_binop_rm - Simple SSE2 binary operator.
1916 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1917 ValueType OpVT, bit Commutable = 0> {
1918 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1919 (ins VR128:$src1, VR128:$src2),
1920 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1921 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1922 let isCommutable = Commutable;
1924 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1925 (ins VR128:$src1, i128mem:$src2),
1926 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1927 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
1928 (bitconvert (memopv2i64 addr:$src2)))))]>;
1931 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1933 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1934 /// to collapse (bitconvert VT to VT) into its operand.
1936 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1937 bit Commutable = 0> {
1938 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1939 (ins VR128:$src1, VR128:$src2),
1940 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1941 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1942 let isCommutable = Commutable;
1944 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1945 (ins VR128:$src1, i128mem:$src2),
1946 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1947 [(set VR128:$dst, (OpNode VR128:$src1,
1948 (memopv2i64 addr:$src2)))]>;
1951 } // Constraints = "$src1 = $dst"
1952 } // ExeDomain = SSEPackedInt
1954 // 128-bit Integer Arithmetic
1956 defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1957 defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1958 defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1959 defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1961 defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1962 defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1963 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1964 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1966 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1967 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1968 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1969 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1971 defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1972 defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1973 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1974 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1976 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1978 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1979 defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1980 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1982 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1984 defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1985 defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1988 defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1989 defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1990 defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1991 defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
1992 defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
1995 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
1996 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
1997 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
1998 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
1999 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2000 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
2002 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2003 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2004 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2005 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
2006 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
2007 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
2009 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2010 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
2011 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
2012 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
2014 // 128-bit logical shifts.
2015 let Constraints = "$src1 = $dst", neverHasSideEffects = 1,
2016 ExeDomain = SSEPackedInt in {
2017 def PSLLDQri : PDIi8<0x73, MRM7r,
2018 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2019 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
2020 def PSRLDQri : PDIi8<0x73, MRM3r,
2021 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2022 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
2023 // PSRADQri doesn't exist in SSE[1-3].
2026 let Predicates = [HasSSE2] in {
2027 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
2028 (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2029 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2030 (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2031 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2032 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2033 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2034 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
2035 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2036 (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2038 // Shift up / down and insert zero's.
2039 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
2040 (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2041 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
2042 (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2046 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2047 defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
2048 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2050 let Constraints = "$src1 = $dst", ExeDomain = SSEPackedInt in {
2051 def PANDNrr : PDI<0xDF, MRMSrcReg,
2052 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2053 "pandn\t{$src2, $dst|$dst, $src2}",
2054 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2057 def PANDNrm : PDI<0xDF, MRMSrcMem,
2058 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2059 "pandn\t{$src2, $dst|$dst, $src2}",
2060 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2061 (memopv2i64 addr:$src2))))]>;
2064 // SSE2 Integer comparison
2065 defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2066 defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2067 defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2068 defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2069 defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2070 defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2072 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
2073 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
2074 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
2075 (PCMPEQBrm VR128:$src1, addr:$src2)>;
2076 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
2077 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
2078 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
2079 (PCMPEQWrm VR128:$src1, addr:$src2)>;
2080 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
2081 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
2082 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
2083 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2085 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
2086 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
2087 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
2088 (PCMPGTBrm VR128:$src1, addr:$src2)>;
2089 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
2090 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
2091 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
2092 (PCMPGTWrm VR128:$src1, addr:$src2)>;
2093 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
2094 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
2095 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
2096 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2099 // Pack instructions
2100 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2101 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2102 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2104 let ExeDomain = SSEPackedInt in {
2106 // Shuffle and unpack instructions
2107 let AddedComplexity = 5 in {
2108 def PSHUFDri : PDIi8<0x70, MRMSrcReg,
2109 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2110 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2111 [(set VR128:$dst, (v4i32 (pshufd:$src2
2112 VR128:$src1, (undef))))]>;
2113 def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
2114 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2115 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2116 [(set VR128:$dst, (v4i32 (pshufd:$src2
2117 (bc_v4i32 (memopv2i64 addr:$src1)),
2121 // SSE2 with ImmT == Imm8 and XS prefix.
2122 def PSHUFHWri : Ii8<0x70, MRMSrcReg,
2123 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2124 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2125 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2127 XS, Requires<[HasSSE2]>;
2128 def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
2129 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2130 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2131 [(set VR128:$dst, (v8i16 (pshufhw:$src2
2132 (bc_v8i16 (memopv2i64 addr:$src1)),
2134 XS, Requires<[HasSSE2]>;
2136 // SSE2 with ImmT == Imm8 and XD prefix.
2137 def PSHUFLWri : Ii8<0x70, MRMSrcReg,
2138 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2139 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2140 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2142 XD, Requires<[HasSSE2]>;
2143 def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
2144 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2145 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2146 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2147 (bc_v8i16 (memopv2i64 addr:$src1)),
2149 XD, Requires<[HasSSE2]>;
2151 // Unpack instructions
2152 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2153 PatFrag unp_frag, PatFrag bc_frag> {
2154 def rr : PDI<opc, MRMSrcReg,
2155 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2156 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2157 [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2158 def rm : PDI<opc, MRMSrcMem,
2159 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2160 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2161 [(set VR128:$dst, (unp_frag VR128:$src1,
2162 (bc_frag (memopv2i64
2166 let Constraints = "$src1 = $dst" in {
2167 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2168 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2169 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2171 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2172 /// knew to collapse (bitconvert VT to VT) into its operand.
2173 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2174 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2175 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2177 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
2178 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2179 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2180 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2182 (v2i64 (unpckl VR128:$src1,
2183 (memopv2i64 addr:$src2))))]>;
2185 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2186 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2187 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2189 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2190 /// knew to collapse (bitconvert VT to VT) into its operand.
2191 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2192 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2193 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2195 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
2196 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2197 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2198 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2200 (v2i64 (unpckh VR128:$src1,
2201 (memopv2i64 addr:$src2))))]>;
2205 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
2206 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2207 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2208 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2210 let Constraints = "$src1 = $dst" in {
2211 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
2212 (outs VR128:$dst), (ins VR128:$src1,
2213 GR32:$src2, i32i8imm:$src3),
2214 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2216 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
2217 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
2218 (outs VR128:$dst), (ins VR128:$src1,
2219 i16mem:$src2, i32i8imm:$src3),
2220 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2222 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2227 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2228 "pmovmskb\t{$src, $dst|$dst, $src}",
2229 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2231 // Conditional store
2233 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2234 "maskmovdqu\t{$mask, $src|$src, $mask}",
2235 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
2238 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2239 "maskmovdqu\t{$mask, $src|$src, $mask}",
2240 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2242 } // ExeDomain = SSEPackedInt
2244 // Non-temporal stores
2245 def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2246 "movntpd\t{$src, $dst|$dst, $src}",
2247 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
2248 let ExeDomain = SSEPackedInt in
2249 def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2250 "movntdq\t{$src, $dst|$dst, $src}",
2251 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2252 def MOVNTImr_Int : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2253 "movnti\t{$src, $dst|$dst, $src}",
2254 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2255 TB, Requires<[HasSSE2]>;
2257 let AddedComplexity = 400 in { // Prefer non-temporal versions
2258 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2259 "movntpd\t{$src, $dst|$dst, $src}",
2260 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
2262 let ExeDomain = SSEPackedInt in
2263 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2264 "movntdq\t{$src, $dst|$dst, $src}",
2265 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
2269 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
2270 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
2271 TB, Requires<[HasSSE2]>;
2273 // Load, store, and memory fence
2274 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
2275 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
2276 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
2277 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2279 // Pause. This "instruction" is encoded as "rep; nop", so even though it
2280 // was introduced with SSE2, it's backward compatible.
2281 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
2283 //TODO: custom lower this so as to never even generate the noop
2284 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2286 def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2287 def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
2288 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2291 // Alias instructions that map zero vector to pxor / xorp* for sse.
2292 // We set canFoldAsLoad because this can be converted to a constant-pool
2293 // load of an all-ones value if folding it would be beneficial.
2294 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
2295 isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
2296 // FIXME: Change encoding to pseudo.
2297 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
2298 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
2300 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2301 "movd\t{$src, $dst|$dst, $src}",
2303 (v4i32 (scalar_to_vector GR32:$src)))]>;
2304 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2305 "movd\t{$src, $dst|$dst, $src}",
2307 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2309 def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2310 "movd\t{$src, $dst|$dst, $src}",
2311 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2313 def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2314 "movd\t{$src, $dst|$dst, $src}",
2315 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2317 // SSE2 instructions with XS prefix
2318 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2319 "movq\t{$src, $dst|$dst, $src}",
2321 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2322 Requires<[HasSSE2]>;
2323 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2324 "movq\t{$src, $dst|$dst, $src}",
2325 [(store (i64 (vector_extract (v2i64 VR128:$src),
2326 (iPTR 0))), addr:$dst)]>;
2328 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
2329 (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
2331 def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2332 "movd\t{$src, $dst|$dst, $src}",
2333 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2335 def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
2336 "movd\t{$src, $dst|$dst, $src}",
2337 [(store (i32 (vector_extract (v4i32 VR128:$src),
2338 (iPTR 0))), addr:$dst)]>;
2340 def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2341 "movd\t{$src, $dst|$dst, $src}",
2342 [(set GR32:$dst, (bitconvert FR32:$src))]>;
2343 def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2344 "movd\t{$src, $dst|$dst, $src}",
2345 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2347 // Store / copy lower 64-bits of a XMM register.
2348 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2349 "movq\t{$src, $dst|$dst, $src}",
2350 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2352 // movd / movq to XMM register zero-extends
2353 let AddedComplexity = 15 in {
2354 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2355 "movd\t{$src, $dst|$dst, $src}",
2356 [(set VR128:$dst, (v4i32 (X86vzmovl
2357 (v4i32 (scalar_to_vector GR32:$src)))))]>;
2358 // This is X86-64 only.
2359 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2360 "mov{d|q}\t{$src, $dst|$dst, $src}",
2361 [(set VR128:$dst, (v2i64 (X86vzmovl
2362 (v2i64 (scalar_to_vector GR64:$src)))))]>;
2365 let AddedComplexity = 20 in {
2366 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2367 "movd\t{$src, $dst|$dst, $src}",
2369 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2370 (loadi32 addr:$src))))))]>;
2372 def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2373 (MOVZDI2PDIrm addr:$src)>;
2374 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2375 (MOVZDI2PDIrm addr:$src)>;
2376 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2377 (MOVZDI2PDIrm addr:$src)>;
2379 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2380 "movq\t{$src, $dst|$dst, $src}",
2382 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2383 (loadi64 addr:$src))))))]>, XS,
2384 Requires<[HasSSE2]>;
2386 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2387 (MOVZQI2PQIrm addr:$src)>;
2388 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2389 (MOVZQI2PQIrm addr:$src)>;
2390 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
2393 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2394 // IA32 document. movq xmm1, xmm2 does clear the high bits.
2395 let AddedComplexity = 15 in
2396 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2397 "movq\t{$src, $dst|$dst, $src}",
2398 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2399 XS, Requires<[HasSSE2]>;
2401 let AddedComplexity = 20 in {
2402 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2403 "movq\t{$src, $dst|$dst, $src}",
2404 [(set VR128:$dst, (v2i64 (X86vzmovl
2405 (loadv2i64 addr:$src))))]>,
2406 XS, Requires<[HasSSE2]>;
2408 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2409 (MOVZPQILo2PQIrm addr:$src)>;
2412 // Instructions for the disassembler
2413 // xr = XMM register
2416 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2417 "movq\t{$src, $dst|$dst, $src}", []>, XS;
2419 //===---------------------------------------------------------------------===//
2420 // SSE3 Instructions
2421 //===---------------------------------------------------------------------===//
2423 // Move Instructions
2424 def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2425 "movshdup\t{$src, $dst|$dst, $src}",
2426 [(set VR128:$dst, (v4f32 (movshdup
2427 VR128:$src, (undef))))]>;
2428 def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2429 "movshdup\t{$src, $dst|$dst, $src}",
2430 [(set VR128:$dst, (movshdup
2431 (memopv4f32 addr:$src), (undef)))]>;
2433 def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2434 "movsldup\t{$src, $dst|$dst, $src}",
2435 [(set VR128:$dst, (v4f32 (movsldup
2436 VR128:$src, (undef))))]>;
2437 def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2438 "movsldup\t{$src, $dst|$dst, $src}",
2439 [(set VR128:$dst, (movsldup
2440 (memopv4f32 addr:$src), (undef)))]>;
2442 def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2443 "movddup\t{$src, $dst|$dst, $src}",
2444 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
2445 def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2446 "movddup\t{$src, $dst|$dst, $src}",
2448 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2451 def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2453 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2455 let AddedComplexity = 5 in {
2456 def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
2457 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2458 def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2459 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2460 def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2461 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2462 def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2463 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2467 let Constraints = "$src1 = $dst" in {
2468 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
2469 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2470 "addsubps\t{$src2, $dst|$dst, $src2}",
2471 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2473 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
2474 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2475 "addsubps\t{$src2, $dst|$dst, $src2}",
2476 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2477 (memop addr:$src2)))]>;
2478 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
2479 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2480 "addsubpd\t{$src2, $dst|$dst, $src2}",
2481 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2483 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
2484 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2485 "addsubpd\t{$src2, $dst|$dst, $src2}",
2486 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2487 (memop addr:$src2)))]>;
2490 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2491 "lddqu\t{$src, $dst|$dst, $src}",
2492 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2495 class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2496 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2497 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2498 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2499 class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2500 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2501 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2502 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
2503 class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2504 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2505 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2506 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2507 class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2508 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2509 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2510 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
2512 let Constraints = "$src1 = $dst" in {
2513 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2514 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2515 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2516 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2517 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2518 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2519 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2520 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2523 // Thread synchronization
2524 def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
2525 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
2526 def MWAIT : I<0x01, MRM_C9, (outs), (ins), "mwait",
2527 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2529 // vector_shuffle v1, <undef> <1, 1, 3, 3>
2530 let AddedComplexity = 15 in
2531 def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
2532 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2533 let AddedComplexity = 20 in
2534 def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2535 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2537 // vector_shuffle v1, <undef> <0, 0, 2, 2>
2538 let AddedComplexity = 15 in
2539 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
2540 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2541 let AddedComplexity = 20 in
2542 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2543 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2545 //===---------------------------------------------------------------------===//
2546 // SSSE3 Instructions
2547 //===---------------------------------------------------------------------===//
2549 /// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
2550 multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2551 Intrinsic IntId64, Intrinsic IntId128> {
2552 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2553 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2554 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2556 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2557 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2559 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2561 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2563 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2564 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2567 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2569 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2572 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
2575 /// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
2576 multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2577 Intrinsic IntId64, Intrinsic IntId128> {
2578 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2580 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2581 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2583 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2585 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2588 (bitconvert (memopv4i16 addr:$src))))]>;
2590 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2592 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2593 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2596 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2598 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2601 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
2604 /// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
2605 multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2606 Intrinsic IntId64, Intrinsic IntId128> {
2607 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2609 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2610 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2612 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2614 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2617 (bitconvert (memopv2i32 addr:$src))))]>;
2619 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2621 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2622 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2625 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2627 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2630 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
2633 defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2634 int_x86_ssse3_pabs_b,
2635 int_x86_ssse3_pabs_b_128>;
2636 defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2637 int_x86_ssse3_pabs_w,
2638 int_x86_ssse3_pabs_w_128>;
2639 defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2640 int_x86_ssse3_pabs_d,
2641 int_x86_ssse3_pabs_d_128>;
2643 /// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
2644 let Constraints = "$src1 = $dst" in {
2645 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2646 Intrinsic IntId64, Intrinsic IntId128,
2647 bit Commutable = 0> {
2648 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2649 (ins VR64:$src1, VR64:$src2),
2650 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2651 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2652 let isCommutable = Commutable;
2654 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2655 (ins VR64:$src1, i64mem:$src2),
2656 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2658 (IntId64 VR64:$src1,
2659 (bitconvert (memopv8i8 addr:$src2))))]>;
2661 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2662 (ins VR128:$src1, VR128:$src2),
2663 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2664 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2666 let isCommutable = Commutable;
2668 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2669 (ins VR128:$src1, i128mem:$src2),
2670 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2672 (IntId128 VR128:$src1,
2673 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2677 /// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
2678 let Constraints = "$src1 = $dst" in {
2679 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2680 Intrinsic IntId64, Intrinsic IntId128,
2681 bit Commutable = 0> {
2682 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2683 (ins VR64:$src1, VR64:$src2),
2684 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2685 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2686 let isCommutable = Commutable;
2688 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2689 (ins VR64:$src1, i64mem:$src2),
2690 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2692 (IntId64 VR64:$src1,
2693 (bitconvert (memopv4i16 addr:$src2))))]>;
2695 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2696 (ins VR128:$src1, VR128:$src2),
2697 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2698 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2700 let isCommutable = Commutable;
2702 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2703 (ins VR128:$src1, i128mem:$src2),
2704 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2706 (IntId128 VR128:$src1,
2707 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2711 /// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
2712 let Constraints = "$src1 = $dst" in {
2713 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2714 Intrinsic IntId64, Intrinsic IntId128,
2715 bit Commutable = 0> {
2716 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2717 (ins VR64:$src1, VR64:$src2),
2718 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2719 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2720 let isCommutable = Commutable;
2722 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2723 (ins VR64:$src1, i64mem:$src2),
2724 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2726 (IntId64 VR64:$src1,
2727 (bitconvert (memopv2i32 addr:$src2))))]>;
2729 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2730 (ins VR128:$src1, VR128:$src2),
2731 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2732 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2734 let isCommutable = Commutable;
2736 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2737 (ins VR128:$src1, i128mem:$src2),
2738 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2740 (IntId128 VR128:$src1,
2741 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2745 let ImmT = NoImm in { // None of these have i8 immediate fields.
2746 defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2747 int_x86_ssse3_phadd_w,
2748 int_x86_ssse3_phadd_w_128>;
2749 defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2750 int_x86_ssse3_phadd_d,
2751 int_x86_ssse3_phadd_d_128>;
2752 defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2753 int_x86_ssse3_phadd_sw,
2754 int_x86_ssse3_phadd_sw_128>;
2755 defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2756 int_x86_ssse3_phsub_w,
2757 int_x86_ssse3_phsub_w_128>;
2758 defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2759 int_x86_ssse3_phsub_d,
2760 int_x86_ssse3_phsub_d_128>;
2761 defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2762 int_x86_ssse3_phsub_sw,
2763 int_x86_ssse3_phsub_sw_128>;
2764 defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2765 int_x86_ssse3_pmadd_ub_sw,
2766 int_x86_ssse3_pmadd_ub_sw_128>;
2767 defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2768 int_x86_ssse3_pmul_hr_sw,
2769 int_x86_ssse3_pmul_hr_sw_128, 1>;
2771 defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2772 int_x86_ssse3_pshuf_b,
2773 int_x86_ssse3_pshuf_b_128>;
2774 defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2775 int_x86_ssse3_psign_b,
2776 int_x86_ssse3_psign_b_128>;
2777 defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2778 int_x86_ssse3_psign_w,
2779 int_x86_ssse3_psign_w_128>;
2780 defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
2781 int_x86_ssse3_psign_d,
2782 int_x86_ssse3_psign_d_128>;
2785 // palignr patterns.
2786 let Constraints = "$src1 = $dst" in {
2787 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2788 (ins VR64:$src1, VR64:$src2, i8imm:$src3),
2789 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2791 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
2792 (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
2793 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2796 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2797 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
2798 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2800 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
2801 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
2802 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2806 let AddedComplexity = 5 in {
2808 def : Pat<(v1i64 (palign:$src3 VR64:$src1, VR64:$src2)),
2809 (PALIGNR64rr VR64:$src2, VR64:$src1,
2810 (SHUFFLE_get_palign_imm VR64:$src3))>,
2811 Requires<[HasSSSE3]>;
2812 def : Pat<(v2i32 (palign:$src3 VR64:$src1, VR64:$src2)),
2813 (PALIGNR64rr VR64:$src2, VR64:$src1,
2814 (SHUFFLE_get_palign_imm VR64:$src3))>,
2815 Requires<[HasSSSE3]>;
2816 def : Pat<(v2f32 (palign:$src3 VR64:$src1, VR64:$src2)),
2817 (PALIGNR64rr VR64:$src2, VR64:$src1,
2818 (SHUFFLE_get_palign_imm VR64:$src3))>,
2819 Requires<[HasSSSE3]>;
2820 def : Pat<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
2821 (PALIGNR64rr VR64:$src2, VR64:$src1,
2822 (SHUFFLE_get_palign_imm VR64:$src3))>,
2823 Requires<[HasSSSE3]>;
2824 def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
2825 (PALIGNR64rr VR64:$src2, VR64:$src1,
2826 (SHUFFLE_get_palign_imm VR64:$src3))>,
2827 Requires<[HasSSSE3]>;
2829 def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
2830 (PALIGNR128rr VR128:$src2, VR128:$src1,
2831 (SHUFFLE_get_palign_imm VR128:$src3))>,
2832 Requires<[HasSSSE3]>;
2833 def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
2834 (PALIGNR128rr VR128:$src2, VR128:$src1,
2835 (SHUFFLE_get_palign_imm VR128:$src3))>,
2836 Requires<[HasSSSE3]>;
2837 def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
2838 (PALIGNR128rr VR128:$src2, VR128:$src1,
2839 (SHUFFLE_get_palign_imm VR128:$src3))>,
2840 Requires<[HasSSSE3]>;
2841 def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
2842 (PALIGNR128rr VR128:$src2, VR128:$src1,
2843 (SHUFFLE_get_palign_imm VR128:$src3))>,
2844 Requires<[HasSSSE3]>;
2847 def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2848 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2849 def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2850 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2852 //===---------------------------------------------------------------------===//
2853 // Non-Instruction Patterns
2854 //===---------------------------------------------------------------------===//
2856 // extload f32 -> f64. This matches load+fextend because we have a hack in
2857 // the isel (PreprocessForFPConvert) that can introduce loads after dag
2859 // Since these loads aren't folded into the fextend, we have to match it
2861 let Predicates = [HasSSE2] in
2862 def : Pat<(fextend (loadf32 addr:$src)),
2863 (CVTSS2SDrm addr:$src)>;
2866 let Predicates = [HasSSE2] in {
2867 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2868 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2869 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2870 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2871 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2872 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2873 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2874 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2875 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2876 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2877 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2878 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2879 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2880 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2881 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2882 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2883 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2884 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2885 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2886 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2887 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2888 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2889 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2890 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2891 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2892 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2893 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2894 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2895 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2896 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2899 // Move scalar to XMM zero-extended
2900 // movd to XMM register zero-extends
2901 let AddedComplexity = 15 in {
2902 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
2903 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
2904 (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
2905 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
2906 (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
2907 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
2908 (MOVSSrr (v4f32 (V_SET0PS)),
2909 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
2910 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
2911 (MOVSSrr (v4i32 (V_SET0PI)),
2912 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
2915 // Splat v2f64 / v2i64
2916 let AddedComplexity = 10 in {
2917 def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
2918 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2919 def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
2920 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2921 def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
2922 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2923 def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
2924 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2927 // Special unary SHUFPSrri case.
2928 def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2929 (SHUFPSrri VR128:$src1, VR128:$src1,
2930 (SHUFFLE_get_shuf_imm VR128:$src3))>;
2931 let AddedComplexity = 5 in
2932 def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2933 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2934 Requires<[HasSSE2]>;
2935 // Special unary SHUFPDrri case.
2936 def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
2937 (SHUFPDrri VR128:$src1, VR128:$src1,
2938 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2939 Requires<[HasSSE2]>;
2940 // Special unary SHUFPDrri case.
2941 def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
2942 (SHUFPDrri VR128:$src1, VR128:$src1,
2943 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2944 Requires<[HasSSE2]>;
2945 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
2946 def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2947 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2948 Requires<[HasSSE2]>;
2950 // Special binary v4i32 shuffle cases with SHUFPS.
2951 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
2952 (SHUFPSrri VR128:$src1, VR128:$src2,
2953 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2954 Requires<[HasSSE2]>;
2955 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
2956 (SHUFPSrmi VR128:$src1, addr:$src2,
2957 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2958 Requires<[HasSSE2]>;
2959 // Special binary v2i64 shuffle cases using SHUFPDrri.
2960 def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
2961 (SHUFPDrri VR128:$src1, VR128:$src2,
2962 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2963 Requires<[HasSSE2]>;
2965 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
2966 let AddedComplexity = 15 in {
2967 def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
2968 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2969 Requires<[OptForSpeed, HasSSE2]>;
2970 def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
2971 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2972 Requires<[OptForSpeed, HasSSE2]>;
2974 let AddedComplexity = 10 in {
2975 def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
2976 (UNPCKLPSrr VR128:$src, VR128:$src)>;
2977 def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
2978 (PUNPCKLBWrr VR128:$src, VR128:$src)>;
2979 def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
2980 (PUNPCKLWDrr VR128:$src, VR128:$src)>;
2981 def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
2982 (PUNPCKLDQrr VR128:$src, VR128:$src)>;
2985 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
2986 let AddedComplexity = 15 in {
2987 def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
2988 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2989 Requires<[OptForSpeed, HasSSE2]>;
2990 def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
2991 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2992 Requires<[OptForSpeed, HasSSE2]>;
2994 let AddedComplexity = 10 in {
2995 def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
2996 (UNPCKHPSrr VR128:$src, VR128:$src)>;
2997 def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
2998 (PUNPCKHBWrr VR128:$src, VR128:$src)>;
2999 def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
3000 (PUNPCKHWDrr VR128:$src, VR128:$src)>;
3001 def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
3002 (PUNPCKHDQrr VR128:$src, VR128:$src)>;
3005 let AddedComplexity = 20 in {
3006 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
3007 def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
3008 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
3010 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
3011 def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
3012 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
3014 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
3015 def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
3016 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3017 def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
3018 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3021 let AddedComplexity = 20 in {
3022 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
3023 def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
3024 (MOVLPSrm VR128:$src1, addr:$src2)>;
3025 def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
3026 (MOVLPDrm VR128:$src1, addr:$src2)>;
3027 def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
3028 (MOVLPSrm VR128:$src1, addr:$src2)>;
3029 def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
3030 (MOVLPDrm VR128:$src1, addr:$src2)>;
3033 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3034 def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3035 (MOVLPSmr addr:$src1, VR128:$src2)>;
3036 def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3037 (MOVLPDmr addr:$src1, VR128:$src2)>;
3038 def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3040 (MOVLPSmr addr:$src1, VR128:$src2)>;
3041 def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3042 (MOVLPDmr addr:$src1, VR128:$src2)>;
3044 let AddedComplexity = 15 in {
3045 // Setting the lowest element in the vector.
3046 def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
3047 (MOVSSrr (v4i32 VR128:$src1),
3048 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
3049 def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
3050 (MOVSDrr (v2i64 VR128:$src1),
3051 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
3053 // vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
3054 def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
3055 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3056 Requires<[HasSSE2]>;
3057 def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
3058 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3059 Requires<[HasSSE2]>;
3062 // vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3063 // fall back to this for SSE1)
3064 def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
3065 (SHUFPSrri VR128:$src2, VR128:$src1,
3066 (SHUFFLE_get_shuf_imm VR128:$src3))>;
3068 // Set lowest element and zero upper elements.
3069 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
3070 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3072 // Some special case pandn patterns.
3073 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3075 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3076 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3078 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3079 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3081 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3083 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3084 (memop addr:$src2))),
3085 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3086 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3087 (memop addr:$src2))),
3088 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3089 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3090 (memop addr:$src2))),
3091 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3093 // vector -> vector casts
3094 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3095 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3096 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3097 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3098 def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3099 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3100 def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3101 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
3103 // Use movaps / movups for SSE integer load / store (one byte shorter).
3104 def : Pat<(alignedloadv4i32 addr:$src),
3105 (MOVAPSrm addr:$src)>;
3106 def : Pat<(loadv4i32 addr:$src),
3107 (MOVUPSrm addr:$src)>;
3108 def : Pat<(alignedloadv2i64 addr:$src),
3109 (MOVAPSrm addr:$src)>;
3110 def : Pat<(loadv2i64 addr:$src),
3111 (MOVUPSrm addr:$src)>;
3113 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3114 (MOVAPSmr addr:$dst, VR128:$src)>;
3115 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3116 (MOVAPSmr addr:$dst, VR128:$src)>;
3117 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3118 (MOVAPSmr addr:$dst, VR128:$src)>;
3119 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3120 (MOVAPSmr addr:$dst, VR128:$src)>;
3121 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3122 (MOVUPSmr addr:$dst, VR128:$src)>;
3123 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3124 (MOVUPSmr addr:$dst, VR128:$src)>;
3125 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3126 (MOVUPSmr addr:$dst, VR128:$src)>;
3127 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3128 (MOVUPSmr addr:$dst, VR128:$src)>;
3130 //===----------------------------------------------------------------------===//
3131 // SSE4.1 Instructions
3132 //===----------------------------------------------------------------------===//
3134 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
3137 Intrinsic V2F64Int> {
3138 // Intrinsic operation, reg.
3139 // Vector intrinsic operation, reg
3140 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
3141 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3142 !strconcat(OpcodeStr,
3143 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3144 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3147 // Vector intrinsic operation, mem
3148 def PSm_Int : Ii8<opcps, MRMSrcMem,
3149 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3150 !strconcat(OpcodeStr,
3151 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3153 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
3155 Requires<[HasSSE41]>;
3157 // Vector intrinsic operation, reg
3158 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
3159 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3160 !strconcat(OpcodeStr,
3161 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3162 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3165 // Vector intrinsic operation, mem
3166 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
3167 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3168 !strconcat(OpcodeStr,
3169 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3171 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
3175 let Constraints = "$src1 = $dst" in {
3176 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3180 // Intrinsic operation, reg.
3181 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
3183 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3184 !strconcat(OpcodeStr,
3185 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3187 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3190 // Intrinsic operation, mem.
3191 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3193 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
3194 !strconcat(OpcodeStr,
3195 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3197 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3200 // Intrinsic operation, reg.
3201 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
3203 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3204 !strconcat(OpcodeStr,
3205 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3207 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3210 // Intrinsic operation, mem.
3211 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
3213 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3214 !strconcat(OpcodeStr,
3215 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3217 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3222 // FP round - roundss, roundps, roundsd, roundpd
3223 defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3224 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3225 defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3226 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
3228 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3229 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3230 Intrinsic IntId128> {
3231 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3233 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3234 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3235 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3237 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3240 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3243 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3244 int_x86_sse41_phminposuw>;
3246 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3247 let Constraints = "$src1 = $dst" in {
3248 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3249 Intrinsic IntId128, bit Commutable = 0> {
3250 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3251 (ins VR128:$src1, VR128:$src2),
3252 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3253 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3255 let isCommutable = Commutable;
3257 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3258 (ins VR128:$src1, i128mem:$src2),
3259 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3261 (IntId128 VR128:$src1,
3262 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3266 defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3267 int_x86_sse41_pcmpeqq, 1>;
3268 defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3269 int_x86_sse41_packusdw, 0>;
3270 defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3271 int_x86_sse41_pminsb, 1>;
3272 defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3273 int_x86_sse41_pminsd, 1>;
3274 defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3275 int_x86_sse41_pminud, 1>;
3276 defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3277 int_x86_sse41_pminuw, 1>;
3278 defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3279 int_x86_sse41_pmaxsb, 1>;
3280 defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3281 int_x86_sse41_pmaxsd, 1>;
3282 defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3283 int_x86_sse41_pmaxud, 1>;
3284 defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3285 int_x86_sse41_pmaxuw, 1>;
3287 defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3289 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3290 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3291 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3292 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3294 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3295 let Constraints = "$src1 = $dst" in {
3296 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3297 SDNode OpNode, Intrinsic IntId128,
3298 bit Commutable = 0> {
3299 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3300 (ins VR128:$src1, VR128:$src2),
3301 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3302 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3303 VR128:$src2))]>, OpSize {
3304 let isCommutable = Commutable;
3306 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3307 (ins VR128:$src1, VR128:$src2),
3308 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3309 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3311 let isCommutable = Commutable;
3313 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3314 (ins VR128:$src1, i128mem:$src2),
3315 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3317 (OpVT (OpNode VR128:$src1, (memop addr:$src2))))]>, OpSize;
3318 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3319 (ins VR128:$src1, i128mem:$src2),
3320 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3322 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
3327 /// SS48I_binop_rm - Simple SSE41 binary operator.
3328 let Constraints = "$src1 = $dst" in {
3329 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
3330 ValueType OpVT, bit Commutable = 0> {
3331 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3332 (ins VR128:$src1, VR128:$src2),
3333 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3334 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
3336 let isCommutable = Commutable;
3338 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3339 (ins VR128:$src1, i128mem:$src2),
3340 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3341 [(set VR128:$dst, (OpNode VR128:$src1,
3342 (bc_v4i32 (memopv2i64 addr:$src2))))]>,
3347 defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, 1>;
3349 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
3350 let Constraints = "$src1 = $dst" in {
3351 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3352 Intrinsic IntId128, bit Commutable = 0> {
3353 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3354 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3355 !strconcat(OpcodeStr,
3356 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3358 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3360 let isCommutable = Commutable;
3362 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3363 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3364 !strconcat(OpcodeStr,
3365 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3367 (IntId128 VR128:$src1,
3368 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3373 defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3374 int_x86_sse41_blendps, 0>;
3375 defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3376 int_x86_sse41_blendpd, 0>;
3377 defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3378 int_x86_sse41_pblendw, 0>;
3379 defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3380 int_x86_sse41_dpps, 1>;
3381 defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3382 int_x86_sse41_dppd, 1>;
3383 defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
3384 int_x86_sse41_mpsadbw, 0>;
3387 /// SS41I_ternary_int - SSE 4.1 ternary operator
3388 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
3389 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3390 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3391 (ins VR128:$src1, VR128:$src2),
3392 !strconcat(OpcodeStr,
3393 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3394 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3397 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3398 (ins VR128:$src1, i128mem:$src2),
3399 !strconcat(OpcodeStr,
3400 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3403 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3407 defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3408 defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3409 defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3412 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3413 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3414 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3415 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3417 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3418 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3420 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3424 defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3425 defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3426 defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3427 defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3428 defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3429 defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3431 // Common patterns involving scalar load.
3432 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3433 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3434 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3435 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3437 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3438 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3439 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3440 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3442 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3443 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3444 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3445 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3447 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3448 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3449 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3450 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3452 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3453 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3454 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3455 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3457 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3458 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3459 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3460 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3463 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3464 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3465 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3466 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3468 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3469 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3471 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3475 defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3476 defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3477 defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3478 defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3480 // Common patterns involving scalar load
3481 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
3482 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
3483 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
3484 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
3486 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
3487 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
3488 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
3489 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
3492 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3493 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3494 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3495 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3497 // Expecting a i16 load any extended to i32 value.
3498 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3499 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3500 [(set VR128:$dst, (IntId (bitconvert
3501 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3505 defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3506 defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
3508 // Common patterns involving scalar load
3509 def : Pat<(int_x86_sse41_pmovsxbq
3510 (bitconvert (v4i32 (X86vzmovl
3511 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3512 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
3514 def : Pat<(int_x86_sse41_pmovzxbq
3515 (bitconvert (v4i32 (X86vzmovl
3516 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3517 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
3520 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3521 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
3522 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3523 (ins VR128:$src1, i32i8imm:$src2),
3524 !strconcat(OpcodeStr,
3525 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3526 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3528 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3529 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
3530 !strconcat(OpcodeStr,
3531 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3534 // There's an AssertZext in the way of writing the store pattern
3535 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3538 defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
3541 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3542 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
3543 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3544 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
3545 !strconcat(OpcodeStr,
3546 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3549 // There's an AssertZext in the way of writing the store pattern
3550 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3553 defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3556 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3557 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
3558 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3559 (ins VR128:$src1, i32i8imm:$src2),
3560 !strconcat(OpcodeStr,
3561 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3563 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
3564 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3565 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
3566 !strconcat(OpcodeStr,
3567 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3568 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3569 addr:$dst)]>, OpSize;
3572 defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
3575 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3577 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
3578 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3579 (ins VR128:$src1, i32i8imm:$src2),
3580 !strconcat(OpcodeStr,
3581 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3583 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
3585 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3586 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
3587 !strconcat(OpcodeStr,
3588 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3589 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
3590 addr:$dst)]>, OpSize;
3593 defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
3595 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3596 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3599 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3600 Requires<[HasSSE41]>;
3602 let Constraints = "$src1 = $dst" in {
3603 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
3604 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3605 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3606 !strconcat(OpcodeStr,
3607 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3609 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
3610 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3611 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3612 !strconcat(OpcodeStr,
3613 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3615 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3616 imm:$src3))]>, OpSize;
3620 defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3622 let Constraints = "$src1 = $dst" in {
3623 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
3624 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3625 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3626 !strconcat(OpcodeStr,
3627 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3629 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3631 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3632 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3633 !strconcat(OpcodeStr,
3634 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3636 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3637 imm:$src3)))]>, OpSize;
3641 defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3643 // insertps has a few different modes, there's the first two here below which
3644 // are optimized inserts that won't zero arbitrary elements in the destination
3645 // vector. The next one matches the intrinsic and could zero arbitrary elements
3646 // in the target vector.
3647 let Constraints = "$src1 = $dst" in {
3648 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
3649 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3650 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3651 !strconcat(OpcodeStr,
3652 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3654 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
3656 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3657 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3658 !strconcat(OpcodeStr,
3659 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3661 (X86insrtps VR128:$src1,
3662 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
3663 imm:$src3))]>, OpSize;
3667 defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
3669 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3670 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3672 // ptest instruction we'll lower to this in X86ISelLowering primarily from
3673 // the intel intrinsic that corresponds to this.
3674 let Defs = [EFLAGS] in {
3675 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
3676 "ptest \t{$src2, $src1|$src1, $src2}",
3677 [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
3679 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
3680 "ptest \t{$src2, $src1|$src1, $src2}",
3681 [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
3685 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3686 "movntdqa\t{$src, $dst|$dst, $src}",
3687 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
3691 //===----------------------------------------------------------------------===//
3692 // SSE4.2 Instructions
3693 //===----------------------------------------------------------------------===//
3695 /// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3696 let Constraints = "$src1 = $dst" in {
3697 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3698 Intrinsic IntId128, bit Commutable = 0> {
3699 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3700 (ins VR128:$src1, VR128:$src2),
3701 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3702 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3704 let isCommutable = Commutable;
3706 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3707 (ins VR128:$src1, i128mem:$src2),
3708 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3710 (IntId128 VR128:$src1,
3711 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3715 defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
3717 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3718 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3719 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3720 (PCMPGTQrm VR128:$src1, addr:$src2)>;
3722 // crc intrinsic instruction
3723 // This set of instructions are only rm, the only difference is the size
3725 let Constraints = "$src1 = $dst" in {
3726 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
3727 (ins GR32:$src1, i8mem:$src2),
3728 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3730 (int_x86_sse42_crc32_8 GR32:$src1,
3731 (load addr:$src2)))]>;
3732 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
3733 (ins GR32:$src1, GR8:$src2),
3734 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3736 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
3737 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3738 (ins GR32:$src1, i16mem:$src2),
3739 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3741 (int_x86_sse42_crc32_16 GR32:$src1,
3742 (load addr:$src2)))]>,
3744 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3745 (ins GR32:$src1, GR16:$src2),
3746 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3748 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
3750 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3751 (ins GR32:$src1, i32mem:$src2),
3752 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3754 (int_x86_sse42_crc32_32 GR32:$src1,
3755 (load addr:$src2)))]>;
3756 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3757 (ins GR32:$src1, GR32:$src2),
3758 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3760 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
3761 def CRC64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3762 (ins GR64:$src1, i8mem:$src2),
3763 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3765 (int_x86_sse42_crc64_8 GR64:$src1,
3766 (load addr:$src2)))]>,
3768 def CRC64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3769 (ins GR64:$src1, GR8:$src2),
3770 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3772 (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
3774 def CRC64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
3775 (ins GR64:$src1, i64mem:$src2),
3776 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3778 (int_x86_sse42_crc64_64 GR64:$src1,
3779 (load addr:$src2)))]>,
3781 def CRC64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
3782 (ins GR64:$src1, GR64:$src2),
3783 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3785 (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
3789 // String/text processing instructions.
3790 let Defs = [EFLAGS], usesCustomInserter = 1 in {
3791 def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3792 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3793 "#PCMPISTRM128rr PSEUDO!",
3794 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
3795 imm:$src3))]>, OpSize;
3796 def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3797 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3798 "#PCMPISTRM128rm PSEUDO!",
3799 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, (load addr:$src2),
3800 imm:$src3))]>, OpSize;
3803 let Defs = [XMM0, EFLAGS] in {
3804 def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
3805 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3806 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3807 def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
3808 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3809 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3812 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
3813 def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3814 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3815 "#PCMPESTRM128rr PSEUDO!",
3817 (int_x86_sse42_pcmpestrm128
3818 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
3820 def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3821 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3822 "#PCMPESTRM128rm PSEUDO!",
3823 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
3824 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
3828 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
3829 def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
3830 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3831 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3832 def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
3833 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3834 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3837 let Defs = [ECX, EFLAGS] in {
3838 multiclass SS42AI_pcmpistri<Intrinsic IntId128> {
3839 def rr : SS42AI<0x63, MRMSrcReg, (outs),
3840 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3841 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3842 [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
3843 (implicit EFLAGS)]>, OpSize;
3844 def rm : SS42AI<0x63, MRMSrcMem, (outs),
3845 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3846 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3847 [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
3848 (implicit EFLAGS)]>, OpSize;
3852 defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
3853 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
3854 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
3855 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
3856 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
3857 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
3859 let Defs = [ECX, EFLAGS] in {
3860 let Uses = [EAX, EDX] in {
3861 multiclass SS42AI_pcmpestri<Intrinsic IntId128> {
3862 def rr : SS42AI<0x61, MRMSrcReg, (outs),
3863 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3864 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3865 [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
3866 (implicit EFLAGS)]>, OpSize;
3867 def rm : SS42AI<0x61, MRMSrcMem, (outs),
3868 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3869 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3871 (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
3872 (implicit EFLAGS)]>, OpSize;
3877 defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
3878 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
3879 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
3880 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
3881 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
3882 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
3884 //===----------------------------------------------------------------------===//
3885 // AES-NI Instructions
3886 //===----------------------------------------------------------------------===//
3888 let Constraints = "$src1 = $dst" in {
3889 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
3890 Intrinsic IntId128, bit Commutable = 0> {
3891 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
3892 (ins VR128:$src1, VR128:$src2),
3893 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3894 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3896 let isCommutable = Commutable;
3898 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
3899 (ins VR128:$src1, i128mem:$src2),
3900 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3902 (IntId128 VR128:$src1,
3903 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3907 defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
3908 int_x86_aesni_aesenc>;
3909 defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
3910 int_x86_aesni_aesenclast>;
3911 defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
3912 int_x86_aesni_aesdec>;
3913 defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
3914 int_x86_aesni_aesdeclast>;
3916 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
3917 (AESENCrr VR128:$src1, VR128:$src2)>;
3918 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
3919 (AESENCrm VR128:$src1, addr:$src2)>;
3920 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
3921 (AESENCLASTrr VR128:$src1, VR128:$src2)>;
3922 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
3923 (AESENCLASTrm VR128:$src1, addr:$src2)>;
3924 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
3925 (AESDECrr VR128:$src1, VR128:$src2)>;
3926 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
3927 (AESDECrm VR128:$src1, addr:$src2)>;
3928 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
3929 (AESDECLASTrr VR128:$src1, VR128:$src2)>;
3930 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
3931 (AESDECLASTrm VR128:$src1, addr:$src2)>;
3933 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
3935 "aesimc\t{$src1, $dst|$dst, $src1}",
3937 (int_x86_aesni_aesimc VR128:$src1))]>,
3940 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
3941 (ins i128mem:$src1),
3942 "aesimc\t{$src1, $dst|$dst, $src1}",
3944 (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
3947 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
3948 (ins VR128:$src1, i8imm:$src2),
3949 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3951 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
3953 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
3954 (ins i128mem:$src1, i8imm:$src2),
3955 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3957 (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),