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> {
22 let ParserMatchClass = ImmSExti64i32AsmOperand;
25 // 64-bits but only 32 bits are significant, and those bits are treated as being
27 def i64i32imm_pcrel : Operand<i64> {
28 let PrintMethod = "print_pcrel_imm";
29 let ParserMatchClass = X86AbsMemAsmOperand;
33 // 64-bits but only 8 bits are significant.
34 def i64i8imm : Operand<i64> {
35 let ParserMatchClass = ImmSExti64i8AsmOperand;
38 def lea64_32mem : Operand<i32> {
39 let PrintMethod = "printi32mem";
40 let AsmOperandLowerMethod = "lower_lea64_32mem";
41 let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm, i8imm);
42 let ParserMatchClass = X86MemAsmOperand;
46 // Special i64mem for addresses of load folding tail calls. These are not
47 // allowed to use callee-saved registers since they must be scheduled
48 // after callee-saved register are popped.
49 def i64mem_TC : Operand<i64> {
50 let PrintMethod = "printi64mem";
51 let MIOperandInfo = (ops GR64_TC, i8imm, GR64_TC, i32imm, i8imm);
52 let ParserMatchClass = X86MemAsmOperand;
55 //===----------------------------------------------------------------------===//
56 // Complex Pattern Definitions.
58 def lea64addr : ComplexPattern<i64, 5, "SelectLEAAddr",
59 [add, sub, mul, X86mul_imm, shl, or, frameindex,
62 def tls64addr : ComplexPattern<i64, 5, "SelectTLSADDRAddr",
63 [tglobaltlsaddr], []>;
65 //===----------------------------------------------------------------------===//
69 def i64immSExt8 : PatLeaf<(i64 immSext8)>;
71 def GetLo32XForm : SDNodeXForm<imm, [{
72 // Transformation function: get the low 32 bits.
73 return getI32Imm((unsigned)N->getZExtValue());
76 def i64immSExt32 : PatLeaf<(i64 imm), [{
77 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
78 // sign extended field.
79 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
83 def i64immZExt32 : PatLeaf<(i64 imm), [{
84 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
85 // unsignedsign extended field.
86 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
89 def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
90 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
91 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
93 def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
94 def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
95 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
96 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
98 def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
99 def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
100 def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
101 def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
103 //===----------------------------------------------------------------------===//
104 // Instruction list...
107 // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
108 // a stack adjustment and the codegen must know that they may modify the stack
109 // pointer before prolog-epilog rewriting occurs.
110 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
111 // sub / add which can clobber EFLAGS.
112 let Defs = [RSP, EFLAGS], Uses = [RSP] in {
113 def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
115 [(X86callseq_start timm:$amt)]>,
116 Requires<[In64BitMode]>;
117 def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
119 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
120 Requires<[In64BitMode]>;
123 // Interrupt Instructions
124 def IRET64 : RI<0xcf, RawFrm, (outs), (ins), "iret{q}", []>;
126 //===----------------------------------------------------------------------===//
127 // Call Instructions...
130 // All calls clobber the non-callee saved registers. RSP is marked as
131 // a use to prevent stack-pointer assignments that appear immediately
132 // before calls from potentially appearing dead. Uses for argument
133 // registers are added manually.
134 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
135 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
136 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
137 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
138 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
141 // NOTE: this pattern doesn't match "X86call imm", because we do not know
142 // that the offset between an arbitrary immediate and the call will fit in
143 // the 32-bit pcrel field that we have.
144 def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
145 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
146 "call{q}\t$dst", []>,
147 Requires<[In64BitMode, NotWin64]>;
148 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
149 "call{q}\t{*}$dst", [(X86call GR64:$dst)]>,
150 Requires<[NotWin64]>;
151 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
152 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
153 Requires<[NotWin64]>;
155 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
156 "lcall{q}\t{*}$dst", []>;
159 // FIXME: We need to teach codegen about single list of call-clobbered
162 // All calls clobber the non-callee saved registers. RSP is marked as
163 // a use to prevent stack-pointer assignments that appear immediately
164 // before calls from potentially appearing dead. Uses for argument
165 // registers are added manually.
166 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
167 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
168 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
169 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
171 def WINCALL64pcrel32 : I<0xE8, RawFrm,
172 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
175 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
177 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
178 def WINCALL64m : I<0xFF, MRM2m, (outs),
179 (ins i64mem:$dst, variable_ops), "call\t{*}$dst",
180 [(X86call (loadi64 addr:$dst))]>,
185 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
186 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
187 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
188 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
189 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
190 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
192 def TCRETURNdi64 : I<0, Pseudo, (outs),
193 (ins i64i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
194 "#TC_RETURN $dst $offset", []>;
195 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64_TC:$dst, i32imm:$offset,
197 "#TC_RETURN $dst $offset", []>;
199 def TCRETURNmi64 : I<0, Pseudo, (outs),
200 (ins i64mem_TC:$dst, i32imm:$offset, variable_ops),
201 "#TC_RETURN $dst $offset", []>;
203 def TAILJMPd64 : Ii32PCRel<0xE9, RawFrm, (outs),
204 (ins i64i32imm_pcrel:$dst, variable_ops),
205 "jmp\t$dst # TAILCALL", []>;
206 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64_TC:$dst, variable_ops),
207 "jmp{q}\t{*}$dst # TAILCALL", []>;
210 def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst, variable_ops),
211 "jmp{q}\t{*}$dst # TAILCALL", []>;
215 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
216 def JMP64pcrel32 : I<0xE9, RawFrm, (outs), (ins brtarget:$dst),
218 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
219 [(brind GR64:$dst)]>;
220 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
221 [(brind (loadi64 addr:$dst))]>;
222 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
223 "ljmp{q}\t{*}$dst", []>;
226 //===----------------------------------------------------------------------===//
227 // EH Pseudo Instructions
229 let isTerminator = 1, isReturn = 1, isBarrier = 1,
230 hasCtrlDep = 1, isCodeGenOnly = 1 in {
231 def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
232 "ret\t#eh_return, addr: $addr",
233 [(X86ehret GR64:$addr)]>;
237 //===----------------------------------------------------------------------===//
238 // Miscellaneous Instructions...
241 def POPCNT64rr : RI<0xB8, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
242 "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
244 def POPCNT64rm : RI<0xB8, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
245 "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
247 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
248 def LEAVE64 : I<0xC9, RawFrm,
249 (outs), (ins), "leave", []>, Requires<[In64BitMode]>;
250 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
252 def POP64r : I<0x58, AddRegFrm,
253 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
254 def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
255 def POP64rmm: I<0x8F, MRM0m, (outs i64mem:$dst), (ins), "pop{q}\t$dst", []>;
257 let mayStore = 1 in {
258 def PUSH64r : I<0x50, AddRegFrm,
259 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
260 def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
261 def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", []>;
265 let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
266 def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
267 "push{q}\t$imm", []>;
268 def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
269 "push{q}\t$imm", []>;
270 def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i64i32imm:$imm),
271 "push{q}\t$imm", []>;
274 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1, neverHasSideEffects=1 in
275 def POPF64 : I<0x9D, RawFrm, (outs), (ins), "popfq", []>,
276 Requires<[In64BitMode]>;
277 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in
278 def PUSHF64 : I<0x9C, RawFrm, (outs), (ins), "pushfq", []>,
279 Requires<[In64BitMode]>;
281 def LEA64_32r : I<0x8D, MRMSrcMem,
282 (outs GR32:$dst), (ins lea64_32mem:$src),
283 "lea{l}\t{$src|$dst}, {$dst|$src}",
284 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
286 let isReMaterializable = 1 in
287 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
288 "lea{q}\t{$src|$dst}, {$dst|$src}",
289 [(set GR64:$dst, lea64addr:$src)]>;
291 let Constraints = "$src = $dst" in
292 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
294 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
296 // Bit scan instructions.
297 let Defs = [EFLAGS] in {
298 def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
299 "bsf{q}\t{$src, $dst|$dst, $src}",
300 [(set GR64:$dst, EFLAGS, (X86bsf GR64:$src))]>, TB;
301 def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
302 "bsf{q}\t{$src, $dst|$dst, $src}",
303 [(set GR64:$dst, EFLAGS, (X86bsf (loadi64 addr:$src)))]>, TB;
305 def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
306 "bsr{q}\t{$src, $dst|$dst, $src}",
307 [(set GR64:$dst, EFLAGS, (X86bsr GR64:$src))]>, TB;
308 def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
309 "bsr{q}\t{$src, $dst|$dst, $src}",
310 [(set GR64:$dst, EFLAGS, (X86bsr (loadi64 addr:$src)))]>, TB;
314 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI], isCodeGenOnly = 1 in
315 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
316 [(X86rep_movs i64)]>, REP;
317 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI], isCodeGenOnly = 1 in
318 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
319 [(X86rep_stos i64)]>, REP;
321 let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in
322 def MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "movsq", []>;
324 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI,EFLAGS] in
325 def STOSQ : RI<0xAB, RawFrm, (outs), (ins), "stosq", []>;
327 def SCAS64 : RI<0xAF, RawFrm, (outs), (ins), "scasq", []>;
329 def CMPS64 : RI<0xA7, RawFrm, (outs), (ins), "cmpsq", []>;
331 // Fast system-call instructions
332 def SYSEXIT64 : RI<0x35, RawFrm,
333 (outs), (ins), "sysexit", []>, TB, Requires<[In64BitMode]>;
335 //===----------------------------------------------------------------------===//
336 // Move Instructions...
339 let neverHasSideEffects = 1 in
340 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
341 "mov{q}\t{$src, $dst|$dst, $src}", []>;
343 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
344 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
345 "movabs{q}\t{$src, $dst|$dst, $src}",
346 [(set GR64:$dst, imm:$src)]>;
347 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
348 "mov{q}\t{$src, $dst|$dst, $src}",
349 [(set GR64:$dst, i64immSExt32:$src)]>;
352 // The assembler accepts movq of a 64-bit immediate as an alternate spelling of
354 let isAsmParserOnly = 1 in {
355 def MOV64ri_alt : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
356 "mov{q}\t{$src, $dst|$dst, $src}", []>;
359 let isCodeGenOnly = 1 in {
360 def MOV64rr_REV : RI<0x8B, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
361 "mov{q}\t{$src, $dst|$dst, $src}", []>;
364 let canFoldAsLoad = 1, isReMaterializable = 1 in
365 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
366 "mov{q}\t{$src, $dst|$dst, $src}",
367 [(set GR64:$dst, (load addr:$src))]>;
369 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
370 "mov{q}\t{$src, $dst|$dst, $src}",
371 [(store GR64:$src, addr:$dst)]>;
372 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
373 "mov{q}\t{$src, $dst|$dst, $src}",
374 [(store i64immSExt32:$src, addr:$dst)]>;
376 /// Versions of MOV64rr, MOV64rm, and MOV64mr for i64mem_TC and GR64_TC.
377 let isCodeGenOnly = 1 in {
378 let neverHasSideEffects = 1 in
379 def MOV64rr_TC : RI<0x89, MRMDestReg, (outs GR64_TC:$dst), (ins GR64_TC:$src),
380 "mov{q}\t{$src, $dst|$dst, $src}", []>;
383 canFoldAsLoad = 1, isReMaterializable = 1 in
384 def MOV64rm_TC : RI<0x8B, MRMSrcMem, (outs GR64_TC:$dst), (ins i64mem_TC:$src),
385 "mov{q}\t{$src, $dst|$dst, $src}",
389 def MOV64mr_TC : RI<0x89, MRMDestMem, (outs), (ins i64mem_TC:$dst, GR64_TC:$src),
390 "mov{q}\t{$src, $dst|$dst, $src}",
394 def MOV64o8a : RIi8<0xA0, RawFrm, (outs), (ins offset8:$src),
395 "mov{q}\t{$src, %rax|%rax, $src}", []>;
396 def MOV64o64a : RIi32<0xA1, RawFrm, (outs), (ins offset64:$src),
397 "mov{q}\t{$src, %rax|%rax, $src}", []>;
398 def MOV64ao8 : RIi8<0xA2, RawFrm, (outs offset8:$dst), (ins),
399 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
400 def MOV64ao64 : RIi32<0xA3, RawFrm, (outs offset64:$dst), (ins),
401 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
403 // Moves to and from segment registers
404 def MOV64rs : RI<0x8C, MRMDestReg, (outs GR64:$dst), (ins SEGMENT_REG:$src),
405 "mov{q}\t{$src, $dst|$dst, $src}", []>;
406 def MOV64ms : RI<0x8C, MRMDestMem, (outs i64mem:$dst), (ins SEGMENT_REG:$src),
407 "mov{q}\t{$src, $dst|$dst, $src}", []>;
408 def MOV64sr : RI<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR64:$src),
409 "mov{q}\t{$src, $dst|$dst, $src}", []>;
410 def MOV64sm : RI<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i64mem:$src),
411 "mov{q}\t{$src, $dst|$dst, $src}", []>;
413 // Moves to and from debug registers
414 def MOV64rd : I<0x21, MRMDestReg, (outs GR64:$dst), (ins DEBUG_REG:$src),
415 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
416 def MOV64dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR64:$src),
417 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
419 // Moves to and from control registers
420 def MOV64rc : I<0x20, MRMDestReg, (outs GR64:$dst), (ins CONTROL_REG:$src),
421 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
422 def MOV64cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR64:$src),
423 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
425 // Sign/Zero extenders
427 // MOVSX64rr8 always has a REX prefix and it has an 8-bit register
428 // operand, which makes it a rare instruction with an 8-bit register
429 // operand that can never access an h register. If support for h registers
430 // were generalized, this would require a special register class.
431 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
432 "movs{bq|x}\t{$src, $dst|$dst, $src}",
433 [(set GR64:$dst, (sext GR8:$src))]>, TB;
434 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
435 "movs{bq|x}\t{$src, $dst|$dst, $src}",
436 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
437 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
438 "movs{wq|x}\t{$src, $dst|$dst, $src}",
439 [(set GR64:$dst, (sext GR16:$src))]>, TB;
440 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
441 "movs{wq|x}\t{$src, $dst|$dst, $src}",
442 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
443 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
444 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
445 [(set GR64:$dst, (sext GR32:$src))]>;
446 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
447 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
448 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
450 // movzbq and movzwq encodings for the disassembler
451 def MOVZX64rr8_Q : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8:$src),
452 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
453 def MOVZX64rm8_Q : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem:$src),
454 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
455 def MOVZX64rr16_Q : RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
456 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
457 def MOVZX64rm16_Q : RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
458 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
460 // Use movzbl instead of movzbq when the destination is a register; it's
461 // equivalent due to implicit zero-extending, and it has a smaller encoding.
462 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
463 "", [(set GR64:$dst, (zext GR8:$src))]>, TB;
464 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
465 "", [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
466 // Use movzwl instead of movzwq when the destination is a register; it's
467 // equivalent due to implicit zero-extending, and it has a smaller encoding.
468 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
469 "", [(set GR64:$dst, (zext GR16:$src))]>, TB;
470 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
471 "", [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
473 // There's no movzlq instruction, but movl can be used for this purpose, using
474 // implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
475 // extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
476 // zero-extension, however this isn't possible when the 32-bit value is
477 // defined by a truncate or is copied from something where the high bits aren't
478 // necessarily all zero. In such cases, we fall back to these explicit zext
480 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
481 "", [(set GR64:$dst, (zext GR32:$src))]>;
482 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
483 "", [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
485 // Any instruction that defines a 32-bit result leaves the high half of the
486 // register. Truncate can be lowered to EXTRACT_SUBREG. CopyFromReg may
487 // be copying from a truncate. And x86's cmov doesn't do anything if the
488 // condition is false. But any other 32-bit operation will zero-extend
490 def def32 : PatLeaf<(i32 GR32:$src), [{
491 return N->getOpcode() != ISD::TRUNCATE &&
492 N->getOpcode() != TargetOpcode::EXTRACT_SUBREG &&
493 N->getOpcode() != ISD::CopyFromReg &&
494 N->getOpcode() != X86ISD::CMOV;
497 // In the case of a 32-bit def that is known to implicitly zero-extend,
498 // we can use a SUBREG_TO_REG.
499 def : Pat<(i64 (zext def32:$src)),
500 (SUBREG_TO_REG (i64 0), GR32:$src, sub_32bit)>;
502 let neverHasSideEffects = 1 in {
503 let Defs = [RAX], Uses = [EAX] in
504 def CDQE : RI<0x98, RawFrm, (outs), (ins),
505 "{cltq|cdqe}", []>; // RAX = signext(EAX)
507 let Defs = [RAX,RDX], Uses = [RAX] in
508 def CQO : RI<0x99, RawFrm, (outs), (ins),
509 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
512 //===----------------------------------------------------------------------===//
513 // Arithmetic Instructions...
516 let Defs = [EFLAGS] in {
518 def ADD64i32 : RIi32<0x05, RawFrm, (outs), (ins i64i32imm:$src),
519 "add{q}\t{$src, %rax|%rax, $src}", []>;
521 let Constraints = "$src1 = $dst" in {
522 let isConvertibleToThreeAddress = 1 in {
523 let isCommutable = 1 in
524 // Register-Register Addition
525 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst),
526 (ins GR64:$src1, GR64:$src2),
527 "add{q}\t{$src2, $dst|$dst, $src2}",
528 [(set GR64:$dst, EFLAGS,
529 (X86add_flag GR64:$src1, GR64:$src2))]>;
531 // These are alternate spellings for use by the disassembler, we mark them as
532 // code gen only to ensure they aren't matched by the assembler.
533 let isCodeGenOnly = 1 in {
534 def ADD64rr_alt : RI<0x03, MRMSrcReg, (outs GR64:$dst),
535 (ins GR64:$src1, GR64:$src2),
536 "add{l}\t{$src2, $dst|$dst, $src2}", []>;
539 // Register-Integer Addition
540 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst),
541 (ins GR64:$src1, i64i8imm:$src2),
542 "add{q}\t{$src2, $dst|$dst, $src2}",
543 [(set GR64:$dst, EFLAGS,
544 (X86add_flag GR64:$src1, i64immSExt8:$src2))]>;
545 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst),
546 (ins GR64:$src1, i64i32imm:$src2),
547 "add{q}\t{$src2, $dst|$dst, $src2}",
548 [(set GR64:$dst, EFLAGS,
549 (X86add_flag GR64:$src1, i64immSExt32:$src2))]>;
550 } // isConvertibleToThreeAddress
552 // Register-Memory Addition
553 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst),
554 (ins GR64:$src1, i64mem:$src2),
555 "add{q}\t{$src2, $dst|$dst, $src2}",
556 [(set GR64:$dst, EFLAGS,
557 (X86add_flag GR64:$src1, (load addr:$src2)))]>;
559 } // Constraints = "$src1 = $dst"
561 // Memory-Register Addition
562 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
563 "add{q}\t{$src2, $dst|$dst, $src2}",
564 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
566 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
567 "add{q}\t{$src2, $dst|$dst, $src2}",
568 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
570 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
571 "add{q}\t{$src2, $dst|$dst, $src2}",
572 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
575 let Uses = [EFLAGS] in {
577 def ADC64i32 : RIi32<0x15, RawFrm, (outs), (ins i64i32imm:$src),
578 "adc{q}\t{$src, %rax|%rax, $src}", []>;
580 let Constraints = "$src1 = $dst" in {
581 let isCommutable = 1 in
582 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst),
583 (ins GR64:$src1, GR64:$src2),
584 "adc{q}\t{$src2, $dst|$dst, $src2}",
585 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
587 let isCodeGenOnly = 1 in {
588 def ADC64rr_REV : RI<0x13, MRMSrcReg , (outs GR32:$dst),
589 (ins GR64:$src1, GR64:$src2),
590 "adc{q}\t{$src2, $dst|$dst, $src2}", []>;
593 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst),
594 (ins GR64:$src1, i64mem:$src2),
595 "adc{q}\t{$src2, $dst|$dst, $src2}",
596 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
598 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst),
599 (ins GR64:$src1, i64i8imm:$src2),
600 "adc{q}\t{$src2, $dst|$dst, $src2}",
601 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
602 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst),
603 (ins GR64:$src1, i64i32imm:$src2),
604 "adc{q}\t{$src2, $dst|$dst, $src2}",
605 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
606 } // Constraints = "$src1 = $dst"
608 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
609 "adc{q}\t{$src2, $dst|$dst, $src2}",
610 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
611 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
612 "adc{q}\t{$src2, $dst|$dst, $src2}",
613 [(store (adde (load addr:$dst), i64immSExt8:$src2),
615 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
616 "adc{q}\t{$src2, $dst|$dst, $src2}",
617 [(store (adde (load addr:$dst), i64immSExt32:$src2),
621 let Constraints = "$src1 = $dst" in {
622 // Register-Register Subtraction
623 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst),
624 (ins GR64:$src1, GR64:$src2),
625 "sub{q}\t{$src2, $dst|$dst, $src2}",
626 [(set GR64:$dst, EFLAGS,
627 (X86sub_flag GR64:$src1, GR64:$src2))]>;
629 let isCodeGenOnly = 1 in {
630 def SUB64rr_REV : RI<0x2B, MRMSrcReg, (outs GR64:$dst),
631 (ins GR64:$src1, GR64:$src2),
632 "sub{q}\t{$src2, $dst|$dst, $src2}", []>;
635 // Register-Memory Subtraction
636 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst),
637 (ins GR64:$src1, i64mem:$src2),
638 "sub{q}\t{$src2, $dst|$dst, $src2}",
639 [(set GR64:$dst, EFLAGS,
640 (X86sub_flag GR64:$src1, (load addr:$src2)))]>;
642 // Register-Integer Subtraction
643 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
644 (ins GR64:$src1, i64i8imm:$src2),
645 "sub{q}\t{$src2, $dst|$dst, $src2}",
646 [(set GR64:$dst, EFLAGS,
647 (X86sub_flag GR64:$src1, i64immSExt8:$src2))]>;
648 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
649 (ins GR64:$src1, i64i32imm:$src2),
650 "sub{q}\t{$src2, $dst|$dst, $src2}",
651 [(set GR64:$dst, EFLAGS,
652 (X86sub_flag GR64:$src1, i64immSExt32:$src2))]>;
653 } // Constraints = "$src1 = $dst"
655 def SUB64i32 : RIi32<0x2D, RawFrm, (outs), (ins i64i32imm:$src),
656 "sub{q}\t{$src, %rax|%rax, $src}", []>;
658 // Memory-Register Subtraction
659 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
660 "sub{q}\t{$src2, $dst|$dst, $src2}",
661 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
664 // Memory-Integer Subtraction
665 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
666 "sub{q}\t{$src2, $dst|$dst, $src2}",
667 [(store (sub (load addr:$dst), i64immSExt8:$src2),
670 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
671 "sub{q}\t{$src2, $dst|$dst, $src2}",
672 [(store (sub (load addr:$dst), i64immSExt32:$src2),
676 let Uses = [EFLAGS] in {
677 let Constraints = "$src1 = $dst" in {
678 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst),
679 (ins GR64:$src1, GR64:$src2),
680 "sbb{q}\t{$src2, $dst|$dst, $src2}",
681 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
683 let isCodeGenOnly = 1 in {
684 def SBB64rr_REV : RI<0x1B, MRMSrcReg, (outs GR64:$dst),
685 (ins GR64:$src1, GR64:$src2),
686 "sbb{q}\t{$src2, $dst|$dst, $src2}", []>;
689 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst),
690 (ins GR64:$src1, i64mem:$src2),
691 "sbb{q}\t{$src2, $dst|$dst, $src2}",
692 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
694 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst),
695 (ins GR64:$src1, i64i8imm:$src2),
696 "sbb{q}\t{$src2, $dst|$dst, $src2}",
697 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
698 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst),
699 (ins GR64:$src1, i64i32imm:$src2),
700 "sbb{q}\t{$src2, $dst|$dst, $src2}",
701 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
702 } // Constraints = "$src1 = $dst"
704 def SBB64i32 : RIi32<0x1D, RawFrm, (outs), (ins i64i32imm:$src),
705 "sbb{q}\t{$src, %rax|%rax, $src}", []>;
707 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
708 "sbb{q}\t{$src2, $dst|$dst, $src2}",
709 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
710 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
711 "sbb{q}\t{$src2, $dst|$dst, $src2}",
712 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
713 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
714 "sbb{q}\t{$src2, $dst|$dst, $src2}",
715 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
719 // Unsigned multiplication
720 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
721 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
722 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
724 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
725 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
727 // Signed multiplication
728 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
729 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
731 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
732 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
735 let Defs = [EFLAGS] in {
736 let Constraints = "$src1 = $dst" in {
737 let isCommutable = 1 in
738 // Register-Register Signed Integer Multiplication
739 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
740 (ins GR64:$src1, GR64:$src2),
741 "imul{q}\t{$src2, $dst|$dst, $src2}",
742 [(set GR64:$dst, EFLAGS,
743 (X86smul_flag GR64:$src1, GR64:$src2))]>, TB;
745 // Register-Memory Signed Integer Multiplication
746 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
747 (ins GR64:$src1, i64mem:$src2),
748 "imul{q}\t{$src2, $dst|$dst, $src2}",
749 [(set GR64:$dst, EFLAGS,
750 (X86smul_flag GR64:$src1, (load addr:$src2)))]>, TB;
751 } // Constraints = "$src1 = $dst"
753 // Suprisingly enough, these are not two address instructions!
755 // Register-Integer Signed Integer Multiplication
756 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
757 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
758 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
759 [(set GR64:$dst, EFLAGS,
760 (X86smul_flag GR64:$src1, i64immSExt8:$src2))]>;
761 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
762 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
763 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
764 [(set GR64:$dst, EFLAGS,
765 (X86smul_flag GR64:$src1, i64immSExt32:$src2))]>;
767 // Memory-Integer Signed Integer Multiplication
768 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
769 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
770 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
771 [(set GR64:$dst, EFLAGS,
772 (X86smul_flag (load addr:$src1),
773 i64immSExt8:$src2))]>;
774 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
775 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
776 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
777 [(set GR64:$dst, EFLAGS,
778 (X86smul_flag (load addr:$src1),
779 i64immSExt32:$src2))]>;
782 // Unsigned division / remainder
783 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
784 // RDX:RAX/r64 = RAX,RDX
785 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src),
787 // Signed division / remainder
788 // RDX:RAX/r64 = RAX,RDX
789 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src),
790 "idiv{q}\t$src", []>;
792 // RDX:RAX/[mem64] = RAX,RDX
793 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src),
795 // RDX:RAX/[mem64] = RAX,RDX
796 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src),
797 "idiv{q}\t$src", []>;
801 // Unary instructions
802 let Defs = [EFLAGS], CodeSize = 2 in {
803 let Constraints = "$src = $dst" in
804 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
805 [(set GR64:$dst, (ineg GR64:$src)),
807 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
808 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
811 let Constraints = "$src = $dst", isConvertibleToThreeAddress = 1 in
812 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
813 [(set GR64:$dst, EFLAGS, (X86inc_flag GR64:$src))]>;
814 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
815 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
818 let Constraints = "$src = $dst", isConvertibleToThreeAddress = 1 in
819 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
820 [(set GR64:$dst, EFLAGS, (X86dec_flag GR64:$src))]>;
821 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
822 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
825 // In 64-bit mode, single byte INC and DEC cannot be encoded.
826 let Constraints = "$src = $dst", isConvertibleToThreeAddress = 1 in {
827 // Can transform into LEA.
828 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src),
830 [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src))]>,
831 OpSize, Requires<[In64BitMode]>;
832 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src),
834 [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src))]>,
835 Requires<[In64BitMode]>;
836 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src),
838 [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src))]>,
839 OpSize, Requires<[In64BitMode]>;
840 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src),
842 [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src))]>,
843 Requires<[In64BitMode]>;
844 } // Constraints = "$src = $dst", isConvertibleToThreeAddress
846 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
847 // how to unfold them.
848 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
849 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
851 OpSize, Requires<[In64BitMode]>;
852 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
853 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
855 Requires<[In64BitMode]>;
856 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
857 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
859 OpSize, Requires<[In64BitMode]>;
860 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
861 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
863 Requires<[In64BitMode]>;
864 } // Defs = [EFLAGS], CodeSize
867 let Defs = [EFLAGS] in {
868 // Shift instructions
869 let Constraints = "$src1 = $dst" in {
871 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
872 "shl{q}\t{%cl, $dst|$dst, %CL}",
873 [(set GR64:$dst, (shl GR64:$src1, CL))]>;
874 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
875 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst),
876 (ins GR64:$src1, i8imm:$src2),
877 "shl{q}\t{$src2, $dst|$dst, $src2}",
878 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
879 // NOTE: We don't include patterns for shifts of a register by one, because
880 // 'add reg,reg' is cheaper.
881 def SHL64r1 : RI<0xD1, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
883 } // Constraints = "$src1 = $dst"
886 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
887 "shl{q}\t{%cl, $dst|$dst, %CL}",
888 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
889 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
890 "shl{q}\t{$src, $dst|$dst, $src}",
891 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
892 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
894 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
896 let Constraints = "$src1 = $dst" in {
898 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
899 "shr{q}\t{%cl, $dst|$dst, %CL}",
900 [(set GR64:$dst, (srl GR64:$src1, CL))]>;
901 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
902 "shr{q}\t{$src2, $dst|$dst, $src2}",
903 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
904 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
906 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
907 } // Constraints = "$src1 = $dst"
910 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
911 "shr{q}\t{%cl, $dst|$dst, %CL}",
912 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
913 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
914 "shr{q}\t{$src, $dst|$dst, $src}",
915 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
916 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
918 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
920 let Constraints = "$src1 = $dst" in {
922 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
923 "sar{q}\t{%cl, $dst|$dst, %CL}",
924 [(set GR64:$dst, (sra GR64:$src1, CL))]>;
925 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst),
926 (ins GR64:$src1, i8imm:$src2),
927 "sar{q}\t{$src2, $dst|$dst, $src2}",
928 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
929 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
931 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
932 } // Constraints = "$src = $dst"
935 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
936 "sar{q}\t{%cl, $dst|$dst, %CL}",
937 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
938 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
939 "sar{q}\t{$src, $dst|$dst, $src}",
940 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
941 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
943 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
945 // Rotate instructions
947 let Constraints = "$src = $dst" in {
948 def RCL64r1 : RI<0xD1, MRM2r, (outs GR64:$dst), (ins GR64:$src),
949 "rcl{q}\t{1, $dst|$dst, 1}", []>;
950 def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
951 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
953 def RCR64r1 : RI<0xD1, MRM3r, (outs GR64:$dst), (ins GR64:$src),
954 "rcr{q}\t{1, $dst|$dst, 1}", []>;
955 def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
956 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
959 def RCL64rCL : RI<0xD3, MRM2r, (outs GR64:$dst), (ins GR64:$src),
960 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
961 def RCR64rCL : RI<0xD3, MRM3r, (outs GR64:$dst), (ins GR64:$src),
962 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
964 } // Constraints = "$src = $dst"
966 def RCL64m1 : RI<0xD1, MRM2m, (outs), (ins i64mem:$dst),
967 "rcl{q}\t{1, $dst|$dst, 1}", []>;
968 def RCL64mi : RIi8<0xC1, MRM2m, (outs), (ins i64mem:$dst, i8imm:$cnt),
969 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
970 def RCR64m1 : RI<0xD1, MRM3m, (outs), (ins i64mem:$dst),
971 "rcr{q}\t{1, $dst|$dst, 1}", []>;
972 def RCR64mi : RIi8<0xC1, MRM3m, (outs), (ins i64mem:$dst, i8imm:$cnt),
973 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
976 def RCL64mCL : RI<0xD3, MRM2m, (outs), (ins i64mem:$dst),
977 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
978 def RCR64mCL : RI<0xD3, MRM3m, (outs), (ins i64mem:$dst),
979 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
982 let Constraints = "$src1 = $dst" in {
984 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
985 "rol{q}\t{%cl, $dst|$dst, %CL}",
986 [(set GR64:$dst, (rotl GR64:$src1, CL))]>;
987 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst),
988 (ins GR64:$src1, i8imm:$src2),
989 "rol{q}\t{$src2, $dst|$dst, $src2}",
990 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
991 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
993 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
994 } // Constraints = "$src1 = $dst"
997 def ROL64mCL : RI<0xD3, MRM0m, (outs), (ins i64mem:$dst),
998 "rol{q}\t{%cl, $dst|$dst, %CL}",
999 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
1000 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
1001 "rol{q}\t{$src, $dst|$dst, $src}",
1002 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1003 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
1005 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
1007 let Constraints = "$src1 = $dst" in {
1009 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
1010 "ror{q}\t{%cl, $dst|$dst, %CL}",
1011 [(set GR64:$dst, (rotr GR64:$src1, CL))]>;
1012 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst),
1013 (ins GR64:$src1, i8imm:$src2),
1014 "ror{q}\t{$src2, $dst|$dst, $src2}",
1015 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
1016 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
1018 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
1019 } // Constraints = "$src1 = $dst"
1022 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
1023 "ror{q}\t{%cl, $dst|$dst, %CL}",
1024 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
1025 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
1026 "ror{q}\t{$src, $dst|$dst, $src}",
1027 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1028 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
1030 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
1032 // Double shift instructions (generalizations of rotate)
1033 let Constraints = "$src1 = $dst" in {
1034 let Uses = [CL] in {
1035 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst),
1036 (ins GR64:$src1, GR64:$src2),
1037 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1038 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>,
1040 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst),
1041 (ins GR64:$src1, GR64:$src2),
1042 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1043 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>,
1047 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
1048 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
1050 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
1051 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1052 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
1055 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
1057 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
1058 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1059 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
1063 } // Constraints = "$src1 = $dst"
1065 let Uses = [CL] in {
1066 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1067 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1068 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
1070 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1071 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1072 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
1075 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
1076 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
1077 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1078 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
1079 (i8 imm:$src3)), addr:$dst)]>,
1081 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
1082 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
1083 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1084 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
1085 (i8 imm:$src3)), addr:$dst)]>,
1087 } // Defs = [EFLAGS]
1089 //===----------------------------------------------------------------------===//
1090 // Logical Instructions...
1093 let Constraints = "$src = $dst" , AddedComplexity = 15 in
1094 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
1095 [(set GR64:$dst, (not GR64:$src))]>;
1096 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
1097 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
1099 let Defs = [EFLAGS] in {
1100 def AND64i32 : RIi32<0x25, RawFrm, (outs), (ins i64i32imm:$src),
1101 "and{q}\t{$src, %rax|%rax, $src}", []>;
1103 let Constraints = "$src1 = $dst" in {
1104 let isCommutable = 1 in
1105 def AND64rr : RI<0x21, MRMDestReg,
1106 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1107 "and{q}\t{$src2, $dst|$dst, $src2}",
1108 [(set GR64:$dst, EFLAGS,
1109 (X86and_flag GR64:$src1, GR64:$src2))]>;
1110 let isCodeGenOnly = 1 in {
1111 def AND64rr_REV : RI<0x23, MRMSrcReg, (outs GR64:$dst),
1112 (ins GR64:$src1, GR64:$src2),
1113 "and{q}\t{$src2, $dst|$dst, $src2}", []>;
1115 def AND64rm : RI<0x23, MRMSrcMem,
1116 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1117 "and{q}\t{$src2, $dst|$dst, $src2}",
1118 [(set GR64:$dst, EFLAGS,
1119 (X86and_flag GR64:$src1, (load addr:$src2)))]>;
1120 def AND64ri8 : RIi8<0x83, MRM4r,
1121 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
1122 "and{q}\t{$src2, $dst|$dst, $src2}",
1123 [(set GR64:$dst, EFLAGS,
1124 (X86and_flag GR64:$src1, i64immSExt8:$src2))]>;
1125 def AND64ri32 : RIi32<0x81, MRM4r,
1126 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1127 "and{q}\t{$src2, $dst|$dst, $src2}",
1128 [(set GR64:$dst, EFLAGS,
1129 (X86and_flag GR64:$src1, i64immSExt32:$src2))]>;
1130 } // Constraints = "$src1 = $dst"
1132 def AND64mr : RI<0x21, MRMDestMem,
1133 (outs), (ins i64mem:$dst, GR64:$src),
1134 "and{q}\t{$src, $dst|$dst, $src}",
1135 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
1136 (implicit EFLAGS)]>;
1137 def AND64mi8 : RIi8<0x83, MRM4m,
1138 (outs), (ins i64mem:$dst, i64i8imm :$src),
1139 "and{q}\t{$src, $dst|$dst, $src}",
1140 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
1141 (implicit EFLAGS)]>;
1142 def AND64mi32 : RIi32<0x81, MRM4m,
1143 (outs), (ins i64mem:$dst, i64i32imm:$src),
1144 "and{q}\t{$src, $dst|$dst, $src}",
1145 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1146 (implicit EFLAGS)]>;
1148 let Constraints = "$src1 = $dst" in {
1149 let isCommutable = 1 in
1150 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst),
1151 (ins GR64:$src1, GR64:$src2),
1152 "or{q}\t{$src2, $dst|$dst, $src2}",
1153 [(set GR64:$dst, EFLAGS,
1154 (X86or_flag GR64:$src1, GR64:$src2))]>;
1155 let isCodeGenOnly = 1 in {
1156 def OR64rr_REV : RI<0x0B, MRMSrcReg, (outs GR64:$dst),
1157 (ins GR64:$src1, GR64:$src2),
1158 "or{q}\t{$src2, $dst|$dst, $src2}", []>;
1160 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst),
1161 (ins GR64:$src1, i64mem:$src2),
1162 "or{q}\t{$src2, $dst|$dst, $src2}",
1163 [(set GR64:$dst, EFLAGS,
1164 (X86or_flag GR64:$src1, (load addr:$src2)))]>;
1165 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst),
1166 (ins GR64:$src1, i64i8imm:$src2),
1167 "or{q}\t{$src2, $dst|$dst, $src2}",
1168 [(set GR64:$dst, EFLAGS,
1169 (X86or_flag GR64:$src1, i64immSExt8:$src2))]>;
1170 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst),
1171 (ins GR64:$src1, i64i32imm:$src2),
1172 "or{q}\t{$src2, $dst|$dst, $src2}",
1173 [(set GR64:$dst, EFLAGS,
1174 (X86or_flag GR64:$src1, i64immSExt32:$src2))]>;
1175 } // Constraints = "$src1 = $dst"
1177 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1178 "or{q}\t{$src, $dst|$dst, $src}",
1179 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
1180 (implicit EFLAGS)]>;
1181 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
1182 "or{q}\t{$src, $dst|$dst, $src}",
1183 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
1184 (implicit EFLAGS)]>;
1185 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1186 "or{q}\t{$src, $dst|$dst, $src}",
1187 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1188 (implicit EFLAGS)]>;
1190 def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i64i32imm:$src),
1191 "or{q}\t{$src, %rax|%rax, $src}", []>;
1193 let Constraints = "$src1 = $dst" in {
1194 let isCommutable = 1 in
1195 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst),
1196 (ins GR64:$src1, GR64:$src2),
1197 "xor{q}\t{$src2, $dst|$dst, $src2}",
1198 [(set GR64:$dst, EFLAGS,
1199 (X86xor_flag GR64:$src1, GR64:$src2))]>;
1200 let isCodeGenOnly = 1 in {
1201 def XOR64rr_REV : RI<0x33, MRMSrcReg, (outs GR64:$dst),
1202 (ins GR64:$src1, GR64:$src2),
1203 "xor{q}\t{$src2, $dst|$dst, $src2}", []>;
1205 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst),
1206 (ins GR64:$src1, i64mem:$src2),
1207 "xor{q}\t{$src2, $dst|$dst, $src2}",
1208 [(set GR64:$dst, EFLAGS,
1209 (X86xor_flag GR64:$src1, (load addr:$src2)))]>;
1210 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst),
1211 (ins GR64:$src1, i64i8imm:$src2),
1212 "xor{q}\t{$src2, $dst|$dst, $src2}",
1213 [(set GR64:$dst, EFLAGS,
1214 (X86xor_flag GR64:$src1, i64immSExt8:$src2))]>;
1215 def XOR64ri32 : RIi32<0x81, MRM6r,
1216 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1217 "xor{q}\t{$src2, $dst|$dst, $src2}",
1218 [(set GR64:$dst, EFLAGS,
1219 (X86xor_flag GR64:$src1, i64immSExt32:$src2))]>;
1220 } // Constraints = "$src1 = $dst"
1222 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1223 "xor{q}\t{$src, $dst|$dst, $src}",
1224 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1225 (implicit EFLAGS)]>;
1226 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
1227 "xor{q}\t{$src, $dst|$dst, $src}",
1228 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1229 (implicit EFLAGS)]>;
1230 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1231 "xor{q}\t{$src, $dst|$dst, $src}",
1232 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1233 (implicit EFLAGS)]>;
1235 def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i64i32imm:$src),
1236 "xor{q}\t{$src, %rax|%rax, $src}", []>;
1238 } // Defs = [EFLAGS]
1240 //===----------------------------------------------------------------------===//
1241 // Comparison Instructions...
1244 // Integer comparison
1245 let Defs = [EFLAGS] in {
1246 def TEST64i32 : RIi32<0xa9, RawFrm, (outs), (ins i64i32imm:$src),
1247 "test{q}\t{$src, %rax|%rax, $src}", []>;
1248 let isCommutable = 1 in
1249 def TEST64rr : RI<0x85, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1250 "test{q}\t{$src2, $src1|$src1, $src2}",
1251 [(set EFLAGS, (X86cmp (and GR64:$src1, GR64:$src2), 0))]>;
1252 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1253 "test{q}\t{$src2, $src1|$src1, $src2}",
1254 [(set EFLAGS, (X86cmp (and GR64:$src1, (loadi64 addr:$src2)),
1256 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1257 (ins GR64:$src1, i64i32imm:$src2),
1258 "test{q}\t{$src2, $src1|$src1, $src2}",
1259 [(set EFLAGS, (X86cmp (and GR64:$src1, i64immSExt32:$src2),
1261 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1262 (ins i64mem:$src1, i64i32imm:$src2),
1263 "test{q}\t{$src2, $src1|$src1, $src2}",
1264 [(set EFLAGS, (X86cmp (and (loadi64 addr:$src1),
1265 i64immSExt32:$src2), 0))]>;
1268 def CMP64i32 : RIi32<0x3D, RawFrm, (outs), (ins i64i32imm:$src),
1269 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
1270 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1271 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1272 [(set EFLAGS, (X86cmp GR64:$src1, GR64:$src2))]>;
1274 // These are alternate spellings for use by the disassembler, we mark them as
1275 // code gen only to ensure they aren't matched by the assembler.
1276 let isCodeGenOnly = 1 in {
1277 def CMP64mrmrr : RI<0x3B, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1278 "cmp{q}\t{$src2, $src1|$src1, $src2}", []>;
1281 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1282 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1283 [(set EFLAGS, (X86cmp (loadi64 addr:$src1), GR64:$src2))]>;
1284 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1285 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1286 [(set EFLAGS, (X86cmp GR64:$src1, (loadi64 addr:$src2)))]>;
1287 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1288 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1289 [(set EFLAGS, (X86cmp GR64:$src1, i64immSExt8:$src2))]>;
1290 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
1291 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1292 [(set EFLAGS, (X86cmp GR64:$src1, i64immSExt32:$src2))]>;
1293 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1294 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1295 [(set EFLAGS, (X86cmp (loadi64 addr:$src1),
1296 i64immSExt8:$src2))]>;
1297 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1298 (ins i64mem:$src1, i64i32imm:$src2),
1299 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1300 [(set EFLAGS, (X86cmp (loadi64 addr:$src1),
1301 i64immSExt32:$src2))]>;
1302 } // Defs = [EFLAGS]
1305 // TODO: BTC, BTR, and BTS
1306 let Defs = [EFLAGS] in {
1307 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1308 "bt{q}\t{$src2, $src1|$src1, $src2}",
1309 [(set EFLAGS, (X86bt GR64:$src1, GR64:$src2))]>, TB;
1311 // Unlike with the register+register form, the memory+register form of the
1312 // bt instruction does not ignore the high bits of the index. From ISel's
1313 // perspective, this is pretty bizarre. Disable these instructions for now.
1314 def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1315 "bt{q}\t{$src2, $src1|$src1, $src2}",
1316 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
1317 // (implicit EFLAGS)]
1321 def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1322 "bt{q}\t{$src2, $src1|$src1, $src2}",
1323 [(set EFLAGS, (X86bt GR64:$src1, i64immSExt8:$src2))]>, TB,
1325 // Note that these instructions don't need FastBTMem because that
1326 // only applies when the other operand is in a register. When it's
1327 // an immediate, bt is still fast.
1328 def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1329 "bt{q}\t{$src2, $src1|$src1, $src2}",
1330 [(set EFLAGS, (X86bt (loadi64 addr:$src1),
1331 i64immSExt8:$src2))]>, TB;
1333 def BTC64rr : RI<0xBB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1334 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1335 def BTC64mr : RI<0xBB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1336 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1337 def BTC64ri8 : RIi8<0xBA, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1338 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1339 def BTC64mi8 : RIi8<0xBA, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1340 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1342 def BTR64rr : RI<0xB3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1343 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1344 def BTR64mr : RI<0xB3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1345 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1346 def BTR64ri8 : RIi8<0xBA, MRM6r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1347 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1348 def BTR64mi8 : RIi8<0xBA, MRM6m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1349 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1351 def BTS64rr : RI<0xAB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1352 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1353 def BTS64mr : RI<0xAB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1354 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1355 def BTS64ri8 : RIi8<0xBA, MRM5r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1356 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1357 def BTS64mi8 : RIi8<0xBA, MRM5m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1358 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1359 } // Defs = [EFLAGS]
1361 // Conditional moves
1362 let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
1363 let isCommutable = 1 in {
1364 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
1365 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1366 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
1367 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1368 X86_COND_B, EFLAGS))]>, TB;
1369 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
1370 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1371 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
1372 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1373 X86_COND_AE, EFLAGS))]>, TB;
1374 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
1375 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1376 "cmove{q}\t{$src2, $dst|$dst, $src2}",
1377 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1378 X86_COND_E, EFLAGS))]>, TB;
1379 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
1380 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1381 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
1382 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1383 X86_COND_NE, EFLAGS))]>, TB;
1384 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
1385 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1386 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
1387 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1388 X86_COND_BE, EFLAGS))]>, TB;
1389 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
1390 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1391 "cmova{q}\t{$src2, $dst|$dst, $src2}",
1392 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1393 X86_COND_A, EFLAGS))]>, TB;
1394 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
1395 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1396 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
1397 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1398 X86_COND_L, EFLAGS))]>, TB;
1399 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
1400 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1401 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
1402 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1403 X86_COND_GE, EFLAGS))]>, TB;
1404 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
1405 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1406 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
1407 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1408 X86_COND_LE, EFLAGS))]>, TB;
1409 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
1410 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1411 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
1412 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1413 X86_COND_G, EFLAGS))]>, TB;
1414 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1415 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1416 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
1417 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1418 X86_COND_S, EFLAGS))]>, TB;
1419 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1420 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1421 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
1422 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1423 X86_COND_NS, EFLAGS))]>, TB;
1424 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1425 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1426 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
1427 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1428 X86_COND_P, EFLAGS))]>, TB;
1429 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1430 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1431 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
1432 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1433 X86_COND_NP, EFLAGS))]>, TB;
1434 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1435 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1436 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
1437 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1438 X86_COND_O, EFLAGS))]>, TB;
1439 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1440 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1441 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
1442 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1443 X86_COND_NO, EFLAGS))]>, TB;
1444 } // isCommutable = 1
1446 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1447 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1448 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
1449 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1450 X86_COND_B, EFLAGS))]>, TB;
1451 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1452 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1453 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
1454 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1455 X86_COND_AE, EFLAGS))]>, TB;
1456 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1457 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1458 "cmove{q}\t{$src2, $dst|$dst, $src2}",
1459 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1460 X86_COND_E, EFLAGS))]>, TB;
1461 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1462 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1463 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
1464 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1465 X86_COND_NE, EFLAGS))]>, TB;
1466 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1467 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1468 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
1469 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1470 X86_COND_BE, EFLAGS))]>, TB;
1471 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1472 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1473 "cmova{q}\t{$src2, $dst|$dst, $src2}",
1474 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1475 X86_COND_A, EFLAGS))]>, TB;
1476 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1477 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1478 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
1479 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1480 X86_COND_L, EFLAGS))]>, TB;
1481 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1482 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1483 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
1484 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1485 X86_COND_GE, EFLAGS))]>, TB;
1486 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1487 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1488 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
1489 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1490 X86_COND_LE, EFLAGS))]>, TB;
1491 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1492 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1493 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
1494 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1495 X86_COND_G, EFLAGS))]>, TB;
1496 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1497 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1498 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
1499 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1500 X86_COND_S, EFLAGS))]>, TB;
1501 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1502 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1503 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
1504 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1505 X86_COND_NS, EFLAGS))]>, TB;
1506 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1507 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1508 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
1509 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1510 X86_COND_P, EFLAGS))]>, TB;
1511 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1512 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1513 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
1514 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1515 X86_COND_NP, EFLAGS))]>, TB;
1516 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1517 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1518 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
1519 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1520 X86_COND_O, EFLAGS))]>, TB;
1521 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1522 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1523 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
1524 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1525 X86_COND_NO, EFLAGS))]>, TB;
1526 } // Constraints = "$src1 = $dst"
1528 // Use sbb to materialize carry flag into a GPR.
1529 // FIXME: This are pseudo ops that should be replaced with Pat<> patterns.
1530 // However, Pat<> can't replicate the destination reg into the inputs of the
1532 // FIXME: Change this to have encoding Pseudo when X86MCCodeEmitter replaces
1534 let Defs = [EFLAGS], Uses = [EFLAGS], isCodeGenOnly = 1 in
1535 def SETB_C64r : RI<0x19, MRMInitReg, (outs GR64:$dst), (ins), "",
1536 [(set GR64:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
1538 def : Pat<(i64 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
1541 //===----------------------------------------------------------------------===//
1542 // Conversion Instructions...
1545 // f64 -> signed i64
1546 def CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1547 "cvtsd2si{q}\t{$src, $dst|$dst, $src}", []>;
1548 def CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1549 "cvtsd2si{q}\t{$src, $dst|$dst, $src}", []>;
1550 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1551 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1553 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1554 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst),
1556 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1557 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1558 (load addr:$src)))]>;
1559 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1560 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1561 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1562 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1563 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1564 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1565 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1566 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1568 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1569 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst),
1571 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1573 (int_x86_sse2_cvttsd2si64
1574 (load addr:$src)))]>;
1576 // Signed i64 -> f64
1577 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1578 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1579 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1580 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1581 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1582 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1584 let Constraints = "$src1 = $dst" in {
1585 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1586 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1587 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1589 (int_x86_sse2_cvtsi642sd VR128:$src1,
1591 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1592 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1593 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1595 (int_x86_sse2_cvtsi642sd VR128:$src1,
1596 (loadi64 addr:$src2)))]>;
1597 } // Constraints = "$src1 = $dst"
1599 // Signed i64 -> f32
1600 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1601 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1602 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1603 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1604 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1605 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1607 let Constraints = "$src1 = $dst" in {
1608 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1609 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1610 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1612 (int_x86_sse_cvtsi642ss VR128:$src1,
1614 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1616 (ins VR128:$src1, i64mem:$src2),
1617 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1619 (int_x86_sse_cvtsi642ss VR128:$src1,
1620 (loadi64 addr:$src2)))]>;
1621 } // Constraints = "$src1 = $dst"
1623 // f32 -> signed i64
1624 def CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1625 "cvtss2si{q}\t{$src, $dst|$dst, $src}", []>;
1626 def CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1627 "cvtss2si{q}\t{$src, $dst|$dst, $src}", []>;
1628 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1629 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1631 (int_x86_sse_cvtss2si64 VR128:$src))]>;
1632 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1633 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1634 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1635 (load addr:$src)))]>;
1636 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1637 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1638 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1639 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1640 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1641 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1642 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1643 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1645 (int_x86_sse_cvttss2si64 VR128:$src))]>;
1646 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst),
1648 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1650 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1652 // Descriptor-table support instructions
1654 // LLDT is not interpreted specially in 64-bit mode because there is no sign
1656 def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
1657 "sldt{q}\t$dst", []>, TB;
1658 def SLDT64m : RI<0x00, MRM0m, (outs i16mem:$dst), (ins),
1659 "sldt{q}\t$dst", []>, TB;
1661 //===----------------------------------------------------------------------===//
1662 // Alias Instructions
1663 //===----------------------------------------------------------------------===//
1665 // We want to rewrite MOV64r0 in terms of MOV32r0, because it's sometimes a
1666 // smaller encoding, but doing so at isel time interferes with rematerialization
1667 // in the current register allocator. For now, this is rewritten when the
1668 // instruction is lowered to an MCInst.
1669 // FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
1670 // when we have a better way to specify isel priority.
1671 let Defs = [EFLAGS],
1672 AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1673 def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins), "",
1674 [(set GR64:$dst, 0)]>;
1676 // Materialize i64 constant where top 32-bits are zero. This could theoretically
1677 // use MOV32ri with a SUBREG_TO_REG to represent the zero-extension, however
1678 // that would make it more difficult to rematerialize.
1679 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1680 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1681 "", [(set GR64:$dst, i64immZExt32:$src)]>;
1683 //===----------------------------------------------------------------------===//
1684 // Thread Local Storage Instructions
1685 //===----------------------------------------------------------------------===//
1688 // All calls clobber the non-callee saved registers. RSP is marked as
1689 // a use to prevent stack-pointer assignments that appear immediately
1690 // before calls from potentially appearing dead.
1691 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1692 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1693 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1694 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1695 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1697 def TLS_addr64 : I<0, Pseudo, (outs), (ins i64mem:$sym),
1699 "leaq\t$sym(%rip), %rdi; "
1702 "call\t__tls_get_addr@PLT",
1703 [(X86tlsaddr tls64addr:$sym)]>,
1704 Requires<[In64BitMode]>;
1706 // Darwin TLS Support
1707 // For x86_64, the address of the thunk is passed in %rdi, on return
1708 // the address of the variable is in %rax. All other registers are preserved.
1711 usesCustomInserter = 1 in
1712 def TLSCall_64 : I<0, Pseudo, (outs), (ins i64mem:$sym),
1714 [(X86TLSCall addr:$sym)]>,
1715 Requires<[In64BitMode]>;
1717 let AddedComplexity = 5, isCodeGenOnly = 1 in
1718 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1719 "movq\t%gs:$src, $dst",
1720 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1722 let AddedComplexity = 5, isCodeGenOnly = 1 in
1723 def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1724 "movq\t%fs:$src, $dst",
1725 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1727 //===----------------------------------------------------------------------===//
1728 // Atomic Instructions
1729 //===----------------------------------------------------------------------===//
1731 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1732 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1734 "cmpxchgq\t$swap,$ptr",
1735 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1738 let Constraints = "$val = $dst" in {
1739 let Defs = [EFLAGS] in
1740 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins GR64:$val,i64mem:$ptr),
1743 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1746 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst),
1747 (ins GR64:$val,i64mem:$ptr),
1748 "xchg{q}\t{$val, $ptr|$ptr, $val}",
1749 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1751 def XCHG64rr : RI<0x87, MRMSrcReg, (outs GR64:$dst), (ins GR64:$val,GR64:$src),
1752 "xchg{q}\t{$val, $src|$src, $val}", []>;
1755 def XADD64rr : RI<0xC1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1756 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1757 let mayLoad = 1, mayStore = 1 in
1758 def XADD64rm : RI<0xC1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1759 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1761 def CMPXCHG64rr : RI<0xB1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1762 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1763 let mayLoad = 1, mayStore = 1 in
1764 def CMPXCHG64rm : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1765 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1767 let Defs = [RAX, RDX, EFLAGS], Uses = [RAX, RBX, RCX, RDX] in
1768 def CMPXCHG16B : RI<0xC7, MRM1m, (outs), (ins i128mem:$dst),
1769 "cmpxchg16b\t$dst", []>, TB;
1771 def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src),
1772 "xchg{q}\t{$src, %rax|%rax, $src}", []>;
1774 // Optimized codegen when the non-memory output is not used.
1775 let Defs = [EFLAGS], mayLoad = 1, mayStore = 1 in {
1776 // FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1777 def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1779 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1780 def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1781 (ins i64mem:$dst, i64i8imm :$src2),
1783 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1784 def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1785 (ins i64mem:$dst, i64i32imm :$src2),
1787 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1788 def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1790 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1791 def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1792 (ins i64mem:$dst, i64i8imm :$src2),
1794 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1795 def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1796 (ins i64mem:$dst, i64i32imm:$src2),
1798 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1799 def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1801 "inc{q}\t$dst", []>, LOCK;
1802 def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1804 "dec{q}\t$dst", []>, LOCK;
1806 // Atomic exchange, and, or, xor
1807 let Constraints = "$val = $dst", Defs = [EFLAGS],
1808 usesCustomInserter = 1 in {
1809 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1810 "#ATOMAND64 PSEUDO!",
1811 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1812 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1813 "#ATOMOR64 PSEUDO!",
1814 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1815 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1816 "#ATOMXOR64 PSEUDO!",
1817 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1818 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1819 "#ATOMNAND64 PSEUDO!",
1820 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1821 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1822 "#ATOMMIN64 PSEUDO!",
1823 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1824 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1825 "#ATOMMAX64 PSEUDO!",
1826 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1827 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1828 "#ATOMUMIN64 PSEUDO!",
1829 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1830 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1831 "#ATOMUMAX64 PSEUDO!",
1832 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1835 // Segmentation support instructions
1837 // i16mem operand in LAR64rm and GR32 operand in LAR32rr is not a typo.
1838 def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
1839 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1840 def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
1841 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1843 def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1844 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1845 def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
1846 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1848 def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", []>, TB;
1850 def PUSHFS64 : I<0xa0, RawFrm, (outs), (ins),
1851 "push{q}\t%fs", []>, TB;
1852 def PUSHGS64 : I<0xa8, RawFrm, (outs), (ins),
1853 "push{q}\t%gs", []>, TB;
1855 def POPFS64 : I<0xa1, RawFrm, (outs), (ins),
1856 "pop{q}\t%fs", []>, TB;
1857 def POPGS64 : I<0xa9, RawFrm, (outs), (ins),
1858 "pop{q}\t%gs", []>, TB;
1860 def LSS64rm : RI<0xb2, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1861 "lss{q}\t{$src, $dst|$dst, $src}", []>, TB;
1862 def LFS64rm : RI<0xb4, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1863 "lfs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1864 def LGS64rm : RI<0xb5, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1865 "lgs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1867 // Specialized register support
1869 // no m form encodable; use SMSW16m
1870 def SMSW64r : RI<0x01, MRM4r, (outs GR64:$dst), (ins),
1871 "smsw{q}\t$dst", []>, TB;
1873 // String manipulation instructions
1875 def LODSQ : RI<0xAD, RawFrm, (outs), (ins), "lodsq", []>;
1877 //===----------------------------------------------------------------------===//
1878 // Non-Instruction Patterns
1879 //===----------------------------------------------------------------------===//
1881 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1882 // code model mode, should use 'movabs'. FIXME: This is really a hack, the
1883 // 'movabs' predicate should handle this sort of thing.
1884 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1885 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
1886 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1887 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
1888 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1889 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
1890 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1891 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
1892 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1893 (MOV64ri tblockaddress:$dst)>, Requires<[FarData]>;
1895 // In static codegen with small code model, we can get the address of a label
1896 // into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1897 // the MOV64ri64i32 should accept these.
1898 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1899 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1900 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1901 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1902 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1903 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1904 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1905 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1906 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1907 (MOV64ri64i32 tblockaddress:$dst)>, Requires<[SmallCode]>;
1909 // In kernel code model, we can get the address of a label
1910 // into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1911 // the MOV64ri32 should accept these.
1912 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1913 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1914 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1915 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1916 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1917 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1918 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1919 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
1920 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1921 (MOV64ri32 tblockaddress:$dst)>, Requires<[KernelCode]>;
1923 // If we have small model and -static mode, it is safe to store global addresses
1924 // directly as immediates. FIXME: This is really a hack, the 'imm' predicate
1925 // for MOV64mi32 should handle this sort of thing.
1926 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1927 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1928 Requires<[NearData, IsStatic]>;
1929 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1930 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1931 Requires<[NearData, IsStatic]>;
1932 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1933 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1934 Requires<[NearData, IsStatic]>;
1935 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1936 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1937 Requires<[NearData, IsStatic]>;
1938 def : Pat<(store (i64 (X86Wrapper tblockaddress:$src)), addr:$dst),
1939 (MOV64mi32 addr:$dst, tblockaddress:$src)>,
1940 Requires<[NearData, IsStatic]>;
1943 // Direct PC relative function call for small code model. 32-bit displacement
1944 // sign extended to 64-bit.
1945 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1946 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
1947 def : Pat<(X86call (i64 texternalsym:$dst)),
1948 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1950 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1951 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1952 def : Pat<(X86call (i64 texternalsym:$dst)),
1953 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
1956 def : Pat<(X86tcret GR64_TC:$dst, imm:$off),
1957 (TCRETURNri64 GR64_TC:$dst, imm:$off)>,
1958 Requires<[In64BitMode]>;
1960 def : Pat<(X86tcret (load addr:$dst), imm:$off),
1961 (TCRETURNmi64 addr:$dst, imm:$off)>,
1962 Requires<[In64BitMode]>;
1964 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1965 (TCRETURNdi64 tglobaladdr:$dst, imm:$off)>,
1966 Requires<[In64BitMode]>;
1968 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1969 (TCRETURNdi64 texternalsym:$dst, imm:$off)>,
1970 Requires<[In64BitMode]>;
1972 // tls has some funny stuff here...
1973 // This corresponds to movabs $foo@tpoff, %rax
1974 def : Pat<(i64 (X86Wrapper tglobaltlsaddr :$dst)),
1975 (MOV64ri tglobaltlsaddr :$dst)>;
1976 // This corresponds to add $foo@tpoff, %rax
1977 def : Pat<(add GR64:$src1, (X86Wrapper tglobaltlsaddr :$dst)),
1978 (ADD64ri32 GR64:$src1, tglobaltlsaddr :$dst)>;
1979 // This corresponds to mov foo@tpoff(%rbx), %eax
1980 def : Pat<(load (i64 (X86Wrapper tglobaltlsaddr :$dst))),
1981 (MOV64rm tglobaltlsaddr :$dst)>;
1985 // TEST R,R is smaller than CMP R,0
1986 def : Pat<(X86cmp GR64:$src1, 0),
1987 (TEST64rr GR64:$src1, GR64:$src1)>;
1989 // Conditional moves with folded loads with operands swapped and conditions
1991 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1992 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1993 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1994 (CMOVB64rm GR64:$src2, addr:$src1)>;
1995 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1996 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1997 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1998 (CMOVE64rm GR64:$src2, addr:$src1)>;
1999 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
2000 (CMOVA64rm GR64:$src2, addr:$src1)>;
2001 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
2002 (CMOVBE64rm GR64:$src2, addr:$src1)>;
2003 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
2004 (CMOVGE64rm GR64:$src2, addr:$src1)>;
2005 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
2006 (CMOVL64rm GR64:$src2, addr:$src1)>;
2007 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
2008 (CMOVG64rm GR64:$src2, addr:$src1)>;
2009 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
2010 (CMOVLE64rm GR64:$src2, addr:$src1)>;
2011 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
2012 (CMOVNP64rm GR64:$src2, addr:$src1)>;
2013 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
2014 (CMOVP64rm GR64:$src2, addr:$src1)>;
2015 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
2016 (CMOVNS64rm GR64:$src2, addr:$src1)>;
2017 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
2018 (CMOVS64rm GR64:$src2, addr:$src1)>;
2019 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
2020 (CMOVNO64rm GR64:$src2, addr:$src1)>;
2021 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
2022 (CMOVO64rm GR64:$src2, addr:$src1)>;
2024 // zextload bool -> zextload byte
2025 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
2028 // When extloading from 16-bit and smaller memory locations into 64-bit
2029 // registers, use zero-extending loads so that the entire 64-bit register is
2030 // defined, avoiding partial-register updates.
2031 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
2032 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
2033 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
2034 // For other extloads, use subregs, since the high contents of the register are
2035 // defined after an extload.
2036 def : Pat<(extloadi64i32 addr:$src),
2037 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
2040 // anyext. Define these to do an explicit zero-extend to
2041 // avoid partial-register updates.
2042 def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
2043 def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
2044 def : Pat<(i64 (anyext GR32:$src)),
2045 (SUBREG_TO_REG (i64 0), GR32:$src, sub_32bit)>;
2047 //===----------------------------------------------------------------------===//
2049 //===----------------------------------------------------------------------===//
2051 // Odd encoding trick: -128 fits into an 8-bit immediate field while
2052 // +128 doesn't, so in this special case use a sub instead of an add.
2053 def : Pat<(add GR64:$src1, 128),
2054 (SUB64ri8 GR64:$src1, -128)>;
2055 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
2056 (SUB64mi8 addr:$dst, -128)>;
2058 // The same trick applies for 32-bit immediate fields in 64-bit
2060 def : Pat<(add GR64:$src1, 0x0000000080000000),
2061 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
2062 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
2063 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
2065 // Use a 32-bit and with implicit zero-extension instead of a 64-bit and if it
2066 // has an immediate with at least 32 bits of leading zeros, to avoid needing to
2067 // materialize that immediate in a register first.
2068 def : Pat<(and GR64:$src, i64immZExt32:$imm),
2072 (EXTRACT_SUBREG GR64:$src, sub_32bit),
2073 (i32 (GetLo32XForm imm:$imm))),
2076 // r & (2^32-1) ==> movz
2077 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
2078 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, sub_32bit))>;
2079 // r & (2^16-1) ==> movz
2080 def : Pat<(and GR64:$src, 0xffff),
2081 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, sub_16bit)))>;
2082 // r & (2^8-1) ==> movz
2083 def : Pat<(and GR64:$src, 0xff),
2084 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, sub_8bit)))>;
2085 // r & (2^8-1) ==> movz
2086 def : Pat<(and GR32:$src1, 0xff),
2087 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, sub_8bit))>,
2088 Requires<[In64BitMode]>;
2089 // r & (2^8-1) ==> movz
2090 def : Pat<(and GR16:$src1, 0xff),
2091 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, sub_8bit)))>,
2092 Requires<[In64BitMode]>;
2094 // sext_inreg patterns
2095 def : Pat<(sext_inreg GR64:$src, i32),
2096 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, sub_32bit))>;
2097 def : Pat<(sext_inreg GR64:$src, i16),
2098 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, sub_16bit))>;
2099 def : Pat<(sext_inreg GR64:$src, i8),
2100 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, sub_8bit))>;
2101 def : Pat<(sext_inreg GR32:$src, i8),
2102 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, sub_8bit))>,
2103 Requires<[In64BitMode]>;
2104 def : Pat<(sext_inreg GR16:$src, i8),
2105 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, sub_8bit)))>,
2106 Requires<[In64BitMode]>;
2109 def : Pat<(i32 (trunc GR64:$src)),
2110 (EXTRACT_SUBREG GR64:$src, sub_32bit)>;
2111 def : Pat<(i16 (trunc GR64:$src)),
2112 (EXTRACT_SUBREG GR64:$src, sub_16bit)>;
2113 def : Pat<(i8 (trunc GR64:$src)),
2114 (EXTRACT_SUBREG GR64:$src, sub_8bit)>;
2115 def : Pat<(i8 (trunc GR32:$src)),
2116 (EXTRACT_SUBREG GR32:$src, sub_8bit)>,
2117 Requires<[In64BitMode]>;
2118 def : Pat<(i8 (trunc GR16:$src)),
2119 (EXTRACT_SUBREG GR16:$src, sub_8bit)>,
2120 Requires<[In64BitMode]>;
2122 // h-register tricks.
2123 // For now, be conservative on x86-64 and use an h-register extract only if the
2124 // value is immediately zero-extended or stored, which are somewhat common
2125 // cases. This uses a bunch of code to prevent a register requiring a REX prefix
2126 // from being allocated in the same instruction as the h register, as there's
2127 // currently no way to describe this requirement to the register allocator.
2129 // h-register extract and zero-extend.
2130 def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
2134 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
2137 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
2139 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
2141 Requires<[In64BitMode]>;
2142 def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)),
2143 (MOVZX32_NOREXrr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src,
2146 Requires<[In64BitMode]>;
2147 def : Pat<(srl GR16:$src, (i8 8)),
2150 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2153 Requires<[In64BitMode]>;
2154 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
2156 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2158 Requires<[In64BitMode]>;
2159 def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
2161 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2163 Requires<[In64BitMode]>;
2164 def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
2168 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2171 def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
2175 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2179 // h-register extract and store.
2180 def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
2183 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
2185 def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
2188 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
2190 Requires<[In64BitMode]>;
2191 def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
2194 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2196 Requires<[In64BitMode]>;
2198 // (shl x, 1) ==> (add x, x)
2199 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
2201 // (shl x (and y, 63)) ==> (shl x, y)
2202 def : Pat<(shl GR64:$src1, (and CL, 63)),
2203 (SHL64rCL GR64:$src1)>;
2204 def : Pat<(store (shl (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2205 (SHL64mCL addr:$dst)>;
2207 def : Pat<(srl GR64:$src1, (and CL, 63)),
2208 (SHR64rCL GR64:$src1)>;
2209 def : Pat<(store (srl (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2210 (SHR64mCL addr:$dst)>;
2212 def : Pat<(sra GR64:$src1, (and CL, 63)),
2213 (SAR64rCL GR64:$src1)>;
2214 def : Pat<(store (sra (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2215 (SAR64mCL addr:$dst)>;
2217 // (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
2218 let AddedComplexity = 5 in { // Try this before the selecting to OR
2219 def : Pat<(or_is_add GR64:$src1, i64immSExt8:$src2),
2220 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2221 def : Pat<(or_is_add GR64:$src1, i64immSExt32:$src2),
2222 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
2223 def : Pat<(or_is_add GR64:$src1, GR64:$src2),
2224 (ADD64rr GR64:$src1, GR64:$src2)>;
2225 } // AddedComplexity
2227 // X86 specific add which produces a flag.
2228 def : Pat<(addc GR64:$src1, GR64:$src2),
2229 (ADD64rr GR64:$src1, GR64:$src2)>;
2230 def : Pat<(addc GR64:$src1, (load addr:$src2)),
2231 (ADD64rm GR64:$src1, addr:$src2)>;
2232 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
2233 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2234 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
2235 (ADD64ri32 GR64:$src1, imm:$src2)>;
2237 def : Pat<(subc GR64:$src1, GR64:$src2),
2238 (SUB64rr GR64:$src1, GR64:$src2)>;
2239 def : Pat<(subc GR64:$src1, (load addr:$src2)),
2240 (SUB64rm GR64:$src1, addr:$src2)>;
2241 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
2242 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
2243 def : Pat<(subc GR64:$src1, imm:$src2),
2244 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
2246 //===----------------------------------------------------------------------===//
2247 // EFLAGS-defining Patterns
2248 //===----------------------------------------------------------------------===//
2251 def : Pat<(add GR64:$src1, GR64:$src2),
2252 (ADD64rr GR64:$src1, GR64:$src2)>;
2253 def : Pat<(add GR64:$src1, i64immSExt8:$src2),
2254 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2255 def : Pat<(add GR64:$src1, i64immSExt32:$src2),
2256 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
2257 def : Pat<(add GR64:$src1, (loadi64 addr:$src2)),
2258 (ADD64rm GR64:$src1, addr:$src2)>;
2261 def : Pat<(sub GR64:$src1, GR64:$src2),
2262 (SUB64rr GR64:$src1, GR64:$src2)>;
2263 def : Pat<(sub GR64:$src1, (loadi64 addr:$src2)),
2264 (SUB64rm GR64:$src1, addr:$src2)>;
2265 def : Pat<(sub GR64:$src1, i64immSExt8:$src2),
2266 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
2267 def : Pat<(sub GR64:$src1, i64immSExt32:$src2),
2268 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
2271 def : Pat<(mul GR64:$src1, GR64:$src2),
2272 (IMUL64rr GR64:$src1, GR64:$src2)>;
2273 def : Pat<(mul GR64:$src1, (loadi64 addr:$src2)),
2274 (IMUL64rm GR64:$src1, addr:$src2)>;
2275 def : Pat<(mul GR64:$src1, i64immSExt8:$src2),
2276 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
2277 def : Pat<(mul GR64:$src1, i64immSExt32:$src2),
2278 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
2279 def : Pat<(mul (loadi64 addr:$src1), i64immSExt8:$src2),
2280 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
2281 def : Pat<(mul (loadi64 addr:$src1), i64immSExt32:$src2),
2282 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
2285 def : Pat<(add GR16:$src, 1), (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2286 def : Pat<(add GR16:$src, -1), (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2287 def : Pat<(add GR32:$src, 1), (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2288 def : Pat<(add GR32:$src, -1), (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2289 def : Pat<(add GR64:$src, 1), (INC64r GR64:$src)>;
2290 def : Pat<(add GR64:$src, -1), (DEC64r GR64:$src)>;
2293 def : Pat<(or GR64:$src1, GR64:$src2),
2294 (OR64rr GR64:$src1, GR64:$src2)>;
2295 def : Pat<(or GR64:$src1, i64immSExt8:$src2),
2296 (OR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2297 def : Pat<(or GR64:$src1, i64immSExt32:$src2),
2298 (OR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2299 def : Pat<(or GR64:$src1, (loadi64 addr:$src2)),
2300 (OR64rm GR64:$src1, addr:$src2)>;
2303 def : Pat<(xor GR64:$src1, GR64:$src2),
2304 (XOR64rr GR64:$src1, GR64:$src2)>;
2305 def : Pat<(xor GR64:$src1, i64immSExt8:$src2),
2306 (XOR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2307 def : Pat<(xor GR64:$src1, i64immSExt32:$src2),
2308 (XOR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2309 def : Pat<(xor GR64:$src1, (loadi64 addr:$src2)),
2310 (XOR64rm GR64:$src1, addr:$src2)>;
2313 def : Pat<(and GR64:$src1, GR64:$src2),
2314 (AND64rr GR64:$src1, GR64:$src2)>;
2315 def : Pat<(and GR64:$src1, i64immSExt8:$src2),
2316 (AND64ri8 GR64:$src1, i64immSExt8:$src2)>;
2317 def : Pat<(and GR64:$src1, i64immSExt32:$src2),
2318 (AND64ri32 GR64:$src1, i64immSExt32:$src2)>;
2319 def : Pat<(and GR64:$src1, (loadi64 addr:$src2)),
2320 (AND64rm GR64:$src1, addr:$src2)>;
2322 //===----------------------------------------------------------------------===//
2323 // X86-64 SSE Instructions
2324 //===----------------------------------------------------------------------===//
2326 // Move instructions...
2328 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2329 "mov{d|q}\t{$src, $dst|$dst, $src}",
2331 (v2i64 (scalar_to_vector GR64:$src)))]>;
2332 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
2333 "mov{d|q}\t{$src, $dst|$dst, $src}",
2334 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2337 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
2338 "mov{d|q}\t{$src, $dst|$dst, $src}",
2339 [(set FR64:$dst, (bitconvert GR64:$src))]>;
2340 def MOV64toSDrm : S3SI<0x7E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
2341 "movq\t{$src, $dst|$dst, $src}",
2342 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2344 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
2345 "mov{d|q}\t{$src, $dst|$dst, $src}",
2346 [(set GR64:$dst, (bitconvert FR64:$src))]>;
2347 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
2348 "movq\t{$src, $dst|$dst, $src}",
2349 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;