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> {
32 let ParserMatchClass = ImmSExt8AsmOperand;
35 def lea64mem : Operand<i64> {
36 let PrintMethod = "printlea64mem";
37 let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i32imm);
38 let ParserMatchClass = X86MemAsmOperand;
41 def lea64_32mem : Operand<i32> {
42 let PrintMethod = "printlea64_32mem";
43 let AsmOperandLowerMethod = "lower_lea64_32mem";
44 let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm);
45 let ParserMatchClass = X86MemAsmOperand;
48 //===----------------------------------------------------------------------===//
49 // Complex Pattern Definitions.
51 def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
52 [add, sub, mul, X86mul_imm, shl, or, frameindex,
55 def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
56 [tglobaltlsaddr], []>;
58 //===----------------------------------------------------------------------===//
62 def i64immSExt8 : PatLeaf<(i64 imm), [{
63 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
64 // sign extended field.
65 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
68 def i64immSExt32 : PatLeaf<(i64 imm), [{
69 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
70 // sign extended field.
71 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
74 def i64immZExt32 : PatLeaf<(i64 imm), [{
75 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
76 // unsignedsign extended field.
77 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
80 def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
81 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
82 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
84 def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
85 def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
86 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
87 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
89 def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
90 def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
91 def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
92 def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
94 //===----------------------------------------------------------------------===//
95 // Instruction list...
98 // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
99 // a stack adjustment and the codegen must know that they may modify the stack
100 // pointer before prolog-epilog rewriting occurs.
101 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
102 // sub / add which can clobber EFLAGS.
103 let Defs = [RSP, EFLAGS], Uses = [RSP] in {
104 def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
106 [(X86callseq_start timm:$amt)]>,
107 Requires<[In64BitMode]>;
108 def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
110 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
111 Requires<[In64BitMode]>;
114 //===----------------------------------------------------------------------===//
115 // Call Instructions...
118 // All calls clobber the non-callee saved registers. RSP is marked as
119 // a use to prevent stack-pointer assignments that appear immediately
120 // before calls from potentially appearing dead. Uses for argument
121 // registers are added manually.
122 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
123 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
124 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
125 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
126 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
129 // NOTE: this pattern doesn't match "X86call imm", because we do not know
130 // that the offset between an arbitrary immediate and the call will fit in
131 // the 32-bit pcrel field that we have.
132 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
133 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
135 Requires<[In64BitMode, NotWin64]>;
136 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
137 "call\t{*}$dst", [(X86call GR64:$dst)]>,
138 Requires<[NotWin64]>;
139 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
140 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
141 Requires<[NotWin64]>;
143 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
144 "lcall{q}\t{*}$dst", []>;
147 // FIXME: We need to teach codegen about single list of call-clobbered registers.
149 // All calls clobber the non-callee saved registers. RSP is marked as
150 // a use to prevent stack-pointer assignments that appear immediately
151 // before calls from potentially appearing dead. Uses for argument
152 // registers are added manually.
153 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
154 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
155 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
156 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
158 def WINCALL64pcrel32 : I<0xE8, RawFrm,
159 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
162 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
164 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
165 def WINCALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
167 [(X86call (loadi64 addr:$dst))]>, Requires<[IsWin64]>;
171 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
172 def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
174 "#TC_RETURN $dst $offset",
177 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
178 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
180 "#TC_RETURN $dst $offset",
184 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
185 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
186 "jmp{q}\t{*}$dst # TAILCALL",
190 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
191 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
192 [(brind GR64:$dst)]>;
193 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
194 [(brind (loadi64 addr:$dst))]>;
195 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
196 "ljmp{q}\t{*}$dst", []>;
199 //===----------------------------------------------------------------------===//
200 // EH Pseudo Instructions
202 let isTerminator = 1, isReturn = 1, isBarrier = 1,
204 def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
205 "ret\t#eh_return, addr: $addr",
206 [(X86ehret GR64:$addr)]>;
210 //===----------------------------------------------------------------------===//
211 // Miscellaneous Instructions...
213 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
214 def LEAVE64 : I<0xC9, RawFrm,
215 (outs), (ins), "leave", []>;
216 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
218 def POP64r : I<0x58, AddRegFrm,
219 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
220 def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
221 def POP64rmm: I<0x8F, MRM0m, (outs i64mem:$dst), (ins), "pop{q}\t$dst", []>;
223 let mayStore = 1 in {
224 def PUSH64r : I<0x50, AddRegFrm,
225 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
226 def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
227 def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", []>;
231 let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
232 def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
233 "push{q}\t$imm", []>;
234 def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
235 "push{q}\t$imm", []>;
236 def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
237 "push{q}\t$imm", []>;
240 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
241 def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
242 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
243 def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
245 def LEA64_32r : I<0x8D, MRMSrcMem,
246 (outs GR32:$dst), (ins lea64_32mem:$src),
247 "lea{l}\t{$src|$dst}, {$dst|$src}",
248 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
250 let isReMaterializable = 1 in
251 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
252 "lea{q}\t{$src|$dst}, {$dst|$src}",
253 [(set GR64:$dst, lea64addr:$src)]>;
255 let isTwoAddress = 1 in
256 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
258 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
260 // Bit scan instructions.
261 let Defs = [EFLAGS] in {
262 def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
263 "bsf{q}\t{$src, $dst|$dst, $src}",
264 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
265 def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
266 "bsf{q}\t{$src, $dst|$dst, $src}",
267 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
268 (implicit EFLAGS)]>, TB;
270 def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
271 "bsr{q}\t{$src, $dst|$dst, $src}",
272 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
273 def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
274 "bsr{q}\t{$src, $dst|$dst, $src}",
275 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
276 (implicit EFLAGS)]>, TB;
280 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
281 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
282 [(X86rep_movs i64)]>, REP;
283 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
284 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
285 [(X86rep_stos i64)]>, REP;
287 // Fast system-call instructions
288 def SYSEXIT64 : RI<0x35, RawFrm,
289 (outs), (ins), "sysexit", []>, TB;
291 //===----------------------------------------------------------------------===//
292 // Move Instructions...
295 let neverHasSideEffects = 1 in
296 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
297 "mov{q}\t{$src, $dst|$dst, $src}", []>;
299 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
300 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
301 "movabs{q}\t{$src, $dst|$dst, $src}",
302 [(set GR64:$dst, imm:$src)]>;
303 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
304 "mov{q}\t{$src, $dst|$dst, $src}",
305 [(set GR64:$dst, i64immSExt32:$src)]>;
308 let canFoldAsLoad = 1 in
309 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
310 "mov{q}\t{$src, $dst|$dst, $src}",
311 [(set GR64:$dst, (load addr:$src))]>;
313 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
314 "mov{q}\t{$src, $dst|$dst, $src}",
315 [(store GR64:$src, addr:$dst)]>;
316 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
317 "mov{q}\t{$src, $dst|$dst, $src}",
318 [(store i64immSExt32:$src, addr:$dst)]>;
320 def MOV64o8a : RIi8<0xA0, RawFrm, (outs), (ins i8imm:$src),
321 "mov{q}\t{$src, %rax|%rax, $src}", []>;
322 def MOV64o32a : RIi32<0xA1, RawFrm, (outs), (ins i32imm:$src),
323 "mov{q}\t{$src, %rax|%rax, $src}", []>;
324 def MOV64ao8 : RIi8<0xA2, RawFrm, (outs i8imm:$dst), (ins),
325 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
326 def MOV64ao32 : RIi32<0xA3, RawFrm, (outs i32imm:$dst), (ins),
327 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
329 // Sign/Zero extenders
331 // MOVSX64rr8 always has a REX prefix and it has an 8-bit register
332 // operand, which makes it a rare instruction with an 8-bit register
333 // operand that can never access an h register. If support for h registers
334 // were generalized, this would require a special register class.
335 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
336 "movs{bq|x}\t{$src, $dst|$dst, $src}",
337 [(set GR64:$dst, (sext GR8:$src))]>, TB;
338 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
339 "movs{bq|x}\t{$src, $dst|$dst, $src}",
340 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
341 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
342 "movs{wq|x}\t{$src, $dst|$dst, $src}",
343 [(set GR64:$dst, (sext GR16:$src))]>, TB;
344 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
345 "movs{wq|x}\t{$src, $dst|$dst, $src}",
346 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
347 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
348 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
349 [(set GR64:$dst, (sext GR32:$src))]>;
350 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
351 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
352 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
354 // Use movzbl instead of movzbq when the destination is a register; it's
355 // equivalent due to implicit zero-extending, and it has a smaller encoding.
356 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
357 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
358 [(set GR64:$dst, (zext GR8:$src))]>, TB;
359 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
360 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
361 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
362 // Use movzwl instead of movzwq when the destination is a register; it's
363 // equivalent due to implicit zero-extending, and it has a smaller encoding.
364 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
365 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
366 [(set GR64:$dst, (zext GR16:$src))]>, TB;
367 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
368 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
369 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
371 // There's no movzlq instruction, but movl can be used for this purpose, using
372 // implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
373 // extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
374 // zero-extension, however this isn't possible when the 32-bit value is
375 // defined by a truncate or is copied from something where the high bits aren't
376 // necessarily all zero. In such cases, we fall back to these explicit zext
378 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
379 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
380 [(set GR64:$dst, (zext GR32:$src))]>;
381 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
382 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
383 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
385 // Any instruction that defines a 32-bit result leaves the high half of the
386 // register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
387 // be copying from a truncate, but any other 32-bit operation will zero-extend
389 def def32 : PatLeaf<(i32 GR32:$src), [{
390 return N->getOpcode() != ISD::TRUNCATE &&
391 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
392 N->getOpcode() != ISD::CopyFromReg;
395 // In the case of a 32-bit def that is known to implicitly zero-extend,
396 // we can use a SUBREG_TO_REG.
397 def : Pat<(i64 (zext def32:$src)),
398 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
400 let neverHasSideEffects = 1 in {
401 let Defs = [RAX], Uses = [EAX] in
402 def CDQE : RI<0x98, RawFrm, (outs), (ins),
403 "{cltq|cdqe}", []>; // RAX = signext(EAX)
405 let Defs = [RAX,RDX], Uses = [RAX] in
406 def CQO : RI<0x99, RawFrm, (outs), (ins),
407 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
410 //===----------------------------------------------------------------------===//
411 // Arithmetic Instructions...
414 let Defs = [EFLAGS] in {
416 def ADD64i32 : RI<0x05, RawFrm, (outs), (ins i32imm:$src),
417 "add{q}\t{$src, %rax|%rax, $src}", []>;
419 let isTwoAddress = 1 in {
420 let isConvertibleToThreeAddress = 1 in {
421 let isCommutable = 1 in
422 // Register-Register Addition
423 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
424 "add{q}\t{$src2, $dst|$dst, $src2}",
425 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
428 // Register-Integer Addition
429 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
430 "add{q}\t{$src2, $dst|$dst, $src2}",
431 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
433 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
434 "add{q}\t{$src2, $dst|$dst, $src2}",
435 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
437 } // isConvertibleToThreeAddress
439 // Register-Memory Addition
440 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
441 "add{q}\t{$src2, $dst|$dst, $src2}",
442 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
446 // Memory-Register Addition
447 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
448 "add{q}\t{$src2, $dst|$dst, $src2}",
449 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
451 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
452 "add{q}\t{$src2, $dst|$dst, $src2}",
453 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
455 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
456 "add{q}\t{$src2, $dst|$dst, $src2}",
457 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
460 let Uses = [EFLAGS] in {
462 def ADC64i32 : RI<0x15, RawFrm, (outs), (ins i32imm:$src),
463 "adc{q}\t{$src, %rax|%rax, $src}", []>;
465 let isTwoAddress = 1 in {
466 let isCommutable = 1 in
467 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
468 "adc{q}\t{$src2, $dst|$dst, $src2}",
469 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
471 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
472 "adc{q}\t{$src2, $dst|$dst, $src2}",
473 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
475 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
476 "adc{q}\t{$src2, $dst|$dst, $src2}",
477 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
478 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
479 "adc{q}\t{$src2, $dst|$dst, $src2}",
480 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
483 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
484 "adc{q}\t{$src2, $dst|$dst, $src2}",
485 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
486 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
487 "adc{q}\t{$src2, $dst|$dst, $src2}",
488 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
489 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
490 "adc{q}\t{$src2, $dst|$dst, $src2}",
491 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
494 let isTwoAddress = 1 in {
495 // Register-Register Subtraction
496 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
497 "sub{q}\t{$src2, $dst|$dst, $src2}",
498 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
501 // Register-Memory Subtraction
502 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
503 "sub{q}\t{$src2, $dst|$dst, $src2}",
504 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
507 // Register-Integer Subtraction
508 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
509 (ins GR64:$src1, i64i8imm:$src2),
510 "sub{q}\t{$src2, $dst|$dst, $src2}",
511 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
513 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
514 (ins GR64:$src1, i64i32imm:$src2),
515 "sub{q}\t{$src2, $dst|$dst, $src2}",
516 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
520 def SUB64i32 : RI<0x2D, RawFrm, (outs), (ins i32imm:$src),
521 "sub{q}\t{$src, %rax|%rax, $src}", []>;
523 // Memory-Register Subtraction
524 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
525 "sub{q}\t{$src2, $dst|$dst, $src2}",
526 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
529 // Memory-Integer Subtraction
530 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
531 "sub{q}\t{$src2, $dst|$dst, $src2}",
532 [(store (sub (load addr:$dst), i64immSExt8:$src2),
535 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
536 "sub{q}\t{$src2, $dst|$dst, $src2}",
537 [(store (sub (load addr:$dst), i64immSExt32:$src2),
541 let Uses = [EFLAGS] in {
542 let isTwoAddress = 1 in {
543 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
544 "sbb{q}\t{$src2, $dst|$dst, $src2}",
545 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
547 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
548 "sbb{q}\t{$src2, $dst|$dst, $src2}",
549 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
551 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
552 "sbb{q}\t{$src2, $dst|$dst, $src2}",
553 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
554 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
555 "sbb{q}\t{$src2, $dst|$dst, $src2}",
556 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
559 def SBB64i32 : RI<0x1D, RawFrm, (outs), (ins i32imm:$src),
560 "sbb{q}\t{$src, %rax|%rax, $src}", []>;
562 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
563 "sbb{q}\t{$src2, $dst|$dst, $src2}",
564 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
565 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
566 "sbb{q}\t{$src2, $dst|$dst, $src2}",
567 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
568 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
569 "sbb{q}\t{$src2, $dst|$dst, $src2}",
570 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
574 // Unsigned multiplication
575 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
576 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
577 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
579 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
580 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
582 // Signed multiplication
583 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
584 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
586 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
587 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
590 let Defs = [EFLAGS] in {
591 let isTwoAddress = 1 in {
592 let isCommutable = 1 in
593 // Register-Register Signed Integer Multiplication
594 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
595 (ins GR64:$src1, GR64:$src2),
596 "imul{q}\t{$src2, $dst|$dst, $src2}",
597 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
598 (implicit EFLAGS)]>, TB;
600 // Register-Memory Signed Integer Multiplication
601 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
602 (ins GR64:$src1, i64mem:$src2),
603 "imul{q}\t{$src2, $dst|$dst, $src2}",
604 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
605 (implicit EFLAGS)]>, TB;
608 // Suprisingly enough, these are not two address instructions!
610 // Register-Integer Signed Integer Multiplication
611 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
612 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
613 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
614 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
616 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
617 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
618 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
619 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
622 // Memory-Integer Signed Integer Multiplication
623 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
624 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
625 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
626 [(set GR64:$dst, (mul (load addr:$src1),
629 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
630 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
631 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
632 [(set GR64:$dst, (mul (load addr:$src1),
633 i64immSExt32:$src2)),
637 // Unsigned division / remainder
638 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
639 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
641 // Signed division / remainder
642 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
643 "idiv{q}\t$src", []>;
645 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
647 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
648 "idiv{q}\t$src", []>;
652 // Unary instructions
653 let Defs = [EFLAGS], CodeSize = 2 in {
654 let isTwoAddress = 1 in
655 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
656 [(set GR64:$dst, (ineg GR64:$src)),
658 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
659 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
662 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
663 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
664 [(set GR64:$dst, (add GR64:$src, 1)),
666 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
667 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
670 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
671 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
672 [(set GR64:$dst, (add GR64:$src, -1)),
674 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
675 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
678 // In 64-bit mode, single byte INC and DEC cannot be encoded.
679 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
680 // Can transform into LEA.
681 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
682 [(set GR16:$dst, (add GR16:$src, 1)),
684 OpSize, Requires<[In64BitMode]>;
685 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
686 [(set GR32:$dst, (add GR32:$src, 1)),
688 Requires<[In64BitMode]>;
689 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
690 [(set GR16:$dst, (add GR16:$src, -1)),
692 OpSize, Requires<[In64BitMode]>;
693 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
694 [(set GR32:$dst, (add GR32:$src, -1)),
696 Requires<[In64BitMode]>;
697 } // isConvertibleToThreeAddress
699 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
700 // how to unfold them.
701 let isTwoAddress = 0, CodeSize = 2 in {
702 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
703 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
705 OpSize, Requires<[In64BitMode]>;
706 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
707 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
709 Requires<[In64BitMode]>;
710 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
711 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
713 OpSize, Requires<[In64BitMode]>;
714 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
715 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
717 Requires<[In64BitMode]>;
719 } // Defs = [EFLAGS], CodeSize
722 let Defs = [EFLAGS] in {
723 // Shift instructions
724 let isTwoAddress = 1 in {
726 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
727 "shl{q}\t{%cl, $dst|$dst, %CL}",
728 [(set GR64:$dst, (shl GR64:$src, CL))]>;
729 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
730 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
731 "shl{q}\t{$src2, $dst|$dst, $src2}",
732 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
733 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
738 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
739 "shl{q}\t{%cl, $dst|$dst, %CL}",
740 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
741 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
742 "shl{q}\t{$src, $dst|$dst, $src}",
743 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
744 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
746 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
748 let isTwoAddress = 1 in {
750 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
751 "shr{q}\t{%cl, $dst|$dst, %CL}",
752 [(set GR64:$dst, (srl GR64:$src, CL))]>;
753 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
754 "shr{q}\t{$src2, $dst|$dst, $src2}",
755 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
756 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
758 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
762 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
763 "shr{q}\t{%cl, $dst|$dst, %CL}",
764 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
765 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
766 "shr{q}\t{$src, $dst|$dst, $src}",
767 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
768 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
770 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
772 let isTwoAddress = 1 in {
774 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
775 "sar{q}\t{%cl, $dst|$dst, %CL}",
776 [(set GR64:$dst, (sra GR64:$src, CL))]>;
777 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
778 "sar{q}\t{$src2, $dst|$dst, $src2}",
779 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
780 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
782 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
786 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
787 "sar{q}\t{%cl, $dst|$dst, %CL}",
788 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
789 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
790 "sar{q}\t{$src, $dst|$dst, $src}",
791 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
792 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
794 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
796 // Rotate instructions
797 let isTwoAddress = 1 in {
799 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
800 "rol{q}\t{%cl, $dst|$dst, %CL}",
801 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
802 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
803 "rol{q}\t{$src2, $dst|$dst, $src2}",
804 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
805 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
807 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
811 def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
812 "rol{q}\t{%cl, $dst|$dst, %CL}",
813 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
814 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
815 "rol{q}\t{$src, $dst|$dst, $src}",
816 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
817 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
819 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
821 let isTwoAddress = 1 in {
823 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
824 "ror{q}\t{%cl, $dst|$dst, %CL}",
825 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
826 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
827 "ror{q}\t{$src2, $dst|$dst, $src2}",
828 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
829 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
831 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
835 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
836 "ror{q}\t{%cl, $dst|$dst, %CL}",
837 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
838 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
839 "ror{q}\t{$src, $dst|$dst, $src}",
840 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
841 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
843 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
845 // Double shift instructions (generalizations of rotate)
846 let isTwoAddress = 1 in {
848 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
849 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
850 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
851 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
852 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
853 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
856 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
857 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
858 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
859 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
860 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
863 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
864 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
865 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
866 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
873 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
874 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
875 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
877 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
878 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
879 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
882 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
883 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
884 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
885 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
886 (i8 imm:$src3)), addr:$dst)]>,
888 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
889 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
890 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
891 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
892 (i8 imm:$src3)), addr:$dst)]>,
896 //===----------------------------------------------------------------------===//
897 // Logical Instructions...
900 let isTwoAddress = 1 , AddedComplexity = 15 in
901 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
902 [(set GR64:$dst, (not GR64:$src))]>;
903 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
904 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
906 let Defs = [EFLAGS] in {
907 def AND64i32 : RI<0x25, RawFrm, (outs), (ins i32imm:$src),
908 "and{q}\t{$src, %rax|%rax, $src}", []>;
910 let isTwoAddress = 1 in {
911 let isCommutable = 1 in
912 def AND64rr : RI<0x21, MRMDestReg,
913 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
914 "and{q}\t{$src2, $dst|$dst, $src2}",
915 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
917 def AND64rm : RI<0x23, MRMSrcMem,
918 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
919 "and{q}\t{$src2, $dst|$dst, $src2}",
920 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
922 def AND64ri8 : RIi8<0x83, MRM4r,
923 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
924 "and{q}\t{$src2, $dst|$dst, $src2}",
925 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
927 def AND64ri32 : RIi32<0x81, MRM4r,
928 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
929 "and{q}\t{$src2, $dst|$dst, $src2}",
930 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
934 def AND64mr : RI<0x21, MRMDestMem,
935 (outs), (ins i64mem:$dst, GR64:$src),
936 "and{q}\t{$src, $dst|$dst, $src}",
937 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
939 def AND64mi8 : RIi8<0x83, MRM4m,
940 (outs), (ins i64mem:$dst, i64i8imm :$src),
941 "and{q}\t{$src, $dst|$dst, $src}",
942 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
944 def AND64mi32 : RIi32<0x81, MRM4m,
945 (outs), (ins i64mem:$dst, i64i32imm:$src),
946 "and{q}\t{$src, $dst|$dst, $src}",
947 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
950 let isTwoAddress = 1 in {
951 let isCommutable = 1 in
952 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
953 "or{q}\t{$src2, $dst|$dst, $src2}",
954 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
956 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
957 "or{q}\t{$src2, $dst|$dst, $src2}",
958 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
960 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
961 "or{q}\t{$src2, $dst|$dst, $src2}",
962 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
964 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
965 "or{q}\t{$src2, $dst|$dst, $src2}",
966 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
970 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
971 "or{q}\t{$src, $dst|$dst, $src}",
972 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
974 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
975 "or{q}\t{$src, $dst|$dst, $src}",
976 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
978 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
979 "or{q}\t{$src, $dst|$dst, $src}",
980 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
983 def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i32imm:$src),
984 "or{q}\t{$src, %rax|%rax, $src}", []>;
986 let isTwoAddress = 1 in {
987 let isCommutable = 1 in
988 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
989 "xor{q}\t{$src2, $dst|$dst, $src2}",
990 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
992 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
993 "xor{q}\t{$src2, $dst|$dst, $src2}",
994 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
996 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
997 "xor{q}\t{$src2, $dst|$dst, $src2}",
998 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
1000 def XOR64ri32 : RIi32<0x81, MRM6r,
1001 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1002 "xor{q}\t{$src2, $dst|$dst, $src2}",
1003 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
1004 (implicit EFLAGS)]>;
1007 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1008 "xor{q}\t{$src, $dst|$dst, $src}",
1009 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1010 (implicit EFLAGS)]>;
1011 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
1012 "xor{q}\t{$src, $dst|$dst, $src}",
1013 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1014 (implicit EFLAGS)]>;
1015 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1016 "xor{q}\t{$src, $dst|$dst, $src}",
1017 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1018 (implicit EFLAGS)]>;
1020 def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i32imm:$src),
1021 "xor{q}\t{$src, %rax|%rax, $src}", []>;
1023 } // Defs = [EFLAGS]
1025 //===----------------------------------------------------------------------===//
1026 // Comparison Instructions...
1029 // Integer comparison
1030 let Defs = [EFLAGS] in {
1031 def TEST64i32 : RI<0xa9, RawFrm, (outs), (ins i32imm:$src),
1032 "test{q}\t{$src, %rax|%rax, $src}", []>;
1033 let isCommutable = 1 in
1034 def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1035 "test{q}\t{$src2, $src1|$src1, $src2}",
1036 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
1037 (implicit EFLAGS)]>;
1038 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1039 "test{q}\t{$src2, $src1|$src1, $src2}",
1040 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1041 (implicit EFLAGS)]>;
1042 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1043 (ins GR64:$src1, i64i32imm:$src2),
1044 "test{q}\t{$src2, $src1|$src1, $src2}",
1045 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1046 (implicit EFLAGS)]>;
1047 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1048 (ins i64mem:$src1, i64i32imm:$src2),
1049 "test{q}\t{$src2, $src1|$src1, $src2}",
1050 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1051 (implicit EFLAGS)]>;
1054 def CMP64i32 : RI<0x3D, RawFrm, (outs), (ins i32imm:$src),
1055 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
1056 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1057 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1058 [(X86cmp GR64:$src1, GR64:$src2),
1059 (implicit EFLAGS)]>;
1060 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1061 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1062 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1063 (implicit EFLAGS)]>;
1064 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1065 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1066 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1067 (implicit EFLAGS)]>;
1068 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1069 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1070 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1071 (implicit EFLAGS)]>;
1072 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
1073 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1074 [(X86cmp GR64:$src1, i64immSExt32:$src2),
1075 (implicit EFLAGS)]>;
1076 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1077 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1078 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
1079 (implicit EFLAGS)]>;
1080 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1081 (ins i64mem:$src1, i64i32imm:$src2),
1082 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1083 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1084 (implicit EFLAGS)]>;
1085 } // Defs = [EFLAGS]
1088 // TODO: BTC, BTR, and BTS
1089 let Defs = [EFLAGS] in {
1090 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1091 "bt{q}\t{$src2, $src1|$src1, $src2}",
1092 [(X86bt GR64:$src1, GR64:$src2),
1093 (implicit EFLAGS)]>, TB;
1095 // Unlike with the register+register form, the memory+register form of the
1096 // bt instruction does not ignore the high bits of the index. From ISel's
1097 // perspective, this is pretty bizarre. Disable these instructions for now.
1098 //def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1099 // "bt{q}\t{$src2, $src1|$src1, $src2}",
1100 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
1101 // (implicit EFLAGS)]>, TB;
1103 def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1104 "bt{q}\t{$src2, $src1|$src1, $src2}",
1105 [(X86bt GR64:$src1, i64immSExt8:$src2),
1106 (implicit EFLAGS)]>, TB;
1107 // Note that these instructions don't need FastBTMem because that
1108 // only applies when the other operand is in a register. When it's
1109 // an immediate, bt is still fast.
1110 def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1111 "bt{q}\t{$src2, $src1|$src1, $src2}",
1112 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1113 (implicit EFLAGS)]>, TB;
1114 } // Defs = [EFLAGS]
1116 // Conditional moves
1117 let Uses = [EFLAGS], isTwoAddress = 1 in {
1118 let isCommutable = 1 in {
1119 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
1120 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1121 "cmovb\t{$src2, $dst|$dst, $src2}",
1122 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1123 X86_COND_B, EFLAGS))]>, TB;
1124 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
1125 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1126 "cmovae\t{$src2, $dst|$dst, $src2}",
1127 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1128 X86_COND_AE, EFLAGS))]>, TB;
1129 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
1130 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1131 "cmove\t{$src2, $dst|$dst, $src2}",
1132 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1133 X86_COND_E, EFLAGS))]>, TB;
1134 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
1135 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1136 "cmovne\t{$src2, $dst|$dst, $src2}",
1137 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1138 X86_COND_NE, EFLAGS))]>, TB;
1139 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
1140 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1141 "cmovbe\t{$src2, $dst|$dst, $src2}",
1142 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1143 X86_COND_BE, EFLAGS))]>, TB;
1144 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
1145 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1146 "cmova\t{$src2, $dst|$dst, $src2}",
1147 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1148 X86_COND_A, EFLAGS))]>, TB;
1149 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
1150 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1151 "cmovl\t{$src2, $dst|$dst, $src2}",
1152 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1153 X86_COND_L, EFLAGS))]>, TB;
1154 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
1155 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1156 "cmovge\t{$src2, $dst|$dst, $src2}",
1157 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1158 X86_COND_GE, EFLAGS))]>, TB;
1159 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
1160 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1161 "cmovle\t{$src2, $dst|$dst, $src2}",
1162 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1163 X86_COND_LE, EFLAGS))]>, TB;
1164 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
1165 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1166 "cmovg\t{$src2, $dst|$dst, $src2}",
1167 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1168 X86_COND_G, EFLAGS))]>, TB;
1169 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1170 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1171 "cmovs\t{$src2, $dst|$dst, $src2}",
1172 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1173 X86_COND_S, EFLAGS))]>, TB;
1174 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1175 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1176 "cmovns\t{$src2, $dst|$dst, $src2}",
1177 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1178 X86_COND_NS, EFLAGS))]>, TB;
1179 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1180 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1181 "cmovp\t{$src2, $dst|$dst, $src2}",
1182 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1183 X86_COND_P, EFLAGS))]>, TB;
1184 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1185 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1186 "cmovnp\t{$src2, $dst|$dst, $src2}",
1187 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1188 X86_COND_NP, EFLAGS))]>, TB;
1189 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1190 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1191 "cmovo\t{$src2, $dst|$dst, $src2}",
1192 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1193 X86_COND_O, EFLAGS))]>, TB;
1194 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1195 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1196 "cmovno\t{$src2, $dst|$dst, $src2}",
1197 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1198 X86_COND_NO, EFLAGS))]>, TB;
1199 } // isCommutable = 1
1201 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1202 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1203 "cmovb\t{$src2, $dst|$dst, $src2}",
1204 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1205 X86_COND_B, EFLAGS))]>, TB;
1206 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1207 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1208 "cmovae\t{$src2, $dst|$dst, $src2}",
1209 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1210 X86_COND_AE, EFLAGS))]>, TB;
1211 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1212 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1213 "cmove\t{$src2, $dst|$dst, $src2}",
1214 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1215 X86_COND_E, EFLAGS))]>, TB;
1216 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1217 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1218 "cmovne\t{$src2, $dst|$dst, $src2}",
1219 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1220 X86_COND_NE, EFLAGS))]>, TB;
1221 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1222 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1223 "cmovbe\t{$src2, $dst|$dst, $src2}",
1224 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1225 X86_COND_BE, EFLAGS))]>, TB;
1226 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1227 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1228 "cmova\t{$src2, $dst|$dst, $src2}",
1229 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1230 X86_COND_A, EFLAGS))]>, TB;
1231 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1232 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1233 "cmovl\t{$src2, $dst|$dst, $src2}",
1234 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1235 X86_COND_L, EFLAGS))]>, TB;
1236 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1237 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1238 "cmovge\t{$src2, $dst|$dst, $src2}",
1239 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1240 X86_COND_GE, EFLAGS))]>, TB;
1241 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1242 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1243 "cmovle\t{$src2, $dst|$dst, $src2}",
1244 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1245 X86_COND_LE, EFLAGS))]>, TB;
1246 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1247 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1248 "cmovg\t{$src2, $dst|$dst, $src2}",
1249 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1250 X86_COND_G, EFLAGS))]>, TB;
1251 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1252 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1253 "cmovs\t{$src2, $dst|$dst, $src2}",
1254 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1255 X86_COND_S, EFLAGS))]>, TB;
1256 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1257 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1258 "cmovns\t{$src2, $dst|$dst, $src2}",
1259 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1260 X86_COND_NS, EFLAGS))]>, TB;
1261 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1262 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1263 "cmovp\t{$src2, $dst|$dst, $src2}",
1264 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1265 X86_COND_P, EFLAGS))]>, TB;
1266 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1267 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1268 "cmovnp\t{$src2, $dst|$dst, $src2}",
1269 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1270 X86_COND_NP, EFLAGS))]>, TB;
1271 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1272 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1273 "cmovo\t{$src2, $dst|$dst, $src2}",
1274 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1275 X86_COND_O, EFLAGS))]>, TB;
1276 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1277 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1278 "cmovno\t{$src2, $dst|$dst, $src2}",
1279 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1280 X86_COND_NO, EFLAGS))]>, TB;
1283 //===----------------------------------------------------------------------===//
1284 // Conversion Instructions...
1287 // f64 -> signed i64
1288 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1289 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1291 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1292 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1293 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1294 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1295 (load addr:$src)))]>;
1296 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1297 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1298 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1299 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1300 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1301 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1302 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1303 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1305 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1306 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1307 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1309 (int_x86_sse2_cvttsd2si64
1310 (load addr:$src)))]>;
1312 // Signed i64 -> f64
1313 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1314 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1315 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1316 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1317 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1318 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1320 let isTwoAddress = 1 in {
1321 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1322 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1323 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1325 (int_x86_sse2_cvtsi642sd VR128:$src1,
1327 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1328 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1329 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1331 (int_x86_sse2_cvtsi642sd VR128:$src1,
1332 (loadi64 addr:$src2)))]>;
1335 // Signed i64 -> f32
1336 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1337 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1338 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1339 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1340 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1341 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1343 let isTwoAddress = 1 in {
1344 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1345 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1346 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1348 (int_x86_sse_cvtsi642ss VR128:$src1,
1350 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1351 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1352 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1354 (int_x86_sse_cvtsi642ss VR128:$src1,
1355 (loadi64 addr:$src2)))]>;
1358 // f32 -> signed i64
1359 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1360 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1362 (int_x86_sse_cvtss2si64 VR128:$src))]>;
1363 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1364 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1365 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1366 (load addr:$src)))]>;
1367 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1368 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1369 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1370 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1371 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1372 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1373 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1374 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1376 (int_x86_sse_cvttss2si64 VR128:$src))]>;
1377 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1378 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1380 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1382 //===----------------------------------------------------------------------===//
1383 // Alias Instructions
1384 //===----------------------------------------------------------------------===//
1386 // Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1387 // equivalent due to implicit zero-extending, and it sometimes has a smaller
1389 // FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
1390 // when we have a better way to specify isel priority.
1391 let AddedComplexity = 1 in
1393 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
1396 // Materialize i64 constant where top 32-bits are zero.
1397 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1398 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1399 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1400 [(set GR64:$dst, i64immZExt32:$src)]>;
1402 //===----------------------------------------------------------------------===//
1403 // Thread Local Storage Instructions
1404 //===----------------------------------------------------------------------===//
1406 // All calls clobber the non-callee saved registers. RSP is marked as
1407 // a use to prevent stack-pointer assignments that appear immediately
1408 // before calls from potentially appearing dead.
1409 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1410 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1411 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1412 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1413 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1415 def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
1417 "leaq\t$sym(%rip), %rdi; "
1420 "call\t__tls_get_addr@PLT",
1421 [(X86tlsaddr tls64addr:$sym)]>,
1422 Requires<[In64BitMode]>;
1424 let AddedComplexity = 5, isCodeGenOnly = 1 in
1425 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1426 "movq\t%gs:$src, $dst",
1427 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1429 let AddedComplexity = 5, isCodeGenOnly = 1 in
1430 def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1431 "movq\t%fs:$src, $dst",
1432 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1434 //===----------------------------------------------------------------------===//
1435 // Atomic Instructions
1436 //===----------------------------------------------------------------------===//
1438 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1439 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1441 "cmpxchgq\t$swap,$ptr",
1442 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1445 let Constraints = "$val = $dst" in {
1446 let Defs = [EFLAGS] in
1447 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1450 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1453 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1455 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1458 // Optimized codegen when the non-memory output is not used.
1459 // FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1460 def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1462 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1463 def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1464 (ins i64mem:$dst, i64i8imm :$src2),
1466 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1467 def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1468 (ins i64mem:$dst, i64i32imm :$src2),
1470 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1471 def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1473 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1474 def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1475 (ins i64mem:$dst, i64i8imm :$src2),
1477 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1478 def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1479 (ins i64mem:$dst, i64i32imm:$src2),
1481 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1482 def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1484 "inc{q}\t$dst", []>, LOCK;
1485 def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1487 "dec{q}\t$dst", []>, LOCK;
1489 // Atomic exchange, and, or, xor
1490 let Constraints = "$val = $dst", Defs = [EFLAGS],
1491 usesCustomDAGSchedInserter = 1 in {
1492 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1493 "#ATOMAND64 PSEUDO!",
1494 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1495 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1496 "#ATOMOR64 PSEUDO!",
1497 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1498 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1499 "#ATOMXOR64 PSEUDO!",
1500 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1501 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1502 "#ATOMNAND64 PSEUDO!",
1503 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1504 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1505 "#ATOMMIN64 PSEUDO!",
1506 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1507 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1508 "#ATOMMAX64 PSEUDO!",
1509 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1510 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1511 "#ATOMUMIN64 PSEUDO!",
1512 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1513 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1514 "#ATOMUMAX64 PSEUDO!",
1515 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1518 //===----------------------------------------------------------------------===//
1519 // Non-Instruction Patterns
1520 //===----------------------------------------------------------------------===//
1522 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1523 // code model mode, should use 'movabs'. FIXME: This is really a hack, the
1524 // 'movabs' predicate should handle this sort of thing.
1525 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1526 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
1527 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1528 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
1529 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1530 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
1531 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1532 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
1534 // In static codegen with small code model, we can get the address of a label
1535 // into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1536 // the MOV64ri64i32 should accept these.
1537 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1538 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1539 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1540 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1541 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1542 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1543 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1544 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1546 // In kernel code model, we can get the address of a label
1547 // into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1548 // the MOV64ri32 should accept these.
1549 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1550 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1551 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1552 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1553 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1554 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1555 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1556 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
1558 // If we have small model and -static mode, it is safe to store global addresses
1559 // directly as immediates. FIXME: This is really a hack, the 'imm' predicate
1560 // for MOV64mi32 should handle this sort of thing.
1561 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1562 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1563 Requires<[NearData, IsStatic]>;
1564 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1565 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1566 Requires<[NearData, IsStatic]>;
1567 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1568 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1569 Requires<[NearData, IsStatic]>;
1570 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1571 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1572 Requires<[NearData, IsStatic]>;
1575 // Direct PC relative function call for small code model. 32-bit displacement
1576 // sign extended to 64-bit.
1577 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1578 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
1579 def : Pat<(X86call (i64 texternalsym:$dst)),
1580 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1582 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1583 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1584 def : Pat<(X86call (i64 texternalsym:$dst)),
1585 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
1588 def : Pat<(X86tcret GR64:$dst, imm:$off),
1589 (TCRETURNri64 GR64:$dst, imm:$off)>;
1591 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1592 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1594 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1595 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1599 // TEST R,R is smaller than CMP R,0
1600 def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
1601 (TEST64rr GR64:$src1, GR64:$src1)>;
1603 // Conditional moves with folded loads with operands swapped and conditions
1605 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1606 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1607 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1608 (CMOVB64rm GR64:$src2, addr:$src1)>;
1609 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1610 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1611 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1612 (CMOVE64rm GR64:$src2, addr:$src1)>;
1613 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1614 (CMOVA64rm GR64:$src2, addr:$src1)>;
1615 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1616 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1617 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1618 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1619 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1620 (CMOVL64rm GR64:$src2, addr:$src1)>;
1621 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1622 (CMOVG64rm GR64:$src2, addr:$src1)>;
1623 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1624 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1625 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1626 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1627 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1628 (CMOVP64rm GR64:$src2, addr:$src1)>;
1629 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1630 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1631 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1632 (CMOVS64rm GR64:$src2, addr:$src1)>;
1633 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1634 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1635 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1636 (CMOVO64rm GR64:$src2, addr:$src1)>;
1638 // zextload bool -> zextload byte
1639 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1642 // When extloading from 16-bit and smaller memory locations into 64-bit registers,
1643 // use zero-extending loads so that the entire 64-bit register is defined, avoiding
1644 // partial-register updates.
1645 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1646 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1647 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1648 // For other extloads, use subregs, since the high contents of the register are
1649 // defined after an extload.
1650 def : Pat<(extloadi64i32 addr:$src),
1651 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
1654 // anyext. Define these to do an explicit zero-extend to
1655 // avoid partial-register updates.
1656 def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1657 def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1658 def : Pat<(i64 (anyext GR32:$src)),
1659 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
1661 //===----------------------------------------------------------------------===//
1663 //===----------------------------------------------------------------------===//
1665 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1666 // +128 doesn't, so in this special case use a sub instead of an add.
1667 def : Pat<(add GR64:$src1, 128),
1668 (SUB64ri8 GR64:$src1, -128)>;
1669 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1670 (SUB64mi8 addr:$dst, -128)>;
1672 // The same trick applies for 32-bit immediate fields in 64-bit
1674 def : Pat<(add GR64:$src1, 0x0000000080000000),
1675 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1676 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1677 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1679 // r & (2^32-1) ==> movz
1680 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1681 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1682 // r & (2^16-1) ==> movz
1683 def : Pat<(and GR64:$src, 0xffff),
1684 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1685 // r & (2^8-1) ==> movz
1686 def : Pat<(and GR64:$src, 0xff),
1687 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1688 // r & (2^8-1) ==> movz
1689 def : Pat<(and GR32:$src1, 0xff),
1690 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
1691 Requires<[In64BitMode]>;
1692 // r & (2^8-1) ==> movz
1693 def : Pat<(and GR16:$src1, 0xff),
1694 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1695 Requires<[In64BitMode]>;
1697 // sext_inreg patterns
1698 def : Pat<(sext_inreg GR64:$src, i32),
1699 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1700 def : Pat<(sext_inreg GR64:$src, i16),
1701 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1702 def : Pat<(sext_inreg GR64:$src, i8),
1703 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1704 def : Pat<(sext_inreg GR32:$src, i8),
1705 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1706 Requires<[In64BitMode]>;
1707 def : Pat<(sext_inreg GR16:$src, i8),
1708 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1709 Requires<[In64BitMode]>;
1712 def : Pat<(i32 (trunc GR64:$src)),
1713 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
1714 def : Pat<(i16 (trunc GR64:$src)),
1715 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
1716 def : Pat<(i8 (trunc GR64:$src)),
1717 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
1718 def : Pat<(i8 (trunc GR32:$src)),
1719 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
1720 Requires<[In64BitMode]>;
1721 def : Pat<(i8 (trunc GR16:$src)),
1722 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1723 Requires<[In64BitMode]>;
1725 // h-register tricks.
1726 // For now, be conservative on x86-64 and use an h-register extract only if the
1727 // value is immediately zero-extended or stored, which are somewhat common
1728 // cases. This uses a bunch of code to prevent a register requiring a REX prefix
1729 // from being allocated in the same instruction as the h register, as there's
1730 // currently no way to describe this requirement to the register allocator.
1732 // h-register extract and zero-extend.
1733 def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1737 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
1738 x86_subreg_8bit_hi)),
1740 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1742 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
1743 x86_subreg_8bit_hi))>,
1744 Requires<[In64BitMode]>;
1745 def : Pat<(srl_su GR16:$src, (i8 8)),
1748 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1749 x86_subreg_8bit_hi)),
1751 Requires<[In64BitMode]>;
1752 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1754 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1755 x86_subreg_8bit_hi))>,
1756 Requires<[In64BitMode]>;
1757 def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
1759 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1760 x86_subreg_8bit_hi))>,
1761 Requires<[In64BitMode]>;
1762 def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1766 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1767 x86_subreg_8bit_hi)),
1769 def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
1773 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1774 x86_subreg_8bit_hi)),
1777 // h-register extract and store.
1778 def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1781 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
1782 x86_subreg_8bit_hi))>;
1783 def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1786 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
1787 x86_subreg_8bit_hi))>,
1788 Requires<[In64BitMode]>;
1789 def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1792 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1793 x86_subreg_8bit_hi))>,
1794 Requires<[In64BitMode]>;
1796 // (shl x, 1) ==> (add x, x)
1797 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1799 // (shl x (and y, 63)) ==> (shl x, y)
1800 def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1801 (SHL64rCL GR64:$src1)>;
1802 def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1803 (SHL64mCL addr:$dst)>;
1805 def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1806 (SHR64rCL GR64:$src1)>;
1807 def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1808 (SHR64mCL addr:$dst)>;
1810 def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1811 (SAR64rCL GR64:$src1)>;
1812 def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1813 (SAR64mCL addr:$dst)>;
1815 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1816 def : Pat<(or (srl GR64:$src1, CL:$amt),
1817 (shl GR64:$src2, (sub 64, CL:$amt))),
1818 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1820 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1821 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1822 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1824 def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1825 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1826 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1828 def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1829 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1831 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1833 def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1834 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1836 def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1837 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1838 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1840 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1841 def : Pat<(or (shl GR64:$src1, CL:$amt),
1842 (srl GR64:$src2, (sub 64, CL:$amt))),
1843 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1845 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1846 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1847 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1849 def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1850 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1851 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1853 def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1854 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1856 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1858 def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1859 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1861 def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1862 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1863 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1865 // X86 specific add which produces a flag.
1866 def : Pat<(addc GR64:$src1, GR64:$src2),
1867 (ADD64rr GR64:$src1, GR64:$src2)>;
1868 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1869 (ADD64rm GR64:$src1, addr:$src2)>;
1870 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1871 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1872 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1873 (ADD64ri32 GR64:$src1, imm:$src2)>;
1875 def : Pat<(subc GR64:$src1, GR64:$src2),
1876 (SUB64rr GR64:$src1, GR64:$src2)>;
1877 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1878 (SUB64rm GR64:$src1, addr:$src2)>;
1879 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1880 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1881 def : Pat<(subc GR64:$src1, imm:$src2),
1882 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1884 //===----------------------------------------------------------------------===//
1885 // EFLAGS-defining Patterns
1886 //===----------------------------------------------------------------------===//
1888 // Register-Register Addition with EFLAGS result
1889 def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
1891 (ADD64rr GR64:$src1, GR64:$src2)>;
1893 // Register-Integer Addition with EFLAGS result
1894 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
1896 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1897 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
1899 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
1901 // Register-Memory Addition with EFLAGS result
1902 def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
1904 (ADD64rm GR64:$src1, addr:$src2)>;
1906 // Memory-Register Addition with EFLAGS result
1907 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
1910 (ADD64mr addr:$dst, GR64:$src2)>;
1911 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1914 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
1915 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1918 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
1920 // Register-Register Subtraction with EFLAGS result
1921 def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
1923 (SUB64rr GR64:$src1, GR64:$src2)>;
1925 // Register-Memory Subtraction with EFLAGS result
1926 def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
1928 (SUB64rm GR64:$src1, addr:$src2)>;
1930 // Register-Integer Subtraction with EFLAGS result
1931 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
1933 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1934 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
1936 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1938 // Memory-Register Subtraction with EFLAGS result
1939 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
1942 (SUB64mr addr:$dst, GR64:$src2)>;
1944 // Memory-Integer Subtraction with EFLAGS result
1945 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1948 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
1949 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1952 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
1954 // Register-Register Signed Integer Multiplication with EFLAGS result
1955 def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
1957 (IMUL64rr GR64:$src1, GR64:$src2)>;
1959 // Register-Memory Signed Integer Multiplication with EFLAGS result
1960 def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
1962 (IMUL64rm GR64:$src1, addr:$src2)>;
1964 // Register-Integer Signed Integer Multiplication with EFLAGS result
1965 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
1967 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
1968 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
1970 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
1972 // Memory-Integer Signed Integer Multiplication with EFLAGS result
1973 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
1975 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
1976 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
1978 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
1980 // INC and DEC with EFLAGS result. Note that these do not set CF.
1981 def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1982 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1983 def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1985 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1986 def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1987 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1988 def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1990 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1992 def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1993 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1994 def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1996 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1997 def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1998 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1999 def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
2001 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2003 def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
2004 (INC64r GR64:$src)>;
2005 def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
2007 (INC64m addr:$dst)>;
2008 def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
2009 (DEC64r GR64:$src)>;
2010 def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
2012 (DEC64m addr:$dst)>;
2014 //===----------------------------------------------------------------------===//
2015 // X86-64 SSE Instructions
2016 //===----------------------------------------------------------------------===//
2018 // Move instructions...
2020 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2021 "mov{d|q}\t{$src, $dst|$dst, $src}",
2023 (v2i64 (scalar_to_vector GR64:$src)))]>;
2024 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
2025 "mov{d|q}\t{$src, $dst|$dst, $src}",
2026 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2029 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
2030 "mov{d|q}\t{$src, $dst|$dst, $src}",
2031 [(set FR64:$dst, (bitconvert GR64:$src))]>;
2032 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
2033 "movq\t{$src, $dst|$dst, $src}",
2034 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2036 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
2037 "mov{d|q}\t{$src, $dst|$dst, $src}",
2038 [(set GR64:$dst, (bitconvert FR64:$src))]>;
2039 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
2040 "movq\t{$src, $dst|$dst, $src}",
2041 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
2043 //===----------------------------------------------------------------------===//
2044 // X86-64 SSE4.1 Instructions
2045 //===----------------------------------------------------------------------===//
2047 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2048 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
2049 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
2050 (ins VR128:$src1, i32i8imm:$src2),
2051 !strconcat(OpcodeStr,
2052 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2054 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
2055 def mr : SS4AIi8<opc, MRMDestMem, (outs),
2056 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2057 !strconcat(OpcodeStr,
2058 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2059 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2060 addr:$dst)]>, OpSize, REX_W;
2063 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2065 let isTwoAddress = 1 in {
2066 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
2067 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
2068 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2069 !strconcat(OpcodeStr,
2070 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2072 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2074 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
2075 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2076 !strconcat(OpcodeStr,
2077 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2079 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2080 imm:$src3)))]>, OpSize, REX_W;
2084 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;
2086 // -disable-16bit support.
2087 def : Pat<(truncstorei16 (i64 imm:$src), addr:$dst),
2088 (MOV16mi addr:$dst, imm:$src)>;
2089 def : Pat<(truncstorei16 GR64:$src, addr:$dst),
2090 (MOV16mr addr:$dst, (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
2091 def : Pat<(i64 (sextloadi16 addr:$dst)),
2092 (MOVSX64rm16 addr:$dst)>;
2093 def : Pat<(i64 (zextloadi16 addr:$dst)),
2094 (MOVZX64rm16 addr:$dst)>;
2095 def : Pat<(i64 (extloadi16 addr:$dst)),
2096 (MOVZX64rm16 addr:$dst)>;