1 //====- X86InstrSSE.td - Describe the X86 Instruction Set --*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the X86 SSE instruction set, defining the instructions,
11 // and properties of the instructions which are needed for code generation,
12 // machine code emission, and analysis.
14 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
18 // SSE specific DAG Nodes.
19 //===----------------------------------------------------------------------===//
21 def SDTX86FPShiftOp : SDTypeProfile<1, 2, [ SDTCisSameAs<0, 1>,
22 SDTCisFP<0>, SDTCisInt<2> ]>;
23 def SDTX86VFCMP : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<1, 2>,
24 SDTCisFP<1>, SDTCisVT<3, i8>]>;
26 def X86fmin : SDNode<"X86ISD::FMIN", SDTFPBinOp>;
27 def X86fmax : SDNode<"X86ISD::FMAX", SDTFPBinOp>;
28 def X86fand : SDNode<"X86ISD::FAND", SDTFPBinOp,
29 [SDNPCommutative, SDNPAssociative]>;
30 def X86for : SDNode<"X86ISD::FOR", SDTFPBinOp,
31 [SDNPCommutative, SDNPAssociative]>;
32 def X86fxor : SDNode<"X86ISD::FXOR", SDTFPBinOp,
33 [SDNPCommutative, SDNPAssociative]>;
34 def X86frsqrt : SDNode<"X86ISD::FRSQRT", SDTFPUnaryOp>;
35 def X86frcp : SDNode<"X86ISD::FRCP", SDTFPUnaryOp>;
36 def X86fsrl : SDNode<"X86ISD::FSRL", SDTX86FPShiftOp>;
37 def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest>;
38 def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest>;
39 def X86pshufb : SDNode<"X86ISD::PSHUFB",
40 SDTypeProfile<1, 2, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
42 def X86pextrb : SDNode<"X86ISD::PEXTRB",
43 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
44 def X86pextrw : SDNode<"X86ISD::PEXTRW",
45 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
46 def X86pinsrb : SDNode<"X86ISD::PINSRB",
47 SDTypeProfile<1, 3, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
48 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
49 def X86pinsrw : SDNode<"X86ISD::PINSRW",
50 SDTypeProfile<1, 3, [SDTCisVT<0, v8i16>, SDTCisSameAs<0,1>,
51 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
52 def X86insrtps : SDNode<"X86ISD::INSERTPS",
53 SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisSameAs<0,1>,
54 SDTCisVT<2, v4f32>, SDTCisPtrTy<3>]>>;
55 def X86vzmovl : SDNode<"X86ISD::VZEXT_MOVL",
56 SDTypeProfile<1, 1, [SDTCisSameAs<0,1>]>>;
57 def X86vzload : SDNode<"X86ISD::VZEXT_LOAD", SDTLoad,
58 [SDNPHasChain, SDNPMayLoad]>;
59 def X86vshl : SDNode<"X86ISD::VSHL", SDTIntShiftOp>;
60 def X86vshr : SDNode<"X86ISD::VSRL", SDTIntShiftOp>;
61 def X86cmpps : SDNode<"X86ISD::CMPPS", SDTX86VFCMP>;
62 def X86cmppd : SDNode<"X86ISD::CMPPD", SDTX86VFCMP>;
63 def X86pcmpeqb : SDNode<"X86ISD::PCMPEQB", SDTIntBinOp, [SDNPCommutative]>;
64 def X86pcmpeqw : SDNode<"X86ISD::PCMPEQW", SDTIntBinOp, [SDNPCommutative]>;
65 def X86pcmpeqd : SDNode<"X86ISD::PCMPEQD", SDTIntBinOp, [SDNPCommutative]>;
66 def X86pcmpeqq : SDNode<"X86ISD::PCMPEQQ", SDTIntBinOp, [SDNPCommutative]>;
67 def X86pcmpgtb : SDNode<"X86ISD::PCMPGTB", SDTIntBinOp>;
68 def X86pcmpgtw : SDNode<"X86ISD::PCMPGTW", SDTIntBinOp>;
69 def X86pcmpgtd : SDNode<"X86ISD::PCMPGTD", SDTIntBinOp>;
70 def X86pcmpgtq : SDNode<"X86ISD::PCMPGTQ", SDTIntBinOp>;
72 def SDTX86CmpPTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>,
75 def X86ptest : SDNode<"X86ISD::PTEST", SDTX86CmpPTest>;
77 //===----------------------------------------------------------------------===//
78 // SSE Complex Patterns
79 //===----------------------------------------------------------------------===//
81 // These are 'extloads' from a scalar to the low element of a vector, zeroing
82 // the top elements. These are used for the SSE 'ss' and 'sd' instruction
84 def sse_load_f32 : ComplexPattern<v4f32, 5, "SelectScalarSSELoad", [],
85 [SDNPHasChain, SDNPMayLoad]>;
86 def sse_load_f64 : ComplexPattern<v2f64, 5, "SelectScalarSSELoad", [],
87 [SDNPHasChain, SDNPMayLoad]>;
89 def ssmem : Operand<v4f32> {
90 let PrintMethod = "printf32mem";
91 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
92 let ParserMatchClass = X86MemAsmOperand;
94 def sdmem : Operand<v2f64> {
95 let PrintMethod = "printf64mem";
96 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
97 let ParserMatchClass = X86MemAsmOperand;
100 //===----------------------------------------------------------------------===//
101 // SSE pattern fragments
102 //===----------------------------------------------------------------------===//
104 def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
105 def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
106 def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
107 def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
109 // Like 'store', but always requires vector alignment.
110 def alignedstore : PatFrag<(ops node:$val, node:$ptr),
111 (store node:$val, node:$ptr), [{
112 return cast<StoreSDNode>(N)->getAlignment() >= 16;
115 // Like 'load', but always requires vector alignment.
116 def alignedload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
117 return cast<LoadSDNode>(N)->getAlignment() >= 16;
120 def alignedloadfsf32 : PatFrag<(ops node:$ptr),
121 (f32 (alignedload node:$ptr))>;
122 def alignedloadfsf64 : PatFrag<(ops node:$ptr),
123 (f64 (alignedload node:$ptr))>;
124 def alignedloadv4f32 : PatFrag<(ops node:$ptr),
125 (v4f32 (alignedload node:$ptr))>;
126 def alignedloadv2f64 : PatFrag<(ops node:$ptr),
127 (v2f64 (alignedload node:$ptr))>;
128 def alignedloadv4i32 : PatFrag<(ops node:$ptr),
129 (v4i32 (alignedload node:$ptr))>;
130 def alignedloadv2i64 : PatFrag<(ops node:$ptr),
131 (v2i64 (alignedload node:$ptr))>;
133 // Like 'load', but uses special alignment checks suitable for use in
134 // memory operands in most SSE instructions, which are required to
135 // be naturally aligned on some targets but not on others. If the subtarget
136 // allows unaligned accesses, match any load, though this may require
137 // setting a feature bit in the processor (on startup, for example).
138 // Opteron 10h and later implement such a feature.
139 def memop : PatFrag<(ops node:$ptr), (load node:$ptr), [{
140 return Subtarget->hasVectorUAMem()
141 || cast<LoadSDNode>(N)->getAlignment() >= 16;
144 def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
145 def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
146 def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
147 def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
148 def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
149 def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
150 def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
152 // SSSE3 uses MMX registers for some instructions. They aren't aligned on a
154 // FIXME: 8 byte alignment for mmx reads is not required
155 def memop64 : PatFrag<(ops node:$ptr), (load node:$ptr), [{
156 return cast<LoadSDNode>(N)->getAlignment() >= 8;
159 def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
160 def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
161 def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
162 def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
165 // Like 'store', but requires the non-temporal bit to be set
166 def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
167 (st node:$val, node:$ptr), [{
168 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
169 return ST->isNonTemporal();
173 def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
174 (st node:$val, node:$ptr), [{
175 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
176 return ST->isNonTemporal() && !ST->isTruncatingStore() &&
177 ST->getAddressingMode() == ISD::UNINDEXED &&
178 ST->getAlignment() >= 16;
182 def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
183 (st node:$val, node:$ptr), [{
184 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
185 return ST->isNonTemporal() &&
186 ST->getAlignment() < 16;
190 def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
191 def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
192 def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
193 def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
194 def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
195 def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
197 def vzmovl_v2i64 : PatFrag<(ops node:$src),
198 (bitconvert (v2i64 (X86vzmovl
199 (v2i64 (scalar_to_vector (loadi64 node:$src))))))>;
200 def vzmovl_v4i32 : PatFrag<(ops node:$src),
201 (bitconvert (v4i32 (X86vzmovl
202 (v4i32 (scalar_to_vector (loadi32 node:$src))))))>;
204 def vzload_v2i64 : PatFrag<(ops node:$src),
205 (bitconvert (v2i64 (X86vzload node:$src)))>;
208 def fp32imm0 : PatLeaf<(f32 fpimm), [{
209 return N->isExactlyValue(+0.0);
212 // BYTE_imm - Transform bit immediates into byte immediates.
213 def BYTE_imm : SDNodeXForm<imm, [{
214 // Transformation function: imm >> 3
215 return getI32Imm(N->getZExtValue() >> 3);
218 // SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
220 def SHUFFLE_get_shuf_imm : SDNodeXForm<vector_shuffle, [{
221 return getI8Imm(X86::getShuffleSHUFImmediate(N));
224 // SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
226 def SHUFFLE_get_pshufhw_imm : SDNodeXForm<vector_shuffle, [{
227 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
230 // SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
232 def SHUFFLE_get_pshuflw_imm : SDNodeXForm<vector_shuffle, [{
233 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
236 // SHUFFLE_get_palign_imm xform function: convert vector_shuffle mask to
238 def SHUFFLE_get_palign_imm : SDNodeXForm<vector_shuffle, [{
239 return getI8Imm(X86::getShufflePALIGNRImmediate(N));
242 def splat_lo : PatFrag<(ops node:$lhs, node:$rhs),
243 (vector_shuffle node:$lhs, node:$rhs), [{
244 ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N);
245 return SVOp->isSplat() && SVOp->getSplatIndex() == 0;
248 def movddup : PatFrag<(ops node:$lhs, node:$rhs),
249 (vector_shuffle node:$lhs, node:$rhs), [{
250 return X86::isMOVDDUPMask(cast<ShuffleVectorSDNode>(N));
253 def movhlps : PatFrag<(ops node:$lhs, node:$rhs),
254 (vector_shuffle node:$lhs, node:$rhs), [{
255 return X86::isMOVHLPSMask(cast<ShuffleVectorSDNode>(N));
258 def movhlps_undef : PatFrag<(ops node:$lhs, node:$rhs),
259 (vector_shuffle node:$lhs, node:$rhs), [{
260 return X86::isMOVHLPS_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
263 def movlhps : PatFrag<(ops node:$lhs, node:$rhs),
264 (vector_shuffle node:$lhs, node:$rhs), [{
265 return X86::isMOVLHPSMask(cast<ShuffleVectorSDNode>(N));
268 def movlp : PatFrag<(ops node:$lhs, node:$rhs),
269 (vector_shuffle node:$lhs, node:$rhs), [{
270 return X86::isMOVLPMask(cast<ShuffleVectorSDNode>(N));
273 def movl : PatFrag<(ops node:$lhs, node:$rhs),
274 (vector_shuffle node:$lhs, node:$rhs), [{
275 return X86::isMOVLMask(cast<ShuffleVectorSDNode>(N));
278 def movshdup : PatFrag<(ops node:$lhs, node:$rhs),
279 (vector_shuffle node:$lhs, node:$rhs), [{
280 return X86::isMOVSHDUPMask(cast<ShuffleVectorSDNode>(N));
283 def movsldup : PatFrag<(ops node:$lhs, node:$rhs),
284 (vector_shuffle node:$lhs, node:$rhs), [{
285 return X86::isMOVSLDUPMask(cast<ShuffleVectorSDNode>(N));
288 def unpckl : PatFrag<(ops node:$lhs, node:$rhs),
289 (vector_shuffle node:$lhs, node:$rhs), [{
290 return X86::isUNPCKLMask(cast<ShuffleVectorSDNode>(N));
293 def unpckh : PatFrag<(ops node:$lhs, node:$rhs),
294 (vector_shuffle node:$lhs, node:$rhs), [{
295 return X86::isUNPCKHMask(cast<ShuffleVectorSDNode>(N));
298 def unpckl_undef : PatFrag<(ops node:$lhs, node:$rhs),
299 (vector_shuffle node:$lhs, node:$rhs), [{
300 return X86::isUNPCKL_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
303 def unpckh_undef : PatFrag<(ops node:$lhs, node:$rhs),
304 (vector_shuffle node:$lhs, node:$rhs), [{
305 return X86::isUNPCKH_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
308 def pshufd : PatFrag<(ops node:$lhs, node:$rhs),
309 (vector_shuffle node:$lhs, node:$rhs), [{
310 return X86::isPSHUFDMask(cast<ShuffleVectorSDNode>(N));
311 }], SHUFFLE_get_shuf_imm>;
313 def shufp : PatFrag<(ops node:$lhs, node:$rhs),
314 (vector_shuffle node:$lhs, node:$rhs), [{
315 return X86::isSHUFPMask(cast<ShuffleVectorSDNode>(N));
316 }], SHUFFLE_get_shuf_imm>;
318 def pshufhw : PatFrag<(ops node:$lhs, node:$rhs),
319 (vector_shuffle node:$lhs, node:$rhs), [{
320 return X86::isPSHUFHWMask(cast<ShuffleVectorSDNode>(N));
321 }], SHUFFLE_get_pshufhw_imm>;
323 def pshuflw : PatFrag<(ops node:$lhs, node:$rhs),
324 (vector_shuffle node:$lhs, node:$rhs), [{
325 return X86::isPSHUFLWMask(cast<ShuffleVectorSDNode>(N));
326 }], SHUFFLE_get_pshuflw_imm>;
328 def palign : PatFrag<(ops node:$lhs, node:$rhs),
329 (vector_shuffle node:$lhs, node:$rhs), [{
330 return X86::isPALIGNRMask(cast<ShuffleVectorSDNode>(N));
331 }], SHUFFLE_get_palign_imm>;
333 //===----------------------------------------------------------------------===//
334 // SSE scalar FP Instructions
335 //===----------------------------------------------------------------------===//
337 // CMOV* - Used to implement the SSE SELECT DAG operation. Expanded after
338 // instruction selection into a branch sequence.
339 let Uses = [EFLAGS], usesCustomInserter = 1 in {
340 def CMOV_FR32 : I<0, Pseudo,
341 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
342 "#CMOV_FR32 PSEUDO!",
343 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
345 def CMOV_FR64 : I<0, Pseudo,
346 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
347 "#CMOV_FR64 PSEUDO!",
348 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
350 def CMOV_V4F32 : I<0, Pseudo,
351 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
352 "#CMOV_V4F32 PSEUDO!",
354 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
356 def CMOV_V2F64 : I<0, Pseudo,
357 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
358 "#CMOV_V2F64 PSEUDO!",
360 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
362 def CMOV_V2I64 : I<0, Pseudo,
363 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
364 "#CMOV_V2I64 PSEUDO!",
366 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
370 //===----------------------------------------------------------------------===//
371 // SSE 1 & 2 Instructions Classes
372 //===----------------------------------------------------------------------===//
374 /// sse12_fp_scalar - SSE 1 & 2 scalar instructions class
375 multiclass sse12_fp_scalar<bits<8> opc, string OpcodeStr, SDNode OpNode,
376 RegisterClass RC, X86MemOperand x86memop> {
377 let isCommutable = 1 in {
378 def rr : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
379 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1, RC:$src2))]>;
381 def rm : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
382 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1, (load addr:$src2)))]>;
385 /// sse12_fp_scalar_int - SSE 1 & 2 scalar instructions intrinsics class
386 multiclass sse12_fp_scalar_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
387 string asm, string SSEVer, string FPSizeStr,
388 Operand memopr, ComplexPattern mem_cpat> {
389 def rr_Int : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
390 asm, [(set RC:$dst, (
391 !nameconcat<Intrinsic>("int_x86_sse",
392 !strconcat(SSEVer, !strconcat("_",
393 !strconcat(OpcodeStr, FPSizeStr))))
394 RC:$src1, RC:$src2))]>;
395 def rm_Int : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, memopr:$src2),
396 asm, [(set RC:$dst, (
397 !nameconcat<Intrinsic>("int_x86_sse",
398 !strconcat(SSEVer, !strconcat("_",
399 !strconcat(OpcodeStr, FPSizeStr))))
400 RC:$src1, mem_cpat:$src2))]>;
403 /// sse12_fp_packed - SSE 1 & 2 packed instructions class
404 multiclass sse12_fp_packed<bits<8> opc, string OpcodeStr, SDNode OpNode,
405 RegisterClass RC, ValueType vt,
406 X86MemOperand x86memop, PatFrag mem_frag,
407 Domain d, bit MayLoad = 0> {
408 let isCommutable = 1 in
409 def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
410 OpcodeStr, [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))],d>;
411 let mayLoad = MayLoad in
412 def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
413 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1,
414 (mem_frag addr:$src2)))],d>;
417 /// sse12_fp_packed_logical_rm - SSE 1 & 2 packed instructions class
418 multiclass sse12_fp_packed_logical_rm<bits<8> opc, RegisterClass RC, Domain d,
419 string OpcodeStr, X86MemOperand x86memop,
420 list<dag> pat_rr, list<dag> pat_rm> {
421 let isCommutable = 1 in
422 def rr : PI<opc, MRMSrcReg, (outs RC:$dst),
423 (ins RC:$src1, RC:$src2), OpcodeStr, pat_rr, d>;
424 def rm : PI<opc, MRMSrcMem, (outs RC:$dst),
425 (ins RC:$src1, x86memop:$src2), OpcodeStr, pat_rm, d>;
428 /// sse12_fp_packed_int - SSE 1 & 2 packed instructions intrinsics class
429 multiclass sse12_fp_packed_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
430 string asm, string SSEVer, string FPSizeStr,
431 X86MemOperand x86memop, PatFrag mem_frag,
433 def rr_Int : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
434 asm, [(set RC:$dst, (
435 !nameconcat<Intrinsic>("int_x86_sse",
436 !strconcat(SSEVer, !strconcat("_",
437 !strconcat(OpcodeStr, FPSizeStr))))
438 RC:$src1, RC:$src2))], d>;
439 def rm_Int : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
440 asm, [(set RC:$dst, (
441 !nameconcat<Intrinsic>("int_x86_sse",
442 !strconcat(SSEVer, !strconcat("_",
443 !strconcat(OpcodeStr, FPSizeStr))))
444 RC:$src1, (mem_frag addr:$src2)))], d>;
447 /// 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 multiclass sse12_cmp<RegisterClass RC, X86MemOperand x86memop, Intrinsic Int,
464 string asm, Domain d, Operand sse_imm_op> {
465 def rri : PIi8<0xC2, MRMSrcReg,
466 (outs RC:$dst), (ins RC:$src1, RC:$src, sse_imm_op:$cc), asm,
467 [(set RC:$dst, (Int RC:$src1, RC:$src, imm:$cc))], d>;
468 def rmi : PIi8<0xC2, MRMSrcMem,
469 (outs RC:$dst), (ins RC:$src1, f128mem:$src, sse_imm_op:$cc), asm,
470 [(set RC:$dst, (Int RC:$src1, (memop addr:$src), imm:$cc))], d>;
473 // FIXME: rename instructions to only use the class above
474 multiclass sse12_cmp_alt<RegisterClass RC, string asm, Domain d,
475 Operand sse_imm_op> {
476 def rri_alt : PIi8<0xC2, MRMSrcReg,
477 (outs RC:$dst), (ins RC:$src1, RC:$src, sse_imm_op:$src2), asm,
479 def rmi_alt : PIi8<0xC2, MRMSrcMem,
480 (outs RC:$dst), (ins RC:$src1, f128mem:$src, sse_imm_op:$src2), asm,
484 //===----------------------------------------------------------------------===//
486 //===----------------------------------------------------------------------===//
488 // Conversion Instructions
490 // Match intrinsics which expect XMM operand(s).
491 def CVTSS2SIrr: SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
492 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
493 def CVTSS2SIrm: SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
494 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
496 def CVTDQ2PSrr : PSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
497 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
498 def CVTDQ2PSrm : PSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
499 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
501 // Aliases for intrinsics
502 def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
503 "cvttss2si\t{$src, $dst|$dst, $src}",
505 (int_x86_sse_cvttss2si VR128:$src))]>;
506 def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
507 "cvttss2si\t{$src, $dst|$dst, $src}",
509 (int_x86_sse_cvttss2si(load addr:$src)))]>;
511 let Constraints = "$src1 = $dst" in {
512 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
513 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
514 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
515 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
517 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
518 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
519 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
520 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
521 (loadi32 addr:$src2)))]>;
524 // Compare Instructions
525 let Defs = [EFLAGS] in {
526 def COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
527 "comiss\t{$src2, $src1|$src1, $src2}", []>;
528 def COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
529 "comiss\t{$src2, $src1|$src1, $src2}", []>;
532 //===----------------------------------------------------------------------===//
533 // SSE 1 & 2 - Move Instructions
534 //===----------------------------------------------------------------------===//
536 class sse12_move_rr<RegisterClass RC, ValueType vt, string asm> :
537 SI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, RC:$src2), asm,
538 [(set (vt VR128:$dst), (movl VR128:$src1, (scalar_to_vector RC:$src2)))]>;
540 // Loading from memory automatically zeroing upper bits.
541 class sse12_move_rm<RegisterClass RC, X86MemOperand x86memop,
542 PatFrag mem_pat, string OpcodeStr> :
543 SI<0x10, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src),
544 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
545 [(set RC:$dst, (mem_pat addr:$src))]>;
547 // Move Instructions. Register-to-register movss/movsd is not used for FR32/64
548 // register copies because it's a partial register update; FsMOVAPSrr/FsMOVAPDrr
549 // is used instead. Register-to-register movss/movsd is not modeled as an
550 // INSERT_SUBREG because INSERT_SUBREG requires that the insert be implementable
551 // in terms of a copy, and just mentioned, we don't use movss/movsd for copies.
552 let isAsmParserOnly = 1 in {
553 def VMOVSSrr : sse12_move_rr<FR32, v4f32,
554 "movss\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XS, VEX_4V;
555 def VMOVSDrr : sse12_move_rr<FR64, v2f64,
556 "movsd\t{$src2, $src1, $dst|$dst, $src1, $src2}">, XD, VEX_4V;
558 let canFoldAsLoad = 1, isReMaterializable = 1 in {
559 def VMOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS, VEX;
561 let AddedComplexity = 20 in
562 def VMOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD, VEX;
566 let Constraints = "$src1 = $dst" in {
567 def MOVSSrr : sse12_move_rr<FR32, v4f32,
568 "movss\t{$src2, $dst|$dst, $src2}">, XS;
569 def MOVSDrr : sse12_move_rr<FR64, v2f64,
570 "movsd\t{$src2, $dst|$dst, $src2}">, XD;
573 let canFoldAsLoad = 1, isReMaterializable = 1 in {
574 def MOVSSrm : sse12_move_rm<FR32, f32mem, loadf32, "movss">, XS;
576 let AddedComplexity = 20 in
577 def MOVSDrm : sse12_move_rm<FR64, f64mem, loadf64, "movsd">, XD;
580 let AddedComplexity = 15 in {
581 // Extract the low 32-bit value from one vector and insert it into another.
582 def : Pat<(v4f32 (movl VR128:$src1, VR128:$src2)),
583 (MOVSSrr (v4f32 VR128:$src1),
584 (EXTRACT_SUBREG (v4f32 VR128:$src2), sub_ss))>;
585 // Extract the low 64-bit value from one vector and insert it into another.
586 def : Pat<(v2f64 (movl VR128:$src1, VR128:$src2)),
587 (MOVSDrr (v2f64 VR128:$src1),
588 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
591 // Implicitly promote a 32-bit scalar to a vector.
592 def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
593 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss)>;
594 // Implicitly promote a 64-bit scalar to a vector.
595 def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
596 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
598 let AddedComplexity = 20 in {
599 // MOVSSrm zeros the high parts of the register; represent this
600 // with SUBREG_TO_REG.
601 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
602 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
603 def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
604 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
605 def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
606 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
607 // MOVSDrm zeros the high parts of the register; represent this
608 // with SUBREG_TO_REG.
609 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
610 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
611 def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
612 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
613 def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
614 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
615 def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
616 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
617 def : Pat<(v2f64 (X86vzload addr:$src)),
618 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
621 // Store scalar value to memory.
622 def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
623 "movss\t{$src, $dst|$dst, $src}",
624 [(store FR32:$src, addr:$dst)]>;
625 def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
626 "movsd\t{$src, $dst|$dst, $src}",
627 [(store FR64:$src, addr:$dst)]>;
629 let isAsmParserOnly = 1 in {
630 def VMOVSSmr : SI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
631 "movss\t{$src, $dst|$dst, $src}",
632 [(store FR32:$src, addr:$dst)]>, XS, VEX_4V;
633 def VMOVSDmr : SI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
634 "movsd\t{$src, $dst|$dst, $src}",
635 [(store FR64:$src, addr:$dst)]>, XD, VEX_4V;
638 // Extract and store.
639 def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
642 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
643 def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
646 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
648 //===----------------------------------------------------------------------===//
649 // SSE 1 & 2 - Conversion Instructions
650 //===----------------------------------------------------------------------===//
652 // Conversion instructions
653 def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
654 "cvttss2si\t{$src, $dst|$dst, $src}",
655 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
656 def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
657 "cvttss2si\t{$src, $dst|$dst, $src}",
658 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
659 def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
660 "cvttsd2si\t{$src, $dst|$dst, $src}",
661 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
662 def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
663 "cvttsd2si\t{$src, $dst|$dst, $src}",
664 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
666 def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
667 "cvtsi2ss\t{$src, $dst|$dst, $src}",
668 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
669 def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
670 "cvtsi2ss\t{$src, $dst|$dst, $src}",
671 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
672 def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
673 "cvtsi2sd\t{$src, $dst|$dst, $src}",
674 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
675 def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
676 "cvtsi2sd\t{$src, $dst|$dst, $src}",
677 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
679 // Match intrinsics which expect XMM operand(s).
680 def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
681 "cvtss2si\t{$src, $dst|$dst, $src}",
682 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
683 def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
684 "cvtss2si\t{$src, $dst|$dst, $src}",
685 [(set GR32:$dst, (int_x86_sse_cvtss2si
686 (load addr:$src)))]>;
687 def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
688 "cvtsd2si\t{$src, $dst|$dst, $src}",
689 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
690 def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
691 "cvtsd2si\t{$src, $dst|$dst, $src}",
692 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
693 (load addr:$src)))]>;
695 // Match intrinsics which expect MM and XMM operand(s).
696 def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
697 "cvtps2pi\t{$src, $dst|$dst, $src}",
698 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
699 def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
700 "cvtps2pi\t{$src, $dst|$dst, $src}",
701 [(set VR64:$dst, (int_x86_sse_cvtps2pi
702 (load addr:$src)))]>;
703 def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
704 "cvtpd2pi\t{$src, $dst|$dst, $src}",
705 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
706 def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
707 "cvtpd2pi\t{$src, $dst|$dst, $src}",
708 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
709 (memop addr:$src)))]>;
711 // Match intrinsics which expect MM and XMM operand(s).
712 def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
713 "cvttps2pi\t{$src, $dst|$dst, $src}",
714 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
715 def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
716 "cvttps2pi\t{$src, $dst|$dst, $src}",
717 [(set VR64:$dst, (int_x86_sse_cvttps2pi
718 (load addr:$src)))]>;
719 def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
720 "cvttpd2pi\t{$src, $dst|$dst, $src}",
721 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
722 def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
723 "cvttpd2pi\t{$src, $dst|$dst, $src}",
724 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
725 (memop addr:$src)))]>;
727 let Constraints = "$src1 = $dst" in {
728 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
729 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
730 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
731 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
733 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
734 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
735 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
736 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
737 (load addr:$src2)))]>;
740 //===----------------------------------------------------------------------===//
741 // SSE 1 & 2 - Compare Instructions
742 //===----------------------------------------------------------------------===//
744 // Comparison instructions
745 let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
746 def CMPSSrr : SSIi8<0xC2, MRMSrcReg,
747 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
748 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
750 def CMPSSrm : SSIi8<0xC2, MRMSrcMem,
751 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
752 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
754 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
755 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
756 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
758 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
759 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
760 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
762 // Accept explicit immediate argument form instead of comparison code.
763 let isAsmParserOnly = 1 in {
764 def CMPSSrr_alt : SSIi8<0xC2, MRMSrcReg,
765 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, i8imm:$src2),
766 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
768 def CMPSSrm_alt : SSIi8<0xC2, MRMSrcMem,
769 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, i8imm:$src2),
770 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
772 def CMPSDrr_alt : SDIi8<0xC2, MRMSrcReg,
773 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, i8imm:$src2),
774 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
776 def CMPSDrm_alt : SDIi8<0xC2, MRMSrcMem,
777 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, i8imm:$src2),
778 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
782 let Defs = [EFLAGS] in {
783 def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
784 "ucomiss\t{$src2, $src1|$src1, $src2}",
785 [(set EFLAGS, (X86cmp FR32:$src1, FR32:$src2))]>;
786 def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
787 "ucomiss\t{$src2, $src1|$src1, $src2}",
788 [(set EFLAGS, (X86cmp FR32:$src1, (loadf32 addr:$src2)))]>;
789 def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
790 "ucomisd\t{$src2, $src1|$src1, $src2}",
791 [(set EFLAGS, (X86cmp FR64:$src1, FR64:$src2))]>;
792 def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
793 "ucomisd\t{$src2, $src1|$src1, $src2}",
794 [(set EFLAGS, (X86cmp FR64:$src1, (loadf64 addr:$src2)))]>;
797 // Aliases to match intrinsics which expect XMM operand(s).
798 let Constraints = "$src1 = $dst" in {
799 def Int_CMPSSrr : SSIi8<0xC2, MRMSrcReg,
801 (ins VR128:$src1, VR128:$src, SSECC:$cc),
802 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
803 [(set VR128:$dst, (int_x86_sse_cmp_ss
805 VR128:$src, imm:$cc))]>;
806 def Int_CMPSSrm : SSIi8<0xC2, MRMSrcMem,
808 (ins VR128:$src1, f32mem:$src, SSECC:$cc),
809 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
810 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
811 (load addr:$src), imm:$cc))]>;
813 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
815 (ins VR128:$src1, VR128:$src, SSECC:$cc),
816 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
817 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
818 VR128:$src, imm:$cc))]>;
819 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
821 (ins VR128:$src1, f64mem:$src, SSECC:$cc),
822 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
823 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
824 (load addr:$src), imm:$cc))]>;
827 let Defs = [EFLAGS] in {
828 def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
829 "ucomiss\t{$src2, $src1|$src1, $src2}",
830 [(set EFLAGS, (X86ucomi (v4f32 VR128:$src1),
832 def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
833 "ucomiss\t{$src2, $src1|$src1, $src2}",
834 [(set EFLAGS, (X86ucomi (v4f32 VR128:$src1),
835 (load addr:$src2)))]>;
836 def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
837 "ucomisd\t{$src2, $src1|$src1, $src2}",
838 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
840 def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
841 "ucomisd\t{$src2, $src1|$src1, $src2}",
842 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
843 (load addr:$src2)))]>;
845 def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
846 "comiss\t{$src2, $src1|$src1, $src2}",
847 [(set EFLAGS, (X86comi (v4f32 VR128:$src1),
849 def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
850 "comiss\t{$src2, $src1|$src1, $src2}",
851 [(set EFLAGS, (X86comi (v4f32 VR128:$src1),
852 (load addr:$src2)))]>;
853 def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
854 "comisd\t{$src2, $src1|$src1, $src2}",
855 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
857 def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
858 "comisd\t{$src2, $src1|$src1, $src2}",
859 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
860 (load addr:$src2)))]>;
863 // Aliases of packed SSE1 & SSE2 instructions for scalar use. These all have
864 // names that start with 'Fs'.
866 // Alias instructions that map fld0 to pxor for sse.
867 let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
868 canFoldAsLoad = 1 in {
869 // FIXME: Set encoding to pseudo!
870 def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins), "",
871 [(set FR32:$dst, fp32imm0)]>,
872 Requires<[HasSSE1]>, TB, OpSize;
873 def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
874 [(set FR64:$dst, fpimm0)]>,
875 Requires<[HasSSE2]>, TB, OpSize;
878 // Alias instruction to do FR32 or FR64 reg-to-reg copy using movaps. Upper
879 // bits are disregarded.
880 let neverHasSideEffects = 1 in {
881 def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
882 "movaps\t{$src, $dst|$dst, $src}", []>;
883 def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
884 "movapd\t{$src, $dst|$dst, $src}", []>;
887 // Alias instruction to load FR32 or FR64 from f128mem using movaps. Upper
888 // bits are disregarded.
889 let canFoldAsLoad = 1, isReMaterializable = 1 in {
890 def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
891 "movaps\t{$src, $dst|$dst, $src}",
892 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
893 def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
894 "movapd\t{$src, $dst|$dst, $src}",
895 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
898 //===----------------------------------------------------------------------===//
899 // SSE 1 & 2 - Logical Instructions
900 //===----------------------------------------------------------------------===//
902 /// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
904 multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
905 SDNode OpNode, bit MayLoad = 0> {
906 let isAsmParserOnly = 1 in {
907 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
908 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR32,
909 f32, f128mem, memopfsf32, SSEPackedSingle, MayLoad>, VEX_4V;
911 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
912 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode, FR64,
913 f64, f128mem, memopfsf64, SSEPackedDouble, MayLoad>, OpSize,
917 let Constraints = "$src1 = $dst" in {
918 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
919 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, FR32, f32,
920 f128mem, memopfsf32, SSEPackedSingle, MayLoad>, TB;
922 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
923 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, FR64, f64,
924 f128mem, memopfsf64, SSEPackedDouble, MayLoad>, TB, OpSize;
928 // Alias bitwise logical operations using SSE logical ops on packed FP values.
929 defm FsAND : sse12_fp_alias_pack_logical<0x54, "and", X86fand>;
930 defm FsOR : sse12_fp_alias_pack_logical<0x56, "or", X86for>;
931 defm FsXOR : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor>;
933 let neverHasSideEffects = 1, Pattern = []<dag>, isCommutable = 0 in
934 defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef, 1>;
936 /// sse12_fp_packed_logical - SSE 1 & 2 packed FP logical ops
938 multiclass sse12_fp_packed_logical<bits<8> opc, string OpcodeStr,
939 SDNode OpNode, int HasPat = 0,
940 list<list<dag>> Pattern = []> {
941 let isAsmParserOnly = 1 in {
942 defm V#NAME#PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
943 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
945 !if(HasPat, Pattern[0], // rr
946 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
948 !if(HasPat, Pattern[2], // rm
949 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
950 (memopv2i64 addr:$src2)))])>,
953 defm V#NAME#PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
954 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
956 !if(HasPat, Pattern[1], // rr
957 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
960 !if(HasPat, Pattern[3], // rm
961 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
962 (memopv2i64 addr:$src2)))])>,
965 let Constraints = "$src1 = $dst" in {
966 defm PS : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedSingle,
967 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"), f128mem,
968 !if(HasPat, Pattern[0], // rr
969 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
971 !if(HasPat, Pattern[2], // rm
972 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
973 (memopv2i64 addr:$src2)))])>, TB;
975 defm PD : sse12_fp_packed_logical_rm<opc, VR128, SSEPackedDouble,
976 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"), f128mem,
977 !if(HasPat, Pattern[1], // rr
978 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
981 !if(HasPat, Pattern[3], // rm
982 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
983 (memopv2i64 addr:$src2)))])>,
988 defm AND : sse12_fp_packed_logical<0x54, "and", and>;
989 defm OR : sse12_fp_packed_logical<0x56, "or", or>;
990 defm XOR : sse12_fp_packed_logical<0x57, "xor", xor>;
991 let isCommutable = 0 in
992 defm ANDN : sse12_fp_packed_logical<0x55, "andn", undef /* dummy */, 1, [
994 [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
995 (bc_v2i64 (v4i32 immAllOnesV))),
998 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
999 (bc_v2i64 (v2f64 VR128:$src2))))],
1001 [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1002 (bc_v2i64 (v4i32 immAllOnesV))),
1003 (memopv2i64 addr:$src2))))],
1005 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1006 (memopv2i64 addr:$src2)))]]>;
1008 //===----------------------------------------------------------------------===//
1009 // SSE 1 & 2 - Arithmetic Instructions
1010 //===----------------------------------------------------------------------===//
1012 /// basic_sse12_fp_binop_rm - SSE 1 & 2 binops come in both scalar and
1015 /// In addition, we also have a special variant of the scalar form here to
1016 /// represent the associated intrinsic operation. This form is unlike the
1017 /// plain scalar form, in that it takes an entire vector (instead of a scalar)
1018 /// and leaves the top elements unmodified (therefore these cannot be commuted).
1020 /// These three forms can each be reg+reg or reg+mem.
1022 multiclass basic_sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
1025 let isAsmParserOnly = 1 in {
1026 defm V#NAME#SS : sse12_fp_scalar<opc,
1027 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1028 OpNode, FR32, f32mem>, XS, VEX_4V;
1030 defm V#NAME#SD : sse12_fp_scalar<opc,
1031 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1032 OpNode, FR64, f64mem>, XD, VEX_4V;
1034 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1035 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1036 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
1039 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1040 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1041 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
1044 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1045 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1046 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
1048 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1049 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1050 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
1053 let Constraints = "$src1 = $dst" in {
1054 defm SS : sse12_fp_scalar<opc,
1055 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1056 OpNode, FR32, f32mem>, XS;
1058 defm SD : sse12_fp_scalar<opc,
1059 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1060 OpNode, FR64, f64mem>, XD;
1062 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1063 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
1064 f128mem, memopv4f32, SSEPackedSingle>, TB;
1066 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1067 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
1068 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1070 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1071 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1072 "", "_ss", ssmem, sse_load_f32>, XS;
1074 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1075 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1076 "2", "_sd", sdmem, sse_load_f64>, XD;
1080 // Arithmetic instructions
1081 defm ADD : basic_sse12_fp_binop_rm<0x58, "add", fadd>;
1082 defm MUL : basic_sse12_fp_binop_rm<0x59, "mul", fmul>;
1084 let isCommutable = 0 in {
1085 defm SUB : basic_sse12_fp_binop_rm<0x5C, "sub", fsub>;
1086 defm DIV : basic_sse12_fp_binop_rm<0x5E, "div", fdiv>;
1089 /// sse12_fp_binop_rm - Other SSE 1 & 2 binops
1091 /// This multiclass is like basic_sse12_fp_binop_rm, with the addition of
1092 /// instructions for a full-vector intrinsic form. Operations that map
1093 /// onto C operators don't use this form since they just use the plain
1094 /// vector form instead of having a separate vector intrinsic form.
1096 multiclass sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
1099 let isAsmParserOnly = 1 in {
1100 // Scalar operation, reg+reg.
1101 defm V#NAME#SS : sse12_fp_scalar<opc,
1102 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1103 OpNode, FR32, f32mem>, XS, VEX_4V;
1105 defm V#NAME#SD : sse12_fp_scalar<opc,
1106 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1107 OpNode, FR64, f64mem>, XD, VEX_4V;
1109 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1110 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1111 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
1114 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1115 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
1116 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
1119 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1120 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1121 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
1123 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1124 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1125 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
1127 defm V#NAME#PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1128 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1129 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, VEX_4V;
1131 defm V#NAME#PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1132 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1133 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, OpSize,
1137 let Constraints = "$src1 = $dst" in {
1138 // Scalar operation, reg+reg.
1139 defm SS : sse12_fp_scalar<opc,
1140 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1141 OpNode, FR32, f32mem>, XS;
1142 defm SD : sse12_fp_scalar<opc,
1143 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1144 OpNode, FR64, f64mem>, XD;
1145 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1146 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
1147 f128mem, memopv4f32, SSEPackedSingle>, TB;
1149 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
1150 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
1151 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1153 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1154 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
1155 "", "_ss", ssmem, sse_load_f32>, XS;
1157 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
1158 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
1159 "2", "_sd", sdmem, sse_load_f64>, XD;
1161 defm PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1162 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1163 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, TB;
1165 defm PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
1166 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1167 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
1171 let isCommutable = 0 in {
1172 defm MAX : sse12_fp_binop_rm<0x5F, "max", X86fmax>;
1173 defm MIN : sse12_fp_binop_rm<0x5D, "min", X86fmin>;
1176 //===----------------------------------------------------------------------===//
1177 // SSE packed FP Instructions
1179 // Move Instructions
1180 let neverHasSideEffects = 1 in
1181 def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1182 "movaps\t{$src, $dst|$dst, $src}", []>;
1183 let canFoldAsLoad = 1, isReMaterializable = 1 in
1184 def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1185 "movaps\t{$src, $dst|$dst, $src}",
1186 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
1188 def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1189 "movaps\t{$src, $dst|$dst, $src}",
1190 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
1192 let neverHasSideEffects = 1 in
1193 def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1194 "movups\t{$src, $dst|$dst, $src}", []>;
1195 let canFoldAsLoad = 1, isReMaterializable = 1 in
1196 def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1197 "movups\t{$src, $dst|$dst, $src}",
1198 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
1199 def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1200 "movups\t{$src, $dst|$dst, $src}",
1201 [(store (v4f32 VR128:$src), addr:$dst)]>;
1203 // Intrinsic forms of MOVUPS load and store
1204 let canFoldAsLoad = 1, isReMaterializable = 1 in
1205 def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1206 "movups\t{$src, $dst|$dst, $src}",
1207 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
1208 def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1209 "movups\t{$src, $dst|$dst, $src}",
1210 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
1212 let Constraints = "$src1 = $dst" in {
1213 let AddedComplexity = 20 in {
1214 def MOVLPSrm : PSI<0x12, MRMSrcMem,
1215 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1216 "movlps\t{$src2, $dst|$dst, $src2}",
1219 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
1220 def MOVHPSrm : PSI<0x16, MRMSrcMem,
1221 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1222 "movhps\t{$src2, $dst|$dst, $src2}",
1224 (movlhps VR128:$src1,
1225 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
1226 } // AddedComplexity
1227 } // Constraints = "$src1 = $dst"
1230 def : Pat<(movlhps VR128:$src1, (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
1231 (MOVHPSrm (v4i32 VR128:$src1), addr:$src2)>;
1233 def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1234 "movlps\t{$src, $dst|$dst, $src}",
1235 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
1236 (iPTR 0))), addr:$dst)]>;
1238 // v2f64 extract element 1 is always custom lowered to unpack high to low
1239 // and extract element 0 so the non-store version isn't too horrible.
1240 def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1241 "movhps\t{$src, $dst|$dst, $src}",
1242 [(store (f64 (vector_extract
1243 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
1244 (undef)), (iPTR 0))), addr:$dst)]>;
1246 let Constraints = "$src1 = $dst" in {
1247 let AddedComplexity = 20 in {
1248 def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
1249 (ins VR128:$src1, VR128:$src2),
1250 "movlhps\t{$src2, $dst|$dst, $src2}",
1252 (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
1254 def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
1255 (ins VR128:$src1, VR128:$src2),
1256 "movhlps\t{$src2, $dst|$dst, $src2}",
1258 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
1259 } // AddedComplexity
1260 } // Constraints = "$src1 = $dst"
1262 let AddedComplexity = 20 in {
1263 def : Pat<(v4f32 (movddup VR128:$src, (undef))),
1264 (MOVLHPSrr (v4f32 VR128:$src), (v4f32 VR128:$src))>;
1265 def : Pat<(v2i64 (movddup VR128:$src, (undef))),
1266 (MOVLHPSrr (v2i64 VR128:$src), (v2i64 VR128:$src))>;
1273 /// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
1275 /// In addition, we also have a special variant of the scalar form here to
1276 /// represent the associated intrinsic operation. This form is unlike the
1277 /// plain scalar form, in that it takes an entire vector (instead of a
1278 /// scalar) and leaves the top elements undefined.
1280 /// And, we have a special variant form for a full-vector intrinsic form.
1282 /// These four forms can each have a reg or a mem operand, so there are a
1283 /// total of eight "instructions".
1285 multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
1289 bit Commutable = 0> {
1290 // Scalar operation, reg.
1291 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
1292 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1293 [(set FR32:$dst, (OpNode FR32:$src))]> {
1294 let isCommutable = Commutable;
1297 // Scalar operation, mem.
1298 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
1299 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1300 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
1301 Requires<[HasSSE1, OptForSize]>;
1303 // Vector operation, reg.
1304 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1305 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1306 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
1307 let isCommutable = Commutable;
1310 // Vector operation, mem.
1311 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1312 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1313 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
1315 // Intrinsic operation, reg.
1316 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1317 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1318 [(set VR128:$dst, (F32Int VR128:$src))]> {
1319 let isCommutable = Commutable;
1322 // Intrinsic operation, mem.
1323 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
1324 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
1325 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1327 // Vector intrinsic operation, reg
1328 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1329 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1330 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
1331 let isCommutable = Commutable;
1334 // Vector intrinsic operation, mem
1335 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1336 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
1337 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
1341 defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
1342 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
1344 // Reciprocal approximations. Note that these typically require refinement
1345 // in order to obtain suitable precision.
1346 defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
1347 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
1348 defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
1349 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
1352 let Constraints = "$src1 = $dst" in {
1353 defm CMPPS : sse12_cmp<VR128, f128mem, int_x86_sse_cmp_ps,
1354 "cmp${cc}ps\t{$src, $dst|$dst, $src}", SSEPackedSingle, SSECC>,
1356 defm CMPPD : sse12_cmp<VR128, f128mem, int_x86_sse2_cmp_pd,
1357 "cmp${cc}pd\t{$src, $dst|$dst, $src}", SSEPackedDouble, SSECC>,
1360 let isAsmParserOnly = 1 in {
1361 defm VCMPPS : sse12_cmp<VR128, f128mem, int_x86_sse_cmp_ps,
1362 "cmp${cc}ps\t{$src, $src1, $dst|$dst, $src1, $src}",
1363 SSEPackedSingle, SSECC>, VEX_4V;
1364 defm VCMPPD : sse12_cmp<VR128, f128mem, int_x86_sse2_cmp_pd,
1365 "cmp${cc}pd\t{$src, $src1, $dst|$dst, $src1, $src}",
1366 SSEPackedSingle, SSECC>, OpSize, VEX_4V;
1369 let isAsmParserOnly = 1, Pattern = []<dag> in {
1370 // Accept explicit immediate argument form instead of comparison code.
1371 let Constraints = "$src1 = $dst" in {
1372 defm CMPPS : sse12_cmp_alt<VR128,
1373 "cmpps\t{$src2, $src, $dst|$dst, $src, $src2}",
1374 SSEPackedSingle, i8imm>, TB;
1375 defm CMPPD : sse12_cmp_alt<VR128,
1376 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}",
1377 SSEPackedDouble, i8imm>, TB, OpSize;
1379 defm VCMPPS : sse12_cmp_alt<VR128,
1380 "cmpps\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src}",
1381 SSEPackedSingle, i8imm>, VEX_4V;
1382 defm VCMPPD : sse12_cmp_alt<VR128,
1383 "cmppd\t{$src2, $src, $src1, $dst|$dst, $src1, $src, $src2}",
1384 SSEPackedSingle, i8imm>, OpSize, VEX_4V;
1387 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
1388 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
1389 def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
1390 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
1391 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
1392 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
1393 def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
1394 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
1396 // Shuffle and unpack instructions
1397 let Constraints = "$src1 = $dst" in {
1398 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
1399 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
1400 (outs VR128:$dst), (ins VR128:$src1,
1401 VR128:$src2, i8imm:$src3),
1402 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1404 (v4f32 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
1405 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
1406 (outs VR128:$dst), (ins VR128:$src1,
1407 f128mem:$src2, i8imm:$src3),
1408 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1411 VR128:$src1, (memopv4f32 addr:$src2))))]>;
1412 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
1413 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1414 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1416 (v2f64 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
1417 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
1418 (outs VR128:$dst), (ins VR128:$src1,
1419 f128mem:$src2, i8imm:$src3),
1420 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1423 VR128:$src1, (memopv2f64 addr:$src2))))]>;
1425 let AddedComplexity = 10 in {
1426 let Constraints = "", isAsmParserOnly = 1 in {
1427 defm VUNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
1428 VR128, f128mem, "unpckhps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1429 SSEPackedSingle>, VEX_4V;
1430 defm VUNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
1431 VR128, f128mem, "unpckhpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1432 SSEPackedDouble>, OpSize, VEX_4V;
1433 defm VUNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
1434 VR128, f128mem, "unpcklps\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1435 SSEPackedSingle>, VEX_4V;
1436 defm VUNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
1437 VR128, f128mem, "unpcklpd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
1438 SSEPackedDouble>, OpSize, VEX_4V;
1440 defm UNPCKHPS: sse12_unpack_interleave<0x15, unpckh, v4f32, memopv4f32,
1441 VR128, f128mem, "unpckhps\t{$src2, $dst|$dst, $src2}",
1442 SSEPackedSingle>, TB;
1443 defm UNPCKHPD: sse12_unpack_interleave<0x15, unpckh, v2f64, memopv2f64,
1444 VR128, f128mem, "unpckhpd\t{$src2, $dst|$dst, $src2}",
1445 SSEPackedDouble>, TB, OpSize;
1446 defm UNPCKLPS: sse12_unpack_interleave<0x14, unpckl, v4f32, memopv4f32,
1447 VR128, f128mem, "unpcklps\t{$src2, $dst|$dst, $src2}",
1448 SSEPackedSingle>, TB;
1449 defm UNPCKLPD: sse12_unpack_interleave<0x14, unpckl, v2f64, memopv2f64,
1450 VR128, f128mem, "unpcklpd\t{$src2, $dst|$dst, $src2}",
1451 SSEPackedDouble>, TB, OpSize;
1452 } // AddedComplexity
1453 } // Constraints = "$src1 = $dst"
1456 def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1457 "movmskps\t{$src, $dst|$dst, $src}",
1458 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
1459 def MOVMSKPDrr : PDI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1460 "movmskpd\t{$src, $dst|$dst, $src}",
1461 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
1463 // Prefetch intrinsic.
1464 def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
1465 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
1466 def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
1467 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
1468 def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
1469 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
1470 def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
1471 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
1473 // Non-temporal stores
1474 def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1475 "movntps\t{$src, $dst|$dst, $src}",
1476 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
1478 let AddedComplexity = 400 in { // Prefer non-temporal versions
1479 def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1480 "movntps\t{$src, $dst|$dst, $src}",
1481 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1483 def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1484 "movntdq\t{$src, $dst|$dst, $src}",
1485 [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
1487 def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1488 "movnti\t{$src, $dst|$dst, $src}",
1489 [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
1490 TB, Requires<[HasSSE2]>;
1492 def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1493 "movnti\t{$src, $dst|$dst, $src}",
1494 [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
1495 TB, Requires<[HasSSE2]>;
1498 // Load, store, and memory fence
1499 def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
1500 TB, Requires<[HasSSE1]>;
1503 def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
1504 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
1505 def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
1506 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
1508 // Alias instructions that map zero vector to pxor / xorp* for sse.
1509 // We set canFoldAsLoad because this can be converted to a constant-pool
1510 // load of an all-zeros value if folding it would be beneficial.
1511 // FIXME: Change encoding to pseudo!
1512 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
1513 isCodeGenOnly = 1 in {
1514 def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1515 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
1516 def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1517 [(set VR128:$dst, (v2f64 immAllZerosV))]>;
1518 let ExeDomain = SSEPackedInt in
1519 def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
1520 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
1523 def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
1524 def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
1525 def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
1527 def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
1528 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
1530 //===---------------------------------------------------------------------===//
1531 // SSE2 Instructions
1532 //===---------------------------------------------------------------------===//
1534 // Conversion instructions
1535 def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
1536 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1537 [(set FR32:$dst, (fround FR64:$src))]>;
1538 def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
1539 "cvtsd2ss\t{$src, $dst|$dst, $src}",
1540 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
1541 Requires<[HasSSE2, OptForSize]>;
1543 def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1544 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1545 def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1546 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1547 def COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1548 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1549 def COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1550 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1552 // SSE2 instructions with XS prefix
1553 def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
1554 "cvtss2sd\t{$src, $dst|$dst, $src}",
1555 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1556 Requires<[HasSSE2]>;
1557 def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
1558 "cvtss2sd\t{$src, $dst|$dst, $src}",
1559 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1560 Requires<[HasSSE2, OptForSize]>;
1562 def : Pat<(extloadf32 addr:$src),
1563 (CVTSS2SDrr (MOVSSrm addr:$src))>,
1564 Requires<[HasSSE2, OptForSpeed]>;
1566 // Match intrinsics which expect MM and XMM operand(s).
1567 def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1568 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1569 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1570 def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1571 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1572 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
1573 (load addr:$src)))]>;
1575 // Aliases for intrinsics
1576 def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
1577 "cvttsd2si\t{$src, $dst|$dst, $src}",
1579 (int_x86_sse2_cvttsd2si VR128:$src))]>;
1580 def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
1581 "cvttsd2si\t{$src, $dst|$dst, $src}",
1582 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1583 (load addr:$src)))]>;
1585 //===---------------------------------------------------------------------===//
1586 // SSE packed FP Instructions
1588 // Move Instructions
1589 let neverHasSideEffects = 1 in
1590 def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1591 "movapd\t{$src, $dst|$dst, $src}", []>;
1592 let canFoldAsLoad = 1, isReMaterializable = 1 in
1593 def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1594 "movapd\t{$src, $dst|$dst, $src}",
1595 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
1597 def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1598 "movapd\t{$src, $dst|$dst, $src}",
1599 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
1601 let neverHasSideEffects = 1 in
1602 def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1603 "movupd\t{$src, $dst|$dst, $src}", []>;
1604 let canFoldAsLoad = 1 in
1605 def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1606 "movupd\t{$src, $dst|$dst, $src}",
1607 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
1608 def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1609 "movupd\t{$src, $dst|$dst, $src}",
1610 [(store (v2f64 VR128:$src), addr:$dst)]>;
1612 // Intrinsic forms of MOVUPD load and store
1613 def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1614 "movupd\t{$src, $dst|$dst, $src}",
1615 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
1616 def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1617 "movupd\t{$src, $dst|$dst, $src}",
1618 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
1620 let Constraints = "$src1 = $dst" in {
1621 let AddedComplexity = 20 in {
1622 def MOVLPDrm : PDI<0x12, MRMSrcMem,
1623 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1624 "movlpd\t{$src2, $dst|$dst, $src2}",
1626 (v2f64 (movlp VR128:$src1,
1627 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1628 def MOVHPDrm : PDI<0x16, MRMSrcMem,
1629 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1630 "movhpd\t{$src2, $dst|$dst, $src2}",
1632 (v2f64 (movlhps VR128:$src1,
1633 (scalar_to_vector (loadf64 addr:$src2)))))]>;
1634 } // AddedComplexity
1635 } // Constraints = "$src1 = $dst"
1637 def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1638 "movlpd\t{$src, $dst|$dst, $src}",
1639 [(store (f64 (vector_extract (v2f64 VR128:$src),
1640 (iPTR 0))), addr:$dst)]>;
1642 // v2f64 extract element 1 is always custom lowered to unpack high to low
1643 // and extract element 0 so the non-store version isn't too horrible.
1644 def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
1645 "movhpd\t{$src, $dst|$dst, $src}",
1646 [(store (f64 (vector_extract
1647 (v2f64 (unpckh VR128:$src, (undef))),
1648 (iPTR 0))), addr:$dst)]>;
1650 // SSE2 instructions without OpSize prefix
1651 def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1652 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1653 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1654 TB, Requires<[HasSSE2]>;
1655 def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1656 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1657 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1658 (bitconvert (memopv2i64 addr:$src))))]>,
1659 TB, Requires<[HasSSE2]>;
1661 // SSE2 instructions with XS prefix
1662 def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1663 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1664 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1665 XS, Requires<[HasSSE2]>;
1666 def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1667 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1668 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1669 (bitconvert (memopv2i64 addr:$src))))]>,
1670 XS, Requires<[HasSSE2]>;
1672 def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1673 "cvtps2dq\t{$src, $dst|$dst, $src}",
1674 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
1675 def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1676 "cvtps2dq\t{$src, $dst|$dst, $src}",
1677 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1678 (memop addr:$src)))]>;
1679 // SSE2 packed instructions with XS prefix
1680 def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1681 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1682 def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1683 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1685 def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1686 "cvttps2dq\t{$src, $dst|$dst, $src}",
1688 (int_x86_sse2_cvttps2dq VR128:$src))]>,
1689 XS, Requires<[HasSSE2]>;
1690 def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1691 "cvttps2dq\t{$src, $dst|$dst, $src}",
1692 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1693 (memop addr:$src)))]>,
1694 XS, Requires<[HasSSE2]>;
1696 // SSE2 packed instructions with XD prefix
1697 def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1698 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1699 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1700 XD, Requires<[HasSSE2]>;
1701 def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1702 "cvtpd2dq\t{$src, $dst|$dst, $src}",
1703 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1704 (memop addr:$src)))]>,
1705 XD, Requires<[HasSSE2]>;
1707 def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1708 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1709 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
1710 def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
1711 "cvttpd2dq\t{$src, $dst|$dst, $src}",
1712 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1713 (memop addr:$src)))]>;
1715 // SSE2 instructions without OpSize prefix
1716 def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1717 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1718 def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1719 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1721 def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1722 "cvtps2pd\t{$src, $dst|$dst, $src}",
1723 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1724 TB, Requires<[HasSSE2]>;
1725 def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1726 "cvtps2pd\t{$src, $dst|$dst, $src}",
1727 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1728 (load addr:$src)))]>,
1729 TB, Requires<[HasSSE2]>;
1731 def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1732 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1733 def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1734 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1737 def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1738 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1739 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
1740 def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1741 "cvtpd2ps\t{$src, $dst|$dst, $src}",
1742 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1743 (memop addr:$src)))]>;
1745 // Match intrinsics which expect XMM operand(s).
1746 // Aliases for intrinsics
1747 let Constraints = "$src1 = $dst" in {
1748 def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
1749 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
1750 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1751 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1753 def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
1754 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
1755 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
1756 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1757 (loadi32 addr:$src2)))]>;
1758 def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
1759 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1760 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1761 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1763 def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
1764 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
1765 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
1766 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1767 (load addr:$src2)))]>;
1768 def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
1769 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
1770 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1771 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1772 VR128:$src2))]>, XS,
1773 Requires<[HasSSE2]>;
1774 def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
1775 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
1776 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
1777 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1778 (load addr:$src2)))]>, XS,
1779 Requires<[HasSSE2]>;
1784 /// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1786 /// In addition, we also have a special variant of the scalar form here to
1787 /// represent the associated intrinsic operation. This form is unlike the
1788 /// plain scalar form, in that it takes an entire vector (instead of a
1789 /// scalar) and leaves the top elements undefined.
1791 /// And, we have a special variant form for a full-vector intrinsic form.
1793 /// These four forms can each have a reg or a mem operand, so there are a
1794 /// total of eight "instructions".
1796 multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1800 bit Commutable = 0> {
1801 // Scalar operation, reg.
1802 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
1803 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1804 [(set FR64:$dst, (OpNode FR64:$src))]> {
1805 let isCommutable = Commutable;
1808 // Scalar operation, mem.
1809 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
1810 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1811 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1813 // Vector operation, reg.
1814 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1815 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1816 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1817 let isCommutable = Commutable;
1820 // Vector operation, mem.
1821 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1822 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1823 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
1825 // Intrinsic operation, reg.
1826 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1827 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1828 [(set VR128:$dst, (F64Int VR128:$src))]> {
1829 let isCommutable = Commutable;
1832 // Intrinsic operation, mem.
1833 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
1834 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
1835 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1837 // Vector intrinsic operation, reg
1838 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1839 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1840 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1841 let isCommutable = Commutable;
1844 // Vector intrinsic operation, mem
1845 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1846 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
1847 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
1851 defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1852 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1854 // There is no f64 version of the reciprocal approximation instructions.
1856 //===---------------------------------------------------------------------===//
1857 // SSE integer instructions
1858 let ExeDomain = SSEPackedInt in {
1860 // Move Instructions
1861 let neverHasSideEffects = 1 in
1862 def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1863 "movdqa\t{$src, $dst|$dst, $src}", []>;
1864 let canFoldAsLoad = 1, mayLoad = 1 in
1865 def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1866 "movdqa\t{$src, $dst|$dst, $src}",
1867 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
1869 def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1870 "movdqa\t{$src, $dst|$dst, $src}",
1871 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
1872 let canFoldAsLoad = 1, mayLoad = 1 in
1873 def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1874 "movdqu\t{$src, $dst|$dst, $src}",
1875 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
1876 XS, Requires<[HasSSE2]>;
1878 def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1879 "movdqu\t{$src, $dst|$dst, $src}",
1880 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
1881 XS, Requires<[HasSSE2]>;
1883 // Intrinsic forms of MOVDQU load and store
1884 let canFoldAsLoad = 1 in
1885 def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
1886 "movdqu\t{$src, $dst|$dst, $src}",
1887 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1888 XS, Requires<[HasSSE2]>;
1889 def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
1890 "movdqu\t{$src, $dst|$dst, $src}",
1891 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1892 XS, Requires<[HasSSE2]>;
1894 let Constraints = "$src1 = $dst" in {
1896 multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1897 bit Commutable = 0> {
1898 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1899 (ins VR128:$src1, VR128:$src2),
1900 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1901 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1902 let isCommutable = Commutable;
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
1912 multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1914 Intrinsic IntId, Intrinsic IntId2> {
1915 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1916 (ins VR128:$src1, VR128:$src2),
1917 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1918 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
1919 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1920 (ins VR128:$src1, i128mem:$src2),
1921 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1922 [(set VR128:$dst, (IntId VR128:$src1,
1923 (bitconvert (memopv2i64 addr:$src2))))]>;
1924 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
1925 (ins VR128:$src1, i32i8imm:$src2),
1926 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1927 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1930 /// PDI_binop_rm - Simple SSE2 binary operator.
1931 multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1932 ValueType OpVT, bit Commutable = 0> {
1933 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1934 (ins VR128:$src1, VR128:$src2),
1935 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1936 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1937 let isCommutable = Commutable;
1939 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1940 (ins VR128:$src1, i128mem:$src2),
1941 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1942 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
1943 (bitconvert (memopv2i64 addr:$src2)))))]>;
1946 /// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1948 /// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1949 /// to collapse (bitconvert VT to VT) into its operand.
1951 multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1952 bit Commutable = 0> {
1953 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1954 (ins VR128:$src1, VR128:$src2),
1955 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1956 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1957 let isCommutable = Commutable;
1959 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1960 (ins VR128:$src1, i128mem:$src2),
1961 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1962 [(set VR128:$dst, (OpNode VR128:$src1,
1963 (memopv2i64 addr:$src2)))]>;
1966 } // Constraints = "$src1 = $dst"
1967 } // ExeDomain = SSEPackedInt
1969 // 128-bit Integer Arithmetic
1971 defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1972 defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1973 defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1974 defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1976 defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1977 defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1978 defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1979 defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1981 defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1982 defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1983 defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1984 defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1986 defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1987 defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1988 defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1989 defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1991 defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1993 defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1994 defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1995 defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1997 defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1999 defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
2000 defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
2003 defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
2004 defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
2005 defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
2006 defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
2007 defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
2010 defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
2011 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
2012 defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
2013 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
2014 defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2015 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
2017 defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2018 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2019 defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2020 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
2021 defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
2022 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
2024 defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2025 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
2026 defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
2027 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
2029 // 128-bit logical shifts.
2030 let Constraints = "$src1 = $dst", neverHasSideEffects = 1,
2031 ExeDomain = SSEPackedInt in {
2032 def PSLLDQri : PDIi8<0x73, MRM7r,
2033 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2034 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
2035 def PSRLDQri : PDIi8<0x73, MRM3r,
2036 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
2037 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
2038 // PSRADQri doesn't exist in SSE[1-3].
2041 let Predicates = [HasSSE2] in {
2042 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
2043 (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2044 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
2045 (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2046 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2047 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2048 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2049 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
2050 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
2051 (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
2053 // Shift up / down and insert zero's.
2054 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
2055 (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2056 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
2057 (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
2061 defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2062 defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
2063 defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2065 let Constraints = "$src1 = $dst", ExeDomain = SSEPackedInt in {
2066 def PANDNrr : PDI<0xDF, MRMSrcReg,
2067 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2068 "pandn\t{$src2, $dst|$dst, $src2}",
2069 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2072 def PANDNrm : PDI<0xDF, MRMSrcMem,
2073 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2074 "pandn\t{$src2, $dst|$dst, $src2}",
2075 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2076 (memopv2i64 addr:$src2))))]>;
2079 // SSE2 Integer comparison
2080 defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2081 defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2082 defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2083 defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2084 defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2085 defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2087 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
2088 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
2089 def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
2090 (PCMPEQBrm VR128:$src1, addr:$src2)>;
2091 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
2092 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
2093 def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
2094 (PCMPEQWrm VR128:$src1, addr:$src2)>;
2095 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
2096 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
2097 def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
2098 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2100 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
2101 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
2102 def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
2103 (PCMPGTBrm VR128:$src1, addr:$src2)>;
2104 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
2105 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
2106 def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
2107 (PCMPGTWrm VR128:$src1, addr:$src2)>;
2108 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
2109 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
2110 def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
2111 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2114 // Pack instructions
2115 defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2116 defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2117 defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2119 let ExeDomain = SSEPackedInt in {
2121 // Shuffle and unpack instructions
2122 let AddedComplexity = 5 in {
2123 def PSHUFDri : PDIi8<0x70, MRMSrcReg,
2124 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2125 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2126 [(set VR128:$dst, (v4i32 (pshufd:$src2
2127 VR128:$src1, (undef))))]>;
2128 def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
2129 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2130 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2131 [(set VR128:$dst, (v4i32 (pshufd:$src2
2132 (bc_v4i32 (memopv2i64 addr:$src1)),
2136 // SSE2 with ImmT == Imm8 and XS prefix.
2137 def PSHUFHWri : Ii8<0x70, MRMSrcReg,
2138 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2139 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2140 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2142 XS, Requires<[HasSSE2]>;
2143 def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
2144 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2145 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2146 [(set VR128:$dst, (v8i16 (pshufhw:$src2
2147 (bc_v8i16 (memopv2i64 addr:$src1)),
2149 XS, Requires<[HasSSE2]>;
2151 // SSE2 with ImmT == Imm8 and XD prefix.
2152 def PSHUFLWri : Ii8<0x70, MRMSrcReg,
2153 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
2154 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2155 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2157 XD, Requires<[HasSSE2]>;
2158 def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
2159 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
2160 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2161 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2162 (bc_v8i16 (memopv2i64 addr:$src1)),
2164 XD, Requires<[HasSSE2]>;
2166 // Unpack instructions
2167 multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2168 PatFrag unp_frag, PatFrag bc_frag> {
2169 def rr : PDI<opc, MRMSrcReg,
2170 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2171 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2172 [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2173 def rm : PDI<opc, MRMSrcMem,
2174 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2175 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2176 [(set VR128:$dst, (unp_frag VR128:$src1,
2177 (bc_frag (memopv2i64
2181 let Constraints = "$src1 = $dst" in {
2182 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2183 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2184 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2186 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2187 /// knew to collapse (bitconvert VT to VT) into its operand.
2188 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
2189 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2190 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2192 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
2193 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
2194 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2195 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
2197 (v2i64 (unpckl VR128:$src1,
2198 (memopv2i64 addr:$src2))))]>;
2200 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2201 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2202 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2204 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2205 /// knew to collapse (bitconvert VT to VT) into its operand.
2206 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
2207 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2208 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2210 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
2211 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
2212 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2213 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
2215 (v2i64 (unpckh VR128:$src1,
2216 (memopv2i64 addr:$src2))))]>;
2220 def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
2221 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
2222 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2223 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2225 let Constraints = "$src1 = $dst" in {
2226 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
2227 (outs VR128:$dst), (ins VR128:$src1,
2228 GR32:$src2, i32i8imm:$src3),
2229 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2231 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
2232 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
2233 (outs VR128:$dst), (ins VR128:$src1,
2234 i16mem:$src2, i32i8imm:$src3),
2235 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2237 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2242 def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
2243 "pmovmskb\t{$src, $dst|$dst, $src}",
2244 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2246 // Conditional store
2248 def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2249 "maskmovdqu\t{$mask, $src|$src, $mask}",
2250 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
2253 def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2254 "maskmovdqu\t{$mask, $src|$src, $mask}",
2255 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2257 } // ExeDomain = SSEPackedInt
2259 // Non-temporal stores
2260 def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2261 "movntpd\t{$src, $dst|$dst, $src}",
2262 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
2263 let ExeDomain = SSEPackedInt in
2264 def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2265 "movntdq\t{$src, $dst|$dst, $src}",
2266 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2267 def MOVNTImr_Int : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2268 "movnti\t{$src, $dst|$dst, $src}",
2269 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2270 TB, Requires<[HasSSE2]>;
2272 let AddedComplexity = 400 in { // Prefer non-temporal versions
2273 def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2274 "movntpd\t{$src, $dst|$dst, $src}",
2275 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
2277 let ExeDomain = SSEPackedInt in
2278 def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2279 "movntdq\t{$src, $dst|$dst, $src}",
2280 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
2284 def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
2285 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
2286 TB, Requires<[HasSSE2]>;
2288 // Load, store, and memory fence
2289 def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
2290 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
2291 def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
2292 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2294 // Pause. This "instruction" is encoded as "rep; nop", so even though it
2295 // was introduced with SSE2, it's backward compatible.
2296 def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
2298 //TODO: custom lower this so as to never even generate the noop
2299 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2301 def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2302 def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
2303 def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
2306 // Alias instructions that map zero vector to pxor / xorp* for sse.
2307 // We set canFoldAsLoad because this can be converted to a constant-pool
2308 // load of an all-ones value if folding it would be beneficial.
2309 let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
2310 isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
2311 // FIXME: Change encoding to pseudo.
2312 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
2313 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
2315 def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2316 "movd\t{$src, $dst|$dst, $src}",
2318 (v4i32 (scalar_to_vector GR32:$src)))]>;
2319 def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2320 "movd\t{$src, $dst|$dst, $src}",
2322 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2324 def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
2325 "movd\t{$src, $dst|$dst, $src}",
2326 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2328 def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
2329 "movd\t{$src, $dst|$dst, $src}",
2330 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2332 // SSE2 instructions with XS prefix
2333 def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2334 "movq\t{$src, $dst|$dst, $src}",
2336 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2337 Requires<[HasSSE2]>;
2338 def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2339 "movq\t{$src, $dst|$dst, $src}",
2340 [(store (i64 (vector_extract (v2i64 VR128:$src),
2341 (iPTR 0))), addr:$dst)]>;
2343 def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
2344 (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
2346 def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
2347 "movd\t{$src, $dst|$dst, $src}",
2348 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2350 def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
2351 "movd\t{$src, $dst|$dst, $src}",
2352 [(store (i32 (vector_extract (v4i32 VR128:$src),
2353 (iPTR 0))), addr:$dst)]>;
2355 def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
2356 "movd\t{$src, $dst|$dst, $src}",
2357 [(set GR32:$dst, (bitconvert FR32:$src))]>;
2358 def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
2359 "movd\t{$src, $dst|$dst, $src}",
2360 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2362 // Store / copy lower 64-bits of a XMM register.
2363 def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
2364 "movq\t{$src, $dst|$dst, $src}",
2365 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2367 // movd / movq to XMM register zero-extends
2368 let AddedComplexity = 15 in {
2369 def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
2370 "movd\t{$src, $dst|$dst, $src}",
2371 [(set VR128:$dst, (v4i32 (X86vzmovl
2372 (v4i32 (scalar_to_vector GR32:$src)))))]>;
2373 // This is X86-64 only.
2374 def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2375 "mov{d|q}\t{$src, $dst|$dst, $src}",
2376 [(set VR128:$dst, (v2i64 (X86vzmovl
2377 (v2i64 (scalar_to_vector GR64:$src)))))]>;
2380 let AddedComplexity = 20 in {
2381 def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
2382 "movd\t{$src, $dst|$dst, $src}",
2384 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
2385 (loadi32 addr:$src))))))]>;
2387 def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2388 (MOVZDI2PDIrm addr:$src)>;
2389 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2390 (MOVZDI2PDIrm addr:$src)>;
2391 def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2392 (MOVZDI2PDIrm addr:$src)>;
2394 def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
2395 "movq\t{$src, $dst|$dst, $src}",
2397 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
2398 (loadi64 addr:$src))))))]>, XS,
2399 Requires<[HasSSE2]>;
2401 def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2402 (MOVZQI2PQIrm addr:$src)>;
2403 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2404 (MOVZQI2PQIrm addr:$src)>;
2405 def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
2408 // Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2409 // IA32 document. movq xmm1, xmm2 does clear the high bits.
2410 let AddedComplexity = 15 in
2411 def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2412 "movq\t{$src, $dst|$dst, $src}",
2413 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
2414 XS, Requires<[HasSSE2]>;
2416 let AddedComplexity = 20 in {
2417 def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2418 "movq\t{$src, $dst|$dst, $src}",
2419 [(set VR128:$dst, (v2i64 (X86vzmovl
2420 (loadv2i64 addr:$src))))]>,
2421 XS, Requires<[HasSSE2]>;
2423 def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2424 (MOVZPQILo2PQIrm addr:$src)>;
2427 // Instructions for the disassembler
2428 // xr = XMM register
2431 def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2432 "movq\t{$src, $dst|$dst, $src}", []>, XS;
2434 //===---------------------------------------------------------------------===//
2435 // SSE3 Instructions
2436 //===---------------------------------------------------------------------===//
2438 // Conversion Instructions
2439 def CVTPD2DQrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2440 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2441 def CVTPD2DQrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2442 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
2443 def CVTDQ2PDrm : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2444 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2445 def CVTDQ2PDrr : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2446 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
2448 // Move Instructions
2449 def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2450 "movshdup\t{$src, $dst|$dst, $src}",
2451 [(set VR128:$dst, (v4f32 (movshdup
2452 VR128:$src, (undef))))]>;
2453 def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2454 "movshdup\t{$src, $dst|$dst, $src}",
2455 [(set VR128:$dst, (movshdup
2456 (memopv4f32 addr:$src), (undef)))]>;
2458 def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2459 "movsldup\t{$src, $dst|$dst, $src}",
2460 [(set VR128:$dst, (v4f32 (movsldup
2461 VR128:$src, (undef))))]>;
2462 def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
2463 "movsldup\t{$src, $dst|$dst, $src}",
2464 [(set VR128:$dst, (movsldup
2465 (memopv4f32 addr:$src), (undef)))]>;
2467 def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2468 "movddup\t{$src, $dst|$dst, $src}",
2469 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
2470 def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2471 "movddup\t{$src, $dst|$dst, $src}",
2473 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2476 def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2478 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2480 let AddedComplexity = 5 in {
2481 def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
2482 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2483 def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2484 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2485 def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2486 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2487 def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2488 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2492 let Constraints = "$src1 = $dst" in {
2493 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
2494 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2495 "addsubps\t{$src2, $dst|$dst, $src2}",
2496 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2498 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
2499 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2500 "addsubps\t{$src2, $dst|$dst, $src2}",
2501 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2502 (memop addr:$src2)))]>;
2503 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
2504 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2505 "addsubpd\t{$src2, $dst|$dst, $src2}",
2506 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2508 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
2509 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2510 "addsubpd\t{$src2, $dst|$dst, $src2}",
2511 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2512 (memop addr:$src2)))]>;
2515 def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2516 "lddqu\t{$src, $dst|$dst, $src}",
2517 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2520 class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2521 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2522 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2523 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2524 class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2525 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2526 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2527 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
2528 class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
2529 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2530 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2531 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2532 class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
2533 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
2534 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2535 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
2537 let Constraints = "$src1 = $dst" in {
2538 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2539 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2540 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2541 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2542 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2543 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2544 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2545 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2548 // Thread synchronization
2549 def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
2550 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
2551 def MWAIT : I<0x01, MRM_C9, (outs), (ins), "mwait",
2552 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2554 // vector_shuffle v1, <undef> <1, 1, 3, 3>
2555 let AddedComplexity = 15 in
2556 def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
2557 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2558 let AddedComplexity = 20 in
2559 def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2560 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2562 // vector_shuffle v1, <undef> <0, 0, 2, 2>
2563 let AddedComplexity = 15 in
2564 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
2565 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2566 let AddedComplexity = 20 in
2567 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
2568 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2570 //===---------------------------------------------------------------------===//
2571 // SSSE3 Instructions
2572 //===---------------------------------------------------------------------===//
2574 /// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
2575 multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2576 Intrinsic IntId64, Intrinsic IntId128> {
2577 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2578 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2579 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2581 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2582 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2584 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2586 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2588 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2589 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2592 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2594 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2597 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
2600 /// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
2601 multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2602 Intrinsic IntId64, Intrinsic IntId128> {
2603 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2605 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2606 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2608 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2610 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2613 (bitconvert (memopv4i16 addr:$src))))]>;
2615 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2617 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2618 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2621 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2623 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2626 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
2629 /// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
2630 multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2631 Intrinsic IntId64, Intrinsic IntId128> {
2632 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2634 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2635 [(set VR64:$dst, (IntId64 VR64:$src))]>;
2637 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2639 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2642 (bitconvert (memopv2i32 addr:$src))))]>;
2644 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2646 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2647 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2650 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2652 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2655 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
2658 defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2659 int_x86_ssse3_pabs_b,
2660 int_x86_ssse3_pabs_b_128>;
2661 defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2662 int_x86_ssse3_pabs_w,
2663 int_x86_ssse3_pabs_w_128>;
2664 defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2665 int_x86_ssse3_pabs_d,
2666 int_x86_ssse3_pabs_d_128>;
2668 /// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
2669 let Constraints = "$src1 = $dst" in {
2670 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2671 Intrinsic IntId64, Intrinsic IntId128,
2672 bit Commutable = 0> {
2673 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2674 (ins VR64:$src1, VR64:$src2),
2675 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2676 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2677 let isCommutable = Commutable;
2679 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2680 (ins VR64:$src1, i64mem:$src2),
2681 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2683 (IntId64 VR64:$src1,
2684 (bitconvert (memopv8i8 addr:$src2))))]>;
2686 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2687 (ins VR128:$src1, VR128:$src2),
2688 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2689 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2691 let isCommutable = Commutable;
2693 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2694 (ins VR128:$src1, i128mem:$src2),
2695 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2697 (IntId128 VR128:$src1,
2698 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2702 /// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
2703 let Constraints = "$src1 = $dst" in {
2704 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2705 Intrinsic IntId64, Intrinsic IntId128,
2706 bit Commutable = 0> {
2707 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2708 (ins VR64:$src1, VR64:$src2),
2709 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2710 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2711 let isCommutable = Commutable;
2713 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2714 (ins VR64:$src1, i64mem:$src2),
2715 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2717 (IntId64 VR64:$src1,
2718 (bitconvert (memopv4i16 addr:$src2))))]>;
2720 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2721 (ins VR128:$src1, VR128:$src2),
2722 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2723 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2725 let isCommutable = Commutable;
2727 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2728 (ins VR128:$src1, i128mem:$src2),
2729 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2731 (IntId128 VR128:$src1,
2732 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2736 /// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
2737 let Constraints = "$src1 = $dst" in {
2738 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2739 Intrinsic IntId64, Intrinsic IntId128,
2740 bit Commutable = 0> {
2741 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2742 (ins VR64:$src1, VR64:$src2),
2743 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2744 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2745 let isCommutable = Commutable;
2747 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2748 (ins VR64:$src1, i64mem:$src2),
2749 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2751 (IntId64 VR64:$src1,
2752 (bitconvert (memopv2i32 addr:$src2))))]>;
2754 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2755 (ins VR128:$src1, VR128:$src2),
2756 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2757 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2759 let isCommutable = Commutable;
2761 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2762 (ins VR128:$src1, i128mem:$src2),
2763 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2765 (IntId128 VR128:$src1,
2766 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2770 let ImmT = NoImm in { // None of these have i8 immediate fields.
2771 defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2772 int_x86_ssse3_phadd_w,
2773 int_x86_ssse3_phadd_w_128>;
2774 defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2775 int_x86_ssse3_phadd_d,
2776 int_x86_ssse3_phadd_d_128>;
2777 defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2778 int_x86_ssse3_phadd_sw,
2779 int_x86_ssse3_phadd_sw_128>;
2780 defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2781 int_x86_ssse3_phsub_w,
2782 int_x86_ssse3_phsub_w_128>;
2783 defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2784 int_x86_ssse3_phsub_d,
2785 int_x86_ssse3_phsub_d_128>;
2786 defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2787 int_x86_ssse3_phsub_sw,
2788 int_x86_ssse3_phsub_sw_128>;
2789 defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2790 int_x86_ssse3_pmadd_ub_sw,
2791 int_x86_ssse3_pmadd_ub_sw_128>;
2792 defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2793 int_x86_ssse3_pmul_hr_sw,
2794 int_x86_ssse3_pmul_hr_sw_128, 1>;
2796 defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2797 int_x86_ssse3_pshuf_b,
2798 int_x86_ssse3_pshuf_b_128>;
2799 defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2800 int_x86_ssse3_psign_b,
2801 int_x86_ssse3_psign_b_128>;
2802 defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2803 int_x86_ssse3_psign_w,
2804 int_x86_ssse3_psign_w_128>;
2805 defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
2806 int_x86_ssse3_psign_d,
2807 int_x86_ssse3_psign_d_128>;
2810 // palignr patterns.
2811 let Constraints = "$src1 = $dst" in {
2812 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2813 (ins VR64:$src1, VR64:$src2, i8imm:$src3),
2814 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2816 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
2817 (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
2818 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2821 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2822 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
2823 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2825 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
2826 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
2827 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2831 let AddedComplexity = 5 in {
2833 def : Pat<(v1i64 (palign:$src3 VR64:$src1, VR64:$src2)),
2834 (PALIGNR64rr VR64:$src2, VR64:$src1,
2835 (SHUFFLE_get_palign_imm VR64:$src3))>,
2836 Requires<[HasSSSE3]>;
2837 def : Pat<(v2i32 (palign:$src3 VR64:$src1, VR64:$src2)),
2838 (PALIGNR64rr VR64:$src2, VR64:$src1,
2839 (SHUFFLE_get_palign_imm VR64:$src3))>,
2840 Requires<[HasSSSE3]>;
2841 def : Pat<(v2f32 (palign:$src3 VR64:$src1, VR64:$src2)),
2842 (PALIGNR64rr VR64:$src2, VR64:$src1,
2843 (SHUFFLE_get_palign_imm VR64:$src3))>,
2844 Requires<[HasSSSE3]>;
2845 def : Pat<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
2846 (PALIGNR64rr VR64:$src2, VR64:$src1,
2847 (SHUFFLE_get_palign_imm VR64:$src3))>,
2848 Requires<[HasSSSE3]>;
2849 def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
2850 (PALIGNR64rr VR64:$src2, VR64:$src1,
2851 (SHUFFLE_get_palign_imm VR64:$src3))>,
2852 Requires<[HasSSSE3]>;
2854 def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
2855 (PALIGNR128rr VR128:$src2, VR128:$src1,
2856 (SHUFFLE_get_palign_imm VR128:$src3))>,
2857 Requires<[HasSSSE3]>;
2858 def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
2859 (PALIGNR128rr VR128:$src2, VR128:$src1,
2860 (SHUFFLE_get_palign_imm VR128:$src3))>,
2861 Requires<[HasSSSE3]>;
2862 def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
2863 (PALIGNR128rr VR128:$src2, VR128:$src1,
2864 (SHUFFLE_get_palign_imm VR128:$src3))>,
2865 Requires<[HasSSSE3]>;
2866 def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
2867 (PALIGNR128rr VR128:$src2, VR128:$src1,
2868 (SHUFFLE_get_palign_imm VR128:$src3))>,
2869 Requires<[HasSSSE3]>;
2872 def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2873 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2874 def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2875 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2877 //===---------------------------------------------------------------------===//
2878 // Non-Instruction Patterns
2879 //===---------------------------------------------------------------------===//
2881 // extload f32 -> f64. This matches load+fextend because we have a hack in
2882 // the isel (PreprocessForFPConvert) that can introduce loads after dag
2884 // Since these loads aren't folded into the fextend, we have to match it
2886 let Predicates = [HasSSE2] in
2887 def : Pat<(fextend (loadf32 addr:$src)),
2888 (CVTSS2SDrm addr:$src)>;
2891 let Predicates = [HasSSE2] in {
2892 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2893 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2894 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2895 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2896 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2897 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2898 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2899 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2900 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2901 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2902 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2903 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2904 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2905 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2906 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2907 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2908 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2909 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2910 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2911 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2912 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2913 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2914 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2915 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2916 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2917 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2918 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2919 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2920 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2921 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2924 // Move scalar to XMM zero-extended
2925 // movd to XMM register zero-extends
2926 let AddedComplexity = 15 in {
2927 // Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
2928 def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
2929 (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
2930 def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
2931 (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
2932 def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
2933 (MOVSSrr (v4f32 (V_SET0PS)),
2934 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
2935 def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
2936 (MOVSSrr (v4i32 (V_SET0PI)),
2937 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
2940 // Splat v2f64 / v2i64
2941 let AddedComplexity = 10 in {
2942 def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
2943 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2944 def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
2945 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2946 def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
2947 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2948 def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
2949 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2952 // Special unary SHUFPSrri case.
2953 def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2954 (SHUFPSrri VR128:$src1, VR128:$src1,
2955 (SHUFFLE_get_shuf_imm VR128:$src3))>;
2956 let AddedComplexity = 5 in
2957 def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2958 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2959 Requires<[HasSSE2]>;
2960 // Special unary SHUFPDrri case.
2961 def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
2962 (SHUFPDrri VR128:$src1, VR128:$src1,
2963 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2964 Requires<[HasSSE2]>;
2965 // Special unary SHUFPDrri case.
2966 def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
2967 (SHUFPDrri VR128:$src1, VR128:$src1,
2968 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2969 Requires<[HasSSE2]>;
2970 // Unary v4f32 shuffle with PSHUF* in order to fold a load.
2971 def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2972 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2973 Requires<[HasSSE2]>;
2975 // Special binary v4i32 shuffle cases with SHUFPS.
2976 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
2977 (SHUFPSrri VR128:$src1, VR128:$src2,
2978 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2979 Requires<[HasSSE2]>;
2980 def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
2981 (SHUFPSrmi VR128:$src1, addr:$src2,
2982 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2983 Requires<[HasSSE2]>;
2984 // Special binary v2i64 shuffle cases using SHUFPDrri.
2985 def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
2986 (SHUFPDrri VR128:$src1, VR128:$src2,
2987 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2988 Requires<[HasSSE2]>;
2990 // vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
2991 let AddedComplexity = 15 in {
2992 def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
2993 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2994 Requires<[OptForSpeed, HasSSE2]>;
2995 def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
2996 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2997 Requires<[OptForSpeed, HasSSE2]>;
2999 let AddedComplexity = 10 in {
3000 def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
3001 (UNPCKLPSrr VR128:$src, VR128:$src)>;
3002 def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
3003 (PUNPCKLBWrr VR128:$src, VR128:$src)>;
3004 def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
3005 (PUNPCKLWDrr VR128:$src, VR128:$src)>;
3006 def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
3007 (PUNPCKLDQrr VR128:$src, VR128:$src)>;
3010 // vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
3011 let AddedComplexity = 15 in {
3012 def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
3013 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3014 Requires<[OptForSpeed, HasSSE2]>;
3015 def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
3016 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
3017 Requires<[OptForSpeed, HasSSE2]>;
3019 let AddedComplexity = 10 in {
3020 def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
3021 (UNPCKHPSrr VR128:$src, VR128:$src)>;
3022 def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
3023 (PUNPCKHBWrr VR128:$src, VR128:$src)>;
3024 def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
3025 (PUNPCKHWDrr VR128:$src, VR128:$src)>;
3026 def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
3027 (PUNPCKHDQrr VR128:$src, VR128:$src)>;
3030 let AddedComplexity = 20 in {
3031 // vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
3032 def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
3033 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
3035 // vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
3036 def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
3037 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
3039 // vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
3040 def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
3041 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3042 def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
3043 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
3046 let AddedComplexity = 20 in {
3047 // vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
3048 def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
3049 (MOVLPSrm VR128:$src1, addr:$src2)>;
3050 def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
3051 (MOVLPDrm VR128:$src1, addr:$src2)>;
3052 def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
3053 (MOVLPSrm VR128:$src1, addr:$src2)>;
3054 def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
3055 (MOVLPDrm VR128:$src1, addr:$src2)>;
3058 // (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3059 def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3060 (MOVLPSmr addr:$src1, VR128:$src2)>;
3061 def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3062 (MOVLPDmr addr:$src1, VR128:$src2)>;
3063 def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3065 (MOVLPSmr addr:$src1, VR128:$src2)>;
3066 def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
3067 (MOVLPDmr addr:$src1, VR128:$src2)>;
3069 let AddedComplexity = 15 in {
3070 // Setting the lowest element in the vector.
3071 def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
3072 (MOVSSrr (v4i32 VR128:$src1),
3073 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
3074 def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
3075 (MOVSDrr (v2i64 VR128:$src1),
3076 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
3078 // vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
3079 def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
3080 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3081 Requires<[HasSSE2]>;
3082 def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
3083 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
3084 Requires<[HasSSE2]>;
3087 // vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3088 // fall back to this for SSE1)
3089 def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
3090 (SHUFPSrri VR128:$src2, VR128:$src1,
3091 (SHUFFLE_get_shuf_imm VR128:$src3))>;
3093 // Set lowest element and zero upper elements.
3094 def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
3095 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
3097 // Some special case pandn patterns.
3098 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3100 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3101 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3103 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3104 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3106 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3108 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3109 (memop addr:$src2))),
3110 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3111 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3112 (memop addr:$src2))),
3113 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3114 def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3115 (memop addr:$src2))),
3116 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3118 // vector -> vector casts
3119 def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3120 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3121 def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3122 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3123 def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3124 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3125 def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3126 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
3128 // Use movaps / movups for SSE integer load / store (one byte shorter).
3129 def : Pat<(alignedloadv4i32 addr:$src),
3130 (MOVAPSrm addr:$src)>;
3131 def : Pat<(loadv4i32 addr:$src),
3132 (MOVUPSrm addr:$src)>;
3133 def : Pat<(alignedloadv2i64 addr:$src),
3134 (MOVAPSrm addr:$src)>;
3135 def : Pat<(loadv2i64 addr:$src),
3136 (MOVUPSrm addr:$src)>;
3138 def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3139 (MOVAPSmr addr:$dst, VR128:$src)>;
3140 def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3141 (MOVAPSmr addr:$dst, VR128:$src)>;
3142 def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3143 (MOVAPSmr addr:$dst, VR128:$src)>;
3144 def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3145 (MOVAPSmr addr:$dst, VR128:$src)>;
3146 def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3147 (MOVUPSmr addr:$dst, VR128:$src)>;
3148 def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3149 (MOVUPSmr addr:$dst, VR128:$src)>;
3150 def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3151 (MOVUPSmr addr:$dst, VR128:$src)>;
3152 def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3153 (MOVUPSmr addr:$dst, VR128:$src)>;
3155 //===----------------------------------------------------------------------===//
3156 // SSE4.1 Instructions
3157 //===----------------------------------------------------------------------===//
3159 multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
3162 Intrinsic V2F64Int> {
3163 // Intrinsic operation, reg.
3164 // Vector intrinsic operation, reg
3165 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
3166 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3167 !strconcat(OpcodeStr,
3168 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3169 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3172 // Vector intrinsic operation, mem
3173 def PSm_Int : Ii8<opcps, MRMSrcMem,
3174 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3175 !strconcat(OpcodeStr,
3176 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3178 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
3180 Requires<[HasSSE41]>;
3182 // Vector intrinsic operation, reg
3183 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
3184 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
3185 !strconcat(OpcodeStr,
3186 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3187 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3190 // Vector intrinsic operation, mem
3191 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
3192 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
3193 !strconcat(OpcodeStr,
3194 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3196 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
3200 let Constraints = "$src1 = $dst" in {
3201 multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3205 // Intrinsic operation, reg.
3206 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
3208 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3209 !strconcat(OpcodeStr,
3210 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3212 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3215 // Intrinsic operation, mem.
3216 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3218 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
3219 !strconcat(OpcodeStr,
3220 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3222 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3225 // Intrinsic operation, reg.
3226 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
3228 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3229 !strconcat(OpcodeStr,
3230 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3232 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3235 // Intrinsic operation, mem.
3236 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
3238 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3239 !strconcat(OpcodeStr,
3240 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3242 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3247 // FP round - roundss, roundps, roundsd, roundpd
3248 defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3249 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3250 defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3251 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
3253 // SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3254 multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3255 Intrinsic IntId128> {
3256 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3258 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3259 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3260 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3262 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3265 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3268 defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3269 int_x86_sse41_phminposuw>;
3271 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3272 let Constraints = "$src1 = $dst" in {
3273 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3274 Intrinsic IntId128, bit Commutable = 0> {
3275 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3276 (ins VR128:$src1, VR128:$src2),
3277 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3278 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3280 let isCommutable = Commutable;
3282 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3283 (ins VR128:$src1, i128mem:$src2),
3284 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3286 (IntId128 VR128:$src1,
3287 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3291 defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3292 int_x86_sse41_pcmpeqq, 1>;
3293 defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3294 int_x86_sse41_packusdw, 0>;
3295 defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3296 int_x86_sse41_pminsb, 1>;
3297 defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3298 int_x86_sse41_pminsd, 1>;
3299 defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3300 int_x86_sse41_pminud, 1>;
3301 defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3302 int_x86_sse41_pminuw, 1>;
3303 defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3304 int_x86_sse41_pmaxsb, 1>;
3305 defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3306 int_x86_sse41_pmaxsd, 1>;
3307 defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3308 int_x86_sse41_pmaxud, 1>;
3309 defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3310 int_x86_sse41_pmaxuw, 1>;
3312 defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3314 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3315 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3316 def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3317 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3319 /// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3320 let Constraints = "$src1 = $dst" in {
3321 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3322 SDNode OpNode, Intrinsic IntId128,
3323 bit Commutable = 0> {
3324 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3325 (ins VR128:$src1, VR128:$src2),
3326 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3327 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3328 VR128:$src2))]>, OpSize {
3329 let isCommutable = Commutable;
3331 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3332 (ins VR128:$src1, VR128:$src2),
3333 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3334 [(set VR128:$dst, (IntId128 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}"),
3342 (OpVT (OpNode VR128:$src1, (memop addr:$src2))))]>, OpSize;
3343 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3344 (ins VR128:$src1, i128mem:$src2),
3345 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3347 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
3352 /// SS48I_binop_rm - Simple SSE41 binary operator.
3353 let Constraints = "$src1 = $dst" in {
3354 multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
3355 ValueType OpVT, bit Commutable = 0> {
3356 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3357 (ins VR128:$src1, VR128:$src2),
3358 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3359 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
3361 let isCommutable = Commutable;
3363 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3364 (ins VR128:$src1, i128mem:$src2),
3365 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3366 [(set VR128:$dst, (OpNode VR128:$src1,
3367 (bc_v4i32 (memopv2i64 addr:$src2))))]>,
3372 defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, 1>;
3374 /// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
3375 let Constraints = "$src1 = $dst" in {
3376 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3377 Intrinsic IntId128, bit Commutable = 0> {
3378 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3379 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3380 !strconcat(OpcodeStr,
3381 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3383 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3385 let isCommutable = Commutable;
3387 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3388 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3389 !strconcat(OpcodeStr,
3390 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3392 (IntId128 VR128:$src1,
3393 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3398 defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3399 int_x86_sse41_blendps, 0>;
3400 defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3401 int_x86_sse41_blendpd, 0>;
3402 defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3403 int_x86_sse41_pblendw, 0>;
3404 defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3405 int_x86_sse41_dpps, 1>;
3406 defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3407 int_x86_sse41_dppd, 1>;
3408 defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
3409 int_x86_sse41_mpsadbw, 0>;
3412 /// SS41I_ternary_int - SSE 4.1 ternary operator
3413 let Uses = [XMM0], Constraints = "$src1 = $dst" in {
3414 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3415 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3416 (ins VR128:$src1, VR128:$src2),
3417 !strconcat(OpcodeStr,
3418 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3419 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3422 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3423 (ins VR128:$src1, i128mem:$src2),
3424 !strconcat(OpcodeStr,
3425 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3428 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3432 defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3433 defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3434 defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3437 multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3438 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3439 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3440 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3442 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3443 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3445 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3449 defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3450 defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3451 defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3452 defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3453 defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3454 defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3456 // Common patterns involving scalar load.
3457 def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3458 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3459 def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3460 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3462 def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3463 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3464 def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3465 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3467 def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3468 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3469 def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3470 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3472 def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3473 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3474 def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3475 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3477 def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3478 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3479 def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3480 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3482 def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3483 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3484 def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3485 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3488 multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3489 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3490 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3491 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3493 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3494 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3496 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3500 defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3501 defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3502 defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3503 defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3505 // Common patterns involving scalar load
3506 def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
3507 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
3508 def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
3509 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
3511 def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
3512 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
3513 def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
3514 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
3517 multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3518 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3519 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3520 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3522 // Expecting a i16 load any extended to i32 value.
3523 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3524 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3525 [(set VR128:$dst, (IntId (bitconvert
3526 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3530 defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3531 defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
3533 // Common patterns involving scalar load
3534 def : Pat<(int_x86_sse41_pmovsxbq
3535 (bitconvert (v4i32 (X86vzmovl
3536 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3537 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
3539 def : Pat<(int_x86_sse41_pmovzxbq
3540 (bitconvert (v4i32 (X86vzmovl
3541 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
3542 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
3545 /// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3546 multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
3547 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3548 (ins VR128:$src1, i32i8imm:$src2),
3549 !strconcat(OpcodeStr,
3550 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3551 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3553 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3554 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
3555 !strconcat(OpcodeStr,
3556 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3559 // There's an AssertZext in the way of writing the store pattern
3560 // (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3563 defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
3566 /// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3567 multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
3568 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3569 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
3570 !strconcat(OpcodeStr,
3571 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3574 // There's an AssertZext in the way of writing the store pattern
3575 // (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3578 defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3581 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3582 multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
3583 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3584 (ins VR128:$src1, i32i8imm:$src2),
3585 !strconcat(OpcodeStr,
3586 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3588 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
3589 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3590 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
3591 !strconcat(OpcodeStr,
3592 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3593 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3594 addr:$dst)]>, OpSize;
3597 defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
3600 /// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3602 multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
3603 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
3604 (ins VR128:$src1, i32i8imm:$src2),
3605 !strconcat(OpcodeStr,
3606 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3608 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
3610 def mr : SS4AIi8<opc, MRMDestMem, (outs),
3611 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
3612 !strconcat(OpcodeStr,
3613 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3614 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
3615 addr:$dst)]>, OpSize;
3618 defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
3620 // Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3621 def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3624 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3625 Requires<[HasSSE41]>;
3627 let Constraints = "$src1 = $dst" in {
3628 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
3629 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3630 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3631 !strconcat(OpcodeStr,
3632 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3634 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
3635 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3636 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3637 !strconcat(OpcodeStr,
3638 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3640 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3641 imm:$src3))]>, OpSize;
3645 defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3647 let Constraints = "$src1 = $dst" in {
3648 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
3649 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3650 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3651 !strconcat(OpcodeStr,
3652 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3654 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3656 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3657 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3658 !strconcat(OpcodeStr,
3659 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3661 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3662 imm:$src3)))]>, OpSize;
3666 defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3668 // insertps has a few different modes, there's the first two here below which
3669 // are optimized inserts that won't zero arbitrary elements in the destination
3670 // vector. The next one matches the intrinsic and could zero arbitrary elements
3671 // in the target vector.
3672 let Constraints = "$src1 = $dst" in {
3673 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
3674 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3675 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3676 !strconcat(OpcodeStr,
3677 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3679 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
3681 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
3682 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3683 !strconcat(OpcodeStr,
3684 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3686 (X86insrtps VR128:$src1,
3687 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
3688 imm:$src3))]>, OpSize;
3692 defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
3694 def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3695 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3697 // ptest instruction we'll lower to this in X86ISelLowering primarily from
3698 // the intel intrinsic that corresponds to this.
3699 let Defs = [EFLAGS] in {
3700 def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
3701 "ptest \t{$src2, $src1|$src1, $src2}",
3702 [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
3704 def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
3705 "ptest \t{$src2, $src1|$src1, $src2}",
3706 [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
3710 def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3711 "movntdqa\t{$src, $dst|$dst, $src}",
3712 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
3716 //===----------------------------------------------------------------------===//
3717 // SSE4.2 Instructions
3718 //===----------------------------------------------------------------------===//
3720 /// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3721 let Constraints = "$src1 = $dst" in {
3722 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3723 Intrinsic IntId128, bit Commutable = 0> {
3724 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3725 (ins VR128:$src1, VR128:$src2),
3726 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3727 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3729 let isCommutable = Commutable;
3731 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3732 (ins VR128:$src1, i128mem:$src2),
3733 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3735 (IntId128 VR128:$src1,
3736 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3740 defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
3742 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3743 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3744 def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3745 (PCMPGTQrm VR128:$src1, addr:$src2)>;
3747 // crc intrinsic instruction
3748 // This set of instructions are only rm, the only difference is the size
3750 let Constraints = "$src1 = $dst" in {
3751 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
3752 (ins GR32:$src1, i8mem:$src2),
3753 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3755 (int_x86_sse42_crc32_8 GR32:$src1,
3756 (load addr:$src2)))]>;
3757 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
3758 (ins GR32:$src1, GR8:$src2),
3759 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3761 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
3762 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3763 (ins GR32:$src1, i16mem:$src2),
3764 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3766 (int_x86_sse42_crc32_16 GR32:$src1,
3767 (load addr:$src2)))]>,
3769 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3770 (ins GR32:$src1, GR16:$src2),
3771 "crc32{w} \t{$src2, $src1|$src1, $src2}",
3773 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
3775 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3776 (ins GR32:$src1, i32mem:$src2),
3777 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3779 (int_x86_sse42_crc32_32 GR32:$src1,
3780 (load addr:$src2)))]>;
3781 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3782 (ins GR32:$src1, GR32:$src2),
3783 "crc32{l} \t{$src2, $src1|$src1, $src2}",
3785 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
3786 def CRC64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3787 (ins GR64:$src1, i8mem:$src2),
3788 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3790 (int_x86_sse42_crc64_8 GR64:$src1,
3791 (load addr:$src2)))]>,
3793 def CRC64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3794 (ins GR64:$src1, GR8:$src2),
3795 "crc32{b} \t{$src2, $src1|$src1, $src2}",
3797 (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
3799 def CRC64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
3800 (ins GR64:$src1, i64mem:$src2),
3801 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3803 (int_x86_sse42_crc64_64 GR64:$src1,
3804 (load addr:$src2)))]>,
3806 def CRC64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
3807 (ins GR64:$src1, GR64:$src2),
3808 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3810 (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
3814 // String/text processing instructions.
3815 let Defs = [EFLAGS], usesCustomInserter = 1 in {
3816 def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3817 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3818 "#PCMPISTRM128rr PSEUDO!",
3819 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
3820 imm:$src3))]>, OpSize;
3821 def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3822 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3823 "#PCMPISTRM128rm PSEUDO!",
3824 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, (load addr:$src2),
3825 imm:$src3))]>, OpSize;
3828 let Defs = [XMM0, EFLAGS] in {
3829 def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
3830 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3831 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3832 def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
3833 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3834 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
3837 let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
3838 def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
3839 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3840 "#PCMPESTRM128rr PSEUDO!",
3842 (int_x86_sse42_pcmpestrm128
3843 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
3845 def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
3846 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3847 "#PCMPESTRM128rm PSEUDO!",
3848 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
3849 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
3853 let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
3854 def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
3855 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3856 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3857 def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
3858 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3859 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
3862 let Defs = [ECX, EFLAGS] in {
3863 multiclass SS42AI_pcmpistri<Intrinsic IntId128> {
3864 def rr : SS42AI<0x63, MRMSrcReg, (outs),
3865 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3866 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3867 [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
3868 (implicit EFLAGS)]>, OpSize;
3869 def rm : SS42AI<0x63, MRMSrcMem, (outs),
3870 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3871 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3872 [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
3873 (implicit EFLAGS)]>, OpSize;
3877 defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
3878 defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
3879 defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
3880 defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
3881 defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
3882 defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
3884 let Defs = [ECX, EFLAGS] in {
3885 let Uses = [EAX, EDX] in {
3886 multiclass SS42AI_pcmpestri<Intrinsic IntId128> {
3887 def rr : SS42AI<0x61, MRMSrcReg, (outs),
3888 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3889 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3890 [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
3891 (implicit EFLAGS)]>, OpSize;
3892 def rm : SS42AI<0x61, MRMSrcMem, (outs),
3893 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3894 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3896 (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
3897 (implicit EFLAGS)]>, OpSize;
3902 defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
3903 defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
3904 defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
3905 defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
3906 defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
3907 defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
3909 //===----------------------------------------------------------------------===//
3910 // AES-NI Instructions
3911 //===----------------------------------------------------------------------===//
3913 let Constraints = "$src1 = $dst" in {
3914 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
3915 Intrinsic IntId128, bit Commutable = 0> {
3916 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
3917 (ins VR128:$src1, VR128:$src2),
3918 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3919 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3921 let isCommutable = Commutable;
3923 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
3924 (ins VR128:$src1, i128mem:$src2),
3925 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3927 (IntId128 VR128:$src1,
3928 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3932 defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
3933 int_x86_aesni_aesenc>;
3934 defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
3935 int_x86_aesni_aesenclast>;
3936 defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
3937 int_x86_aesni_aesdec>;
3938 defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
3939 int_x86_aesni_aesdeclast>;
3941 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
3942 (AESENCrr VR128:$src1, VR128:$src2)>;
3943 def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
3944 (AESENCrm VR128:$src1, addr:$src2)>;
3945 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
3946 (AESENCLASTrr VR128:$src1, VR128:$src2)>;
3947 def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
3948 (AESENCLASTrm VR128:$src1, addr:$src2)>;
3949 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
3950 (AESDECrr VR128:$src1, VR128:$src2)>;
3951 def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
3952 (AESDECrm VR128:$src1, addr:$src2)>;
3953 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
3954 (AESDECLASTrr VR128:$src1, VR128:$src2)>;
3955 def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
3956 (AESDECLASTrm VR128:$src1, addr:$src2)>;
3958 def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
3960 "aesimc\t{$src1, $dst|$dst, $src1}",
3962 (int_x86_aesni_aesimc VR128:$src1))]>,
3965 def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
3966 (ins i128mem:$src1),
3967 "aesimc\t{$src1, $dst|$dst, $src1}",
3969 (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
3972 def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
3973 (ins VR128:$src1, i8imm:$src2),
3974 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3976 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
3978 def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
3979 (ins i128mem:$src1, i8imm:$src2),
3980 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3982 (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),