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), [{ return i64immSExt32(N); }]>;
79 def i64immZExt32 : PatLeaf<(i64 imm), [{
80 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
81 // unsignedsign extended field.
82 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
85 def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
86 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
87 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
89 def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
90 def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
91 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
92 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
94 def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
95 def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
96 def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
97 def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
99 //===----------------------------------------------------------------------===//
100 // Instruction list...
103 // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
104 // a stack adjustment and the codegen must know that they may modify the stack
105 // pointer before prolog-epilog rewriting occurs.
106 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
107 // sub / add which can clobber EFLAGS.
108 let Defs = [RSP, EFLAGS], Uses = [RSP] in {
109 def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
111 [(X86callseq_start timm:$amt)]>,
112 Requires<[In64BitMode]>;
113 def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
115 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
116 Requires<[In64BitMode]>;
119 // Interrupt Instructions
120 def IRET64 : RI<0xcf, RawFrm, (outs), (ins), "iretq", []>,
121 Requires<[In64BitMode]>;
123 def SYSRETQ : RI<0x07, RawFrm,
124 (outs), (ins), "sysretq", []>, TB, Requires<[In64BitMode]>;
127 //===----------------------------------------------------------------------===//
128 // Call Instructions...
131 // All calls clobber the non-callee saved registers. RSP is marked as
132 // a use to prevent stack-pointer assignments that appear immediately
133 // before calls from potentially appearing dead. Uses for argument
134 // registers are added manually.
135 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
136 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
137 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
138 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
139 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
142 // NOTE: this pattern doesn't match "X86call imm", because we do not know
143 // that the offset between an arbitrary immediate and the call will fit in
144 // the 32-bit pcrel field that we have.
145 def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
146 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
147 "call{q}\t$dst", []>,
148 Requires<[In64BitMode, NotWin64]>;
149 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
150 "call{q}\t{*}$dst", [(X86call GR64:$dst)]>,
151 Requires<[NotWin64]>;
152 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
153 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
154 Requires<[NotWin64]>;
156 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
157 "lcall{q}\t{*}$dst", []>;
160 // FIXME: We need to teach codegen about single list of call-clobbered
162 let isCall = 1, isCodeGenOnly = 1 in
163 // All calls clobber the non-callee saved registers. RSP is marked as
164 // a use to prevent stack-pointer assignments that appear immediately
165 // before calls from potentially appearing dead. Uses for argument
166 // registers are added manually.
167 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
168 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
169 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
170 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
172 def WINCALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
173 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
176 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
178 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
179 def WINCALL64m : I<0xFF, MRM2m, (outs),
180 (ins i64mem:$dst, variable_ops), "call\t{*}$dst",
181 [(X86call (loadi64 addr:$dst))]>,
186 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
188 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
189 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
190 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
191 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
192 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
194 def TCRETURNdi64 : I<0, Pseudo, (outs),
195 (ins i64i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
196 "#TC_RETURN $dst $offset", []>;
197 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64_TC:$dst, i32imm:$offset,
199 "#TC_RETURN $dst $offset", []>;
201 def TCRETURNmi64 : I<0, Pseudo, (outs),
202 (ins i64mem_TC:$dst, i32imm:$offset, variable_ops),
203 "#TC_RETURN $dst $offset", []>;
205 def TAILJMPd64 : Ii32PCRel<0xE9, RawFrm, (outs),
206 (ins i64i32imm_pcrel:$dst, variable_ops),
207 "jmp\t$dst # TAILCALL", []>;
208 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64_TC:$dst, variable_ops),
209 "jmp{q}\t{*}$dst # TAILCALL", []>;
212 def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst, variable_ops),
213 "jmp{q}\t{*}$dst # TAILCALL", []>;
217 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
218 def JMP64pcrel32 : I<0xE9, RawFrm, (outs), (ins brtarget:$dst),
220 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
221 [(brind GR64:$dst)]>, Requires<[In64BitMode]>;
222 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
223 [(brind (loadi64 addr:$dst))]>, Requires<[In64BitMode]>;
224 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
225 "ljmp{q}\t{*}$dst", []>;
228 //===----------------------------------------------------------------------===//
229 // EH Pseudo Instructions
231 let isTerminator = 1, isReturn = 1, isBarrier = 1,
232 hasCtrlDep = 1, isCodeGenOnly = 1 in {
233 def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
234 "ret\t#eh_return, addr: $addr",
235 [(X86ehret GR64:$addr)]>;
239 //===----------------------------------------------------------------------===//
240 // Miscellaneous Instructions...
243 def POPCNT64rr : RI<0xB8, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
244 "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
246 def POPCNT64rm : RI<0xB8, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
247 "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
249 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
250 def LEAVE64 : I<0xC9, RawFrm,
251 (outs), (ins), "leave", []>, Requires<[In64BitMode]>;
252 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
254 def POP64r : I<0x58, AddRegFrm,
255 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
256 def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
257 def POP64rmm: I<0x8F, MRM0m, (outs i64mem:$dst), (ins), "pop{q}\t$dst", []>;
259 let mayStore = 1 in {
260 def PUSH64r : I<0x50, AddRegFrm,
261 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
262 def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
263 def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", []>;
267 let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
268 def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
269 "push{q}\t$imm", []>;
270 def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
271 "push{q}\t$imm", []>;
272 def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i64i32imm:$imm),
273 "push{q}\t$imm", []>;
276 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1, neverHasSideEffects=1 in
277 def POPF64 : I<0x9D, RawFrm, (outs), (ins), "popfq", []>,
278 Requires<[In64BitMode]>;
279 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in
280 def PUSHF64 : I<0x9C, RawFrm, (outs), (ins), "pushfq", []>,
281 Requires<[In64BitMode]>;
283 def LEA64_32r : I<0x8D, MRMSrcMem,
284 (outs GR32:$dst), (ins lea64_32mem:$src),
285 "lea{l}\t{$src|$dst}, {$dst|$src}",
286 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
288 let isReMaterializable = 1 in
289 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
290 "lea{q}\t{$src|$dst}, {$dst|$src}",
291 [(set GR64:$dst, lea64addr:$src)]>;
293 let Constraints = "$src = $dst" in
294 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
296 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
298 // Bit scan instructions.
299 let Defs = [EFLAGS] in {
300 def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
301 "bsf{q}\t{$src, $dst|$dst, $src}",
302 [(set GR64:$dst, EFLAGS, (X86bsf GR64:$src))]>, TB;
303 def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
304 "bsf{q}\t{$src, $dst|$dst, $src}",
305 [(set GR64:$dst, EFLAGS, (X86bsf (loadi64 addr:$src)))]>, TB;
307 def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
308 "bsr{q}\t{$src, $dst|$dst, $src}",
309 [(set GR64:$dst, EFLAGS, (X86bsr GR64:$src))]>, TB;
310 def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
311 "bsr{q}\t{$src, $dst|$dst, $src}",
312 [(set GR64:$dst, EFLAGS, (X86bsr (loadi64 addr:$src)))]>, TB;
316 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI], isCodeGenOnly = 1 in
317 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
318 [(X86rep_movs i64)]>, REP;
319 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI], isCodeGenOnly = 1 in
320 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
321 [(X86rep_stos i64)]>, REP;
323 let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in
324 def MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "movsq", []>;
326 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI,EFLAGS] in
327 def STOSQ : RI<0xAB, RawFrm, (outs), (ins), "stosq", []>;
329 def SCAS64 : RI<0xAF, RawFrm, (outs), (ins), "scasq", []>;
331 def CMPS64 : RI<0xA7, RawFrm, (outs), (ins), "cmpsq", []>;
333 // Fast system-call instructions
334 def SYSEXIT64 : RI<0x35, RawFrm,
335 (outs), (ins), "sysexit", []>, TB, Requires<[In64BitMode]>;
337 //===----------------------------------------------------------------------===//
338 // Move Instructions...
341 let neverHasSideEffects = 1 in
342 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
343 "mov{q}\t{$src, $dst|$dst, $src}", []>;
345 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
346 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
347 "movabs{q}\t{$src, $dst|$dst, $src}",
348 [(set GR64:$dst, imm:$src)]>;
349 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
350 "mov{q}\t{$src, $dst|$dst, $src}",
351 [(set GR64:$dst, i64immSExt32:$src)]>;
354 // The assembler accepts movq of a 64-bit immediate as an alternate spelling of
356 let isAsmParserOnly = 1 in {
357 def MOV64ri_alt : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
358 "mov{q}\t{$src, $dst|$dst, $src}", []>;
361 let isCodeGenOnly = 1 in {
362 def MOV64rr_REV : RI<0x8B, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
363 "mov{q}\t{$src, $dst|$dst, $src}", []>;
366 let canFoldAsLoad = 1, isReMaterializable = 1 in
367 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
368 "mov{q}\t{$src, $dst|$dst, $src}",
369 [(set GR64:$dst, (load addr:$src))]>;
371 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
372 "mov{q}\t{$src, $dst|$dst, $src}",
373 [(store GR64:$src, addr:$dst)]>;
374 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
375 "mov{q}\t{$src, $dst|$dst, $src}",
376 [(store i64immSExt32:$src, addr:$dst)]>;
378 /// Versions of MOV64rr, MOV64rm, and MOV64mr for i64mem_TC and GR64_TC.
379 let isCodeGenOnly = 1 in {
380 let neverHasSideEffects = 1 in
381 def MOV64rr_TC : RI<0x89, MRMDestReg, (outs GR64_TC:$dst), (ins GR64_TC:$src),
382 "mov{q}\t{$src, $dst|$dst, $src}", []>;
385 canFoldAsLoad = 1, isReMaterializable = 1 in
386 def MOV64rm_TC : RI<0x8B, MRMSrcMem, (outs GR64_TC:$dst), (ins i64mem_TC:$src),
387 "mov{q}\t{$src, $dst|$dst, $src}",
391 def MOV64mr_TC : RI<0x89, MRMDestMem, (outs), (ins i64mem_TC:$dst, GR64_TC:$src),
392 "mov{q}\t{$src, $dst|$dst, $src}",
396 // FIXME: These definitions are utterly broken
397 // Just leave them commented out for now because they're useless outside
398 // of the large code model, and most compilers won't generate the instructions
401 def MOV64o8a : RIi8<0xA0, RawFrm, (outs), (ins offset8:$src),
402 "mov{q}\t{$src, %rax|%rax, $src}", []>;
403 def MOV64o64a : RIi32<0xA1, RawFrm, (outs), (ins offset64:$src),
404 "mov{q}\t{$src, %rax|%rax, $src}", []>;
405 def MOV64ao8 : RIi8<0xA2, RawFrm, (outs offset8:$dst), (ins),
406 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
407 def MOV64ao64 : RIi32<0xA3, RawFrm, (outs offset64:$dst), (ins),
408 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
411 // Moves to and from segment registers
412 def MOV64rs : RI<0x8C, MRMDestReg, (outs GR64:$dst), (ins SEGMENT_REG:$src),
413 "mov{q}\t{$src, $dst|$dst, $src}", []>;
414 def MOV64ms : RI<0x8C, MRMDestMem, (outs i64mem:$dst), (ins SEGMENT_REG:$src),
415 "mov{q}\t{$src, $dst|$dst, $src}", []>;
416 def MOV64sr : RI<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR64:$src),
417 "mov{q}\t{$src, $dst|$dst, $src}", []>;
418 def MOV64sm : RI<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i64mem:$src),
419 "mov{q}\t{$src, $dst|$dst, $src}", []>;
421 // Moves to and from debug registers
422 def MOV64rd : I<0x21, MRMDestReg, (outs GR64:$dst), (ins DEBUG_REG:$src),
423 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
424 def MOV64dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR64:$src),
425 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
427 // Moves to and from control registers
428 def MOV64rc : I<0x20, MRMDestReg, (outs GR64:$dst), (ins CONTROL_REG:$src),
429 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
430 def MOV64cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR64:$src),
431 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
433 // Sign/Zero extenders
435 // MOVSX64rr8 always has a REX prefix and it has an 8-bit register
436 // operand, which makes it a rare instruction with an 8-bit register
437 // operand that can never access an h register. If support for h registers
438 // were generalized, this would require a special register class.
439 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
440 "movs{bq|x}\t{$src, $dst|$dst, $src}",
441 [(set GR64:$dst, (sext GR8:$src))]>, TB;
442 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
443 "movs{bq|x}\t{$src, $dst|$dst, $src}",
444 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
445 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
446 "movs{wq|x}\t{$src, $dst|$dst, $src}",
447 [(set GR64:$dst, (sext GR16:$src))]>, TB;
448 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
449 "movs{wq|x}\t{$src, $dst|$dst, $src}",
450 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
451 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
452 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
453 [(set GR64:$dst, (sext GR32:$src))]>;
454 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
455 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
456 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
458 // movzbq and movzwq encodings for the disassembler
459 def MOVZX64rr8_Q : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8:$src),
460 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
461 def MOVZX64rm8_Q : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem:$src),
462 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
463 def MOVZX64rr16_Q : RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
464 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
465 def MOVZX64rm16_Q : RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
466 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
468 // Use movzbl instead of movzbq when the destination is a register; it's
469 // equivalent due to implicit zero-extending, and it has a smaller encoding.
470 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
471 "", [(set GR64:$dst, (zext GR8:$src))]>, TB;
472 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
473 "", [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
474 // Use movzwl instead of movzwq when the destination is a register; it's
475 // equivalent due to implicit zero-extending, and it has a smaller encoding.
476 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
477 "", [(set GR64:$dst, (zext GR16:$src))]>, TB;
478 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
479 "", [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
481 // There's no movzlq instruction, but movl can be used for this purpose, using
482 // implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
483 // extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
484 // zero-extension, however this isn't possible when the 32-bit value is
485 // defined by a truncate or is copied from something where the high bits aren't
486 // necessarily all zero. In such cases, we fall back to these explicit zext
488 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
489 "", [(set GR64:$dst, (zext GR32:$src))]>;
490 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
491 "", [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
493 // Any instruction that defines a 32-bit result leaves the high half of the
494 // register. Truncate can be lowered to EXTRACT_SUBREG. CopyFromReg may
495 // be copying from a truncate. And x86's cmov doesn't do anything if the
496 // condition is false. But any other 32-bit operation will zero-extend
498 def def32 : PatLeaf<(i32 GR32:$src), [{
499 return N->getOpcode() != ISD::TRUNCATE &&
500 N->getOpcode() != TargetOpcode::EXTRACT_SUBREG &&
501 N->getOpcode() != ISD::CopyFromReg &&
502 N->getOpcode() != X86ISD::CMOV;
505 // In the case of a 32-bit def that is known to implicitly zero-extend,
506 // we can use a SUBREG_TO_REG.
507 def : Pat<(i64 (zext def32:$src)),
508 (SUBREG_TO_REG (i64 0), GR32:$src, sub_32bit)>;
510 let neverHasSideEffects = 1 in {
511 let Defs = [RAX], Uses = [EAX] in
512 def CDQE : RI<0x98, RawFrm, (outs), (ins),
513 "{cltq|cdqe}", []>; // RAX = signext(EAX)
515 let Defs = [RAX,RDX], Uses = [RAX] in
516 def CQO : RI<0x99, RawFrm, (outs), (ins),
517 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
520 //===----------------------------------------------------------------------===//
521 // Arithmetic Instructions...
524 let Defs = [EFLAGS] in {
526 def ADD64i32 : RIi32<0x05, RawFrm, (outs), (ins i64i32imm:$src),
527 "add{q}\t{$src, %rax|%rax, $src}", []>;
529 let Constraints = "$src1 = $dst" in {
530 let isConvertibleToThreeAddress = 1 in {
531 let isCommutable = 1 in
532 // Register-Register Addition
533 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst),
534 (ins GR64:$src1, GR64:$src2),
535 "add{q}\t{$src2, $dst|$dst, $src2}",
536 [(set GR64:$dst, EFLAGS,
537 (X86add_flag GR64:$src1, GR64:$src2))]>;
539 // These are alternate spellings for use by the disassembler, we mark them as
540 // code gen only to ensure they aren't matched by the assembler.
541 let isCodeGenOnly = 1 in {
542 def ADD64rr_alt : RI<0x03, MRMSrcReg, (outs GR64:$dst),
543 (ins GR64:$src1, GR64:$src2),
544 "add{l}\t{$src2, $dst|$dst, $src2}", []>;
547 // Register-Integer Addition
548 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst),
549 (ins GR64:$src1, i64i8imm:$src2),
550 "add{q}\t{$src2, $dst|$dst, $src2}",
551 [(set GR64:$dst, EFLAGS,
552 (X86add_flag GR64:$src1, i64immSExt8:$src2))]>;
553 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst),
554 (ins GR64:$src1, i64i32imm:$src2),
555 "add{q}\t{$src2, $dst|$dst, $src2}",
556 [(set GR64:$dst, EFLAGS,
557 (X86add_flag GR64:$src1, i64immSExt32:$src2))]>;
558 } // isConvertibleToThreeAddress
560 // Register-Memory Addition
561 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst),
562 (ins GR64:$src1, i64mem:$src2),
563 "add{q}\t{$src2, $dst|$dst, $src2}",
564 [(set GR64:$dst, EFLAGS,
565 (X86add_flag GR64:$src1, (load addr:$src2)))]>;
567 } // Constraints = "$src1 = $dst"
569 // Memory-Register Addition
570 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
571 "add{q}\t{$src2, $dst|$dst, $src2}",
572 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
574 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
575 "add{q}\t{$src2, $dst|$dst, $src2}",
576 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
578 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
579 "add{q}\t{$src2, $dst|$dst, $src2}",
580 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
583 let Uses = [EFLAGS] in {
585 def ADC64i32 : RIi32<0x15, RawFrm, (outs), (ins i64i32imm:$src),
586 "adc{q}\t{$src, %rax|%rax, $src}", []>;
588 let Constraints = "$src1 = $dst" in {
589 let isCommutable = 1 in
590 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst),
591 (ins GR64:$src1, GR64:$src2),
592 "adc{q}\t{$src2, $dst|$dst, $src2}",
593 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
595 let isCodeGenOnly = 1 in {
596 def ADC64rr_REV : RI<0x13, MRMSrcReg , (outs GR32:$dst),
597 (ins GR64:$src1, GR64:$src2),
598 "adc{q}\t{$src2, $dst|$dst, $src2}", []>;
601 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst),
602 (ins GR64:$src1, i64mem:$src2),
603 "adc{q}\t{$src2, $dst|$dst, $src2}",
604 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
606 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst),
607 (ins GR64:$src1, i64i8imm:$src2),
608 "adc{q}\t{$src2, $dst|$dst, $src2}",
609 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
610 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst),
611 (ins GR64:$src1, i64i32imm:$src2),
612 "adc{q}\t{$src2, $dst|$dst, $src2}",
613 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
614 } // Constraints = "$src1 = $dst"
616 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
617 "adc{q}\t{$src2, $dst|$dst, $src2}",
618 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
619 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
620 "adc{q}\t{$src2, $dst|$dst, $src2}",
621 [(store (adde (load addr:$dst), i64immSExt8:$src2),
623 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
624 "adc{q}\t{$src2, $dst|$dst, $src2}",
625 [(store (adde (load addr:$dst), i64immSExt32:$src2),
629 let Constraints = "$src1 = $dst" in {
630 // Register-Register Subtraction
631 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst),
632 (ins GR64:$src1, GR64:$src2),
633 "sub{q}\t{$src2, $dst|$dst, $src2}",
634 [(set GR64:$dst, EFLAGS,
635 (X86sub_flag GR64:$src1, GR64:$src2))]>;
637 let isCodeGenOnly = 1 in {
638 def SUB64rr_REV : RI<0x2B, MRMSrcReg, (outs GR64:$dst),
639 (ins GR64:$src1, GR64:$src2),
640 "sub{q}\t{$src2, $dst|$dst, $src2}", []>;
643 // Register-Memory Subtraction
644 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst),
645 (ins GR64:$src1, i64mem:$src2),
646 "sub{q}\t{$src2, $dst|$dst, $src2}",
647 [(set GR64:$dst, EFLAGS,
648 (X86sub_flag GR64:$src1, (load addr:$src2)))]>;
650 // Register-Integer Subtraction
651 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
652 (ins GR64:$src1, i64i8imm:$src2),
653 "sub{q}\t{$src2, $dst|$dst, $src2}",
654 [(set GR64:$dst, EFLAGS,
655 (X86sub_flag GR64:$src1, i64immSExt8:$src2))]>;
656 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
657 (ins GR64:$src1, i64i32imm:$src2),
658 "sub{q}\t{$src2, $dst|$dst, $src2}",
659 [(set GR64:$dst, EFLAGS,
660 (X86sub_flag GR64:$src1, i64immSExt32:$src2))]>;
661 } // Constraints = "$src1 = $dst"
663 def SUB64i32 : RIi32<0x2D, RawFrm, (outs), (ins i64i32imm:$src),
664 "sub{q}\t{$src, %rax|%rax, $src}", []>;
666 // Memory-Register Subtraction
667 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
668 "sub{q}\t{$src2, $dst|$dst, $src2}",
669 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
672 // Memory-Integer Subtraction
673 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
674 "sub{q}\t{$src2, $dst|$dst, $src2}",
675 [(store (sub (load addr:$dst), i64immSExt8:$src2),
678 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
679 "sub{q}\t{$src2, $dst|$dst, $src2}",
680 [(store (sub (load addr:$dst), i64immSExt32:$src2),
684 let Uses = [EFLAGS] in {
685 let Constraints = "$src1 = $dst" in {
686 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst),
687 (ins GR64:$src1, GR64:$src2),
688 "sbb{q}\t{$src2, $dst|$dst, $src2}",
689 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
691 let isCodeGenOnly = 1 in {
692 def SBB64rr_REV : RI<0x1B, MRMSrcReg, (outs GR64:$dst),
693 (ins GR64:$src1, GR64:$src2),
694 "sbb{q}\t{$src2, $dst|$dst, $src2}", []>;
697 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst),
698 (ins GR64:$src1, i64mem:$src2),
699 "sbb{q}\t{$src2, $dst|$dst, $src2}",
700 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
702 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst),
703 (ins GR64:$src1, i64i8imm:$src2),
704 "sbb{q}\t{$src2, $dst|$dst, $src2}",
705 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
706 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst),
707 (ins GR64:$src1, i64i32imm:$src2),
708 "sbb{q}\t{$src2, $dst|$dst, $src2}",
709 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
710 } // Constraints = "$src1 = $dst"
712 def SBB64i32 : RIi32<0x1D, RawFrm, (outs), (ins i64i32imm:$src),
713 "sbb{q}\t{$src, %rax|%rax, $src}", []>;
715 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
716 "sbb{q}\t{$src2, $dst|$dst, $src2}",
717 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
718 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
719 "sbb{q}\t{$src2, $dst|$dst, $src2}",
720 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
721 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
722 "sbb{q}\t{$src2, $dst|$dst, $src2}",
723 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
727 // Unsigned multiplication
728 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
729 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
730 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
732 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
733 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
735 // Signed multiplication
736 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
737 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
739 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
740 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
743 let Defs = [EFLAGS] in {
744 let Constraints = "$src1 = $dst" in {
745 let isCommutable = 1 in
746 // Register-Register Signed Integer Multiplication
747 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
748 (ins GR64:$src1, GR64:$src2),
749 "imul{q}\t{$src2, $dst|$dst, $src2}",
750 [(set GR64:$dst, EFLAGS,
751 (X86smul_flag GR64:$src1, GR64:$src2))]>, TB;
753 // Register-Memory Signed Integer Multiplication
754 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
755 (ins GR64:$src1, i64mem:$src2),
756 "imul{q}\t{$src2, $dst|$dst, $src2}",
757 [(set GR64:$dst, EFLAGS,
758 (X86smul_flag GR64:$src1, (load addr:$src2)))]>, TB;
759 } // Constraints = "$src1 = $dst"
761 // Suprisingly enough, these are not two address instructions!
763 // Register-Integer Signed Integer Multiplication
764 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
765 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
766 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
767 [(set GR64:$dst, EFLAGS,
768 (X86smul_flag GR64:$src1, i64immSExt8:$src2))]>;
769 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
770 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
771 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
772 [(set GR64:$dst, EFLAGS,
773 (X86smul_flag GR64:$src1, i64immSExt32:$src2))]>;
775 // Memory-Integer Signed Integer Multiplication
776 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
777 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
778 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
779 [(set GR64:$dst, EFLAGS,
780 (X86smul_flag (load addr:$src1),
781 i64immSExt8:$src2))]>;
782 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
783 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
784 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
785 [(set GR64:$dst, EFLAGS,
786 (X86smul_flag (load addr:$src1),
787 i64immSExt32:$src2))]>;
790 // Unsigned division / remainder
791 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
792 // RDX:RAX/r64 = RAX,RDX
793 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src),
795 // Signed division / remainder
796 // RDX:RAX/r64 = RAX,RDX
797 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src),
798 "idiv{q}\t$src", []>;
800 // RDX:RAX/[mem64] = RAX,RDX
801 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src),
803 // RDX:RAX/[mem64] = RAX,RDX
804 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src),
805 "idiv{q}\t$src", []>;
809 // Unary instructions
810 let Defs = [EFLAGS], CodeSize = 2 in {
811 let Constraints = "$src = $dst" in
812 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
813 [(set GR64:$dst, (ineg GR64:$src)),
815 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
816 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
819 let Constraints = "$src = $dst", isConvertibleToThreeAddress = 1 in
820 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
821 [(set GR64:$dst, EFLAGS, (X86inc_flag GR64:$src))]>;
822 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
823 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
826 let Constraints = "$src = $dst", isConvertibleToThreeAddress = 1 in
827 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
828 [(set GR64:$dst, EFLAGS, (X86dec_flag GR64:$src))]>;
829 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
830 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
833 // In 64-bit mode, single byte INC and DEC cannot be encoded.
834 let Constraints = "$src = $dst", isConvertibleToThreeAddress = 1 in {
835 // Can transform into LEA.
836 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src),
838 [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src))]>,
839 OpSize, Requires<[In64BitMode]>;
840 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src),
842 [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src))]>,
843 Requires<[In64BitMode]>;
844 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src),
846 [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src))]>,
847 OpSize, Requires<[In64BitMode]>;
848 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src),
850 [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src))]>,
851 Requires<[In64BitMode]>;
852 } // Constraints = "$src = $dst", isConvertibleToThreeAddress
854 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
855 // how to unfold them.
856 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
857 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
859 OpSize, Requires<[In64BitMode]>;
860 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
861 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
863 Requires<[In64BitMode]>;
864 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
865 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
867 OpSize, Requires<[In64BitMode]>;
868 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
869 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
871 Requires<[In64BitMode]>;
872 } // Defs = [EFLAGS], CodeSize
875 let Defs = [EFLAGS] in {
876 // Shift instructions
877 let Constraints = "$src1 = $dst" in {
879 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
880 "shl{q}\t{%cl, $dst|$dst, %CL}",
881 [(set GR64:$dst, (shl GR64:$src1, CL))]>;
882 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
883 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst),
884 (ins GR64:$src1, i8imm:$src2),
885 "shl{q}\t{$src2, $dst|$dst, $src2}",
886 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
887 // NOTE: We don't include patterns for shifts of a register by one, because
888 // 'add reg,reg' is cheaper.
889 def SHL64r1 : RI<0xD1, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
891 } // Constraints = "$src1 = $dst"
894 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
895 "shl{q}\t{%cl, $dst|$dst, %CL}",
896 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
897 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
898 "shl{q}\t{$src, $dst|$dst, $src}",
899 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
900 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
902 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
904 let Constraints = "$src1 = $dst" in {
906 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
907 "shr{q}\t{%cl, $dst|$dst, %CL}",
908 [(set GR64:$dst, (srl GR64:$src1, CL))]>;
909 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
910 "shr{q}\t{$src2, $dst|$dst, $src2}",
911 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
912 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
914 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
915 } // Constraints = "$src1 = $dst"
918 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
919 "shr{q}\t{%cl, $dst|$dst, %CL}",
920 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
921 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
922 "shr{q}\t{$src, $dst|$dst, $src}",
923 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
924 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
926 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
928 let Constraints = "$src1 = $dst" in {
930 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
931 "sar{q}\t{%cl, $dst|$dst, %CL}",
932 [(set GR64:$dst, (sra GR64:$src1, CL))]>;
933 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst),
934 (ins GR64:$src1, i8imm:$src2),
935 "sar{q}\t{$src2, $dst|$dst, $src2}",
936 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
937 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
939 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
940 } // Constraints = "$src = $dst"
943 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
944 "sar{q}\t{%cl, $dst|$dst, %CL}",
945 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
946 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
947 "sar{q}\t{$src, $dst|$dst, $src}",
948 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
949 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
951 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
953 // Rotate instructions
955 let Constraints = "$src = $dst" in {
956 def RCL64r1 : RI<0xD1, MRM2r, (outs GR64:$dst), (ins GR64:$src),
957 "rcl{q}\t{1, $dst|$dst, 1}", []>;
958 def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
959 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
961 def RCR64r1 : RI<0xD1, MRM3r, (outs GR64:$dst), (ins GR64:$src),
962 "rcr{q}\t{1, $dst|$dst, 1}", []>;
963 def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
964 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
967 def RCL64rCL : RI<0xD3, MRM2r, (outs GR64:$dst), (ins GR64:$src),
968 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
969 def RCR64rCL : RI<0xD3, MRM3r, (outs GR64:$dst), (ins GR64:$src),
970 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
972 } // Constraints = "$src = $dst"
974 def RCL64m1 : RI<0xD1, MRM2m, (outs), (ins i64mem:$dst),
975 "rcl{q}\t{1, $dst|$dst, 1}", []>;
976 def RCL64mi : RIi8<0xC1, MRM2m, (outs), (ins i64mem:$dst, i8imm:$cnt),
977 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
978 def RCR64m1 : RI<0xD1, MRM3m, (outs), (ins i64mem:$dst),
979 "rcr{q}\t{1, $dst|$dst, 1}", []>;
980 def RCR64mi : RIi8<0xC1, MRM3m, (outs), (ins i64mem:$dst, i8imm:$cnt),
981 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
984 def RCL64mCL : RI<0xD3, MRM2m, (outs), (ins i64mem:$dst),
985 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
986 def RCR64mCL : RI<0xD3, MRM3m, (outs), (ins i64mem:$dst),
987 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
990 let Constraints = "$src1 = $dst" in {
992 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
993 "rol{q}\t{%cl, $dst|$dst, %CL}",
994 [(set GR64:$dst, (rotl GR64:$src1, CL))]>;
995 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst),
996 (ins GR64:$src1, i8imm:$src2),
997 "rol{q}\t{$src2, $dst|$dst, $src2}",
998 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
999 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
1001 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
1002 } // Constraints = "$src1 = $dst"
1005 def ROL64mCL : RI<0xD3, MRM0m, (outs), (ins i64mem:$dst),
1006 "rol{q}\t{%cl, $dst|$dst, %CL}",
1007 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
1008 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
1009 "rol{q}\t{$src, $dst|$dst, $src}",
1010 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1011 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
1013 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
1015 let Constraints = "$src1 = $dst" in {
1017 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
1018 "ror{q}\t{%cl, $dst|$dst, %CL}",
1019 [(set GR64:$dst, (rotr GR64:$src1, CL))]>;
1020 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst),
1021 (ins GR64:$src1, i8imm:$src2),
1022 "ror{q}\t{$src2, $dst|$dst, $src2}",
1023 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
1024 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
1026 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
1027 } // Constraints = "$src1 = $dst"
1030 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
1031 "ror{q}\t{%cl, $dst|$dst, %CL}",
1032 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
1033 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
1034 "ror{q}\t{$src, $dst|$dst, $src}",
1035 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1036 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
1038 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
1040 // Double shift instructions (generalizations of rotate)
1041 let Constraints = "$src1 = $dst" in {
1042 let Uses = [CL] in {
1043 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst),
1044 (ins GR64:$src1, GR64:$src2),
1045 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1046 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>,
1048 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst),
1049 (ins GR64:$src1, GR64:$src2),
1050 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1051 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>,
1055 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
1056 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
1058 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
1059 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1060 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
1063 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
1065 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
1066 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1067 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
1071 } // Constraints = "$src1 = $dst"
1073 let Uses = [CL] in {
1074 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1075 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1076 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
1078 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1079 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1080 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
1083 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
1084 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
1085 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1086 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
1087 (i8 imm:$src3)), addr:$dst)]>,
1089 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
1090 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
1091 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1092 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
1093 (i8 imm:$src3)), addr:$dst)]>,
1095 } // Defs = [EFLAGS]
1097 //===----------------------------------------------------------------------===//
1098 // Logical Instructions...
1101 let Constraints = "$src = $dst" , AddedComplexity = 15 in
1102 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
1103 [(set GR64:$dst, (not GR64:$src))]>;
1104 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
1105 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
1107 let Defs = [EFLAGS] in {
1108 def AND64i32 : RIi32<0x25, RawFrm, (outs), (ins i64i32imm:$src),
1109 "and{q}\t{$src, %rax|%rax, $src}", []>;
1111 let Constraints = "$src1 = $dst" in {
1112 let isCommutable = 1 in
1113 def AND64rr : RI<0x21, MRMDestReg,
1114 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1115 "and{q}\t{$src2, $dst|$dst, $src2}",
1116 [(set GR64:$dst, EFLAGS,
1117 (X86and_flag GR64:$src1, GR64:$src2))]>;
1118 let isCodeGenOnly = 1 in {
1119 def AND64rr_REV : RI<0x23, MRMSrcReg, (outs GR64:$dst),
1120 (ins GR64:$src1, GR64:$src2),
1121 "and{q}\t{$src2, $dst|$dst, $src2}", []>;
1123 def AND64rm : RI<0x23, MRMSrcMem,
1124 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1125 "and{q}\t{$src2, $dst|$dst, $src2}",
1126 [(set GR64:$dst, EFLAGS,
1127 (X86and_flag GR64:$src1, (load addr:$src2)))]>;
1128 def AND64ri8 : RIi8<0x83, MRM4r,
1129 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
1130 "and{q}\t{$src2, $dst|$dst, $src2}",
1131 [(set GR64:$dst, EFLAGS,
1132 (X86and_flag GR64:$src1, i64immSExt8:$src2))]>;
1133 def AND64ri32 : RIi32<0x81, MRM4r,
1134 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1135 "and{q}\t{$src2, $dst|$dst, $src2}",
1136 [(set GR64:$dst, EFLAGS,
1137 (X86and_flag GR64:$src1, i64immSExt32:$src2))]>;
1138 } // Constraints = "$src1 = $dst"
1140 def AND64mr : RI<0x21, MRMDestMem,
1141 (outs), (ins i64mem:$dst, GR64:$src),
1142 "and{q}\t{$src, $dst|$dst, $src}",
1143 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
1144 (implicit EFLAGS)]>;
1145 def AND64mi8 : RIi8<0x83, MRM4m,
1146 (outs), (ins i64mem:$dst, i64i8imm :$src),
1147 "and{q}\t{$src, $dst|$dst, $src}",
1148 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
1149 (implicit EFLAGS)]>;
1150 def AND64mi32 : RIi32<0x81, MRM4m,
1151 (outs), (ins i64mem:$dst, i64i32imm:$src),
1152 "and{q}\t{$src, $dst|$dst, $src}",
1153 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1154 (implicit EFLAGS)]>;
1156 let Constraints = "$src1 = $dst" in {
1157 let isCommutable = 1 in
1158 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst),
1159 (ins GR64:$src1, GR64:$src2),
1160 "or{q}\t{$src2, $dst|$dst, $src2}",
1161 [(set GR64:$dst, EFLAGS,
1162 (X86or_flag GR64:$src1, GR64:$src2))]>;
1163 let isCodeGenOnly = 1 in {
1164 def OR64rr_REV : RI<0x0B, MRMSrcReg, (outs GR64:$dst),
1165 (ins GR64:$src1, GR64:$src2),
1166 "or{q}\t{$src2, $dst|$dst, $src2}", []>;
1168 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst),
1169 (ins GR64:$src1, i64mem:$src2),
1170 "or{q}\t{$src2, $dst|$dst, $src2}",
1171 [(set GR64:$dst, EFLAGS,
1172 (X86or_flag GR64:$src1, (load addr:$src2)))]>;
1173 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst),
1174 (ins GR64:$src1, i64i8imm:$src2),
1175 "or{q}\t{$src2, $dst|$dst, $src2}",
1176 [(set GR64:$dst, EFLAGS,
1177 (X86or_flag GR64:$src1, i64immSExt8:$src2))]>;
1178 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst),
1179 (ins GR64:$src1, i64i32imm:$src2),
1180 "or{q}\t{$src2, $dst|$dst, $src2}",
1181 [(set GR64:$dst, EFLAGS,
1182 (X86or_flag GR64:$src1, i64immSExt32:$src2))]>;
1183 } // Constraints = "$src1 = $dst"
1185 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1186 "or{q}\t{$src, $dst|$dst, $src}",
1187 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
1188 (implicit EFLAGS)]>;
1189 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
1190 "or{q}\t{$src, $dst|$dst, $src}",
1191 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
1192 (implicit EFLAGS)]>;
1193 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1194 "or{q}\t{$src, $dst|$dst, $src}",
1195 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1196 (implicit EFLAGS)]>;
1198 def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i64i32imm:$src),
1199 "or{q}\t{$src, %rax|%rax, $src}", []>;
1201 let Constraints = "$src1 = $dst" in {
1202 let isCommutable = 1 in
1203 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst),
1204 (ins GR64:$src1, GR64:$src2),
1205 "xor{q}\t{$src2, $dst|$dst, $src2}",
1206 [(set GR64:$dst, EFLAGS,
1207 (X86xor_flag GR64:$src1, GR64:$src2))]>;
1208 let isCodeGenOnly = 1 in {
1209 def XOR64rr_REV : RI<0x33, MRMSrcReg, (outs GR64:$dst),
1210 (ins GR64:$src1, GR64:$src2),
1211 "xor{q}\t{$src2, $dst|$dst, $src2}", []>;
1213 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst),
1214 (ins GR64:$src1, i64mem:$src2),
1215 "xor{q}\t{$src2, $dst|$dst, $src2}",
1216 [(set GR64:$dst, EFLAGS,
1217 (X86xor_flag GR64:$src1, (load addr:$src2)))]>;
1218 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst),
1219 (ins GR64:$src1, i64i8imm:$src2),
1220 "xor{q}\t{$src2, $dst|$dst, $src2}",
1221 [(set GR64:$dst, EFLAGS,
1222 (X86xor_flag GR64:$src1, i64immSExt8:$src2))]>;
1223 def XOR64ri32 : RIi32<0x81, MRM6r,
1224 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1225 "xor{q}\t{$src2, $dst|$dst, $src2}",
1226 [(set GR64:$dst, EFLAGS,
1227 (X86xor_flag GR64:$src1, i64immSExt32:$src2))]>;
1228 } // Constraints = "$src1 = $dst"
1230 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1231 "xor{q}\t{$src, $dst|$dst, $src}",
1232 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1233 (implicit EFLAGS)]>;
1234 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
1235 "xor{q}\t{$src, $dst|$dst, $src}",
1236 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1237 (implicit EFLAGS)]>;
1238 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1239 "xor{q}\t{$src, $dst|$dst, $src}",
1240 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1241 (implicit EFLAGS)]>;
1243 def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i64i32imm:$src),
1244 "xor{q}\t{$src, %rax|%rax, $src}", []>;
1246 } // Defs = [EFLAGS]
1248 //===----------------------------------------------------------------------===//
1249 // Comparison Instructions...
1252 // Integer comparison
1253 let Defs = [EFLAGS] in {
1254 def TEST64i32 : RIi32<0xa9, RawFrm, (outs), (ins i64i32imm:$src),
1255 "test{q}\t{$src, %rax|%rax, $src}", []>;
1256 let isCommutable = 1 in
1257 def TEST64rr : RI<0x85, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1258 "test{q}\t{$src2, $src1|$src1, $src2}",
1259 [(set EFLAGS, (X86cmp (and GR64:$src1, GR64:$src2), 0))]>;
1260 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1261 "test{q}\t{$src2, $src1|$src1, $src2}",
1262 [(set EFLAGS, (X86cmp (and GR64:$src1, (loadi64 addr:$src2)),
1264 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1265 (ins GR64:$src1, i64i32imm:$src2),
1266 "test{q}\t{$src2, $src1|$src1, $src2}",
1267 [(set EFLAGS, (X86cmp (and GR64:$src1, i64immSExt32:$src2),
1269 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1270 (ins i64mem:$src1, i64i32imm:$src2),
1271 "test{q}\t{$src2, $src1|$src1, $src2}",
1272 [(set EFLAGS, (X86cmp (and (loadi64 addr:$src1),
1273 i64immSExt32:$src2), 0))]>;
1276 def CMP64i32 : RIi32<0x3D, RawFrm, (outs), (ins i64i32imm:$src),
1277 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
1278 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1279 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1280 [(set EFLAGS, (X86cmp GR64:$src1, GR64:$src2))]>;
1282 // These are alternate spellings for use by the disassembler, we mark them as
1283 // code gen only to ensure they aren't matched by the assembler.
1284 let isCodeGenOnly = 1 in {
1285 def CMP64mrmrr : RI<0x3B, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1286 "cmp{q}\t{$src2, $src1|$src1, $src2}", []>;
1289 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1290 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1291 [(set EFLAGS, (X86cmp (loadi64 addr:$src1), GR64:$src2))]>;
1292 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1293 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1294 [(set EFLAGS, (X86cmp GR64:$src1, (loadi64 addr:$src2)))]>;
1295 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1296 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1297 [(set EFLAGS, (X86cmp GR64:$src1, i64immSExt8:$src2))]>;
1298 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
1299 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1300 [(set EFLAGS, (X86cmp GR64:$src1, i64immSExt32:$src2))]>;
1301 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1302 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1303 [(set EFLAGS, (X86cmp (loadi64 addr:$src1),
1304 i64immSExt8:$src2))]>;
1305 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1306 (ins i64mem:$src1, i64i32imm:$src2),
1307 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1308 [(set EFLAGS, (X86cmp (loadi64 addr:$src1),
1309 i64immSExt32:$src2))]>;
1310 } // Defs = [EFLAGS]
1313 // TODO: BTC, BTR, and BTS
1314 let Defs = [EFLAGS] in {
1315 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1316 "bt{q}\t{$src2, $src1|$src1, $src2}",
1317 [(set EFLAGS, (X86bt GR64:$src1, GR64:$src2))]>, TB;
1319 // Unlike with the register+register form, the memory+register form of the
1320 // bt instruction does not ignore the high bits of the index. From ISel's
1321 // perspective, this is pretty bizarre. Disable these instructions for now.
1322 def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1323 "bt{q}\t{$src2, $src1|$src1, $src2}",
1324 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
1325 // (implicit EFLAGS)]
1329 def BT64ri8 : RIi8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1330 "bt{q}\t{$src2, $src1|$src1, $src2}",
1331 [(set EFLAGS, (X86bt GR64:$src1, i64immSExt8:$src2))]>, TB;
1332 // Note that these instructions don't need FastBTMem because that
1333 // only applies when the other operand is in a register. When it's
1334 // an immediate, bt is still fast.
1335 def BT64mi8 : RIi8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1336 "bt{q}\t{$src2, $src1|$src1, $src2}",
1337 [(set EFLAGS, (X86bt (loadi64 addr:$src1),
1338 i64immSExt8:$src2))]>, TB;
1340 def BTC64rr : RI<0xBB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1341 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1342 def BTC64mr : RI<0xBB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1343 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1344 def BTC64ri8 : RIi8<0xBA, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1345 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1346 def BTC64mi8 : RIi8<0xBA, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1347 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1349 def BTR64rr : RI<0xB3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1350 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1351 def BTR64mr : RI<0xB3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1352 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1353 def BTR64ri8 : RIi8<0xBA, MRM6r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1354 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1355 def BTR64mi8 : RIi8<0xBA, MRM6m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1356 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1358 def BTS64rr : RI<0xAB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1359 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1360 def BTS64mr : RI<0xAB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1361 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1362 def BTS64ri8 : RIi8<0xBA, MRM5r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1363 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1364 def BTS64mi8 : RIi8<0xBA, MRM5m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1365 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1366 } // Defs = [EFLAGS]
1368 // Conditional moves
1369 let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
1370 let isCommutable = 1 in {
1371 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
1372 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1373 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
1374 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1375 X86_COND_B, EFLAGS))]>, TB;
1376 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
1377 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1378 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
1379 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1380 X86_COND_AE, EFLAGS))]>, TB;
1381 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
1382 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1383 "cmove{q}\t{$src2, $dst|$dst, $src2}",
1384 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1385 X86_COND_E, EFLAGS))]>, TB;
1386 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
1387 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1388 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
1389 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1390 X86_COND_NE, EFLAGS))]>, TB;
1391 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
1392 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1393 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
1394 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1395 X86_COND_BE, EFLAGS))]>, TB;
1396 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
1397 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1398 "cmova{q}\t{$src2, $dst|$dst, $src2}",
1399 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1400 X86_COND_A, EFLAGS))]>, TB;
1401 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
1402 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1403 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
1404 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1405 X86_COND_L, EFLAGS))]>, TB;
1406 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
1407 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1408 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
1409 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1410 X86_COND_GE, EFLAGS))]>, TB;
1411 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
1412 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1413 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
1414 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1415 X86_COND_LE, EFLAGS))]>, TB;
1416 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
1417 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1418 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
1419 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1420 X86_COND_G, EFLAGS))]>, TB;
1421 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1422 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1423 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
1424 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1425 X86_COND_S, EFLAGS))]>, TB;
1426 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1427 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1428 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
1429 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1430 X86_COND_NS, EFLAGS))]>, TB;
1431 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1432 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1433 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
1434 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1435 X86_COND_P, EFLAGS))]>, TB;
1436 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1437 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1438 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
1439 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1440 X86_COND_NP, EFLAGS))]>, TB;
1441 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1442 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1443 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
1444 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1445 X86_COND_O, EFLAGS))]>, TB;
1446 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1447 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1448 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
1449 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1450 X86_COND_NO, EFLAGS))]>, TB;
1451 } // isCommutable = 1
1453 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1454 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1455 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
1456 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1457 X86_COND_B, EFLAGS))]>, TB;
1458 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1459 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1460 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
1461 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1462 X86_COND_AE, EFLAGS))]>, TB;
1463 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1464 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1465 "cmove{q}\t{$src2, $dst|$dst, $src2}",
1466 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1467 X86_COND_E, EFLAGS))]>, TB;
1468 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1469 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1470 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
1471 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1472 X86_COND_NE, EFLAGS))]>, TB;
1473 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1474 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1475 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
1476 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1477 X86_COND_BE, EFLAGS))]>, TB;
1478 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1479 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1480 "cmova{q}\t{$src2, $dst|$dst, $src2}",
1481 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1482 X86_COND_A, EFLAGS))]>, TB;
1483 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1484 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1485 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
1486 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1487 X86_COND_L, EFLAGS))]>, TB;
1488 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1489 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1490 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
1491 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1492 X86_COND_GE, EFLAGS))]>, TB;
1493 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1494 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1495 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
1496 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1497 X86_COND_LE, EFLAGS))]>, TB;
1498 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1499 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1500 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
1501 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1502 X86_COND_G, EFLAGS))]>, TB;
1503 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1504 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1505 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
1506 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1507 X86_COND_S, EFLAGS))]>, TB;
1508 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1509 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1510 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
1511 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1512 X86_COND_NS, EFLAGS))]>, TB;
1513 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1514 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1515 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
1516 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1517 X86_COND_P, EFLAGS))]>, TB;
1518 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1519 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1520 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
1521 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1522 X86_COND_NP, EFLAGS))]>, TB;
1523 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1524 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1525 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
1526 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1527 X86_COND_O, EFLAGS))]>, TB;
1528 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1529 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1530 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
1531 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1532 X86_COND_NO, EFLAGS))]>, TB;
1533 } // Constraints = "$src1 = $dst"
1535 // Use sbb to materialize carry flag into a GPR.
1536 // FIXME: This are pseudo ops that should be replaced with Pat<> patterns.
1537 // However, Pat<> can't replicate the destination reg into the inputs of the
1539 // FIXME: Change this to have encoding Pseudo when X86MCCodeEmitter replaces
1541 let Defs = [EFLAGS], Uses = [EFLAGS], isCodeGenOnly = 1 in
1542 def SETB_C64r : RI<0x19, MRMInitReg, (outs GR64:$dst), (ins), "",
1543 [(set GR64:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
1545 def : Pat<(i64 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
1548 //===----------------------------------------------------------------------===//
1549 // Descriptor-table support instructions
1551 // LLDT is not interpreted specially in 64-bit mode because there is no sign
1553 def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
1554 "sldt{q}\t$dst", []>, TB;
1555 def SLDT64m : RI<0x00, MRM0m, (outs i16mem:$dst), (ins),
1556 "sldt{q}\t$dst", []>, TB;
1558 //===----------------------------------------------------------------------===//
1559 // Alias Instructions
1560 //===----------------------------------------------------------------------===//
1562 // We want to rewrite MOV64r0 in terms of MOV32r0, because it's sometimes a
1563 // smaller encoding, but doing so at isel time interferes with rematerialization
1564 // in the current register allocator. For now, this is rewritten when the
1565 // instruction is lowered to an MCInst.
1566 // FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
1567 // when we have a better way to specify isel priority.
1568 let Defs = [EFLAGS],
1569 AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1570 def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins), "",
1571 [(set GR64:$dst, 0)]>;
1573 // Materialize i64 constant where top 32-bits are zero. This could theoretically
1574 // use MOV32ri with a SUBREG_TO_REG to represent the zero-extension, however
1575 // that would make it more difficult to rematerialize.
1576 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1577 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1578 "", [(set GR64:$dst, i64immZExt32:$src)]>;
1580 //===----------------------------------------------------------------------===//
1581 // Thread Local Storage Instructions
1582 //===----------------------------------------------------------------------===//
1585 // All calls clobber the non-callee saved registers. RSP is marked as
1586 // a use to prevent stack-pointer assignments that appear immediately
1587 // before calls from potentially appearing dead.
1588 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1589 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1590 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1591 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1592 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1594 def TLS_addr64 : I<0, Pseudo, (outs), (ins i64mem:$sym),
1596 "leaq\t$sym(%rip), %rdi; "
1599 "call\t__tls_get_addr@PLT",
1600 [(X86tlsaddr tls64addr:$sym)]>,
1601 Requires<[In64BitMode]>;
1603 // Darwin TLS Support
1604 // For x86_64, the address of the thunk is passed in %rdi, on return
1605 // the address of the variable is in %rax. All other registers are preserved.
1608 usesCustomInserter = 1 in
1609 def TLSCall_64 : I<0, Pseudo, (outs), (ins i64mem:$sym),
1611 [(X86TLSCall addr:$sym)]>,
1612 Requires<[In64BitMode]>;
1614 let AddedComplexity = 5, isCodeGenOnly = 1 in
1615 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1616 "movq\t%gs:$src, $dst",
1617 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1619 let AddedComplexity = 5, isCodeGenOnly = 1 in
1620 def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1621 "movq\t%fs:$src, $dst",
1622 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1624 //===----------------------------------------------------------------------===//
1625 // Atomic Instructions
1626 //===----------------------------------------------------------------------===//
1628 // TODO: Get this to fold the constant into the instruction.
1629 let hasSideEffects = 1, Defs = [ESP] in
1630 def Int_MemBarrierNoSSE64 : RI<0x09, MRM1r, (outs), (ins GR64:$zero),
1632 "or{q}\t{$zero, (%rsp)|(%rsp), $zero}",
1633 [(X86MemBarrierNoSSE GR64:$zero)]>,
1634 Requires<[In64BitMode]>, LOCK;
1636 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1637 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1639 "cmpxchgq\t$swap,$ptr",
1640 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1643 let Constraints = "$val = $dst" in {
1644 let Defs = [EFLAGS] in
1645 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins GR64:$val,i64mem:$ptr),
1648 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1651 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst),
1652 (ins GR64:$val,i64mem:$ptr),
1653 "xchg{q}\t{$val, $ptr|$ptr, $val}",
1654 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1656 def XCHG64rr : RI<0x87, MRMSrcReg, (outs GR64:$dst), (ins GR64:$val,GR64:$src),
1657 "xchg{q}\t{$val, $src|$src, $val}", []>;
1660 def XADD64rr : RI<0xC1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1661 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1662 let mayLoad = 1, mayStore = 1 in
1663 def XADD64rm : RI<0xC1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1664 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1666 def CMPXCHG64rr : RI<0xB1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1667 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1668 let mayLoad = 1, mayStore = 1 in
1669 def CMPXCHG64rm : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1670 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1672 let Defs = [RAX, RDX, EFLAGS], Uses = [RAX, RBX, RCX, RDX] in
1673 def CMPXCHG16B : RI<0xC7, MRM1m, (outs), (ins i128mem:$dst),
1674 "cmpxchg16b\t$dst", []>, TB;
1676 def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src),
1677 "xchg{q}\t{$src, %rax|%rax, $src}", []>;
1679 // Optimized codegen when the non-memory output is not used.
1680 let Defs = [EFLAGS], mayLoad = 1, mayStore = 1 in {
1681 // FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1682 def LOCK_ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1684 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1685 def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1686 (ins i64mem:$dst, i64i8imm :$src2),
1688 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1689 def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1690 (ins i64mem:$dst, i64i32imm :$src2),
1692 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1693 def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1695 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1696 def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1697 (ins i64mem:$dst, i64i8imm :$src2),
1699 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1700 def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1701 (ins i64mem:$dst, i64i32imm:$src2),
1703 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1704 def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1706 "inc{q}\t$dst", []>, LOCK;
1707 def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1709 "dec{q}\t$dst", []>, LOCK;
1711 // Atomic exchange, and, or, xor
1712 let Constraints = "$val = $dst", Defs = [EFLAGS],
1713 usesCustomInserter = 1 in {
1714 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1715 "#ATOMAND64 PSEUDO!",
1716 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1717 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1718 "#ATOMOR64 PSEUDO!",
1719 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1720 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1721 "#ATOMXOR64 PSEUDO!",
1722 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1723 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1724 "#ATOMNAND64 PSEUDO!",
1725 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1726 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1727 "#ATOMMIN64 PSEUDO!",
1728 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1729 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1730 "#ATOMMAX64 PSEUDO!",
1731 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1732 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1733 "#ATOMUMIN64 PSEUDO!",
1734 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1735 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1736 "#ATOMUMAX64 PSEUDO!",
1737 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1740 // Segmentation support instructions
1742 // i16mem operand in LAR64rm and GR32 operand in LAR32rr is not a typo.
1743 def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
1744 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1745 def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
1746 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1748 def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1749 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1750 def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
1751 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1753 def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", []>, TB;
1755 def PUSHFS64 : I<0xa0, RawFrm, (outs), (ins),
1756 "push{q}\t%fs", []>, TB;
1757 def PUSHGS64 : I<0xa8, RawFrm, (outs), (ins),
1758 "push{q}\t%gs", []>, TB;
1760 def POPFS64 : I<0xa1, RawFrm, (outs), (ins),
1761 "pop{q}\t%fs", []>, TB;
1762 def POPGS64 : I<0xa9, RawFrm, (outs), (ins),
1763 "pop{q}\t%gs", []>, TB;
1765 def LSS64rm : RI<0xb2, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1766 "lss{q}\t{$src, $dst|$dst, $src}", []>, TB;
1767 def LFS64rm : RI<0xb4, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1768 "lfs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1769 def LGS64rm : RI<0xb5, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1770 "lgs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1772 // Specialized register support
1774 // no m form encodable; use SMSW16m
1775 def SMSW64r : RI<0x01, MRM4r, (outs GR64:$dst), (ins),
1776 "smsw{q}\t$dst", []>, TB;
1778 // String manipulation instructions
1780 def LODSQ : RI<0xAD, RawFrm, (outs), (ins), "lodsq", []>;
1782 //===----------------------------------------------------------------------===//
1783 // Non-Instruction Patterns
1784 //===----------------------------------------------------------------------===//
1786 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1787 // code model mode, should use 'movabs'. FIXME: This is really a hack, the
1788 // 'movabs' predicate should handle this sort of thing.
1789 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1790 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
1791 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1792 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
1793 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1794 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
1795 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1796 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
1797 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1798 (MOV64ri tblockaddress:$dst)>, Requires<[FarData]>;
1800 // In static codegen with small code model, we can get the address of a label
1801 // into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1802 // the MOV64ri64i32 should accept these.
1803 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1804 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1805 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1806 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1807 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1808 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1809 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1810 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1811 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1812 (MOV64ri64i32 tblockaddress:$dst)>, Requires<[SmallCode]>;
1814 // In kernel code model, we can get the address of a label
1815 // into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1816 // the MOV64ri32 should accept these.
1817 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1818 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1819 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1820 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1821 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1822 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1823 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1824 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
1825 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1826 (MOV64ri32 tblockaddress:$dst)>, Requires<[KernelCode]>;
1828 // If we have small model and -static mode, it is safe to store global addresses
1829 // directly as immediates. FIXME: This is really a hack, the 'imm' predicate
1830 // for MOV64mi32 should handle this sort of thing.
1831 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1832 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1833 Requires<[NearData, IsStatic]>;
1834 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1835 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1836 Requires<[NearData, IsStatic]>;
1837 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1838 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1839 Requires<[NearData, IsStatic]>;
1840 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1841 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1842 Requires<[NearData, IsStatic]>;
1843 def : Pat<(store (i64 (X86Wrapper tblockaddress:$src)), addr:$dst),
1844 (MOV64mi32 addr:$dst, tblockaddress:$src)>,
1845 Requires<[NearData, IsStatic]>;
1848 // Direct PC relative function call for small code model. 32-bit displacement
1849 // sign extended to 64-bit.
1850 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1851 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
1852 def : Pat<(X86call (i64 texternalsym:$dst)),
1853 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1855 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1856 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1857 def : Pat<(X86call (i64 texternalsym:$dst)),
1858 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
1861 def : Pat<(X86tcret GR64_TC:$dst, imm:$off),
1862 (TCRETURNri64 GR64_TC:$dst, imm:$off)>,
1863 Requires<[In64BitMode]>;
1865 def : Pat<(X86tcret (load addr:$dst), imm:$off),
1866 (TCRETURNmi64 addr:$dst, imm:$off)>,
1867 Requires<[In64BitMode]>;
1869 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1870 (TCRETURNdi64 tglobaladdr:$dst, imm:$off)>,
1871 Requires<[In64BitMode]>;
1873 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1874 (TCRETURNdi64 texternalsym:$dst, imm:$off)>,
1875 Requires<[In64BitMode]>;
1877 // tls has some funny stuff here...
1878 // This corresponds to movabs $foo@tpoff, %rax
1879 def : Pat<(i64 (X86Wrapper tglobaltlsaddr :$dst)),
1880 (MOV64ri tglobaltlsaddr :$dst)>;
1881 // This corresponds to add $foo@tpoff, %rax
1882 def : Pat<(add GR64:$src1, (X86Wrapper tglobaltlsaddr :$dst)),
1883 (ADD64ri32 GR64:$src1, tglobaltlsaddr :$dst)>;
1884 // This corresponds to mov foo@tpoff(%rbx), %eax
1885 def : Pat<(load (i64 (X86Wrapper tglobaltlsaddr :$dst))),
1886 (MOV64rm tglobaltlsaddr :$dst)>;
1890 // TEST R,R is smaller than CMP R,0
1891 def : Pat<(X86cmp GR64:$src1, 0),
1892 (TEST64rr GR64:$src1, GR64:$src1)>;
1894 // Conditional moves with folded loads with operands swapped and conditions
1896 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1897 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1898 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1899 (CMOVB64rm GR64:$src2, addr:$src1)>;
1900 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1901 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1902 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1903 (CMOVE64rm GR64:$src2, addr:$src1)>;
1904 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1905 (CMOVA64rm GR64:$src2, addr:$src1)>;
1906 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1907 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1908 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1909 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1910 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1911 (CMOVL64rm GR64:$src2, addr:$src1)>;
1912 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1913 (CMOVG64rm GR64:$src2, addr:$src1)>;
1914 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1915 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1916 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1917 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1918 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1919 (CMOVP64rm GR64:$src2, addr:$src1)>;
1920 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1921 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1922 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1923 (CMOVS64rm GR64:$src2, addr:$src1)>;
1924 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1925 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1926 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1927 (CMOVO64rm GR64:$src2, addr:$src1)>;
1929 // zextload bool -> zextload byte
1930 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1933 // When extloading from 16-bit and smaller memory locations into 64-bit
1934 // registers, use zero-extending loads so that the entire 64-bit register is
1935 // defined, avoiding partial-register updates.
1936 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1937 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1938 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1939 // For other extloads, use subregs, since the high contents of the register are
1940 // defined after an extload.
1941 def : Pat<(extloadi64i32 addr:$src),
1942 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
1945 // anyext. Define these to do an explicit zero-extend to
1946 // avoid partial-register updates.
1947 def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1948 def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1949 def : Pat<(i64 (anyext GR32:$src)),
1950 (SUBREG_TO_REG (i64 0), GR32:$src, sub_32bit)>;
1952 //===----------------------------------------------------------------------===//
1954 //===----------------------------------------------------------------------===//
1956 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1957 // +128 doesn't, so in this special case use a sub instead of an add.
1958 def : Pat<(add GR64:$src1, 128),
1959 (SUB64ri8 GR64:$src1, -128)>;
1960 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1961 (SUB64mi8 addr:$dst, -128)>;
1963 // The same trick applies for 32-bit immediate fields in 64-bit
1965 def : Pat<(add GR64:$src1, 0x0000000080000000),
1966 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1967 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1968 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1970 // Use a 32-bit and with implicit zero-extension instead of a 64-bit and if it
1971 // has an immediate with at least 32 bits of leading zeros, to avoid needing to
1972 // materialize that immediate in a register first.
1973 def : Pat<(and GR64:$src, i64immZExt32:$imm),
1977 (EXTRACT_SUBREG GR64:$src, sub_32bit),
1978 (i32 (GetLo32XForm imm:$imm))),
1981 // r & (2^32-1) ==> movz
1982 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1983 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, sub_32bit))>;
1984 // r & (2^16-1) ==> movz
1985 def : Pat<(and GR64:$src, 0xffff),
1986 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, sub_16bit)))>;
1987 // r & (2^8-1) ==> movz
1988 def : Pat<(and GR64:$src, 0xff),
1989 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, sub_8bit)))>;
1990 // r & (2^8-1) ==> movz
1991 def : Pat<(and GR32:$src1, 0xff),
1992 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, sub_8bit))>,
1993 Requires<[In64BitMode]>;
1994 // r & (2^8-1) ==> movz
1995 def : Pat<(and GR16:$src1, 0xff),
1996 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, sub_8bit)))>,
1997 Requires<[In64BitMode]>;
1999 // sext_inreg patterns
2000 def : Pat<(sext_inreg GR64:$src, i32),
2001 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, sub_32bit))>;
2002 def : Pat<(sext_inreg GR64:$src, i16),
2003 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, sub_16bit))>;
2004 def : Pat<(sext_inreg GR64:$src, i8),
2005 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, sub_8bit))>;
2006 def : Pat<(sext_inreg GR32:$src, i8),
2007 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, sub_8bit))>,
2008 Requires<[In64BitMode]>;
2009 def : Pat<(sext_inreg GR16:$src, i8),
2010 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, sub_8bit)))>,
2011 Requires<[In64BitMode]>;
2014 def : Pat<(i32 (trunc GR64:$src)),
2015 (EXTRACT_SUBREG GR64:$src, sub_32bit)>;
2016 def : Pat<(i16 (trunc GR64:$src)),
2017 (EXTRACT_SUBREG GR64:$src, sub_16bit)>;
2018 def : Pat<(i8 (trunc GR64:$src)),
2019 (EXTRACT_SUBREG GR64:$src, sub_8bit)>;
2020 def : Pat<(i8 (trunc GR32:$src)),
2021 (EXTRACT_SUBREG GR32:$src, sub_8bit)>,
2022 Requires<[In64BitMode]>;
2023 def : Pat<(i8 (trunc GR16:$src)),
2024 (EXTRACT_SUBREG GR16:$src, sub_8bit)>,
2025 Requires<[In64BitMode]>;
2027 // h-register tricks.
2028 // For now, be conservative on x86-64 and use an h-register extract only if the
2029 // value is immediately zero-extended or stored, which are somewhat common
2030 // cases. This uses a bunch of code to prevent a register requiring a REX prefix
2031 // from being allocated in the same instruction as the h register, as there's
2032 // currently no way to describe this requirement to the register allocator.
2034 // h-register extract and zero-extend.
2035 def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
2039 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
2042 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
2044 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
2046 Requires<[In64BitMode]>;
2047 def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)),
2048 (MOVZX32_NOREXrr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src,
2051 Requires<[In64BitMode]>;
2052 def : Pat<(srl GR16:$src, (i8 8)),
2055 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2058 Requires<[In64BitMode]>;
2059 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
2061 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2063 Requires<[In64BitMode]>;
2064 def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
2066 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2068 Requires<[In64BitMode]>;
2069 def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
2073 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2076 def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
2080 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2084 // h-register extract and store.
2085 def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
2088 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
2090 def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
2093 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
2095 Requires<[In64BitMode]>;
2096 def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
2099 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2101 Requires<[In64BitMode]>;
2103 // (shl x, 1) ==> (add x, x)
2104 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
2106 // (shl x (and y, 63)) ==> (shl x, y)
2107 def : Pat<(shl GR64:$src1, (and CL, 63)),
2108 (SHL64rCL GR64:$src1)>;
2109 def : Pat<(store (shl (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2110 (SHL64mCL addr:$dst)>;
2112 def : Pat<(srl GR64:$src1, (and CL, 63)),
2113 (SHR64rCL GR64:$src1)>;
2114 def : Pat<(store (srl (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2115 (SHR64mCL addr:$dst)>;
2117 def : Pat<(sra GR64:$src1, (and CL, 63)),
2118 (SAR64rCL GR64:$src1)>;
2119 def : Pat<(store (sra (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2120 (SAR64mCL addr:$dst)>;
2122 // (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
2123 let AddedComplexity = 5 in { // Try this before the selecting to OR
2124 def : Pat<(or_is_add GR64:$src1, i64immSExt8:$src2),
2125 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2126 def : Pat<(or_is_add GR64:$src1, i64immSExt32:$src2),
2127 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
2128 def : Pat<(or_is_add GR64:$src1, GR64:$src2),
2129 (ADD64rr GR64:$src1, GR64:$src2)>;
2130 } // AddedComplexity
2132 // X86 specific add which produces a flag.
2133 def : Pat<(addc GR64:$src1, GR64:$src2),
2134 (ADD64rr GR64:$src1, GR64:$src2)>;
2135 def : Pat<(addc GR64:$src1, (load addr:$src2)),
2136 (ADD64rm GR64:$src1, addr:$src2)>;
2137 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
2138 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2139 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
2140 (ADD64ri32 GR64:$src1, imm:$src2)>;
2142 def : Pat<(subc GR64:$src1, GR64:$src2),
2143 (SUB64rr GR64:$src1, GR64:$src2)>;
2144 def : Pat<(subc GR64:$src1, (load addr:$src2)),
2145 (SUB64rm GR64:$src1, addr:$src2)>;
2146 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
2147 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
2148 def : Pat<(subc GR64:$src1, imm:$src2),
2149 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
2151 //===----------------------------------------------------------------------===//
2152 // EFLAGS-defining Patterns
2153 //===----------------------------------------------------------------------===//
2156 def : Pat<(add GR64:$src1, GR64:$src2),
2157 (ADD64rr GR64:$src1, GR64:$src2)>;
2158 def : Pat<(add GR64:$src1, i64immSExt8:$src2),
2159 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2160 def : Pat<(add GR64:$src1, i64immSExt32:$src2),
2161 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
2162 def : Pat<(add GR64:$src1, (loadi64 addr:$src2)),
2163 (ADD64rm GR64:$src1, addr:$src2)>;
2166 def : Pat<(sub GR64:$src1, GR64:$src2),
2167 (SUB64rr GR64:$src1, GR64:$src2)>;
2168 def : Pat<(sub GR64:$src1, (loadi64 addr:$src2)),
2169 (SUB64rm GR64:$src1, addr:$src2)>;
2170 def : Pat<(sub GR64:$src1, i64immSExt8:$src2),
2171 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
2172 def : Pat<(sub GR64:$src1, i64immSExt32:$src2),
2173 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
2176 def : Pat<(mul GR64:$src1, GR64:$src2),
2177 (IMUL64rr GR64:$src1, GR64:$src2)>;
2178 def : Pat<(mul GR64:$src1, (loadi64 addr:$src2)),
2179 (IMUL64rm GR64:$src1, addr:$src2)>;
2180 def : Pat<(mul GR64:$src1, i64immSExt8:$src2),
2181 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
2182 def : Pat<(mul GR64:$src1, i64immSExt32:$src2),
2183 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
2184 def : Pat<(mul (loadi64 addr:$src1), i64immSExt8:$src2),
2185 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
2186 def : Pat<(mul (loadi64 addr:$src1), i64immSExt32:$src2),
2187 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
2190 def : Pat<(add GR16:$src, 1), (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2191 def : Pat<(add GR16:$src, -1), (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2192 def : Pat<(add GR32:$src, 1), (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2193 def : Pat<(add GR32:$src, -1), (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2194 def : Pat<(add GR64:$src, 1), (INC64r GR64:$src)>;
2195 def : Pat<(add GR64:$src, -1), (DEC64r GR64:$src)>;
2198 def : Pat<(or GR64:$src1, GR64:$src2),
2199 (OR64rr GR64:$src1, GR64:$src2)>;
2200 def : Pat<(or GR64:$src1, i64immSExt8:$src2),
2201 (OR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2202 def : Pat<(or GR64:$src1, i64immSExt32:$src2),
2203 (OR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2204 def : Pat<(or GR64:$src1, (loadi64 addr:$src2)),
2205 (OR64rm GR64:$src1, addr:$src2)>;
2208 def : Pat<(xor GR64:$src1, GR64:$src2),
2209 (XOR64rr GR64:$src1, GR64:$src2)>;
2210 def : Pat<(xor GR64:$src1, i64immSExt8:$src2),
2211 (XOR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2212 def : Pat<(xor GR64:$src1, i64immSExt32:$src2),
2213 (XOR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2214 def : Pat<(xor GR64:$src1, (loadi64 addr:$src2)),
2215 (XOR64rm GR64:$src1, addr:$src2)>;
2218 def : Pat<(and GR64:$src1, GR64:$src2),
2219 (AND64rr GR64:$src1, GR64:$src2)>;
2220 def : Pat<(and GR64:$src1, i64immSExt8:$src2),
2221 (AND64ri8 GR64:$src1, i64immSExt8:$src2)>;
2222 def : Pat<(and GR64:$src1, i64immSExt32:$src2),
2223 (AND64ri32 GR64:$src1, i64immSExt32:$src2)>;
2224 def : Pat<(and GR64:$src1, (loadi64 addr:$src2)),
2225 (AND64rm GR64:$src1, addr:$src2)>;
2227 //===----------------------------------------------------------------------===//
2228 // X86-64 SSE Instructions
2229 //===----------------------------------------------------------------------===//
2231 // Move instructions...
2233 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2234 "mov{d|q}\t{$src, $dst|$dst, $src}",
2236 (v2i64 (scalar_to_vector GR64:$src)))]>;
2237 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
2238 "mov{d|q}\t{$src, $dst|$dst, $src}",
2239 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2242 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
2243 "mov{d|q}\t{$src, $dst|$dst, $src}",
2244 [(set FR64:$dst, (bitconvert GR64:$src))]>;
2245 def MOV64toSDrm : S3SI<0x7E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
2246 "movq\t{$src, $dst|$dst, $src}",
2247 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2249 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
2250 "mov{d|q}\t{$src, $dst|$dst, $src}",
2251 [(set GR64:$dst, (bitconvert FR64:$src))]>;
2252 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
2253 "movq\t{$src, $dst|$dst, $src}",
2254 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;