1 //====- X86Instr64bit.td - Describe X86-64 Instructions ----*- 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-64 instruction set, defining the instructions,
11 // and properties of the instructions which are needed for code generation,
12 // machine code emission, and analysis.
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
17 // Operand Definitions.
20 // 64-bits but only 32 bits are significant.
21 def i64i32imm : Operand<i64>;
23 // 64-bits but only 32 bits are significant, and those bits are treated as being
25 def i64i32imm_pcrel : Operand<i64> {
26 let PrintMethod = "print_pcrel_imm";
30 // 64-bits but only 8 bits are significant.
31 def i64i8imm : Operand<i64>;
33 def lea64mem : Operand<i64> {
34 let PrintMethod = "printlea64mem";
35 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
38 def lea64_32mem : Operand<i32> {
39 let PrintMethod = "printlea64_32mem";
40 let AsmOperandLowerMethod = "lower_lea64_32mem";
41 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
44 //===----------------------------------------------------------------------===//
45 // Complex Pattern Definitions.
47 def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
48 [add, mul, X86mul_imm, shl, or, frameindex,
51 def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
52 [tglobaltlsaddr], []>;
54 //===----------------------------------------------------------------------===//
58 def i64immSExt8 : PatLeaf<(i64 imm), [{
59 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
60 // sign extended field.
61 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
64 def i64immSExt32 : PatLeaf<(i64 imm), [{
65 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
66 // sign extended field.
67 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
70 def i64immZExt32 : PatLeaf<(i64 imm), [{
71 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
72 // unsignedsign extended field.
73 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
76 def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
77 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
78 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
80 def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
81 def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
82 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
83 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
85 def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
86 def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
87 def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
88 def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
90 //===----------------------------------------------------------------------===//
91 // Instruction list...
94 // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
95 // a stack adjustment and the codegen must know that they may modify the stack
96 // pointer before prolog-epilog rewriting occurs.
97 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
98 // sub / add which can clobber EFLAGS.
99 let Defs = [RSP, EFLAGS], Uses = [RSP] in {
100 def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
102 [(X86callseq_start timm:$amt)]>,
103 Requires<[In64BitMode]>;
104 def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
106 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
107 Requires<[In64BitMode]>;
110 //===----------------------------------------------------------------------===//
111 // Call Instructions...
114 // All calls clobber the non-callee saved registers. RSP is marked as
115 // a use to prevent stack-pointer assignments that appear immediately
116 // before calls from potentially appearing dead. Uses for argument
117 // registers are added manually.
118 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
119 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
120 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
121 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
122 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
125 // NOTE: this pattern doesn't match "X86call imm", because we do not know
126 // that the offset between an arbitrary immediate and the call will fit in
127 // the 32-bit pcrel field that we have.
128 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
129 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
131 Requires<[In64BitMode]>;
132 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
133 "call\t{*}$dst", [(X86call GR64:$dst)]>;
134 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
135 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
140 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
141 def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
143 "#TC_RETURN $dst $offset",
146 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
147 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
149 "#TC_RETURN $dst $offset",
153 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
154 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
155 "jmp{q}\t{*}$dst # TAILCALL",
159 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
160 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
161 [(brind GR64:$dst)]>;
162 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
163 [(brind (loadi64 addr:$dst))]>;
166 //===----------------------------------------------------------------------===//
167 // EH Pseudo Instructions
169 let isTerminator = 1, isReturn = 1, isBarrier = 1,
171 def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
172 "ret\t#eh_return, addr: $addr",
173 [(X86ehret GR64:$addr)]>;
177 //===----------------------------------------------------------------------===//
178 // Miscellaneous Instructions...
180 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
181 def LEAVE64 : I<0xC9, RawFrm,
182 (outs), (ins), "leave", []>;
183 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
185 def POP64r : I<0x58, AddRegFrm,
186 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
188 def PUSH64r : I<0x50, AddRegFrm,
189 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
192 let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
193 def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
194 "push{q}\t$imm", []>;
195 def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
196 "push{q}\t$imm", []>;
197 def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
198 "push{q}\t$imm", []>;
201 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
202 def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
203 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
204 def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
206 def LEA64_32r : I<0x8D, MRMSrcMem,
207 (outs GR32:$dst), (ins lea64_32mem:$src),
208 "lea{l}\t{$src|$dst}, {$dst|$src}",
209 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
211 let isReMaterializable = 1 in
212 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
213 "lea{q}\t{$src|$dst}, {$dst|$src}",
214 [(set GR64:$dst, lea64addr:$src)]>;
216 let isTwoAddress = 1 in
217 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
219 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
221 // Bit scan instructions.
222 let Defs = [EFLAGS] in {
223 def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
224 "bsf{q}\t{$src, $dst|$dst, $src}",
225 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
226 def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
227 "bsf{q}\t{$src, $dst|$dst, $src}",
228 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
229 (implicit EFLAGS)]>, TB;
231 def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
232 "bsr{q}\t{$src, $dst|$dst, $src}",
233 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
234 def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
235 "bsr{q}\t{$src, $dst|$dst, $src}",
236 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
237 (implicit EFLAGS)]>, TB;
241 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
242 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
243 [(X86rep_movs i64)]>, REP;
244 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
245 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
246 [(X86rep_stos i64)]>, REP;
248 //===----------------------------------------------------------------------===//
249 // Move Instructions...
252 let neverHasSideEffects = 1 in
253 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
254 "mov{q}\t{$src, $dst|$dst, $src}", []>;
256 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
257 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
258 "movabs{q}\t{$src, $dst|$dst, $src}",
259 [(set GR64:$dst, imm:$src)]>;
260 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
261 "mov{q}\t{$src, $dst|$dst, $src}",
262 [(set GR64:$dst, i64immSExt32:$src)]>;
265 let canFoldAsLoad = 1 in
266 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
267 "mov{q}\t{$src, $dst|$dst, $src}",
268 [(set GR64:$dst, (load addr:$src))]>;
270 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
271 "mov{q}\t{$src, $dst|$dst, $src}",
272 [(store GR64:$src, addr:$dst)]>;
273 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
274 "mov{q}\t{$src, $dst|$dst, $src}",
275 [(store i64immSExt32:$src, addr:$dst)]>;
277 // Sign/Zero extenders
279 // MOVSX64rr8 always has a REX prefix and it has an 8-bit register
280 // operand, which makes it a rare instruction with an 8-bit register
281 // operand that can never access an h register. If support for h registers
282 // were generalized, this would require a special register class.
283 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
284 "movs{bq|x}\t{$src, $dst|$dst, $src}",
285 [(set GR64:$dst, (sext GR8:$src))]>, TB;
286 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
287 "movs{bq|x}\t{$src, $dst|$dst, $src}",
288 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
289 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
290 "movs{wq|x}\t{$src, $dst|$dst, $src}",
291 [(set GR64:$dst, (sext GR16:$src))]>, TB;
292 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
293 "movs{wq|x}\t{$src, $dst|$dst, $src}",
294 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
295 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
296 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
297 [(set GR64:$dst, (sext GR32:$src))]>;
298 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
299 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
300 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
302 // Use movzbl instead of movzbq when the destination is a register; it's
303 // equivalent due to implicit zero-extending, and it has a smaller encoding.
304 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
305 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
306 [(set GR64:$dst, (zext GR8:$src))]>, TB;
307 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
308 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
309 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
310 // Use movzwl instead of movzwq when the destination is a register; it's
311 // equivalent due to implicit zero-extending, and it has a smaller encoding.
312 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
313 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
314 [(set GR64:$dst, (zext GR16:$src))]>, TB;
315 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
316 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
317 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
319 // There's no movzlq instruction, but movl can be used for this purpose, using
320 // implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
321 // extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
322 // zero-extension, however this isn't possible when the 32-bit value is
323 // defined by a truncate or is copied from something where the high bits aren't
324 // necessarily all zero. In such cases, we fall back to these explicit zext
326 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
327 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
328 [(set GR64:$dst, (zext GR32:$src))]>;
329 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
330 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
331 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
333 // Any instruction that defines a 32-bit result leaves the high half of the
334 // register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
335 // be copying from a truncate, but any other 32-bit operation will zero-extend
337 def def32 : PatLeaf<(i32 GR32:$src), [{
338 return N->getOpcode() != ISD::TRUNCATE &&
339 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
340 N->getOpcode() != ISD::CopyFromReg;
343 // In the case of a 32-bit def that is known to implicitly zero-extend,
344 // we can use a SUBREG_TO_REG.
345 def : Pat<(i64 (zext def32:$src)),
346 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
348 let neverHasSideEffects = 1 in {
349 let Defs = [RAX], Uses = [EAX] in
350 def CDQE : RI<0x98, RawFrm, (outs), (ins),
351 "{cltq|cdqe}", []>; // RAX = signext(EAX)
353 let Defs = [RAX,RDX], Uses = [RAX] in
354 def CQO : RI<0x99, RawFrm, (outs), (ins),
355 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
358 //===----------------------------------------------------------------------===//
359 // Arithmetic Instructions...
362 let Defs = [EFLAGS] in {
363 let isTwoAddress = 1 in {
364 let isConvertibleToThreeAddress = 1 in {
365 let isCommutable = 1 in
366 // Register-Register Addition
367 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
368 "add{q}\t{$src2, $dst|$dst, $src2}",
369 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
372 // Register-Integer Addition
373 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
374 "add{q}\t{$src2, $dst|$dst, $src2}",
375 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
377 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
378 "add{q}\t{$src2, $dst|$dst, $src2}",
379 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
381 } // isConvertibleToThreeAddress
383 // Register-Memory Addition
384 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
385 "add{q}\t{$src2, $dst|$dst, $src2}",
386 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
390 // Memory-Register Addition
391 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
392 "add{q}\t{$src2, $dst|$dst, $src2}",
393 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
395 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
396 "add{q}\t{$src2, $dst|$dst, $src2}",
397 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
399 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
400 "add{q}\t{$src2, $dst|$dst, $src2}",
401 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
404 let Uses = [EFLAGS] in {
405 let isTwoAddress = 1 in {
406 let isCommutable = 1 in
407 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
408 "adc{q}\t{$src2, $dst|$dst, $src2}",
409 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
411 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
412 "adc{q}\t{$src2, $dst|$dst, $src2}",
413 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
415 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
416 "adc{q}\t{$src2, $dst|$dst, $src2}",
417 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
418 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
419 "adc{q}\t{$src2, $dst|$dst, $src2}",
420 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
423 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
424 "adc{q}\t{$src2, $dst|$dst, $src2}",
425 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
426 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
427 "adc{q}\t{$src2, $dst|$dst, $src2}",
428 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
429 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
430 "adc{q}\t{$src2, $dst|$dst, $src2}",
431 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
434 let isTwoAddress = 1 in {
435 // Register-Register Subtraction
436 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
437 "sub{q}\t{$src2, $dst|$dst, $src2}",
438 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
441 // Register-Memory Subtraction
442 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
443 "sub{q}\t{$src2, $dst|$dst, $src2}",
444 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
447 // Register-Integer Subtraction
448 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
449 (ins GR64:$src1, i64i8imm:$src2),
450 "sub{q}\t{$src2, $dst|$dst, $src2}",
451 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
453 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
454 (ins GR64:$src1, i64i32imm:$src2),
455 "sub{q}\t{$src2, $dst|$dst, $src2}",
456 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
460 // Memory-Register Subtraction
461 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
462 "sub{q}\t{$src2, $dst|$dst, $src2}",
463 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
466 // Memory-Integer Subtraction
467 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
468 "sub{q}\t{$src2, $dst|$dst, $src2}",
469 [(store (sub (load addr:$dst), i64immSExt8:$src2),
472 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
473 "sub{q}\t{$src2, $dst|$dst, $src2}",
474 [(store (sub (load addr:$dst), i64immSExt32:$src2),
478 let Uses = [EFLAGS] in {
479 let isTwoAddress = 1 in {
480 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
481 "sbb{q}\t{$src2, $dst|$dst, $src2}",
482 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
484 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
485 "sbb{q}\t{$src2, $dst|$dst, $src2}",
486 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
488 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
489 "sbb{q}\t{$src2, $dst|$dst, $src2}",
490 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
491 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
492 "sbb{q}\t{$src2, $dst|$dst, $src2}",
493 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
496 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
497 "sbb{q}\t{$src2, $dst|$dst, $src2}",
498 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
499 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
500 "sbb{q}\t{$src2, $dst|$dst, $src2}",
501 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
502 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
503 "sbb{q}\t{$src2, $dst|$dst, $src2}",
504 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
508 // Unsigned multiplication
509 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
510 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
511 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
513 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
514 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
516 // Signed multiplication
517 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
518 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
520 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
521 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
524 let Defs = [EFLAGS] in {
525 let isTwoAddress = 1 in {
526 let isCommutable = 1 in
527 // Register-Register Signed Integer Multiplication
528 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
529 (ins GR64:$src1, GR64:$src2),
530 "imul{q}\t{$src2, $dst|$dst, $src2}",
531 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
532 (implicit EFLAGS)]>, TB;
534 // Register-Memory Signed Integer Multiplication
535 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
536 (ins GR64:$src1, i64mem:$src2),
537 "imul{q}\t{$src2, $dst|$dst, $src2}",
538 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
539 (implicit EFLAGS)]>, TB;
542 // Suprisingly enough, these are not two address instructions!
544 // Register-Integer Signed Integer Multiplication
545 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
546 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
547 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
548 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
550 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
551 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
552 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
553 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
556 // Memory-Integer Signed Integer Multiplication
557 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
558 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
559 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
560 [(set GR64:$dst, (mul (load addr:$src1),
563 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
564 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
565 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
566 [(set GR64:$dst, (mul (load addr:$src1),
567 i64immSExt32:$src2)),
571 // Unsigned division / remainder
572 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
573 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
575 // Signed division / remainder
576 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
577 "idiv{q}\t$src", []>;
579 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
581 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
582 "idiv{q}\t$src", []>;
586 // Unary instructions
587 let Defs = [EFLAGS], CodeSize = 2 in {
588 let isTwoAddress = 1 in
589 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
590 [(set GR64:$dst, (ineg GR64:$src)),
592 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
593 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
596 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
597 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
598 [(set GR64:$dst, (add GR64:$src, 1)),
600 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
601 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
604 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
605 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
606 [(set GR64:$dst, (add GR64:$src, -1)),
608 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
609 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
612 // In 64-bit mode, single byte INC and DEC cannot be encoded.
613 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
614 // Can transform into LEA.
615 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
616 [(set GR16:$dst, (add GR16:$src, 1)),
618 OpSize, Requires<[In64BitMode]>;
619 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
620 [(set GR32:$dst, (add GR32:$src, 1)),
622 Requires<[In64BitMode]>;
623 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
624 [(set GR16:$dst, (add GR16:$src, -1)),
626 OpSize, Requires<[In64BitMode]>;
627 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
628 [(set GR32:$dst, (add GR32:$src, -1)),
630 Requires<[In64BitMode]>;
631 } // isConvertibleToThreeAddress
633 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
634 // how to unfold them.
635 let isTwoAddress = 0, CodeSize = 2 in {
636 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
637 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
639 OpSize, Requires<[In64BitMode]>;
640 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
641 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
643 Requires<[In64BitMode]>;
644 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
645 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
647 OpSize, Requires<[In64BitMode]>;
648 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
649 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
651 Requires<[In64BitMode]>;
653 } // Defs = [EFLAGS], CodeSize
656 let Defs = [EFLAGS] in {
657 // Shift instructions
658 let isTwoAddress = 1 in {
660 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
661 "shl{q}\t{%cl, $dst|$dst, %CL}",
662 [(set GR64:$dst, (shl GR64:$src, CL))]>;
663 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
664 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
665 "shl{q}\t{$src2, $dst|$dst, $src2}",
666 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
667 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
672 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
673 "shl{q}\t{%cl, $dst|$dst, %CL}",
674 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
675 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
676 "shl{q}\t{$src, $dst|$dst, $src}",
677 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
678 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
680 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
682 let isTwoAddress = 1 in {
684 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
685 "shr{q}\t{%cl, $dst|$dst, %CL}",
686 [(set GR64:$dst, (srl GR64:$src, CL))]>;
687 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
688 "shr{q}\t{$src2, $dst|$dst, $src2}",
689 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
690 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
692 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
696 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
697 "shr{q}\t{%cl, $dst|$dst, %CL}",
698 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
699 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
700 "shr{q}\t{$src, $dst|$dst, $src}",
701 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
702 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
704 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
706 let isTwoAddress = 1 in {
708 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
709 "sar{q}\t{%cl, $dst|$dst, %CL}",
710 [(set GR64:$dst, (sra GR64:$src, CL))]>;
711 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
712 "sar{q}\t{$src2, $dst|$dst, $src2}",
713 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
714 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
716 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
720 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
721 "sar{q}\t{%cl, $dst|$dst, %CL}",
722 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
723 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
724 "sar{q}\t{$src, $dst|$dst, $src}",
725 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
726 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
728 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
730 // Rotate instructions
731 let isTwoAddress = 1 in {
733 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
734 "rol{q}\t{%cl, $dst|$dst, %CL}",
735 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
736 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
737 "rol{q}\t{$src2, $dst|$dst, $src2}",
738 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
739 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
741 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
745 def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
746 "rol{q}\t{%cl, $dst|$dst, %CL}",
747 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
748 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
749 "rol{q}\t{$src, $dst|$dst, $src}",
750 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
751 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
753 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
755 let isTwoAddress = 1 in {
757 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
758 "ror{q}\t{%cl, $dst|$dst, %CL}",
759 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
760 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
761 "ror{q}\t{$src2, $dst|$dst, $src2}",
762 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
763 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
765 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
769 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
770 "ror{q}\t{%cl, $dst|$dst, %CL}",
771 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
772 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
773 "ror{q}\t{$src, $dst|$dst, $src}",
774 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
775 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
777 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
779 // Double shift instructions (generalizations of rotate)
780 let isTwoAddress = 1 in {
782 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
783 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
784 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
785 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
786 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
787 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
790 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
791 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
792 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
793 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
794 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
797 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
798 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
799 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
800 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
807 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
808 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
809 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
811 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
812 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
813 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
816 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
817 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
818 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
819 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
820 (i8 imm:$src3)), addr:$dst)]>,
822 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
823 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
824 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
825 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
826 (i8 imm:$src3)), addr:$dst)]>,
830 //===----------------------------------------------------------------------===//
831 // Logical Instructions...
834 let isTwoAddress = 1 , AddedComplexity = 15 in
835 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
836 [(set GR64:$dst, (not GR64:$src))]>;
837 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
838 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
840 let Defs = [EFLAGS] in {
841 let isTwoAddress = 1 in {
842 let isCommutable = 1 in
843 def AND64rr : RI<0x21, MRMDestReg,
844 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
845 "and{q}\t{$src2, $dst|$dst, $src2}",
846 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
848 def AND64rm : RI<0x23, MRMSrcMem,
849 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
850 "and{q}\t{$src2, $dst|$dst, $src2}",
851 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
853 def AND64ri8 : RIi8<0x83, MRM4r,
854 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
855 "and{q}\t{$src2, $dst|$dst, $src2}",
856 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
858 def AND64ri32 : RIi32<0x81, MRM4r,
859 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
860 "and{q}\t{$src2, $dst|$dst, $src2}",
861 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
865 def AND64mr : RI<0x21, MRMDestMem,
866 (outs), (ins i64mem:$dst, GR64:$src),
867 "and{q}\t{$src, $dst|$dst, $src}",
868 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
870 def AND64mi8 : RIi8<0x83, MRM4m,
871 (outs), (ins i64mem:$dst, i64i8imm :$src),
872 "and{q}\t{$src, $dst|$dst, $src}",
873 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
875 def AND64mi32 : RIi32<0x81, MRM4m,
876 (outs), (ins i64mem:$dst, i64i32imm:$src),
877 "and{q}\t{$src, $dst|$dst, $src}",
878 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
881 let isTwoAddress = 1 in {
882 let isCommutable = 1 in
883 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
884 "or{q}\t{$src2, $dst|$dst, $src2}",
885 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
887 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
888 "or{q}\t{$src2, $dst|$dst, $src2}",
889 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
891 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
892 "or{q}\t{$src2, $dst|$dst, $src2}",
893 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
895 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
896 "or{q}\t{$src2, $dst|$dst, $src2}",
897 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
901 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
902 "or{q}\t{$src, $dst|$dst, $src}",
903 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
905 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
906 "or{q}\t{$src, $dst|$dst, $src}",
907 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
909 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
910 "or{q}\t{$src, $dst|$dst, $src}",
911 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
914 let isTwoAddress = 1 in {
915 let isCommutable = 1 in
916 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
917 "xor{q}\t{$src2, $dst|$dst, $src2}",
918 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
920 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
921 "xor{q}\t{$src2, $dst|$dst, $src2}",
922 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
924 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
925 "xor{q}\t{$src2, $dst|$dst, $src2}",
926 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
928 def XOR64ri32 : RIi32<0x81, MRM6r,
929 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
930 "xor{q}\t{$src2, $dst|$dst, $src2}",
931 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
935 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
936 "xor{q}\t{$src, $dst|$dst, $src}",
937 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
939 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
940 "xor{q}\t{$src, $dst|$dst, $src}",
941 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
943 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
944 "xor{q}\t{$src, $dst|$dst, $src}",
945 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
949 //===----------------------------------------------------------------------===//
950 // Comparison Instructions...
953 // Integer comparison
954 let Defs = [EFLAGS] in {
955 let isCommutable = 1 in
956 def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
957 "test{q}\t{$src2, $src1|$src1, $src2}",
958 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
960 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
961 "test{q}\t{$src2, $src1|$src1, $src2}",
962 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
964 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
965 (ins GR64:$src1, i64i32imm:$src2),
966 "test{q}\t{$src2, $src1|$src1, $src2}",
967 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
969 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
970 (ins i64mem:$src1, i64i32imm:$src2),
971 "test{q}\t{$src2, $src1|$src1, $src2}",
972 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
975 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
976 "cmp{q}\t{$src2, $src1|$src1, $src2}",
977 [(X86cmp GR64:$src1, GR64:$src2),
979 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
980 "cmp{q}\t{$src2, $src1|$src1, $src2}",
981 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
983 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
984 "cmp{q}\t{$src2, $src1|$src1, $src2}",
985 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
987 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
988 "cmp{q}\t{$src2, $src1|$src1, $src2}",
989 [(X86cmp GR64:$src1, i64immSExt8:$src2),
991 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
992 "cmp{q}\t{$src2, $src1|$src1, $src2}",
993 [(X86cmp GR64:$src1, i64immSExt32:$src2),
995 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
996 "cmp{q}\t{$src2, $src1|$src1, $src2}",
997 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
999 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1000 (ins i64mem:$src1, i64i32imm:$src2),
1001 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1002 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1003 (implicit EFLAGS)]>;
1004 } // Defs = [EFLAGS]
1007 // TODO: BTC, BTR, and BTS
1008 let Defs = [EFLAGS] in {
1009 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1010 "bt{q}\t{$src2, $src1|$src1, $src2}",
1011 [(X86bt GR64:$src1, GR64:$src2),
1012 (implicit EFLAGS)]>, TB;
1014 // Unlike with the register+register form, the memory+register form of the
1015 // bt instruction does not ignore the high bits of the index. From ISel's
1016 // perspective, this is pretty bizarre. Disable these instructions for now.
1017 //def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1018 // "bt{q}\t{$src2, $src1|$src1, $src2}",
1019 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
1020 // (implicit EFLAGS)]>, TB;
1022 def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1023 "bt{q}\t{$src2, $src1|$src1, $src2}",
1024 [(X86bt GR64:$src1, i64immSExt8:$src2),
1025 (implicit EFLAGS)]>, TB;
1026 // Note that these instructions don't need FastBTMem because that
1027 // only applies when the other operand is in a register. When it's
1028 // an immediate, bt is still fast.
1029 def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1030 "bt{q}\t{$src2, $src1|$src1, $src2}",
1031 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1032 (implicit EFLAGS)]>, TB;
1033 } // Defs = [EFLAGS]
1035 // Conditional moves
1036 let Uses = [EFLAGS], isTwoAddress = 1 in {
1037 let isCommutable = 1 in {
1038 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
1039 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1040 "cmovb\t{$src2, $dst|$dst, $src2}",
1041 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1042 X86_COND_B, EFLAGS))]>, TB;
1043 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
1044 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1045 "cmovae\t{$src2, $dst|$dst, $src2}",
1046 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1047 X86_COND_AE, EFLAGS))]>, TB;
1048 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
1049 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1050 "cmove\t{$src2, $dst|$dst, $src2}",
1051 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1052 X86_COND_E, EFLAGS))]>, TB;
1053 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
1054 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1055 "cmovne\t{$src2, $dst|$dst, $src2}",
1056 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1057 X86_COND_NE, EFLAGS))]>, TB;
1058 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
1059 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1060 "cmovbe\t{$src2, $dst|$dst, $src2}",
1061 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1062 X86_COND_BE, EFLAGS))]>, TB;
1063 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
1064 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1065 "cmova\t{$src2, $dst|$dst, $src2}",
1066 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1067 X86_COND_A, EFLAGS))]>, TB;
1068 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
1069 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1070 "cmovl\t{$src2, $dst|$dst, $src2}",
1071 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1072 X86_COND_L, EFLAGS))]>, TB;
1073 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
1074 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1075 "cmovge\t{$src2, $dst|$dst, $src2}",
1076 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1077 X86_COND_GE, EFLAGS))]>, TB;
1078 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
1079 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1080 "cmovle\t{$src2, $dst|$dst, $src2}",
1081 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1082 X86_COND_LE, EFLAGS))]>, TB;
1083 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
1084 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1085 "cmovg\t{$src2, $dst|$dst, $src2}",
1086 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1087 X86_COND_G, EFLAGS))]>, TB;
1088 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1089 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1090 "cmovs\t{$src2, $dst|$dst, $src2}",
1091 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1092 X86_COND_S, EFLAGS))]>, TB;
1093 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1094 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1095 "cmovns\t{$src2, $dst|$dst, $src2}",
1096 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1097 X86_COND_NS, EFLAGS))]>, TB;
1098 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1099 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1100 "cmovp\t{$src2, $dst|$dst, $src2}",
1101 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1102 X86_COND_P, EFLAGS))]>, TB;
1103 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1104 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1105 "cmovnp\t{$src2, $dst|$dst, $src2}",
1106 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1107 X86_COND_NP, EFLAGS))]>, TB;
1108 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1109 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1110 "cmovo\t{$src2, $dst|$dst, $src2}",
1111 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1112 X86_COND_O, EFLAGS))]>, TB;
1113 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1114 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1115 "cmovno\t{$src2, $dst|$dst, $src2}",
1116 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1117 X86_COND_NO, EFLAGS))]>, TB;
1118 } // isCommutable = 1
1120 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1121 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1122 "cmovb\t{$src2, $dst|$dst, $src2}",
1123 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1124 X86_COND_B, EFLAGS))]>, TB;
1125 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1126 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1127 "cmovae\t{$src2, $dst|$dst, $src2}",
1128 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1129 X86_COND_AE, EFLAGS))]>, TB;
1130 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1131 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1132 "cmove\t{$src2, $dst|$dst, $src2}",
1133 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1134 X86_COND_E, EFLAGS))]>, TB;
1135 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1136 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1137 "cmovne\t{$src2, $dst|$dst, $src2}",
1138 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1139 X86_COND_NE, EFLAGS))]>, TB;
1140 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1141 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1142 "cmovbe\t{$src2, $dst|$dst, $src2}",
1143 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1144 X86_COND_BE, EFLAGS))]>, TB;
1145 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1146 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1147 "cmova\t{$src2, $dst|$dst, $src2}",
1148 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1149 X86_COND_A, EFLAGS))]>, TB;
1150 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1151 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1152 "cmovl\t{$src2, $dst|$dst, $src2}",
1153 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1154 X86_COND_L, EFLAGS))]>, TB;
1155 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1156 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1157 "cmovge\t{$src2, $dst|$dst, $src2}",
1158 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1159 X86_COND_GE, EFLAGS))]>, TB;
1160 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1161 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1162 "cmovle\t{$src2, $dst|$dst, $src2}",
1163 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1164 X86_COND_LE, EFLAGS))]>, TB;
1165 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1166 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1167 "cmovg\t{$src2, $dst|$dst, $src2}",
1168 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1169 X86_COND_G, EFLAGS))]>, TB;
1170 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1171 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1172 "cmovs\t{$src2, $dst|$dst, $src2}",
1173 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1174 X86_COND_S, EFLAGS))]>, TB;
1175 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1176 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1177 "cmovns\t{$src2, $dst|$dst, $src2}",
1178 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1179 X86_COND_NS, EFLAGS))]>, TB;
1180 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1181 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1182 "cmovp\t{$src2, $dst|$dst, $src2}",
1183 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1184 X86_COND_P, EFLAGS))]>, TB;
1185 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1186 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1187 "cmovnp\t{$src2, $dst|$dst, $src2}",
1188 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1189 X86_COND_NP, EFLAGS))]>, TB;
1190 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1191 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1192 "cmovo\t{$src2, $dst|$dst, $src2}",
1193 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1194 X86_COND_O, EFLAGS))]>, TB;
1195 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1196 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1197 "cmovno\t{$src2, $dst|$dst, $src2}",
1198 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1199 X86_COND_NO, EFLAGS))]>, TB;
1202 //===----------------------------------------------------------------------===//
1203 // Conversion Instructions...
1206 // f64 -> signed i64
1207 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1208 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1210 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1211 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1212 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1213 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1214 (load addr:$src)))]>;
1215 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1216 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1217 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1218 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1219 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1220 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1221 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1222 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1224 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1225 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1226 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1228 (int_x86_sse2_cvttsd2si64
1229 (load addr:$src)))]>;
1231 // Signed i64 -> f64
1232 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1233 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1234 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1235 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1236 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1237 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1239 let isTwoAddress = 1 in {
1240 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1241 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1242 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1244 (int_x86_sse2_cvtsi642sd VR128:$src1,
1246 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1247 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1248 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1250 (int_x86_sse2_cvtsi642sd VR128:$src1,
1251 (loadi64 addr:$src2)))]>;
1254 // Signed i64 -> f32
1255 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1256 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1257 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1258 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1259 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1260 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1262 let isTwoAddress = 1 in {
1263 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1264 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1265 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1267 (int_x86_sse_cvtsi642ss VR128:$src1,
1269 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1270 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1271 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1273 (int_x86_sse_cvtsi642ss VR128:$src1,
1274 (loadi64 addr:$src2)))]>;
1277 // f32 -> signed i64
1278 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1279 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1281 (int_x86_sse_cvtss2si64 VR128:$src))]>;
1282 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1283 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1284 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1285 (load addr:$src)))]>;
1286 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1287 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1288 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1289 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1290 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1291 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1292 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1293 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1295 (int_x86_sse_cvttss2si64 VR128:$src))]>;
1296 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1297 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1299 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1301 //===----------------------------------------------------------------------===//
1302 // Alias Instructions
1303 //===----------------------------------------------------------------------===//
1305 // Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1306 // equivalent due to implicit zero-extending, and it sometimes has a smaller
1308 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1309 // FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1310 // when we have a better way to specify isel priority.
1311 let Defs = [EFLAGS], AddedComplexity = 1,
1312 isReMaterializable = 1, isAsCheapAsAMove = 1 in
1313 def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1314 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1315 [(set GR64:$dst, 0)]>;
1317 // Materialize i64 constant where top 32-bits are zero.
1318 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1319 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1320 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1321 [(set GR64:$dst, i64immZExt32:$src)]>;
1323 //===----------------------------------------------------------------------===//
1324 // Thread Local Storage Instructions
1325 //===----------------------------------------------------------------------===//
1327 // All calls clobber the non-callee saved registers. RSP is marked as
1328 // a use to prevent stack-pointer assignments that appear immediately
1329 // before calls from potentially appearing dead.
1330 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1331 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1332 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1333 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1334 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1336 def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
1338 "leaq\t$sym(%rip), %rdi; "
1341 "call\t__tls_get_addr@PLT",
1342 [(X86tlsaddr tls64addr:$sym)]>,
1343 Requires<[In64BitMode]>;
1345 let AddedComplexity = 5 in
1346 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1347 "movq\t%gs:$src, $dst",
1348 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1350 let AddedComplexity = 5 in
1351 def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1352 "movq\t%fs:$src, $dst",
1353 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1355 //===----------------------------------------------------------------------===//
1356 // Atomic Instructions
1357 //===----------------------------------------------------------------------===//
1359 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1360 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1362 "cmpxchgq\t$swap,$ptr",
1363 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1366 let Constraints = "$val = $dst" in {
1367 let Defs = [EFLAGS] in
1368 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1371 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1373 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1375 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1378 // Atomic exchange, and, or, xor
1379 let Constraints = "$val = $dst", Defs = [EFLAGS],
1380 usesCustomDAGSchedInserter = 1 in {
1381 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1382 "#ATOMAND64 PSEUDO!",
1383 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1384 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1385 "#ATOMOR64 PSEUDO!",
1386 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1387 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1388 "#ATOMXOR64 PSEUDO!",
1389 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1390 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1391 "#ATOMNAND64 PSEUDO!",
1392 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1393 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1394 "#ATOMMIN64 PSEUDO!",
1395 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1396 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1397 "#ATOMMAX64 PSEUDO!",
1398 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1399 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1400 "#ATOMUMIN64 PSEUDO!",
1401 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1402 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1403 "#ATOMUMAX64 PSEUDO!",
1404 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1407 //===----------------------------------------------------------------------===//
1408 // Non-Instruction Patterns
1409 //===----------------------------------------------------------------------===//
1411 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1412 // code model mode, should use 'movabs'. FIXME: This is really a hack, the
1413 // 'movabs' predicate should handle this sort of thing.
1414 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1415 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1416 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1417 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1418 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1419 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1420 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1421 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1423 // In static codegen with small code model, we can get the address of a label
1424 // into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1425 // the MOV64ri64i32 should accept these.
1426 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1427 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1428 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1429 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1430 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1431 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1432 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1433 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1436 // If we have small model and -static mode, it is safe to store global addresses
1437 // directly as immediates. FIXME: This is really a hack, the 'imm' predicate
1438 // for MOV64mi32 should handle this sort of thing.
1439 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1440 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1441 Requires<[SmallCode, IsStatic]>;
1442 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1443 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1444 Requires<[SmallCode, IsStatic]>;
1445 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1446 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1447 Requires<[SmallCode, IsStatic]>;
1448 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1449 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1450 Requires<[SmallCode, IsStatic]>;
1453 // Direct PC relative function call for small code model. 32-bit displacement
1454 // sign extended to 64-bit.
1455 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1456 (CALL64pcrel32 tglobaladdr:$dst)>;
1457 def : Pat<(X86call (i64 texternalsym:$dst)),
1458 (CALL64pcrel32 texternalsym:$dst)>;
1460 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1461 (CALL64pcrel32 tglobaladdr:$dst)>;
1462 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1463 (CALL64pcrel32 texternalsym:$dst)>;
1465 def : Pat<(X86tailcall GR64:$dst),
1466 (CALL64r GR64:$dst)>;
1470 def : Pat<(X86tailcall GR32:$dst),
1472 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1474 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1477 def : Pat<(X86tcret GR64:$dst, imm:$off),
1478 (TCRETURNri64 GR64:$dst, imm:$off)>;
1480 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1481 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1483 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1484 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1488 // TEST R,R is smaller than CMP R,0
1489 def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
1490 (TEST64rr GR64:$src1, GR64:$src1)>;
1492 // Conditional moves with folded loads with operands swapped and conditions
1494 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1495 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1496 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1497 (CMOVB64rm GR64:$src2, addr:$src1)>;
1498 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1499 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1500 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1501 (CMOVE64rm GR64:$src2, addr:$src1)>;
1502 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1503 (CMOVA64rm GR64:$src2, addr:$src1)>;
1504 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1505 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1506 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1507 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1508 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1509 (CMOVL64rm GR64:$src2, addr:$src1)>;
1510 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1511 (CMOVG64rm GR64:$src2, addr:$src1)>;
1512 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1513 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1514 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1515 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1516 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1517 (CMOVP64rm GR64:$src2, addr:$src1)>;
1518 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1519 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1520 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1521 (CMOVS64rm GR64:$src2, addr:$src1)>;
1522 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1523 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1524 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1525 (CMOVO64rm GR64:$src2, addr:$src1)>;
1527 // zextload bool -> zextload byte
1528 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1531 // When extloading from 16-bit and smaller memory locations into 64-bit registers,
1532 // use zero-extending loads so that the entire 64-bit register is defined, avoiding
1533 // partial-register updates.
1534 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1535 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1536 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1537 // For other extloads, use subregs, since the high contents of the register are
1538 // defined after an extload.
1539 def : Pat<(extloadi64i32 addr:$src),
1540 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1542 def : Pat<(extloadi16i1 addr:$src),
1543 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1545 Requires<[In64BitMode]>;
1546 def : Pat<(extloadi16i8 addr:$src),
1547 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1549 Requires<[In64BitMode]>;
1552 def : Pat<(i64 (anyext GR8:$src)),
1553 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1554 def : Pat<(i64 (anyext GR16:$src)),
1555 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
1556 def : Pat<(i64 (anyext GR32:$src)),
1557 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
1558 def : Pat<(i16 (anyext GR8:$src)),
1559 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1560 Requires<[In64BitMode]>;
1561 def : Pat<(i32 (anyext GR8:$src)),
1562 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1563 Requires<[In64BitMode]>;
1565 //===----------------------------------------------------------------------===//
1567 //===----------------------------------------------------------------------===//
1569 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1570 // +128 doesn't, so in this special case use a sub instead of an add.
1571 def : Pat<(add GR64:$src1, 128),
1572 (SUB64ri8 GR64:$src1, -128)>;
1573 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1574 (SUB64mi8 addr:$dst, -128)>;
1576 // The same trick applies for 32-bit immediate fields in 64-bit
1578 def : Pat<(add GR64:$src1, 0x0000000080000000),
1579 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1580 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1581 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1583 // r & (2^32-1) ==> movz
1584 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1585 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1586 // r & (2^16-1) ==> movz
1587 def : Pat<(and GR64:$src, 0xffff),
1588 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1589 // r & (2^8-1) ==> movz
1590 def : Pat<(and GR64:$src, 0xff),
1591 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1592 // r & (2^8-1) ==> movz
1593 def : Pat<(and GR32:$src1, 0xff),
1594 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
1595 Requires<[In64BitMode]>;
1596 // r & (2^8-1) ==> movz
1597 def : Pat<(and GR16:$src1, 0xff),
1598 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1599 Requires<[In64BitMode]>;
1601 // sext_inreg patterns
1602 def : Pat<(sext_inreg GR64:$src, i32),
1603 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1604 def : Pat<(sext_inreg GR64:$src, i16),
1605 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1606 def : Pat<(sext_inreg GR64:$src, i8),
1607 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1608 def : Pat<(sext_inreg GR32:$src, i8),
1609 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1610 Requires<[In64BitMode]>;
1611 def : Pat<(sext_inreg GR16:$src, i8),
1612 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1613 Requires<[In64BitMode]>;
1616 def : Pat<(i32 (trunc GR64:$src)),
1617 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
1618 def : Pat<(i16 (trunc GR64:$src)),
1619 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
1620 def : Pat<(i8 (trunc GR64:$src)),
1621 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
1622 def : Pat<(i8 (trunc GR32:$src)),
1623 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
1624 Requires<[In64BitMode]>;
1625 def : Pat<(i8 (trunc GR16:$src)),
1626 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1627 Requires<[In64BitMode]>;
1629 // h-register tricks.
1630 // For now, be conservative on x86-64 and use an h-register extract only if the
1631 // value is immediately zero-extended or stored, which are somewhat common
1632 // cases. This uses a bunch of code to prevent a register requiring a REX prefix
1633 // from being allocated in the same instruction as the h register, as there's
1634 // currently no way to describe this requirement to the register allocator.
1636 // h-register extract and zero-extend.
1637 def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1641 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
1642 x86_subreg_8bit_hi)),
1644 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1646 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
1647 x86_subreg_8bit_hi))>,
1648 Requires<[In64BitMode]>;
1649 def : Pat<(srl_su GR16:$src, (i8 8)),
1652 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1653 x86_subreg_8bit_hi)),
1655 Requires<[In64BitMode]>;
1656 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1658 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1659 x86_subreg_8bit_hi))>,
1660 Requires<[In64BitMode]>;
1661 def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1665 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1666 x86_subreg_8bit_hi)),
1669 // h-register extract and store.
1670 def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1673 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
1674 x86_subreg_8bit_hi))>;
1675 def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1678 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
1679 x86_subreg_8bit_hi))>,
1680 Requires<[In64BitMode]>;
1681 def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1684 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1685 x86_subreg_8bit_hi))>,
1686 Requires<[In64BitMode]>;
1688 // (shl x, 1) ==> (add x, x)
1689 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1691 // (shl x (and y, 63)) ==> (shl x, y)
1692 def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1693 (SHL64rCL GR64:$src1)>;
1694 def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1695 (SHL64mCL addr:$dst)>;
1697 def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1698 (SHR64rCL GR64:$src1)>;
1699 def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1700 (SHR64mCL addr:$dst)>;
1702 def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1703 (SAR64rCL GR64:$src1)>;
1704 def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1705 (SAR64mCL addr:$dst)>;
1707 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1708 def : Pat<(or (srl GR64:$src1, CL:$amt),
1709 (shl GR64:$src2, (sub 64, CL:$amt))),
1710 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1712 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1713 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1714 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1716 def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1717 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1718 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1720 def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1721 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1723 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1725 def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1726 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1728 def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1729 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1730 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1732 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1733 def : Pat<(or (shl GR64:$src1, CL:$amt),
1734 (srl GR64:$src2, (sub 64, CL:$amt))),
1735 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1737 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1738 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1739 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1741 def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1742 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1743 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1745 def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1746 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1748 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1750 def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1751 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1753 def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1754 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1755 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1757 // X86 specific add which produces a flag.
1758 def : Pat<(addc GR64:$src1, GR64:$src2),
1759 (ADD64rr GR64:$src1, GR64:$src2)>;
1760 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1761 (ADD64rm GR64:$src1, addr:$src2)>;
1762 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1763 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1764 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1765 (ADD64ri32 GR64:$src1, imm:$src2)>;
1767 def : Pat<(subc GR64:$src1, GR64:$src2),
1768 (SUB64rr GR64:$src1, GR64:$src2)>;
1769 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1770 (SUB64rm GR64:$src1, addr:$src2)>;
1771 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1772 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1773 def : Pat<(subc GR64:$src1, imm:$src2),
1774 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1776 //===----------------------------------------------------------------------===//
1777 // EFLAGS-defining Patterns
1778 //===----------------------------------------------------------------------===//
1780 // Register-Register Addition with EFLAGS result
1781 def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
1783 (ADD64rr GR64:$src1, GR64:$src2)>;
1785 // Register-Integer Addition with EFLAGS result
1786 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
1788 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1789 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
1791 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
1793 // Register-Memory Addition with EFLAGS result
1794 def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
1796 (ADD64rm GR64:$src1, addr:$src2)>;
1798 // Memory-Register Addition with EFLAGS result
1799 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
1802 (ADD64mr addr:$dst, GR64:$src2)>;
1803 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1806 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
1807 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1810 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
1812 // Register-Register Subtraction with EFLAGS result
1813 def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
1815 (SUB64rr GR64:$src1, GR64:$src2)>;
1817 // Register-Memory Subtraction with EFLAGS result
1818 def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
1820 (SUB64rm GR64:$src1, addr:$src2)>;
1822 // Register-Integer Subtraction with EFLAGS result
1823 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
1825 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1826 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
1828 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1830 // Memory-Register Subtraction with EFLAGS result
1831 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
1834 (SUB64mr addr:$dst, GR64:$src2)>;
1836 // Memory-Integer Subtraction with EFLAGS result
1837 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1840 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
1841 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1844 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
1846 // Register-Register Signed Integer Multiplication with EFLAGS result
1847 def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
1849 (IMUL64rr GR64:$src1, GR64:$src2)>;
1851 // Register-Memory Signed Integer Multiplication with EFLAGS result
1852 def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
1854 (IMUL64rm GR64:$src1, addr:$src2)>;
1856 // Register-Integer Signed Integer Multiplication with EFLAGS result
1857 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
1859 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
1860 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
1862 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
1864 // Memory-Integer Signed Integer Multiplication with EFLAGS result
1865 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
1867 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
1868 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
1870 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
1872 // INC and DEC with EFLAGS result. Note that these do not set CF.
1873 def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1874 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1875 def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1877 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1878 def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1879 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1880 def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1882 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1884 def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1885 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1886 def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1888 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1889 def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1890 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1891 def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1893 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1895 def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1896 (INC64r GR64:$src)>;
1897 def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1899 (INC64m addr:$dst)>;
1900 def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1901 (DEC64r GR64:$src)>;
1902 def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1904 (DEC64m addr:$dst)>;
1906 //===----------------------------------------------------------------------===//
1907 // X86-64 SSE Instructions
1908 //===----------------------------------------------------------------------===//
1910 // Move instructions...
1912 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
1913 "mov{d|q}\t{$src, $dst|$dst, $src}",
1915 (v2i64 (scalar_to_vector GR64:$src)))]>;
1916 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
1917 "mov{d|q}\t{$src, $dst|$dst, $src}",
1918 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1921 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1922 "mov{d|q}\t{$src, $dst|$dst, $src}",
1923 [(set FR64:$dst, (bitconvert GR64:$src))]>;
1924 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1925 "movq\t{$src, $dst|$dst, $src}",
1926 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1928 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
1929 "mov{d|q}\t{$src, $dst|$dst, $src}",
1930 [(set GR64:$dst, (bitconvert FR64:$src))]>;
1931 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
1932 "movq\t{$src, $dst|$dst, $src}",
1933 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
1935 //===----------------------------------------------------------------------===//
1936 // X86-64 SSE4.1 Instructions
1937 //===----------------------------------------------------------------------===//
1939 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1940 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
1941 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
1942 (ins VR128:$src1, i32i8imm:$src2),
1943 !strconcat(OpcodeStr,
1944 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1946 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
1947 def mr : SS4AIi8<opc, MRMDestMem, (outs),
1948 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1949 !strconcat(OpcodeStr,
1950 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1951 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1952 addr:$dst)]>, OpSize, REX_W;
1955 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1957 let isTwoAddress = 1 in {
1958 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
1959 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
1960 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1961 !strconcat(OpcodeStr,
1962 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1964 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1966 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
1967 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1968 !strconcat(OpcodeStr,
1969 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1971 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1972 imm:$src3)))]>, OpSize, REX_W;
1976 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;