1 //====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the X86-64 instruction set, defining the instructions,
11 // and properties of the instructions which are needed for code generation,
12 // machine code emission, and analysis.
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
17 // Operand Definitions.
20 // 64-bits but only 32 bits are significant.
21 def i64i32imm : Operand<i64>;
23 // 64-bits but only 32 bits are significant, and those bits are treated as being
25 def i64i32imm_pcrel : Operand<i64> {
26 let PrintMethod = "print_pcrel_imm";
27 let ParserMatchClass = X86AbsMemAsmOperand;
31 // 64-bits but only 8 bits are significant.
32 def i64i8imm : Operand<i64> {
33 let ParserMatchClass = ImmSExt8AsmOperand;
36 // Special i64mem for addresses of load folding tail calls. These are not
37 // allowed to use callee-saved registers since they must be scheduled
38 // after callee-saved register are popped.
39 def i64mem_TC : Operand<i64> {
40 let PrintMethod = "printi64mem";
41 let MIOperandInfo = (ops GR64_TC, i8imm, GR64_TC, i32imm, i8imm);
42 let ParserMatchClass = X86MemAsmOperand;
45 def lea64mem : Operand<i64> {
46 let PrintMethod = "printlea64mem";
47 let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i32imm);
48 let ParserMatchClass = X86NoSegMemAsmOperand;
51 def lea64_32mem : Operand<i32> {
52 let PrintMethod = "printlea64_32mem";
53 let AsmOperandLowerMethod = "lower_lea64_32mem";
54 let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm);
55 let ParserMatchClass = X86NoSegMemAsmOperand;
58 //===----------------------------------------------------------------------===//
59 // Complex Pattern Definitions.
61 def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
62 [add, sub, mul, X86mul_imm, shl, or, frameindex,
65 def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
66 [tglobaltlsaddr], []>;
68 //===----------------------------------------------------------------------===//
72 def i64immSExt8 : PatLeaf<(i64 immSext8)>;
74 def GetLo32XForm : SDNodeXForm<imm, [{
75 // Transformation function: get the low 32 bits.
76 return getI32Imm((unsigned)N->getZExtValue());
79 def i64immSExt32 : PatLeaf<(i64 imm), [{
80 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
81 // sign extended field.
82 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
86 def i64immZExt32 : PatLeaf<(i64 imm), [{
87 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
88 // unsignedsign extended field.
89 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
92 def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
93 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
94 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
96 def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
97 def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
98 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
99 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
101 def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
102 def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
103 def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
104 def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
106 //===----------------------------------------------------------------------===//
107 // Instruction list...
110 // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
111 // a stack adjustment and the codegen must know that they may modify the stack
112 // pointer before prolog-epilog rewriting occurs.
113 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
114 // sub / add which can clobber EFLAGS.
115 let Defs = [RSP, EFLAGS], Uses = [RSP] in {
116 def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
118 [(X86callseq_start timm:$amt)]>,
119 Requires<[In64BitMode]>;
120 def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
122 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
123 Requires<[In64BitMode]>;
126 // Interrupt Instructions
127 def IRET64 : RI<0xcf, RawFrm, (outs), (ins), "iret{q}", []>;
129 //===----------------------------------------------------------------------===//
130 // Call Instructions...
133 // All calls clobber the non-callee saved registers. RSP is marked as
134 // a use to prevent stack-pointer assignments that appear immediately
135 // before calls from potentially appearing dead. Uses for argument
136 // registers are added manually.
137 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
138 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
139 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
140 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
141 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
144 // NOTE: this pattern doesn't match "X86call imm", because we do not know
145 // that the offset between an arbitrary immediate and the call will fit in
146 // the 32-bit pcrel field that we have.
147 def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
148 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
149 "call{q}\t$dst", []>,
150 Requires<[In64BitMode, NotWin64]>;
151 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
152 "call{q}\t{*}$dst", [(X86call GR64:$dst)]>,
153 Requires<[NotWin64]>;
154 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
155 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
156 Requires<[NotWin64]>;
158 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
159 "lcall{q}\t{*}$dst", []>;
162 // FIXME: We need to teach codegen about single list of call-clobbered
165 // All calls clobber the non-callee saved registers. RSP is marked as
166 // a use to prevent stack-pointer assignments that appear immediately
167 // before calls from potentially appearing dead. Uses for argument
168 // registers are added manually.
169 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
170 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
171 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
172 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
174 def WINCALL64pcrel32 : I<0xE8, RawFrm,
175 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
178 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
180 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
181 def WINCALL64m : I<0xFF, MRM2m, (outs),
182 (ins i64mem:$dst, variable_ops), "call\t{*}$dst",
183 [(X86call (loadi64 addr:$dst))]>,
188 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
189 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
190 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
191 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
192 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
193 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
195 def TCRETURNdi64 : I<0, Pseudo, (outs),
196 (ins i64i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
197 "#TC_RETURN $dst $offset", []>;
198 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64_TC:$dst, i32imm:$offset,
200 "#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", []>;
211 def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst, variable_ops),
212 "jmp{q}\t{*}$dst # TAILCALL", []>;
216 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
217 def JMP64pcrel32 : I<0xE9, RawFrm, (outs), (ins brtarget:$dst),
219 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
220 [(brind GR64:$dst)]>;
221 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
222 [(brind (loadi64 addr:$dst))]>;
223 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
224 "ljmp{q}\t{*}$dst", []>;
227 //===----------------------------------------------------------------------===//
228 // EH Pseudo Instructions
230 let isTerminator = 1, isReturn = 1, isBarrier = 1,
231 hasCtrlDep = 1, isCodeGenOnly = 1 in {
232 def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
233 "ret\t#eh_return, addr: $addr",
234 [(X86ehret GR64:$addr)]>;
238 //===----------------------------------------------------------------------===//
239 // Miscellaneous Instructions...
242 def POPCNT64rr : RI<0xB8, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
243 "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
244 def POPCNT64rm : RI<0xB8, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
245 "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
247 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
248 def LEAVE64 : I<0xC9, RawFrm,
249 (outs), (ins), "leave", []>;
250 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
252 def POP64r : I<0x58, AddRegFrm,
253 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
254 def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
255 def POP64rmm: I<0x8F, MRM0m, (outs i64mem:$dst), (ins), "pop{q}\t$dst", []>;
257 let mayStore = 1 in {
258 def PUSH64r : I<0x50, AddRegFrm,
259 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
260 def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
261 def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", []>;
265 let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
266 def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
267 "push{q}\t$imm", []>;
268 def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
269 "push{q}\t$imm", []>;
270 def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
271 "push{q}\t$imm", []>;
274 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
275 def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf{q}", []>, REX_W;
276 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
277 def PUSHFQ64 : I<0x9C, RawFrm, (outs), (ins), "pushf{q}", []>;
279 def LEA64_32r : I<0x8D, MRMSrcMem,
280 (outs GR32:$dst), (ins lea64_32mem:$src),
281 "lea{l}\t{$src|$dst}, {$dst|$src}",
282 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
284 let isReMaterializable = 1 in
285 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
286 "lea{q}\t{$src|$dst}, {$dst|$src}",
287 [(set GR64:$dst, lea64addr:$src)]>;
289 let isTwoAddress = 1 in
290 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
292 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
294 // Bit scan instructions.
295 let Defs = [EFLAGS] in {
296 def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
297 "bsf{q}\t{$src, $dst|$dst, $src}",
298 [(set GR64:$dst, EFLAGS, (X86bsf GR64:$src))]>, TB;
299 def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
300 "bsf{q}\t{$src, $dst|$dst, $src}",
301 [(set GR64:$dst, EFLAGS, (X86bsf (loadi64 addr:$src)))]>, TB;
303 def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
304 "bsr{q}\t{$src, $dst|$dst, $src}",
305 [(set GR64:$dst, EFLAGS, (X86bsr GR64:$src))]>, TB;
306 def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
307 "bsr{q}\t{$src, $dst|$dst, $src}",
308 [(set GR64:$dst, EFLAGS, (X86bsr (loadi64 addr:$src)))]>, TB;
312 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI], isCodeGenOnly = 1 in
313 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
314 [(X86rep_movs i64)]>, REP;
315 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI], isCodeGenOnly = 1 in
316 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
317 [(X86rep_stos i64)]>, REP;
319 let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in
320 def MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "movsq", []>;
322 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI,EFLAGS] in
323 def STOSQ : RI<0xAB, RawFrm, (outs), (ins), "stosq", []>;
325 def SCAS64 : RI<0xAF, RawFrm, (outs), (ins), "scasq", []>;
327 def CMPS64 : RI<0xA7, RawFrm, (outs), (ins), "cmpsq", []>;
329 // Fast system-call instructions
330 def SYSEXIT64 : RI<0x35, RawFrm,
331 (outs), (ins), "sysexit", []>, TB;
333 //===----------------------------------------------------------------------===//
334 // Move Instructions...
337 let neverHasSideEffects = 1 in
338 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
339 "mov{q}\t{$src, $dst|$dst, $src}", []>;
341 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
342 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
343 "movabs{q}\t{$src, $dst|$dst, $src}",
344 [(set GR64:$dst, imm:$src)]>;
345 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
346 "mov{q}\t{$src, $dst|$dst, $src}",
347 [(set GR64:$dst, i64immSExt32:$src)]>;
350 def MOV64rr_REV : RI<0x8B, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
351 "mov{q}\t{$src, $dst|$dst, $src}", []>;
353 let canFoldAsLoad = 1, isReMaterializable = 1 in
354 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
355 "mov{q}\t{$src, $dst|$dst, $src}",
356 [(set GR64:$dst, (load addr:$src))]>;
358 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
359 "mov{q}\t{$src, $dst|$dst, $src}",
360 [(store GR64:$src, addr:$dst)]>;
361 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
362 "mov{q}\t{$src, $dst|$dst, $src}",
363 [(store i64immSExt32:$src, addr:$dst)]>;
365 /// Versions of MOV64rr, MOV64rm, and MOV64mr for i64mem_TC and GR64_TC.
366 let neverHasSideEffects = 1 in
367 def MOV64rr_TC : RI<0x89, MRMDestReg, (outs GR64_TC:$dst), (ins GR64_TC:$src),
368 "mov{q}\t{$src, $dst|$dst, $src}", []>;
371 canFoldAsLoad = 1, isReMaterializable = 1 in
372 def MOV64rm_TC : RI<0x8B, MRMSrcMem, (outs GR64_TC:$dst), (ins i64mem_TC:$src),
373 "mov{q}\t{$src, $dst|$dst, $src}",
377 def MOV64mr_TC : RI<0x89, MRMDestMem, (outs), (ins i64mem_TC:$dst, GR64_TC:$src),
378 "mov{q}\t{$src, $dst|$dst, $src}",
381 def MOV64o8a : RIi8<0xA0, RawFrm, (outs), (ins offset8:$src),
382 "mov{q}\t{$src, %rax|%rax, $src}", []>;
383 def MOV64o64a : RIi32<0xA1, RawFrm, (outs), (ins offset64:$src),
384 "mov{q}\t{$src, %rax|%rax, $src}", []>;
385 def MOV64ao8 : RIi8<0xA2, RawFrm, (outs offset8:$dst), (ins),
386 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
387 def MOV64ao64 : RIi32<0xA3, RawFrm, (outs offset64:$dst), (ins),
388 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
390 // Moves to and from segment registers
391 def MOV64rs : RI<0x8C, MRMDestReg, (outs GR64:$dst), (ins SEGMENT_REG:$src),
392 "mov{q}\t{$src, $dst|$dst, $src}", []>;
393 def MOV64ms : RI<0x8C, MRMDestMem, (outs i64mem:$dst), (ins SEGMENT_REG:$src),
394 "mov{q}\t{$src, $dst|$dst, $src}", []>;
395 def MOV64sr : RI<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR64:$src),
396 "mov{q}\t{$src, $dst|$dst, $src}", []>;
397 def MOV64sm : RI<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i64mem:$src),
398 "mov{q}\t{$src, $dst|$dst, $src}", []>;
400 // Moves to and from debug registers
401 def MOV64rd : I<0x21, MRMDestReg, (outs GR64:$dst), (ins DEBUG_REG:$src),
402 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
403 def MOV64dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR64:$src),
404 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
406 // Moves to and from control registers
407 def MOV64rc : I<0x20, MRMDestReg, (outs GR64:$dst), (ins CONTROL_REG:$src),
408 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
409 def MOV64cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR64:$src),
410 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
412 // Sign/Zero extenders
414 // MOVSX64rr8 always has a REX prefix and it has an 8-bit register
415 // operand, which makes it a rare instruction with an 8-bit register
416 // operand that can never access an h register. If support for h registers
417 // were generalized, this would require a special register class.
418 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
419 "movs{bq|x}\t{$src, $dst|$dst, $src}",
420 [(set GR64:$dst, (sext GR8:$src))]>, TB;
421 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
422 "movs{bq|x}\t{$src, $dst|$dst, $src}",
423 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
424 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
425 "movs{wq|x}\t{$src, $dst|$dst, $src}",
426 [(set GR64:$dst, (sext GR16:$src))]>, TB;
427 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
428 "movs{wq|x}\t{$src, $dst|$dst, $src}",
429 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
430 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
431 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
432 [(set GR64:$dst, (sext GR32:$src))]>;
433 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
434 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
435 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
437 // movzbq and movzwq encodings for the disassembler
438 def MOVZX64rr8_Q : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8:$src),
439 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
440 def MOVZX64rm8_Q : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem:$src),
441 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
442 def MOVZX64rr16_Q : RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
443 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
444 def MOVZX64rm16_Q : RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
445 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
447 // Use movzbl instead of movzbq when the destination is a register; it's
448 // equivalent due to implicit zero-extending, and it has a smaller encoding.
449 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
450 "", [(set GR64:$dst, (zext GR8:$src))]>, TB;
451 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
452 "", [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
453 // Use movzwl instead of movzwq when the destination is a register; it's
454 // equivalent due to implicit zero-extending, and it has a smaller encoding.
455 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
456 "", [(set GR64:$dst, (zext GR16:$src))]>, TB;
457 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
458 "", [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
460 // There's no movzlq instruction, but movl can be used for this purpose, using
461 // implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
462 // extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
463 // zero-extension, however this isn't possible when the 32-bit value is
464 // defined by a truncate or is copied from something where the high bits aren't
465 // necessarily all zero. In such cases, we fall back to these explicit zext
467 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
468 "", [(set GR64:$dst, (zext GR32:$src))]>;
469 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
470 "", [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
472 // Any instruction that defines a 32-bit result leaves the high half of the
473 // register. Truncate can be lowered to EXTRACT_SUBREG. CopyFromReg may
474 // be copying from a truncate. And x86's cmov doesn't do anything if the
475 // condition is false. But any other 32-bit operation will zero-extend
477 def def32 : PatLeaf<(i32 GR32:$src), [{
478 return N->getOpcode() != ISD::TRUNCATE &&
479 N->getOpcode() != TargetOpcode::EXTRACT_SUBREG &&
480 N->getOpcode() != ISD::CopyFromReg &&
481 N->getOpcode() != X86ISD::CMOV;
484 // In the case of a 32-bit def that is known to implicitly zero-extend,
485 // we can use a SUBREG_TO_REG.
486 def : Pat<(i64 (zext def32:$src)),
487 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
489 let neverHasSideEffects = 1 in {
490 let Defs = [RAX], Uses = [EAX] in
491 def CDQE : RI<0x98, RawFrm, (outs), (ins),
492 "{cltq|cdqe}", []>; // RAX = signext(EAX)
494 let Defs = [RAX,RDX], Uses = [RAX] in
495 def CQO : RI<0x99, RawFrm, (outs), (ins),
496 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
499 //===----------------------------------------------------------------------===//
500 // Arithmetic Instructions...
503 let Defs = [EFLAGS] in {
505 def ADD64i32 : RIi32<0x05, RawFrm, (outs), (ins i32imm:$src),
506 "add{q}\t{$src, %rax|%rax, $src}", []>;
508 let isTwoAddress = 1 in {
509 let isConvertibleToThreeAddress = 1 in {
510 let isCommutable = 1 in
511 // Register-Register Addition
512 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst),
513 (ins GR64:$src1, GR64:$src2),
514 "add{q}\t{$src2, $dst|$dst, $src2}",
515 [(set GR64:$dst, EFLAGS,
516 (X86add_flag GR64:$src1, GR64:$src2))]>;
518 // These are alternate spellings for use by the disassembler, we mark them as
519 // code gen only to ensure they aren't matched by the assembler.
520 let isCodeGenOnly = 1 in {
521 def ADD64rr_alt : RI<0x03, MRMSrcReg, (outs GR64:$dst),
522 (ins GR64:$src1, GR64:$src2),
523 "add{l}\t{$src2, $dst|$dst, $src2}", []>;
526 // Register-Integer Addition
527 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst),
528 (ins GR64:$src1, i64i8imm:$src2),
529 "add{q}\t{$src2, $dst|$dst, $src2}",
530 [(set GR64:$dst, EFLAGS,
531 (X86add_flag GR64:$src1, i64immSExt8:$src2))]>;
532 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst),
533 (ins GR64:$src1, i64i32imm:$src2),
534 "add{q}\t{$src2, $dst|$dst, $src2}",
535 [(set GR64:$dst, EFLAGS,
536 (X86add_flag GR64:$src1, i64immSExt32:$src2))]>;
537 } // isConvertibleToThreeAddress
539 // Register-Memory Addition
540 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst),
541 (ins GR64:$src1, i64mem:$src2),
542 "add{q}\t{$src2, $dst|$dst, $src2}",
543 [(set GR64:$dst, EFLAGS,
544 (X86add_flag GR64:$src1, (load addr:$src2)))]>;
548 // Memory-Register Addition
549 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
550 "add{q}\t{$src2, $dst|$dst, $src2}",
551 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
553 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
554 "add{q}\t{$src2, $dst|$dst, $src2}",
555 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
557 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
558 "add{q}\t{$src2, $dst|$dst, $src2}",
559 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
562 let Uses = [EFLAGS] in {
564 def ADC64i32 : RIi32<0x15, RawFrm, (outs), (ins i32imm:$src),
565 "adc{q}\t{$src, %rax|%rax, $src}", []>;
567 let isTwoAddress = 1 in {
568 let isCommutable = 1 in
569 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst),
570 (ins GR64:$src1, GR64:$src2),
571 "adc{q}\t{$src2, $dst|$dst, $src2}",
572 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
574 def ADC64rr_REV : RI<0x13, MRMSrcReg , (outs GR32:$dst),
575 (ins GR64:$src1, GR64:$src2),
576 "adc{q}\t{$src2, $dst|$dst, $src2}", []>;
578 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst),
579 (ins GR64:$src1, i64mem:$src2),
580 "adc{q}\t{$src2, $dst|$dst, $src2}",
581 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
583 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst),
584 (ins GR64:$src1, i64i8imm:$src2),
585 "adc{q}\t{$src2, $dst|$dst, $src2}",
586 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
587 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst),
588 (ins GR64:$src1, i64i32imm:$src2),
589 "adc{q}\t{$src2, $dst|$dst, $src2}",
590 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
593 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
594 "adc{q}\t{$src2, $dst|$dst, $src2}",
595 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
596 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
597 "adc{q}\t{$src2, $dst|$dst, $src2}",
598 [(store (adde (load addr:$dst), i64immSExt8:$src2),
600 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
601 "adc{q}\t{$src2, $dst|$dst, $src2}",
602 [(store (adde (load addr:$dst), i64immSExt32:$src2),
606 let isTwoAddress = 1 in {
607 // Register-Register Subtraction
608 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst),
609 (ins GR64:$src1, GR64:$src2),
610 "sub{q}\t{$src2, $dst|$dst, $src2}",
611 [(set GR64:$dst, EFLAGS,
612 (X86sub_flag GR64:$src1, GR64:$src2))]>;
614 def SUB64rr_REV : RI<0x2B, MRMSrcReg, (outs GR64:$dst),
615 (ins GR64:$src1, GR64:$src2),
616 "sub{q}\t{$src2, $dst|$dst, $src2}", []>;
618 // Register-Memory Subtraction
619 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst),
620 (ins GR64:$src1, i64mem:$src2),
621 "sub{q}\t{$src2, $dst|$dst, $src2}",
622 [(set GR64:$dst, EFLAGS,
623 (X86sub_flag GR64:$src1, (load addr:$src2)))]>;
625 // Register-Integer Subtraction
626 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
627 (ins GR64:$src1, i64i8imm:$src2),
628 "sub{q}\t{$src2, $dst|$dst, $src2}",
629 [(set GR64:$dst, EFLAGS,
630 (X86sub_flag GR64:$src1, i64immSExt8:$src2))]>;
631 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
632 (ins GR64:$src1, i64i32imm:$src2),
633 "sub{q}\t{$src2, $dst|$dst, $src2}",
634 [(set GR64:$dst, EFLAGS,
635 (X86sub_flag GR64:$src1, i64immSExt32:$src2))]>;
638 def SUB64i32 : RIi32<0x2D, RawFrm, (outs), (ins i32imm:$src),
639 "sub{q}\t{$src, %rax|%rax, $src}", []>;
641 // Memory-Register Subtraction
642 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
643 "sub{q}\t{$src2, $dst|$dst, $src2}",
644 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
647 // Memory-Integer Subtraction
648 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
649 "sub{q}\t{$src2, $dst|$dst, $src2}",
650 [(store (sub (load addr:$dst), i64immSExt8:$src2),
653 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
654 "sub{q}\t{$src2, $dst|$dst, $src2}",
655 [(store (sub (load addr:$dst), i64immSExt32:$src2),
659 let Uses = [EFLAGS] in {
660 let isTwoAddress = 1 in {
661 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst),
662 (ins GR64:$src1, GR64:$src2),
663 "sbb{q}\t{$src2, $dst|$dst, $src2}",
664 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
666 def SBB64rr_REV : RI<0x1B, MRMSrcReg, (outs GR64:$dst),
667 (ins GR64:$src1, GR64:$src2),
668 "sbb{q}\t{$src2, $dst|$dst, $src2}", []>;
670 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst),
671 (ins GR64:$src1, i64mem:$src2),
672 "sbb{q}\t{$src2, $dst|$dst, $src2}",
673 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
675 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst),
676 (ins GR64:$src1, i64i8imm:$src2),
677 "sbb{q}\t{$src2, $dst|$dst, $src2}",
678 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
679 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst),
680 (ins GR64:$src1, i64i32imm:$src2),
681 "sbb{q}\t{$src2, $dst|$dst, $src2}",
682 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
685 def SBB64i32 : RIi32<0x1D, RawFrm, (outs), (ins i32imm:$src),
686 "sbb{q}\t{$src, %rax|%rax, $src}", []>;
688 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
689 "sbb{q}\t{$src2, $dst|$dst, $src2}",
690 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
691 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
692 "sbb{q}\t{$src2, $dst|$dst, $src2}",
693 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
694 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
695 "sbb{q}\t{$src2, $dst|$dst, $src2}",
696 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
700 // Unsigned multiplication
701 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
702 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
703 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
705 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
706 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
708 // Signed multiplication
709 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
710 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
712 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
713 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
716 let Defs = [EFLAGS] in {
717 let isTwoAddress = 1 in {
718 let isCommutable = 1 in
719 // Register-Register Signed Integer Multiplication
720 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
721 (ins GR64:$src1, GR64:$src2),
722 "imul{q}\t{$src2, $dst|$dst, $src2}",
723 [(set GR64:$dst, EFLAGS,
724 (X86smul_flag GR64:$src1, GR64:$src2))]>, TB;
726 // Register-Memory Signed Integer Multiplication
727 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
728 (ins GR64:$src1, i64mem:$src2),
729 "imul{q}\t{$src2, $dst|$dst, $src2}",
730 [(set GR64:$dst, EFLAGS,
731 (X86smul_flag GR64:$src1, (load addr:$src2)))]>, TB;
734 // Suprisingly enough, these are not two address instructions!
736 // Register-Integer Signed Integer Multiplication
737 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
738 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
739 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
740 [(set GR64:$dst, EFLAGS,
741 (X86smul_flag GR64:$src1, i64immSExt8:$src2))]>;
742 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
743 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
744 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
745 [(set GR64:$dst, EFLAGS,
746 (X86smul_flag GR64:$src1, i64immSExt32:$src2))]>;
748 // Memory-Integer Signed Integer Multiplication
749 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
750 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
751 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
752 [(set GR64:$dst, EFLAGS,
753 (X86smul_flag (load addr:$src1),
754 i64immSExt8:$src2))]>;
755 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
756 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
757 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
758 [(set GR64:$dst, EFLAGS,
759 (X86smul_flag (load addr:$src1),
760 i64immSExt32:$src2))]>;
763 // Unsigned division / remainder
764 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
765 // RDX:RAX/r64 = RAX,RDX
766 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src),
768 // Signed division / remainder
769 // RDX:RAX/r64 = RAX,RDX
770 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src),
771 "idiv{q}\t$src", []>;
773 // RDX:RAX/[mem64] = RAX,RDX
774 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src),
776 // RDX:RAX/[mem64] = RAX,RDX
777 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src),
778 "idiv{q}\t$src", []>;
782 // Unary instructions
783 let Defs = [EFLAGS], CodeSize = 2 in {
784 let isTwoAddress = 1 in
785 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
786 [(set GR64:$dst, (ineg GR64:$src)),
788 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
789 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
792 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
793 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
794 [(set GR64:$dst, EFLAGS, (X86inc_flag GR64:$src))]>;
795 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
796 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
799 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
800 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
801 [(set GR64:$dst, EFLAGS, (X86dec_flag GR64:$src))]>;
802 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
803 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
806 // In 64-bit mode, single byte INC and DEC cannot be encoded.
807 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
808 // Can transform into LEA.
809 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src),
811 [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src))]>,
812 OpSize, Requires<[In64BitMode]>;
813 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src),
815 [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src))]>,
816 Requires<[In64BitMode]>;
817 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src),
819 [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src))]>,
820 OpSize, Requires<[In64BitMode]>;
821 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src),
823 [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src))]>,
824 Requires<[In64BitMode]>;
825 } // isConvertibleToThreeAddress
827 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
828 // how to unfold them.
829 let isTwoAddress = 0, CodeSize = 2 in {
830 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
831 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
833 OpSize, Requires<[In64BitMode]>;
834 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
835 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
837 Requires<[In64BitMode]>;
838 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
839 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
841 OpSize, Requires<[In64BitMode]>;
842 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
843 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
845 Requires<[In64BitMode]>;
847 } // Defs = [EFLAGS], CodeSize
850 let Defs = [EFLAGS] in {
851 // Shift instructions
852 let isTwoAddress = 1 in {
854 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
855 "shl{q}\t{%cl, $dst|$dst, %CL}",
856 [(set GR64:$dst, (shl GR64:$src, CL))]>;
857 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
858 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst),
859 (ins GR64:$src1, i8imm:$src2),
860 "shl{q}\t{$src2, $dst|$dst, $src2}",
861 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
862 // NOTE: We don't include patterns for shifts of a register by one, because
863 // 'add reg,reg' is cheaper.
864 def SHL64r1 : RI<0xD1, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
869 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
870 "shl{q}\t{%cl, $dst|$dst, %CL}",
871 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
872 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
873 "shl{q}\t{$src, $dst|$dst, $src}",
874 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
875 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
877 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
879 let isTwoAddress = 1 in {
881 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
882 "shr{q}\t{%cl, $dst|$dst, %CL}",
883 [(set GR64:$dst, (srl GR64:$src, CL))]>;
884 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
885 "shr{q}\t{$src2, $dst|$dst, $src2}",
886 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
887 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
889 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
893 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
894 "shr{q}\t{%cl, $dst|$dst, %CL}",
895 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
896 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
897 "shr{q}\t{$src, $dst|$dst, $src}",
898 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
899 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
901 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
903 let isTwoAddress = 1 in {
905 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
906 "sar{q}\t{%cl, $dst|$dst, %CL}",
907 [(set GR64:$dst, (sra GR64:$src, CL))]>;
908 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst),
909 (ins GR64:$src1, i8imm:$src2),
910 "sar{q}\t{$src2, $dst|$dst, $src2}",
911 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
912 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
914 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
918 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
919 "sar{q}\t{%cl, $dst|$dst, %CL}",
920 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
921 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
922 "sar{q}\t{$src, $dst|$dst, $src}",
923 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
924 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
926 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
928 // Rotate instructions
930 let isTwoAddress = 1 in {
931 def RCL64r1 : RI<0xD1, MRM2r, (outs GR64:$dst), (ins GR64:$src),
932 "rcl{q}\t{1, $dst|$dst, 1}", []>;
933 def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
934 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
936 def RCR64r1 : RI<0xD1, MRM3r, (outs GR64:$dst), (ins GR64:$src),
937 "rcr{q}\t{1, $dst|$dst, 1}", []>;
938 def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
939 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
942 def RCL64rCL : RI<0xD3, MRM2r, (outs GR64:$dst), (ins GR64:$src),
943 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
944 def RCR64rCL : RI<0xD3, MRM3r, (outs GR64:$dst), (ins GR64:$src),
945 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
949 let isTwoAddress = 0 in {
950 def RCL64m1 : RI<0xD1, MRM2m, (outs), (ins i64mem:$dst),
951 "rcl{q}\t{1, $dst|$dst, 1}", []>;
952 def RCL64mi : RIi8<0xC1, MRM2m, (outs), (ins i64mem:$dst, i8imm:$cnt),
953 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
954 def RCR64m1 : RI<0xD1, MRM3m, (outs), (ins i64mem:$dst),
955 "rcr{q}\t{1, $dst|$dst, 1}", []>;
956 def RCR64mi : RIi8<0xC1, MRM3m, (outs), (ins i64mem:$dst, i8imm:$cnt),
957 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
960 def RCL64mCL : RI<0xD3, MRM2m, (outs), (ins i64mem:$dst),
961 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
962 def RCR64mCL : RI<0xD3, MRM3m, (outs), (ins i64mem:$dst),
963 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
967 let isTwoAddress = 1 in {
969 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
970 "rol{q}\t{%cl, $dst|$dst, %CL}",
971 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
972 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst),
973 (ins GR64:$src1, i8imm:$src2),
974 "rol{q}\t{$src2, $dst|$dst, $src2}",
975 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
976 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
978 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
982 def ROL64mCL : RI<0xD3, MRM0m, (outs), (ins i64mem:$dst),
983 "rol{q}\t{%cl, $dst|$dst, %CL}",
984 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
985 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
986 "rol{q}\t{$src, $dst|$dst, $src}",
987 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
988 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
990 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
992 let isTwoAddress = 1 in {
994 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
995 "ror{q}\t{%cl, $dst|$dst, %CL}",
996 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
997 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst),
998 (ins GR64:$src1, i8imm:$src2),
999 "ror{q}\t{$src2, $dst|$dst, $src2}",
1000 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
1001 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
1003 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
1007 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
1008 "ror{q}\t{%cl, $dst|$dst, %CL}",
1009 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
1010 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
1011 "ror{q}\t{$src, $dst|$dst, $src}",
1012 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1013 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
1015 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
1017 // Double shift instructions (generalizations of rotate)
1018 let isTwoAddress = 1 in {
1019 let Uses = [CL] in {
1020 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst),
1021 (ins GR64:$src1, GR64:$src2),
1022 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1023 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>,
1025 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst),
1026 (ins GR64:$src1, GR64:$src2),
1027 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1028 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>,
1032 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
1033 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
1035 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
1036 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1037 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
1040 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
1042 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
1043 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1044 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
1050 let Uses = [CL] in {
1051 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1052 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1053 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
1055 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1056 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1057 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
1060 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
1061 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
1062 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1063 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
1064 (i8 imm:$src3)), addr:$dst)]>,
1066 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
1067 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
1068 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1069 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
1070 (i8 imm:$src3)), addr:$dst)]>,
1072 } // Defs = [EFLAGS]
1074 //===----------------------------------------------------------------------===//
1075 // Logical Instructions...
1078 let isTwoAddress = 1 , AddedComplexity = 15 in
1079 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
1080 [(set GR64:$dst, (not GR64:$src))]>;
1081 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
1082 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
1084 let Defs = [EFLAGS] in {
1085 def AND64i32 : RIi32<0x25, RawFrm, (outs), (ins i32imm:$src),
1086 "and{q}\t{$src, %rax|%rax, $src}", []>;
1088 let isTwoAddress = 1 in {
1089 let isCommutable = 1 in
1090 def AND64rr : RI<0x21, MRMDestReg,
1091 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1092 "and{q}\t{$src2, $dst|$dst, $src2}",
1093 [(set GR64:$dst, EFLAGS,
1094 (X86and_flag GR64:$src1, GR64:$src2))]>;
1095 def AND64rr_REV : RI<0x23, MRMSrcReg, (outs GR64:$dst),
1096 (ins GR64:$src1, GR64:$src2),
1097 "and{q}\t{$src2, $dst|$dst, $src2}", []>;
1098 def AND64rm : RI<0x23, MRMSrcMem,
1099 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1100 "and{q}\t{$src2, $dst|$dst, $src2}",
1101 [(set GR64:$dst, EFLAGS,
1102 (X86and_flag GR64:$src1, (load addr:$src2)))]>;
1103 def AND64ri8 : RIi8<0x83, MRM4r,
1104 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
1105 "and{q}\t{$src2, $dst|$dst, $src2}",
1106 [(set GR64:$dst, EFLAGS,
1107 (X86and_flag GR64:$src1, i64immSExt8:$src2))]>;
1108 def AND64ri32 : RIi32<0x81, MRM4r,
1109 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1110 "and{q}\t{$src2, $dst|$dst, $src2}",
1111 [(set GR64:$dst, EFLAGS,
1112 (X86and_flag GR64:$src1, i64immSExt32:$src2))]>;
1115 def AND64mr : RI<0x21, MRMDestMem,
1116 (outs), (ins i64mem:$dst, GR64:$src),
1117 "and{q}\t{$src, $dst|$dst, $src}",
1118 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
1119 (implicit EFLAGS)]>;
1120 def AND64mi8 : RIi8<0x83, MRM4m,
1121 (outs), (ins i64mem:$dst, i64i8imm :$src),
1122 "and{q}\t{$src, $dst|$dst, $src}",
1123 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
1124 (implicit EFLAGS)]>;
1125 def AND64mi32 : RIi32<0x81, MRM4m,
1126 (outs), (ins i64mem:$dst, i64i32imm:$src),
1127 "and{q}\t{$src, $dst|$dst, $src}",
1128 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1129 (implicit EFLAGS)]>;
1131 let isTwoAddress = 1 in {
1132 let isCommutable = 1 in
1133 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst),
1134 (ins GR64:$src1, GR64:$src2),
1135 "or{q}\t{$src2, $dst|$dst, $src2}",
1136 [(set GR64:$dst, EFLAGS,
1137 (X86or_flag GR64:$src1, GR64:$src2))]>;
1138 def OR64rr_REV : RI<0x0B, MRMSrcReg, (outs GR64:$dst),
1139 (ins GR64:$src1, GR64:$src2),
1140 "or{q}\t{$src2, $dst|$dst, $src2}", []>;
1141 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst),
1142 (ins GR64:$src1, i64mem:$src2),
1143 "or{q}\t{$src2, $dst|$dst, $src2}",
1144 [(set GR64:$dst, EFLAGS,
1145 (X86or_flag GR64:$src1, (load addr:$src2)))]>;
1146 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst),
1147 (ins GR64:$src1, i64i8imm:$src2),
1148 "or{q}\t{$src2, $dst|$dst, $src2}",
1149 [(set GR64:$dst, EFLAGS,
1150 (X86or_flag GR64:$src1, i64immSExt8:$src2))]>;
1151 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst),
1152 (ins GR64:$src1, i64i32imm:$src2),
1153 "or{q}\t{$src2, $dst|$dst, $src2}",
1154 [(set GR64:$dst, EFLAGS,
1155 (X86or_flag GR64:$src1, i64immSExt32:$src2))]>;
1158 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1159 "or{q}\t{$src, $dst|$dst, $src}",
1160 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
1161 (implicit EFLAGS)]>;
1162 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
1163 "or{q}\t{$src, $dst|$dst, $src}",
1164 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
1165 (implicit EFLAGS)]>;
1166 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1167 "or{q}\t{$src, $dst|$dst, $src}",
1168 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1169 (implicit EFLAGS)]>;
1171 def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i32imm:$src),
1172 "or{q}\t{$src, %rax|%rax, $src}", []>;
1174 let isTwoAddress = 1 in {
1175 let isCommutable = 1 in
1176 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst),
1177 (ins GR64:$src1, GR64:$src2),
1178 "xor{q}\t{$src2, $dst|$dst, $src2}",
1179 [(set GR64:$dst, EFLAGS,
1180 (X86xor_flag GR64:$src1, GR64:$src2))]>;
1181 def XOR64rr_REV : RI<0x33, MRMSrcReg, (outs GR64:$dst),
1182 (ins GR64:$src1, GR64:$src2),
1183 "xor{q}\t{$src2, $dst|$dst, $src2}", []>;
1184 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst),
1185 (ins GR64:$src1, i64mem:$src2),
1186 "xor{q}\t{$src2, $dst|$dst, $src2}",
1187 [(set GR64:$dst, EFLAGS,
1188 (X86xor_flag GR64:$src1, (load addr:$src2)))]>;
1189 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst),
1190 (ins GR64:$src1, i64i8imm:$src2),
1191 "xor{q}\t{$src2, $dst|$dst, $src2}",
1192 [(set GR64:$dst, EFLAGS,
1193 (X86xor_flag GR64:$src1, i64immSExt8:$src2))]>;
1194 def XOR64ri32 : RIi32<0x81, MRM6r,
1195 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1196 "xor{q}\t{$src2, $dst|$dst, $src2}",
1197 [(set GR64:$dst, EFLAGS,
1198 (X86xor_flag GR64:$src1, i64immSExt32:$src2))]>;
1201 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1202 "xor{q}\t{$src, $dst|$dst, $src}",
1203 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1204 (implicit EFLAGS)]>;
1205 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
1206 "xor{q}\t{$src, $dst|$dst, $src}",
1207 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1208 (implicit EFLAGS)]>;
1209 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1210 "xor{q}\t{$src, $dst|$dst, $src}",
1211 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1212 (implicit EFLAGS)]>;
1214 def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i32imm:$src),
1215 "xor{q}\t{$src, %rax|%rax, $src}", []>;
1217 } // Defs = [EFLAGS]
1219 //===----------------------------------------------------------------------===//
1220 // Comparison Instructions...
1223 // Integer comparison
1224 let Defs = [EFLAGS] in {
1225 def TEST64i32 : RIi32<0xa9, RawFrm, (outs), (ins i32imm:$src),
1226 "test{q}\t{$src, %rax|%rax, $src}", []>;
1227 let isCommutable = 1 in
1228 def TEST64rr : RI<0x85, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1229 "test{q}\t{$src2, $src1|$src1, $src2}",
1230 [(set EFLAGS, (X86cmp (and GR64:$src1, GR64:$src2), 0))]>;
1231 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1232 "test{q}\t{$src2, $src1|$src1, $src2}",
1233 [(set EFLAGS, (X86cmp (and GR64:$src1, (loadi64 addr:$src2)),
1235 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1236 (ins GR64:$src1, i64i32imm:$src2),
1237 "test{q}\t{$src2, $src1|$src1, $src2}",
1238 [(set EFLAGS, (X86cmp (and GR64:$src1, i64immSExt32:$src2),
1240 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1241 (ins i64mem:$src1, i64i32imm:$src2),
1242 "test{q}\t{$src2, $src1|$src1, $src2}",
1243 [(set EFLAGS, (X86cmp (and (loadi64 addr:$src1),
1244 i64immSExt32:$src2), 0))]>;
1247 def CMP64i32 : RIi32<0x3D, RawFrm, (outs), (ins i32imm:$src),
1248 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
1249 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1250 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1251 [(set EFLAGS, (X86cmp GR64:$src1, GR64:$src2))]>;
1253 // These are alternate spellings for use by the disassembler, we mark them as
1254 // code gen only to ensure they aren't matched by the assembler.
1255 let isCodeGenOnly = 1 in {
1256 def CMP64mrmrr : RI<0x3B, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1257 "cmp{q}\t{$src2, $src1|$src1, $src2}", []>;
1260 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1261 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1262 [(set EFLAGS, (X86cmp (loadi64 addr:$src1), GR64:$src2))]>;
1263 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1264 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1265 [(set EFLAGS, (X86cmp GR64:$src1, (loadi64 addr:$src2)))]>;
1266 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1267 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1268 [(set EFLAGS, (X86cmp GR64:$src1, i64immSExt8:$src2))]>;
1269 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
1270 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1271 [(set EFLAGS, (X86cmp GR64:$src1, i64immSExt32:$src2))]>;
1272 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1273 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1274 [(set EFLAGS, (X86cmp (loadi64 addr:$src1),
1275 i64immSExt8:$src2))]>;
1276 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1277 (ins i64mem:$src1, i64i32imm:$src2),
1278 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1279 [(set EFLAGS, (X86cmp (loadi64 addr:$src1),
1280 i64immSExt32:$src2))]>;
1281 } // Defs = [EFLAGS]
1284 // TODO: BTC, BTR, and BTS
1285 let Defs = [EFLAGS] in {
1286 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1287 "bt{q}\t{$src2, $src1|$src1, $src2}",
1288 [(set EFLAGS, (X86bt GR64:$src1, GR64:$src2))]>, TB;
1290 // Unlike with the register+register form, the memory+register form of the
1291 // bt instruction does not ignore the high bits of the index. From ISel's
1292 // perspective, this is pretty bizarre. Disable these instructions for now.
1293 def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1294 "bt{q}\t{$src2, $src1|$src1, $src2}",
1295 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
1296 // (implicit EFLAGS)]
1300 def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1301 "bt{q}\t{$src2, $src1|$src1, $src2}",
1302 [(set EFLAGS, (X86bt GR64:$src1, i64immSExt8:$src2))]>, TB;
1303 // Note that these instructions don't need FastBTMem because that
1304 // only applies when the other operand is in a register. When it's
1305 // an immediate, bt is still fast.
1306 def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1307 "bt{q}\t{$src2, $src1|$src1, $src2}",
1308 [(set EFLAGS, (X86bt (loadi64 addr:$src1),
1309 i64immSExt8:$src2))]>, TB;
1311 def BTC64rr : RI<0xBB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1312 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1313 def BTC64mr : RI<0xBB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1314 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1315 def BTC64ri8 : RIi8<0xBA, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1316 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1317 def BTC64mi8 : RIi8<0xBA, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1318 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1320 def BTR64rr : RI<0xB3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1321 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1322 def BTR64mr : RI<0xB3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1323 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1324 def BTR64ri8 : RIi8<0xBA, MRM6r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1325 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1326 def BTR64mi8 : RIi8<0xBA, MRM6m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1327 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1329 def BTS64rr : RI<0xAB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1330 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1331 def BTS64mr : RI<0xAB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1332 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1333 def BTS64ri8 : RIi8<0xBA, MRM5r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1334 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1335 def BTS64mi8 : RIi8<0xBA, MRM5m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1336 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1337 } // Defs = [EFLAGS]
1339 // Conditional moves
1340 let Uses = [EFLAGS], isTwoAddress = 1 in {
1341 let isCommutable = 1 in {
1342 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
1343 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1344 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
1345 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1346 X86_COND_B, EFLAGS))]>, TB;
1347 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
1348 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1349 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
1350 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1351 X86_COND_AE, EFLAGS))]>, TB;
1352 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
1353 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1354 "cmove{q}\t{$src2, $dst|$dst, $src2}",
1355 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1356 X86_COND_E, EFLAGS))]>, TB;
1357 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
1358 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1359 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
1360 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1361 X86_COND_NE, EFLAGS))]>, TB;
1362 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
1363 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1364 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
1365 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1366 X86_COND_BE, EFLAGS))]>, TB;
1367 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
1368 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1369 "cmova{q}\t{$src2, $dst|$dst, $src2}",
1370 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1371 X86_COND_A, EFLAGS))]>, TB;
1372 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
1373 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1374 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
1375 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1376 X86_COND_L, EFLAGS))]>, TB;
1377 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
1378 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1379 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
1380 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1381 X86_COND_GE, EFLAGS))]>, TB;
1382 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
1383 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1384 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
1385 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1386 X86_COND_LE, EFLAGS))]>, TB;
1387 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
1388 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1389 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
1390 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1391 X86_COND_G, EFLAGS))]>, TB;
1392 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1393 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1394 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
1395 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1396 X86_COND_S, EFLAGS))]>, TB;
1397 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1398 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1399 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
1400 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1401 X86_COND_NS, EFLAGS))]>, TB;
1402 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1403 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1404 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
1405 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1406 X86_COND_P, EFLAGS))]>, TB;
1407 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1408 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1409 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
1410 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1411 X86_COND_NP, EFLAGS))]>, TB;
1412 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1413 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1414 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
1415 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1416 X86_COND_O, EFLAGS))]>, TB;
1417 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1418 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1419 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
1420 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1421 X86_COND_NO, EFLAGS))]>, TB;
1422 } // isCommutable = 1
1424 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1425 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1426 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
1427 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1428 X86_COND_B, EFLAGS))]>, TB;
1429 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1430 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1431 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
1432 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1433 X86_COND_AE, EFLAGS))]>, TB;
1434 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1435 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1436 "cmove{q}\t{$src2, $dst|$dst, $src2}",
1437 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1438 X86_COND_E, EFLAGS))]>, TB;
1439 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1440 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1441 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
1442 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1443 X86_COND_NE, EFLAGS))]>, TB;
1444 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1445 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1446 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
1447 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1448 X86_COND_BE, EFLAGS))]>, TB;
1449 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1450 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1451 "cmova{q}\t{$src2, $dst|$dst, $src2}",
1452 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1453 X86_COND_A, EFLAGS))]>, TB;
1454 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1455 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1456 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
1457 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1458 X86_COND_L, EFLAGS))]>, TB;
1459 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1460 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1461 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
1462 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1463 X86_COND_GE, EFLAGS))]>, TB;
1464 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1465 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1466 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
1467 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1468 X86_COND_LE, EFLAGS))]>, TB;
1469 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1470 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1471 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
1472 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1473 X86_COND_G, EFLAGS))]>, TB;
1474 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1475 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1476 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
1477 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1478 X86_COND_S, EFLAGS))]>, TB;
1479 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1480 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1481 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
1482 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1483 X86_COND_NS, EFLAGS))]>, TB;
1484 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1485 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1486 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
1487 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1488 X86_COND_P, EFLAGS))]>, TB;
1489 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1490 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1491 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
1492 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1493 X86_COND_NP, EFLAGS))]>, TB;
1494 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1495 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1496 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
1497 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1498 X86_COND_O, EFLAGS))]>, TB;
1499 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1500 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1501 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
1502 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1503 X86_COND_NO, EFLAGS))]>, TB;
1506 // Use sbb to materialize carry flag into a GPR.
1507 // FIXME: This are pseudo ops that should be replaced with Pat<> patterns.
1508 // However, Pat<> can't replicate the destination reg into the inputs of the
1510 // FIXME: Change this to have encoding Pseudo when X86MCCodeEmitter replaces
1512 let Defs = [EFLAGS], Uses = [EFLAGS], isCodeGenOnly = 1 in
1513 def SETB_C64r : RI<0x19, MRMInitReg, (outs GR64:$dst), (ins), "",
1514 [(set GR64:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
1516 def : Pat<(i64 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
1519 //===----------------------------------------------------------------------===//
1520 // Conversion Instructions...
1523 // f64 -> signed i64
1524 def CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1525 "cvtsd2si{q}\t{$src, $dst|$dst, $src}", []>;
1526 def CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1527 "cvtsd2si{q}\t{$src, $dst|$dst, $src}", []>;
1528 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1529 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1531 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1532 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst),
1534 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1535 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1536 (load addr:$src)))]>;
1537 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1538 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1539 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1540 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1541 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1542 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1543 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1544 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1546 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1547 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst),
1549 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1551 (int_x86_sse2_cvttsd2si64
1552 (load addr:$src)))]>;
1554 // Signed i64 -> f64
1555 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1556 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1557 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1558 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1559 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1560 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1562 let isTwoAddress = 1 in {
1563 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1564 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1565 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1567 (int_x86_sse2_cvtsi642sd VR128:$src1,
1569 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1570 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1571 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1573 (int_x86_sse2_cvtsi642sd VR128:$src1,
1574 (loadi64 addr:$src2)))]>;
1577 // Signed i64 -> f32
1578 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1579 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1580 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1581 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1582 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1583 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1585 let isTwoAddress = 1 in {
1586 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1587 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1588 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1590 (int_x86_sse_cvtsi642ss VR128:$src1,
1592 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1594 (ins VR128:$src1, i64mem:$src2),
1595 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1597 (int_x86_sse_cvtsi642ss VR128:$src1,
1598 (loadi64 addr:$src2)))]>;
1601 // f32 -> signed i64
1602 def CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1603 "cvtss2si{q}\t{$src, $dst|$dst, $src}", []>;
1604 def CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1605 "cvtss2si{q}\t{$src, $dst|$dst, $src}", []>;
1606 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1607 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1609 (int_x86_sse_cvtss2si64 VR128:$src))]>;
1610 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1611 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1612 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1613 (load addr:$src)))]>;
1614 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1615 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1616 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1617 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1618 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1619 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1620 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1621 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1623 (int_x86_sse_cvttss2si64 VR128:$src))]>;
1624 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst),
1626 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1628 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1630 // Descriptor-table support instructions
1632 // LLDT is not interpreted specially in 64-bit mode because there is no sign
1634 def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
1635 "sldt{q}\t$dst", []>, TB;
1636 def SLDT64m : RI<0x00, MRM0m, (outs i16mem:$dst), (ins),
1637 "sldt{q}\t$dst", []>, TB;
1639 //===----------------------------------------------------------------------===//
1640 // Alias Instructions
1641 //===----------------------------------------------------------------------===//
1643 // We want to rewrite MOV64r0 in terms of MOV32r0, because it's sometimes a
1644 // smaller encoding, but doing so at isel time interferes with rematerialization
1645 // in the current register allocator. For now, this is rewritten when the
1646 // instruction is lowered to an MCInst.
1647 // FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
1648 // when we have a better way to specify isel priority.
1649 let Defs = [EFLAGS],
1650 AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1651 def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins), "",
1652 [(set GR64:$dst, 0)]>;
1654 // Materialize i64 constant where top 32-bits are zero. This could theoretically
1655 // use MOV32ri with a SUBREG_TO_REG to represent the zero-extension, however
1656 // that would make it more difficult to rematerialize.
1657 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1658 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1659 "", [(set GR64:$dst, i64immZExt32:$src)]>;
1661 //===----------------------------------------------------------------------===//
1662 // Thread Local Storage Instructions
1663 //===----------------------------------------------------------------------===//
1665 // All calls clobber the non-callee saved registers. RSP is marked as
1666 // a use to prevent stack-pointer assignments that appear immediately
1667 // before calls from potentially appearing dead.
1668 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1669 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1670 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1671 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1672 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1674 def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
1676 "leaq\t$sym(%rip), %rdi; "
1679 "call\t__tls_get_addr@PLT",
1680 [(X86tlsaddr tls64addr:$sym)]>,
1681 Requires<[In64BitMode]>;
1683 let AddedComplexity = 5, isCodeGenOnly = 1 in
1684 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1685 "movq\t%gs:$src, $dst",
1686 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1688 let AddedComplexity = 5, isCodeGenOnly = 1 in
1689 def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1690 "movq\t%fs:$src, $dst",
1691 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1693 //===----------------------------------------------------------------------===//
1694 // Atomic Instructions
1695 //===----------------------------------------------------------------------===//
1697 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1698 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1700 "cmpxchgq\t$swap,$ptr",
1701 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1704 let Constraints = "$val = $dst" in {
1705 let Defs = [EFLAGS] in
1706 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins GR64:$val,i64mem:$ptr),
1709 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1712 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst),
1713 (ins GR64:$val,i64mem:$ptr),
1714 "xchg{q}\t{$val, $ptr|$ptr, $val}",
1715 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1717 def XCHG64rr : RI<0x87, MRMSrcReg, (outs GR64:$dst), (ins GR64:$val,GR64:$src),
1718 "xchg{q}\t{$val, $src|$src, $val}", []>;
1721 def XADD64rr : RI<0xC1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1722 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1723 def XADD64rm : RI<0xC1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1724 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1726 def CMPXCHG64rr : RI<0xB1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1727 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1728 def CMPXCHG64rm : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1729 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1731 let Defs = [RAX, RDX, EFLAGS], Uses = [RAX, RBX, RCX, RDX] in
1732 def CMPXCHG16B : RI<0xC7, MRM1m, (outs), (ins i128mem:$dst),
1733 "cmpxchg16b\t$dst", []>, TB;
1735 def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src),
1736 "xchg{q}\t{$src, %rax|%rax, $src}", []>;
1738 // Optimized codegen when the non-memory output is not used.
1739 let Defs = [EFLAGS] in {
1740 // FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1741 def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1743 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1744 def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1745 (ins i64mem:$dst, i64i8imm :$src2),
1747 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1748 def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1749 (ins i64mem:$dst, i64i32imm :$src2),
1751 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1752 def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1754 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1755 def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1756 (ins i64mem:$dst, i64i8imm :$src2),
1758 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1759 def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1760 (ins i64mem:$dst, i64i32imm:$src2),
1762 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1763 def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1765 "inc{q}\t$dst", []>, LOCK;
1766 def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1768 "dec{q}\t$dst", []>, LOCK;
1770 // Atomic exchange, and, or, xor
1771 let Constraints = "$val = $dst", Defs = [EFLAGS],
1772 usesCustomInserter = 1 in {
1773 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1774 "#ATOMAND64 PSEUDO!",
1775 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1776 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1777 "#ATOMOR64 PSEUDO!",
1778 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1779 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1780 "#ATOMXOR64 PSEUDO!",
1781 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1782 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1783 "#ATOMNAND64 PSEUDO!",
1784 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1785 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1786 "#ATOMMIN64 PSEUDO!",
1787 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1788 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1789 "#ATOMMAX64 PSEUDO!",
1790 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1791 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1792 "#ATOMUMIN64 PSEUDO!",
1793 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1794 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1795 "#ATOMUMAX64 PSEUDO!",
1796 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1799 // Segmentation support instructions
1801 // i16mem operand in LAR64rm and GR32 operand in LAR32rr is not a typo.
1802 def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
1803 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1804 def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
1805 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1807 def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1808 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1809 def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
1810 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1812 def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", []>, TB;
1814 def PUSHFS64 : I<0xa0, RawFrm, (outs), (ins),
1815 "push{q}\t%fs", []>, TB;
1816 def PUSHGS64 : I<0xa8, RawFrm, (outs), (ins),
1817 "push{q}\t%gs", []>, TB;
1819 def POPFS64 : I<0xa1, RawFrm, (outs), (ins),
1820 "pop{q}\t%fs", []>, TB;
1821 def POPGS64 : I<0xa9, RawFrm, (outs), (ins),
1822 "pop{q}\t%gs", []>, TB;
1824 def LSS64rm : RI<0xb2, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1825 "lss{q}\t{$src, $dst|$dst, $src}", []>, TB;
1826 def LFS64rm : RI<0xb4, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1827 "lfs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1828 def LGS64rm : RI<0xb5, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1829 "lgs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1831 // Specialized register support
1833 // no m form encodable; use SMSW16m
1834 def SMSW64r : RI<0x01, MRM4r, (outs GR64:$dst), (ins),
1835 "smsw{q}\t$dst", []>, TB;
1837 // String manipulation instructions
1839 def LODSQ : RI<0xAD, RawFrm, (outs), (ins), "lodsq", []>;
1841 //===----------------------------------------------------------------------===//
1842 // Non-Instruction Patterns
1843 //===----------------------------------------------------------------------===//
1845 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1846 // code model mode, should use 'movabs'. FIXME: This is really a hack, the
1847 // 'movabs' predicate should handle this sort of thing.
1848 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1849 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
1850 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1851 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
1852 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1853 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
1854 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1855 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
1856 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1857 (MOV64ri tblockaddress:$dst)>, Requires<[FarData]>;
1859 // In static codegen with small code model, we can get the address of a label
1860 // into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1861 // the MOV64ri64i32 should accept these.
1862 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1863 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1864 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1865 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1866 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1867 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1868 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1869 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1870 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1871 (MOV64ri64i32 tblockaddress:$dst)>, Requires<[SmallCode]>;
1873 // In kernel code model, we can get the address of a label
1874 // into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1875 // the MOV64ri32 should accept these.
1876 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1877 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1878 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1879 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1880 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1881 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1882 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1883 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
1884 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1885 (MOV64ri32 tblockaddress:$dst)>, Requires<[KernelCode]>;
1887 // If we have small model and -static mode, it is safe to store global addresses
1888 // directly as immediates. FIXME: This is really a hack, the 'imm' predicate
1889 // for MOV64mi32 should handle this sort of thing.
1890 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1891 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1892 Requires<[NearData, IsStatic]>;
1893 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1894 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1895 Requires<[NearData, IsStatic]>;
1896 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1897 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1898 Requires<[NearData, IsStatic]>;
1899 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1900 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1901 Requires<[NearData, IsStatic]>;
1902 def : Pat<(store (i64 (X86Wrapper tblockaddress:$src)), addr:$dst),
1903 (MOV64mi32 addr:$dst, tblockaddress:$src)>,
1904 Requires<[NearData, IsStatic]>;
1907 // Direct PC relative function call for small code model. 32-bit displacement
1908 // sign extended to 64-bit.
1909 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1910 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
1911 def : Pat<(X86call (i64 texternalsym:$dst)),
1912 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1914 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1915 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1916 def : Pat<(X86call (i64 texternalsym:$dst)),
1917 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
1920 def : Pat<(X86tcret GR64_TC:$dst, imm:$off),
1921 (TCRETURNri64 GR64_TC:$dst, imm:$off)>,
1922 Requires<[In64BitMode]>;
1924 def : Pat<(X86tcret (load addr:$dst), imm:$off),
1925 (TCRETURNmi64 addr:$dst, imm:$off)>,
1926 Requires<[In64BitMode]>;
1928 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1929 (TCRETURNdi64 tglobaladdr:$dst, imm:$off)>,
1930 Requires<[In64BitMode]>;
1932 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1933 (TCRETURNdi64 texternalsym:$dst, imm:$off)>,
1934 Requires<[In64BitMode]>;
1938 // TEST R,R is smaller than CMP R,0
1939 def : Pat<(X86cmp GR64:$src1, 0),
1940 (TEST64rr GR64:$src1, GR64:$src1)>;
1942 // Conditional moves with folded loads with operands swapped and conditions
1944 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1945 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1946 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1947 (CMOVB64rm GR64:$src2, addr:$src1)>;
1948 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1949 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1950 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1951 (CMOVE64rm GR64:$src2, addr:$src1)>;
1952 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1953 (CMOVA64rm GR64:$src2, addr:$src1)>;
1954 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1955 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1956 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1957 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1958 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1959 (CMOVL64rm GR64:$src2, addr:$src1)>;
1960 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1961 (CMOVG64rm GR64:$src2, addr:$src1)>;
1962 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1963 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1964 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1965 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1966 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1967 (CMOVP64rm GR64:$src2, addr:$src1)>;
1968 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1969 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1970 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1971 (CMOVS64rm GR64:$src2, addr:$src1)>;
1972 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1973 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1974 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1975 (CMOVO64rm GR64:$src2, addr:$src1)>;
1977 // zextload bool -> zextload byte
1978 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1981 // When extloading from 16-bit and smaller memory locations into 64-bit
1982 // registers, use zero-extending loads so that the entire 64-bit register is
1983 // defined, avoiding partial-register updates.
1984 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1985 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1986 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1987 // For other extloads, use subregs, since the high contents of the register are
1988 // defined after an extload.
1989 def : Pat<(extloadi64i32 addr:$src),
1990 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
1993 // anyext. Define these to do an explicit zero-extend to
1994 // avoid partial-register updates.
1995 def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1996 def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1997 def : Pat<(i64 (anyext GR32:$src)),
1998 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
2000 //===----------------------------------------------------------------------===//
2002 //===----------------------------------------------------------------------===//
2004 // Odd encoding trick: -128 fits into an 8-bit immediate field while
2005 // +128 doesn't, so in this special case use a sub instead of an add.
2006 def : Pat<(add GR64:$src1, 128),
2007 (SUB64ri8 GR64:$src1, -128)>;
2008 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
2009 (SUB64mi8 addr:$dst, -128)>;
2011 // The same trick applies for 32-bit immediate fields in 64-bit
2013 def : Pat<(add GR64:$src1, 0x0000000080000000),
2014 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
2015 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
2016 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
2018 // Use a 32-bit and with implicit zero-extension instead of a 64-bit and if it
2019 // has an immediate with at least 32 bits of leading zeros, to avoid needing to
2020 // materialize that immediate in a register first.
2021 def : Pat<(and GR64:$src, i64immZExt32:$imm),
2025 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit),
2026 (i32 (GetLo32XForm imm:$imm))),
2029 // r & (2^32-1) ==> movz
2030 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
2031 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
2032 // r & (2^16-1) ==> movz
2033 def : Pat<(and GR64:$src, 0xffff),
2034 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
2035 // r & (2^8-1) ==> movz
2036 def : Pat<(and GR64:$src, 0xff),
2037 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
2038 // r & (2^8-1) ==> movz
2039 def : Pat<(and GR32:$src1, 0xff),
2040 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
2041 Requires<[In64BitMode]>;
2042 // r & (2^8-1) ==> movz
2043 def : Pat<(and GR16:$src1, 0xff),
2044 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
2045 Requires<[In64BitMode]>;
2047 // sext_inreg patterns
2048 def : Pat<(sext_inreg GR64:$src, i32),
2049 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
2050 def : Pat<(sext_inreg GR64:$src, i16),
2051 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
2052 def : Pat<(sext_inreg GR64:$src, i8),
2053 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
2054 def : Pat<(sext_inreg GR32:$src, i8),
2055 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
2056 Requires<[In64BitMode]>;
2057 def : Pat<(sext_inreg GR16:$src, i8),
2058 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
2059 Requires<[In64BitMode]>;
2062 def : Pat<(i32 (trunc GR64:$src)),
2063 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
2064 def : Pat<(i16 (trunc GR64:$src)),
2065 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
2066 def : Pat<(i8 (trunc GR64:$src)),
2067 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
2068 def : Pat<(i8 (trunc GR32:$src)),
2069 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
2070 Requires<[In64BitMode]>;
2071 def : Pat<(i8 (trunc GR16:$src)),
2072 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
2073 Requires<[In64BitMode]>;
2075 // h-register tricks.
2076 // For now, be conservative on x86-64 and use an h-register extract only if the
2077 // value is immediately zero-extended or stored, which are somewhat common
2078 // cases. This uses a bunch of code to prevent a register requiring a REX prefix
2079 // from being allocated in the same instruction as the h register, as there's
2080 // currently no way to describe this requirement to the register allocator.
2082 // h-register extract and zero-extend.
2083 def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
2087 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
2088 x86_subreg_8bit_hi)),
2090 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
2092 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
2093 x86_subreg_8bit_hi))>,
2094 Requires<[In64BitMode]>;
2095 def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)),
2096 (MOVZX32_NOREXrr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src,
2098 x86_subreg_8bit_hi))>,
2099 Requires<[In64BitMode]>;
2100 def : Pat<(srl GR16:$src, (i8 8)),
2103 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2104 x86_subreg_8bit_hi)),
2106 Requires<[In64BitMode]>;
2107 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
2109 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2110 x86_subreg_8bit_hi))>,
2111 Requires<[In64BitMode]>;
2112 def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
2114 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2115 x86_subreg_8bit_hi))>,
2116 Requires<[In64BitMode]>;
2117 def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
2121 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2122 x86_subreg_8bit_hi)),
2124 def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
2128 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2129 x86_subreg_8bit_hi)),
2132 // h-register extract and store.
2133 def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
2136 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
2137 x86_subreg_8bit_hi))>;
2138 def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
2141 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
2142 x86_subreg_8bit_hi))>,
2143 Requires<[In64BitMode]>;
2144 def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
2147 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2148 x86_subreg_8bit_hi))>,
2149 Requires<[In64BitMode]>;
2151 // (shl x, 1) ==> (add x, x)
2152 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
2154 // (shl x (and y, 63)) ==> (shl x, y)
2155 def : Pat<(shl GR64:$src1, (and CL, 63)),
2156 (SHL64rCL GR64:$src1)>;
2157 def : Pat<(store (shl (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2158 (SHL64mCL addr:$dst)>;
2160 def : Pat<(srl GR64:$src1, (and CL, 63)),
2161 (SHR64rCL GR64:$src1)>;
2162 def : Pat<(store (srl (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2163 (SHR64mCL addr:$dst)>;
2165 def : Pat<(sra GR64:$src1, (and CL, 63)),
2166 (SAR64rCL GR64:$src1)>;
2167 def : Pat<(store (sra (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2168 (SAR64mCL addr:$dst)>;
2170 // (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
2171 let AddedComplexity = 5 in { // Try this before the selecting to OR
2172 def : Pat<(or_is_add GR64:$src1, i64immSExt8:$src2),
2173 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2174 def : Pat<(or_is_add GR64:$src1, i64immSExt32:$src2),
2175 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
2176 def : Pat<(or_is_add GR64:$src1, GR64:$src2),
2177 (ADD64rr GR64:$src1, GR64:$src2)>;
2178 } // AddedComplexity
2180 // X86 specific add which produces a flag.
2181 def : Pat<(addc GR64:$src1, GR64:$src2),
2182 (ADD64rr GR64:$src1, GR64:$src2)>;
2183 def : Pat<(addc GR64:$src1, (load addr:$src2)),
2184 (ADD64rm GR64:$src1, addr:$src2)>;
2185 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
2186 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2187 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
2188 (ADD64ri32 GR64:$src1, imm:$src2)>;
2190 def : Pat<(subc GR64:$src1, GR64:$src2),
2191 (SUB64rr GR64:$src1, GR64:$src2)>;
2192 def : Pat<(subc GR64:$src1, (load addr:$src2)),
2193 (SUB64rm GR64:$src1, addr:$src2)>;
2194 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
2195 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
2196 def : Pat<(subc GR64:$src1, imm:$src2),
2197 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
2199 //===----------------------------------------------------------------------===//
2200 // EFLAGS-defining Patterns
2201 //===----------------------------------------------------------------------===//
2204 def : Pat<(add GR64:$src1, GR64:$src2),
2205 (ADD64rr GR64:$src1, GR64:$src2)>;
2206 def : Pat<(add GR64:$src1, i64immSExt8:$src2),
2207 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2208 def : Pat<(add GR64:$src1, i64immSExt32:$src2),
2209 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
2210 def : Pat<(add GR64:$src1, (loadi64 addr:$src2)),
2211 (ADD64rm GR64:$src1, addr:$src2)>;
2214 def : Pat<(sub GR64:$src1, GR64:$src2),
2215 (SUB64rr GR64:$src1, GR64:$src2)>;
2216 def : Pat<(sub GR64:$src1, (loadi64 addr:$src2)),
2217 (SUB64rm GR64:$src1, addr:$src2)>;
2218 def : Pat<(sub GR64:$src1, i64immSExt8:$src2),
2219 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
2220 def : Pat<(sub GR64:$src1, i64immSExt32:$src2),
2221 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
2224 def : Pat<(mul GR64:$src1, GR64:$src2),
2225 (IMUL64rr GR64:$src1, GR64:$src2)>;
2226 def : Pat<(mul GR64:$src1, (loadi64 addr:$src2)),
2227 (IMUL64rm GR64:$src1, addr:$src2)>;
2228 def : Pat<(mul GR64:$src1, i64immSExt8:$src2),
2229 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
2230 def : Pat<(mul GR64:$src1, i64immSExt32:$src2),
2231 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
2232 def : Pat<(mul (loadi64 addr:$src1), i64immSExt8:$src2),
2233 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
2234 def : Pat<(mul (loadi64 addr:$src1), i64immSExt32:$src2),
2235 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
2238 def : Pat<(add GR16:$src, 1), (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2239 def : Pat<(add GR16:$src, -1), (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2240 def : Pat<(add GR32:$src, 1), (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2241 def : Pat<(add GR32:$src, -1), (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2242 def : Pat<(add GR64:$src, 1), (INC64r GR64:$src)>;
2243 def : Pat<(add GR64:$src, -1), (DEC64r GR64:$src)>;
2246 def : Pat<(or GR64:$src1, GR64:$src2),
2247 (OR64rr GR64:$src1, GR64:$src2)>;
2248 def : Pat<(or GR64:$src1, i64immSExt8:$src2),
2249 (OR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2250 def : Pat<(or GR64:$src1, i64immSExt32:$src2),
2251 (OR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2252 def : Pat<(or GR64:$src1, (loadi64 addr:$src2)),
2253 (OR64rm GR64:$src1, addr:$src2)>;
2256 def : Pat<(xor GR64:$src1, GR64:$src2),
2257 (XOR64rr GR64:$src1, GR64:$src2)>;
2258 def : Pat<(xor GR64:$src1, i64immSExt8:$src2),
2259 (XOR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2260 def : Pat<(xor GR64:$src1, i64immSExt32:$src2),
2261 (XOR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2262 def : Pat<(xor GR64:$src1, (loadi64 addr:$src2)),
2263 (XOR64rm GR64:$src1, addr:$src2)>;
2266 def : Pat<(and GR64:$src1, GR64:$src2),
2267 (AND64rr GR64:$src1, GR64:$src2)>;
2268 def : Pat<(and GR64:$src1, i64immSExt8:$src2),
2269 (AND64ri8 GR64:$src1, i64immSExt8:$src2)>;
2270 def : Pat<(and GR64:$src1, i64immSExt32:$src2),
2271 (AND64ri32 GR64:$src1, i64immSExt32:$src2)>;
2272 def : Pat<(and GR64:$src1, (loadi64 addr:$src2)),
2273 (AND64rm GR64:$src1, addr:$src2)>;
2275 //===----------------------------------------------------------------------===//
2276 // X86-64 SSE Instructions
2277 //===----------------------------------------------------------------------===//
2279 // Move instructions...
2281 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2282 "mov{d|q}\t{$src, $dst|$dst, $src}",
2284 (v2i64 (scalar_to_vector GR64:$src)))]>;
2285 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
2286 "mov{d|q}\t{$src, $dst|$dst, $src}",
2287 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2290 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
2291 "mov{d|q}\t{$src, $dst|$dst, $src}",
2292 [(set FR64:$dst, (bitconvert GR64:$src))]>;
2293 def MOV64toSDrm : S3SI<0x7E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
2294 "movq\t{$src, $dst|$dst, $src}",
2295 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2297 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
2298 "mov{d|q}\t{$src, $dst|$dst, $src}",
2299 [(set GR64:$dst, (bitconvert FR64:$src))]>;
2300 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
2301 "movq\t{$src, $dst|$dst, $src}",
2302 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
2304 //===----------------------------------------------------------------------===//
2305 // X86-64 SSE4.1 Instructions
2306 //===----------------------------------------------------------------------===//
2308 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2309 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
2310 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
2311 (ins VR128:$src1, i32i8imm:$src2),
2312 !strconcat(OpcodeStr,
2313 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2315 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
2316 def mr : SS4AIi8<opc, MRMDestMem, (outs),
2317 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2318 !strconcat(OpcodeStr,
2319 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2320 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2321 addr:$dst)]>, OpSize, REX_W;
2324 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2326 let isTwoAddress = 1 in {
2327 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
2328 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
2329 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2330 !strconcat(OpcodeStr,
2331 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2333 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2335 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
2336 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2337 !strconcat(OpcodeStr,
2338 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2340 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2341 imm:$src3)))]>, OpSize, REX_W;
2345 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;