1 //====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the X86-64 instruction set, defining the instructions,
11 // and properties of the instructions which are needed for code generation,
12 // machine code emission, and analysis.
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
17 // Operand Definitions.
20 // 64-bits but only 32 bits are significant.
21 def i64i32imm : Operand<i64>;
22 // 64-bits but only 8 bits are significant.
23 def i64i8imm : Operand<i64>;
25 def lea64mem : Operand<i64> {
26 let PrintMethod = "printlea64mem";
27 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
30 def lea64_32mem : Operand<i32> {
31 let PrintMethod = "printlea64_32mem";
32 let AsmOperandLowerMethod = "lower_lea64_32mem";
33 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
36 //===----------------------------------------------------------------------===//
37 // Complex Pattern Definitions.
39 def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
40 [add, mul, X86mul_imm, shl, or, frameindex, X86Wrapper],
43 //===----------------------------------------------------------------------===//
47 def i64immSExt8 : PatLeaf<(i64 imm), [{
48 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
49 // sign extended field.
50 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
53 def i64immSExt32 : PatLeaf<(i64 imm), [{
54 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
55 // sign extended field.
56 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
59 def i64immZExt32 : PatLeaf<(i64 imm), [{
60 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
61 // unsignedsign extended field.
62 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
65 def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
66 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
67 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
69 def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
70 def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
71 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
72 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
74 def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
75 def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
76 def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
77 def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
79 //===----------------------------------------------------------------------===//
80 // Instruction list...
83 // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
84 // a stack adjustment and the codegen must know that they may modify the stack
85 // pointer before prolog-epilog rewriting occurs.
86 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
87 // sub / add which can clobber EFLAGS.
88 let Defs = [RSP, EFLAGS], Uses = [RSP] in {
89 def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
91 [(X86callseq_start timm:$amt)]>,
92 Requires<[In64BitMode]>;
93 def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
95 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
96 Requires<[In64BitMode]>;
99 //===----------------------------------------------------------------------===//
100 // Call Instructions...
103 // All calls clobber the non-callee saved registers. RSP is marked as
104 // a use to prevent stack-pointer assignments that appear immediately
105 // before calls from potentially appearing dead. Uses for argument
106 // registers are added manually.
107 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
108 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
109 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
110 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
111 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
114 // NOTE: this pattern doesn't match "X86call imm", because we do not know
115 // that the offset between an arbitrary immediate and the call will fit in
116 // the 32-bit pcrel field that we have.
117 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
118 (outs), (ins i64i32imm:$dst, variable_ops),
119 "call\t${dst:call}", []>,
120 Requires<[In64BitMode]>;
121 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
122 "call\t{*}$dst", [(X86call GR64:$dst)]>;
123 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
124 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
129 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
130 def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
132 "#TC_RETURN $dst $offset",
135 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
136 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
138 "#TC_RETURN $dst $offset",
142 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
143 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
144 "jmp{q}\t{*}$dst # TAILCALL",
148 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
149 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
150 [(brind GR64:$dst)]>;
151 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
152 [(brind (loadi64 addr:$dst))]>;
155 //===----------------------------------------------------------------------===//
156 // EH Pseudo Instructions
158 let isTerminator = 1, isReturn = 1, isBarrier = 1,
160 def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
161 "ret\t#eh_return, addr: $addr",
162 [(X86ehret GR64:$addr)]>;
166 //===----------------------------------------------------------------------===//
167 // Miscellaneous Instructions...
169 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
170 def LEAVE64 : I<0xC9, RawFrm,
171 (outs), (ins), "leave", []>;
172 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
174 def POP64r : I<0x58, AddRegFrm,
175 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
177 def PUSH64r : I<0x50, AddRegFrm,
178 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
181 let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
182 def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
183 "push{q}\t$imm", []>;
184 def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
185 "push{q}\t$imm", []>;
186 def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
187 "push{q}\t$imm", []>;
190 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
191 def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
192 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
193 def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
195 def LEA64_32r : I<0x8D, MRMSrcMem,
196 (outs GR32:$dst), (ins lea64_32mem:$src),
197 "lea{l}\t{$src|$dst}, {$dst|$src}",
198 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
200 let isReMaterializable = 1 in
201 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
202 "lea{q}\t{$src|$dst}, {$dst|$src}",
203 [(set GR64:$dst, lea64addr:$src)]>;
205 let isTwoAddress = 1 in
206 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
208 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
210 // Bit scan instructions.
211 let Defs = [EFLAGS] in {
212 def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
213 "bsf{q}\t{$src, $dst|$dst, $src}",
214 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
215 def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
216 "bsf{q}\t{$src, $dst|$dst, $src}",
217 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
218 (implicit EFLAGS)]>, TB;
220 def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
221 "bsr{q}\t{$src, $dst|$dst, $src}",
222 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
223 def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
224 "bsr{q}\t{$src, $dst|$dst, $src}",
225 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
226 (implicit EFLAGS)]>, TB;
230 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
231 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
232 [(X86rep_movs i64)]>, REP;
233 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
234 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
235 [(X86rep_stos i64)]>, REP;
237 //===----------------------------------------------------------------------===//
238 // Move Instructions...
241 let neverHasSideEffects = 1 in
242 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
243 "mov{q}\t{$src, $dst|$dst, $src}", []>;
245 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
246 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
247 "movabs{q}\t{$src, $dst|$dst, $src}",
248 [(set GR64:$dst, imm:$src)]>;
249 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
250 "mov{q}\t{$src, $dst|$dst, $src}",
251 [(set GR64:$dst, i64immSExt32:$src)]>;
254 let canFoldAsLoad = 1 in
255 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
256 "mov{q}\t{$src, $dst|$dst, $src}",
257 [(set GR64:$dst, (load addr:$src))]>;
259 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
260 "mov{q}\t{$src, $dst|$dst, $src}",
261 [(store GR64:$src, addr:$dst)]>;
262 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
263 "mov{q}\t{$src, $dst|$dst, $src}",
264 [(store i64immSExt32:$src, addr:$dst)]>;
266 // Sign/Zero extenders
268 // MOVSX64rr8 always has a REX prefix and it has an 8-bit register
269 // operand, which makes it a rare instruction with an 8-bit register
270 // operand that can never access an h register. If support for h registers
271 // were generalized, this would require a special register class.
272 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
273 "movs{bq|x}\t{$src, $dst|$dst, $src}",
274 [(set GR64:$dst, (sext GR8:$src))]>, TB;
275 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
276 "movs{bq|x}\t{$src, $dst|$dst, $src}",
277 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
278 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
279 "movs{wq|x}\t{$src, $dst|$dst, $src}",
280 [(set GR64:$dst, (sext GR16:$src))]>, TB;
281 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
282 "movs{wq|x}\t{$src, $dst|$dst, $src}",
283 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
284 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
285 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
286 [(set GR64:$dst, (sext GR32:$src))]>;
287 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
288 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
289 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
291 // Use movzbl instead of movzbq when the destination is a register; it's
292 // equivalent due to implicit zero-extending, and it has a smaller encoding.
293 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
294 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
295 [(set GR64:$dst, (zext GR8:$src))]>, TB;
296 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
297 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
298 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
299 // Use movzwl instead of movzwq when the destination is a register; it's
300 // equivalent due to implicit zero-extending, and it has a smaller encoding.
301 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
302 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
303 [(set GR64:$dst, (zext GR16:$src))]>, TB;
304 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
305 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
306 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
308 // There's no movzlq instruction, but movl can be used for this purpose, using
309 // implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
310 // extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
311 // zero-extension, however this isn't possible when the 32-bit value is
312 // defined by a truncate or is copied from something where the high bits aren't
313 // necessarily all zero. In such cases, we fall back to these explicit zext
315 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
316 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
317 [(set GR64:$dst, (zext GR32:$src))]>;
318 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
319 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
320 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
322 // Any instruction that defines a 32-bit result leaves the high half of the
323 // register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
324 // be copying from a truncate, but any other 32-bit operation will zero-extend
326 def def32 : PatLeaf<(i32 GR32:$src), [{
327 return N->getOpcode() != ISD::TRUNCATE &&
328 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
329 N->getOpcode() != ISD::CopyFromReg;
332 // In the case of a 32-bit def that is known to implicitly zero-extend,
333 // we can use a SUBREG_TO_REG.
334 def : Pat<(i64 (zext def32:$src)),
335 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
337 let neverHasSideEffects = 1 in {
338 let Defs = [RAX], Uses = [EAX] in
339 def CDQE : RI<0x98, RawFrm, (outs), (ins),
340 "{cltq|cdqe}", []>; // RAX = signext(EAX)
342 let Defs = [RAX,RDX], Uses = [RAX] in
343 def CQO : RI<0x99, RawFrm, (outs), (ins),
344 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
347 //===----------------------------------------------------------------------===//
348 // Arithmetic Instructions...
351 let Defs = [EFLAGS] in {
352 let isTwoAddress = 1 in {
353 let isConvertibleToThreeAddress = 1 in {
354 let isCommutable = 1 in
355 // Register-Register Addition
356 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
357 "add{q}\t{$src2, $dst|$dst, $src2}",
358 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
361 // Register-Integer Addition
362 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
363 "add{q}\t{$src2, $dst|$dst, $src2}",
364 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
366 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
367 "add{q}\t{$src2, $dst|$dst, $src2}",
368 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
370 } // isConvertibleToThreeAddress
372 // Register-Memory Addition
373 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
374 "add{q}\t{$src2, $dst|$dst, $src2}",
375 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
379 // Memory-Register Addition
380 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
381 "add{q}\t{$src2, $dst|$dst, $src2}",
382 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
384 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
385 "add{q}\t{$src2, $dst|$dst, $src2}",
386 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
388 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
389 "add{q}\t{$src2, $dst|$dst, $src2}",
390 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
393 let Uses = [EFLAGS] in {
394 let isTwoAddress = 1 in {
395 let isCommutable = 1 in
396 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
397 "adc{q}\t{$src2, $dst|$dst, $src2}",
398 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
400 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
401 "adc{q}\t{$src2, $dst|$dst, $src2}",
402 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
404 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
405 "adc{q}\t{$src2, $dst|$dst, $src2}",
406 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
407 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
408 "adc{q}\t{$src2, $dst|$dst, $src2}",
409 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
412 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
413 "adc{q}\t{$src2, $dst|$dst, $src2}",
414 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
415 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
416 "adc{q}\t{$src2, $dst|$dst, $src2}",
417 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
418 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
419 "adc{q}\t{$src2, $dst|$dst, $src2}",
420 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
423 let isTwoAddress = 1 in {
424 // Register-Register Subtraction
425 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
426 "sub{q}\t{$src2, $dst|$dst, $src2}",
427 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
430 // Register-Memory Subtraction
431 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
432 "sub{q}\t{$src2, $dst|$dst, $src2}",
433 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
436 // Register-Integer Subtraction
437 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
438 (ins GR64:$src1, i64i8imm:$src2),
439 "sub{q}\t{$src2, $dst|$dst, $src2}",
440 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
442 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
443 (ins GR64:$src1, i64i32imm:$src2),
444 "sub{q}\t{$src2, $dst|$dst, $src2}",
445 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
449 // Memory-Register Subtraction
450 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
451 "sub{q}\t{$src2, $dst|$dst, $src2}",
452 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
455 // Memory-Integer Subtraction
456 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
457 "sub{q}\t{$src2, $dst|$dst, $src2}",
458 [(store (sub (load addr:$dst), i64immSExt8:$src2),
461 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
462 "sub{q}\t{$src2, $dst|$dst, $src2}",
463 [(store (sub (load addr:$dst), i64immSExt32:$src2),
467 let Uses = [EFLAGS] in {
468 let isTwoAddress = 1 in {
469 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
470 "sbb{q}\t{$src2, $dst|$dst, $src2}",
471 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
473 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
474 "sbb{q}\t{$src2, $dst|$dst, $src2}",
475 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
477 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
478 "sbb{q}\t{$src2, $dst|$dst, $src2}",
479 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
480 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
481 "sbb{q}\t{$src2, $dst|$dst, $src2}",
482 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
485 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
486 "sbb{q}\t{$src2, $dst|$dst, $src2}",
487 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
488 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
489 "sbb{q}\t{$src2, $dst|$dst, $src2}",
490 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
491 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
492 "sbb{q}\t{$src2, $dst|$dst, $src2}",
493 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
497 // Unsigned multiplication
498 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
499 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
500 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
502 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
503 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
505 // Signed multiplication
506 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
507 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
509 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
510 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
513 let Defs = [EFLAGS] in {
514 let isTwoAddress = 1 in {
515 let isCommutable = 1 in
516 // Register-Register Signed Integer Multiplication
517 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
518 (ins GR64:$src1, GR64:$src2),
519 "imul{q}\t{$src2, $dst|$dst, $src2}",
520 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
521 (implicit EFLAGS)]>, TB;
523 // Register-Memory Signed Integer Multiplication
524 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
525 (ins GR64:$src1, i64mem:$src2),
526 "imul{q}\t{$src2, $dst|$dst, $src2}",
527 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
528 (implicit EFLAGS)]>, TB;
531 // Suprisingly enough, these are not two address instructions!
533 // Register-Integer Signed Integer Multiplication
534 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
535 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
536 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
537 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
539 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
540 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
541 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
542 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
545 // Memory-Integer Signed Integer Multiplication
546 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
547 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
548 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
549 [(set GR64:$dst, (mul (load addr:$src1),
552 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
553 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
554 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
555 [(set GR64:$dst, (mul (load addr:$src1),
556 i64immSExt32:$src2)),
560 // Unsigned division / remainder
561 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
562 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
564 // Signed division / remainder
565 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
566 "idiv{q}\t$src", []>;
568 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
570 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
571 "idiv{q}\t$src", []>;
575 // Unary instructions
576 let Defs = [EFLAGS], CodeSize = 2 in {
577 let isTwoAddress = 1 in
578 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
579 [(set GR64:$dst, (ineg GR64:$src)),
581 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
582 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
585 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
586 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
587 [(set GR64:$dst, (add GR64:$src, 1)),
589 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
590 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
593 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
594 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
595 [(set GR64:$dst, (add GR64:$src, -1)),
597 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
598 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
601 // In 64-bit mode, single byte INC and DEC cannot be encoded.
602 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
603 // Can transform into LEA.
604 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
605 [(set GR16:$dst, (add GR16:$src, 1)),
607 OpSize, Requires<[In64BitMode]>;
608 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
609 [(set GR32:$dst, (add GR32:$src, 1)),
611 Requires<[In64BitMode]>;
612 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
613 [(set GR16:$dst, (add GR16:$src, -1)),
615 OpSize, Requires<[In64BitMode]>;
616 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
617 [(set GR32:$dst, (add GR32:$src, -1)),
619 Requires<[In64BitMode]>;
620 } // isConvertibleToThreeAddress
622 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
623 // how to unfold them.
624 let isTwoAddress = 0, CodeSize = 2 in {
625 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
626 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
628 OpSize, Requires<[In64BitMode]>;
629 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
630 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
632 Requires<[In64BitMode]>;
633 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
634 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
636 OpSize, Requires<[In64BitMode]>;
637 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
638 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
640 Requires<[In64BitMode]>;
642 } // Defs = [EFLAGS], CodeSize
645 let Defs = [EFLAGS] in {
646 // Shift instructions
647 let isTwoAddress = 1 in {
649 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
650 "shl{q}\t{%cl, $dst|$dst, %CL}",
651 [(set GR64:$dst, (shl GR64:$src, CL))]>;
652 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
653 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
654 "shl{q}\t{$src2, $dst|$dst, $src2}",
655 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
656 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
661 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
662 "shl{q}\t{%cl, $dst|$dst, %CL}",
663 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
664 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
665 "shl{q}\t{$src, $dst|$dst, $src}",
666 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
667 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
669 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
671 let isTwoAddress = 1 in {
673 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
674 "shr{q}\t{%cl, $dst|$dst, %CL}",
675 [(set GR64:$dst, (srl GR64:$src, CL))]>;
676 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
677 "shr{q}\t{$src2, $dst|$dst, $src2}",
678 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
679 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
681 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
685 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
686 "shr{q}\t{%cl, $dst|$dst, %CL}",
687 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
688 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
689 "shr{q}\t{$src, $dst|$dst, $src}",
690 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
691 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
693 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
695 let isTwoAddress = 1 in {
697 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
698 "sar{q}\t{%cl, $dst|$dst, %CL}",
699 [(set GR64:$dst, (sra GR64:$src, CL))]>;
700 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
701 "sar{q}\t{$src2, $dst|$dst, $src2}",
702 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
703 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
705 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
709 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
710 "sar{q}\t{%cl, $dst|$dst, %CL}",
711 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
712 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
713 "sar{q}\t{$src, $dst|$dst, $src}",
714 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
715 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
717 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
719 // Rotate instructions
720 let isTwoAddress = 1 in {
722 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
723 "rol{q}\t{%cl, $dst|$dst, %CL}",
724 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
725 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
726 "rol{q}\t{$src2, $dst|$dst, $src2}",
727 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
728 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
730 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
734 def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
735 "rol{q}\t{%cl, $dst|$dst, %CL}",
736 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
737 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
738 "rol{q}\t{$src, $dst|$dst, $src}",
739 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
740 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
742 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
744 let isTwoAddress = 1 in {
746 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
747 "ror{q}\t{%cl, $dst|$dst, %CL}",
748 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
749 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
750 "ror{q}\t{$src2, $dst|$dst, $src2}",
751 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
752 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
754 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
758 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
759 "ror{q}\t{%cl, $dst|$dst, %CL}",
760 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
761 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
762 "ror{q}\t{$src, $dst|$dst, $src}",
763 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
764 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
766 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
768 // Double shift instructions (generalizations of rotate)
769 let isTwoAddress = 1 in {
771 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
772 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
773 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
774 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
775 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
776 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
779 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
780 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
781 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
782 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
783 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
786 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
787 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
788 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
789 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
796 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
797 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
798 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
800 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
801 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
802 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
805 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
806 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
807 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
808 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
809 (i8 imm:$src3)), addr:$dst)]>,
811 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
812 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
813 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
814 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
815 (i8 imm:$src3)), addr:$dst)]>,
819 //===----------------------------------------------------------------------===//
820 // Logical Instructions...
823 let isTwoAddress = 1 , AddedComplexity = 15 in
824 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
825 [(set GR64:$dst, (not GR64:$src))]>;
826 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
827 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
829 let Defs = [EFLAGS] in {
830 let isTwoAddress = 1 in {
831 let isCommutable = 1 in
832 def AND64rr : RI<0x21, MRMDestReg,
833 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
834 "and{q}\t{$src2, $dst|$dst, $src2}",
835 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
837 def AND64rm : RI<0x23, MRMSrcMem,
838 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
839 "and{q}\t{$src2, $dst|$dst, $src2}",
840 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
842 def AND64ri8 : RIi8<0x83, MRM4r,
843 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
844 "and{q}\t{$src2, $dst|$dst, $src2}",
845 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
847 def AND64ri32 : RIi32<0x81, MRM4r,
848 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
849 "and{q}\t{$src2, $dst|$dst, $src2}",
850 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
854 def AND64mr : RI<0x21, MRMDestMem,
855 (outs), (ins i64mem:$dst, GR64:$src),
856 "and{q}\t{$src, $dst|$dst, $src}",
857 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
859 def AND64mi8 : RIi8<0x83, MRM4m,
860 (outs), (ins i64mem:$dst, i64i8imm :$src),
861 "and{q}\t{$src, $dst|$dst, $src}",
862 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
864 def AND64mi32 : RIi32<0x81, MRM4m,
865 (outs), (ins i64mem:$dst, i64i32imm:$src),
866 "and{q}\t{$src, $dst|$dst, $src}",
867 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
870 let isTwoAddress = 1 in {
871 let isCommutable = 1 in
872 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
873 "or{q}\t{$src2, $dst|$dst, $src2}",
874 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
876 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
877 "or{q}\t{$src2, $dst|$dst, $src2}",
878 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
880 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
881 "or{q}\t{$src2, $dst|$dst, $src2}",
882 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
884 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
885 "or{q}\t{$src2, $dst|$dst, $src2}",
886 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
890 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
891 "or{q}\t{$src, $dst|$dst, $src}",
892 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
894 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
895 "or{q}\t{$src, $dst|$dst, $src}",
896 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
898 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
899 "or{q}\t{$src, $dst|$dst, $src}",
900 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
903 let isTwoAddress = 1 in {
904 let isCommutable = 1 in
905 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
906 "xor{q}\t{$src2, $dst|$dst, $src2}",
907 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
909 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
910 "xor{q}\t{$src2, $dst|$dst, $src2}",
911 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
913 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
914 "xor{q}\t{$src2, $dst|$dst, $src2}",
915 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
917 def XOR64ri32 : RIi32<0x81, MRM6r,
918 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
919 "xor{q}\t{$src2, $dst|$dst, $src2}",
920 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
924 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
925 "xor{q}\t{$src, $dst|$dst, $src}",
926 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
928 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
929 "xor{q}\t{$src, $dst|$dst, $src}",
930 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
932 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
933 "xor{q}\t{$src, $dst|$dst, $src}",
934 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
938 //===----------------------------------------------------------------------===//
939 // Comparison Instructions...
942 // Integer comparison
943 let Defs = [EFLAGS] in {
944 let isCommutable = 1 in
945 def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
946 "test{q}\t{$src2, $src1|$src1, $src2}",
947 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
949 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
950 "test{q}\t{$src2, $src1|$src1, $src2}",
951 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
953 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
954 (ins GR64:$src1, i64i32imm:$src2),
955 "test{q}\t{$src2, $src1|$src1, $src2}",
956 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
958 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
959 (ins i64mem:$src1, i64i32imm:$src2),
960 "test{q}\t{$src2, $src1|$src1, $src2}",
961 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
964 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
965 "cmp{q}\t{$src2, $src1|$src1, $src2}",
966 [(X86cmp GR64:$src1, GR64:$src2),
968 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
969 "cmp{q}\t{$src2, $src1|$src1, $src2}",
970 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
972 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
973 "cmp{q}\t{$src2, $src1|$src1, $src2}",
974 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
976 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
977 "cmp{q}\t{$src2, $src1|$src1, $src2}",
978 [(X86cmp GR64:$src1, i64immSExt8:$src2),
980 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
981 "cmp{q}\t{$src2, $src1|$src1, $src2}",
982 [(X86cmp GR64:$src1, i64immSExt32:$src2),
984 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
985 "cmp{q}\t{$src2, $src1|$src1, $src2}",
986 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
988 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
989 (ins i64mem:$src1, i64i32imm:$src2),
990 "cmp{q}\t{$src2, $src1|$src1, $src2}",
991 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
996 // TODO: BTC, BTR, and BTS
997 let Defs = [EFLAGS] in {
998 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
999 "bt{q}\t{$src2, $src1|$src1, $src2}",
1000 [(X86bt GR64:$src1, GR64:$src2),
1001 (implicit EFLAGS)]>, TB;
1003 // Unlike with the register+register form, the memory+register form of the
1004 // bt instruction does not ignore the high bits of the index. From ISel's
1005 // perspective, this is pretty bizarre. Disable these instructions for now.
1006 //def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1007 // "bt{q}\t{$src2, $src1|$src1, $src2}",
1008 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
1009 // (implicit EFLAGS)]>, TB;
1011 def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1012 "bt{q}\t{$src2, $src1|$src1, $src2}",
1013 [(X86bt GR64:$src1, i64immSExt8:$src2),
1014 (implicit EFLAGS)]>, TB;
1015 // Note that these instructions don't need FastBTMem because that
1016 // only applies when the other operand is in a register. When it's
1017 // an immediate, bt is still fast.
1018 def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1019 "bt{q}\t{$src2, $src1|$src1, $src2}",
1020 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1021 (implicit EFLAGS)]>, TB;
1022 } // Defs = [EFLAGS]
1024 // Conditional moves
1025 let Uses = [EFLAGS], isTwoAddress = 1 in {
1026 let isCommutable = 1 in {
1027 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
1028 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1029 "cmovb\t{$src2, $dst|$dst, $src2}",
1030 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1031 X86_COND_B, EFLAGS))]>, TB;
1032 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
1033 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1034 "cmovae\t{$src2, $dst|$dst, $src2}",
1035 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1036 X86_COND_AE, EFLAGS))]>, TB;
1037 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
1038 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1039 "cmove\t{$src2, $dst|$dst, $src2}",
1040 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1041 X86_COND_E, EFLAGS))]>, TB;
1042 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
1043 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1044 "cmovne\t{$src2, $dst|$dst, $src2}",
1045 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1046 X86_COND_NE, EFLAGS))]>, TB;
1047 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
1048 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1049 "cmovbe\t{$src2, $dst|$dst, $src2}",
1050 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1051 X86_COND_BE, EFLAGS))]>, TB;
1052 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
1053 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1054 "cmova\t{$src2, $dst|$dst, $src2}",
1055 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1056 X86_COND_A, EFLAGS))]>, TB;
1057 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
1058 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1059 "cmovl\t{$src2, $dst|$dst, $src2}",
1060 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1061 X86_COND_L, EFLAGS))]>, TB;
1062 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
1063 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1064 "cmovge\t{$src2, $dst|$dst, $src2}",
1065 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1066 X86_COND_GE, EFLAGS))]>, TB;
1067 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
1068 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1069 "cmovle\t{$src2, $dst|$dst, $src2}",
1070 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1071 X86_COND_LE, EFLAGS))]>, TB;
1072 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
1073 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1074 "cmovg\t{$src2, $dst|$dst, $src2}",
1075 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1076 X86_COND_G, EFLAGS))]>, TB;
1077 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1078 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1079 "cmovs\t{$src2, $dst|$dst, $src2}",
1080 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1081 X86_COND_S, EFLAGS))]>, TB;
1082 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1083 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1084 "cmovns\t{$src2, $dst|$dst, $src2}",
1085 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1086 X86_COND_NS, EFLAGS))]>, TB;
1087 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1088 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1089 "cmovp\t{$src2, $dst|$dst, $src2}",
1090 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1091 X86_COND_P, EFLAGS))]>, TB;
1092 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1093 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1094 "cmovnp\t{$src2, $dst|$dst, $src2}",
1095 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1096 X86_COND_NP, EFLAGS))]>, TB;
1097 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1098 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1099 "cmovo\t{$src2, $dst|$dst, $src2}",
1100 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1101 X86_COND_O, EFLAGS))]>, TB;
1102 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1103 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1104 "cmovno\t{$src2, $dst|$dst, $src2}",
1105 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1106 X86_COND_NO, EFLAGS))]>, TB;
1107 } // isCommutable = 1
1109 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1110 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1111 "cmovb\t{$src2, $dst|$dst, $src2}",
1112 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1113 X86_COND_B, EFLAGS))]>, TB;
1114 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1115 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1116 "cmovae\t{$src2, $dst|$dst, $src2}",
1117 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1118 X86_COND_AE, EFLAGS))]>, TB;
1119 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1120 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1121 "cmove\t{$src2, $dst|$dst, $src2}",
1122 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1123 X86_COND_E, EFLAGS))]>, TB;
1124 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1125 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1126 "cmovne\t{$src2, $dst|$dst, $src2}",
1127 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1128 X86_COND_NE, EFLAGS))]>, TB;
1129 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1130 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1131 "cmovbe\t{$src2, $dst|$dst, $src2}",
1132 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1133 X86_COND_BE, EFLAGS))]>, TB;
1134 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1135 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1136 "cmova\t{$src2, $dst|$dst, $src2}",
1137 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1138 X86_COND_A, EFLAGS))]>, TB;
1139 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1140 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1141 "cmovl\t{$src2, $dst|$dst, $src2}",
1142 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1143 X86_COND_L, EFLAGS))]>, TB;
1144 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1145 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1146 "cmovge\t{$src2, $dst|$dst, $src2}",
1147 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1148 X86_COND_GE, EFLAGS))]>, TB;
1149 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1150 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1151 "cmovle\t{$src2, $dst|$dst, $src2}",
1152 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1153 X86_COND_LE, EFLAGS))]>, TB;
1154 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1155 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1156 "cmovg\t{$src2, $dst|$dst, $src2}",
1157 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1158 X86_COND_G, EFLAGS))]>, TB;
1159 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1160 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1161 "cmovs\t{$src2, $dst|$dst, $src2}",
1162 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1163 X86_COND_S, EFLAGS))]>, TB;
1164 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1165 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1166 "cmovns\t{$src2, $dst|$dst, $src2}",
1167 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1168 X86_COND_NS, EFLAGS))]>, TB;
1169 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1170 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1171 "cmovp\t{$src2, $dst|$dst, $src2}",
1172 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1173 X86_COND_P, EFLAGS))]>, TB;
1174 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1175 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1176 "cmovnp\t{$src2, $dst|$dst, $src2}",
1177 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1178 X86_COND_NP, EFLAGS))]>, TB;
1179 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1180 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1181 "cmovo\t{$src2, $dst|$dst, $src2}",
1182 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1183 X86_COND_O, EFLAGS))]>, TB;
1184 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1185 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1186 "cmovno\t{$src2, $dst|$dst, $src2}",
1187 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1188 X86_COND_NO, EFLAGS))]>, TB;
1191 //===----------------------------------------------------------------------===//
1192 // Conversion Instructions...
1195 // f64 -> signed i64
1196 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1197 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1199 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1200 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1201 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1202 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1203 (load addr:$src)))]>;
1204 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1205 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1206 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1207 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1208 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1209 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1210 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1211 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1213 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1214 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1215 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1217 (int_x86_sse2_cvttsd2si64
1218 (load addr:$src)))]>;
1220 // Signed i64 -> f64
1221 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1222 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1223 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1224 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1225 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1226 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1228 let isTwoAddress = 1 in {
1229 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1230 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1231 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1233 (int_x86_sse2_cvtsi642sd VR128:$src1,
1235 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1236 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1237 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1239 (int_x86_sse2_cvtsi642sd VR128:$src1,
1240 (loadi64 addr:$src2)))]>;
1243 // Signed i64 -> f32
1244 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1245 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1246 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1247 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1248 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1249 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1251 let isTwoAddress = 1 in {
1252 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1253 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1254 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1256 (int_x86_sse_cvtsi642ss VR128:$src1,
1258 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1259 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1260 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1262 (int_x86_sse_cvtsi642ss VR128:$src1,
1263 (loadi64 addr:$src2)))]>;
1266 // f32 -> signed i64
1267 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1268 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1270 (int_x86_sse_cvtss2si64 VR128:$src))]>;
1271 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1272 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1273 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1274 (load addr:$src)))]>;
1275 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1276 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1277 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1278 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1279 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1280 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1281 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1282 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1284 (int_x86_sse_cvttss2si64 VR128:$src))]>;
1285 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1286 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1288 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1290 //===----------------------------------------------------------------------===//
1291 // Alias Instructions
1292 //===----------------------------------------------------------------------===//
1294 // Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1295 // equivalent due to implicit zero-extending, and it sometimes has a smaller
1297 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1298 // FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1299 // when we have a better way to specify isel priority.
1300 let Defs = [EFLAGS], AddedComplexity = 1,
1301 isReMaterializable = 1, isAsCheapAsAMove = 1 in
1302 def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1303 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1304 [(set GR64:$dst, 0)]>;
1306 // Materialize i64 constant where top 32-bits are zero.
1307 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1308 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1309 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1310 [(set GR64:$dst, i64immZExt32:$src)]>;
1312 //===----------------------------------------------------------------------===//
1313 // Thread Local Storage Instructions
1314 //===----------------------------------------------------------------------===//
1316 // All calls clobber the non-callee saved registers. RSP is marked as
1317 // a use to prevent stack-pointer assignments that appear immediately
1318 // before calls from potentially appearing dead.
1319 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1320 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1321 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1322 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1323 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1325 def TLS_addr64 : I<0, Pseudo, (outs), (ins i64imm:$sym),
1327 "leaq\t${sym:mem}(%rip), %rdi; "
1330 "call\t__tls_get_addr@PLT",
1331 [(X86tlsaddr tglobaltlsaddr:$sym)]>,
1332 Requires<[In64BitMode]>;
1334 let AddedComplexity = 5 in
1335 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1336 "movq\t%gs:$src, $dst",
1337 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1339 let AddedComplexity = 5 in
1340 def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1341 "movq\t%fs:$src, $dst",
1342 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1344 //===----------------------------------------------------------------------===//
1345 // Atomic Instructions
1346 //===----------------------------------------------------------------------===//
1348 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1349 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1351 "cmpxchgq\t$swap,$ptr",
1352 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1355 let Constraints = "$val = $dst" in {
1356 let Defs = [EFLAGS] in
1357 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1360 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1362 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1364 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1367 // Atomic exchange, and, or, xor
1368 let Constraints = "$val = $dst", Defs = [EFLAGS],
1369 usesCustomDAGSchedInserter = 1 in {
1370 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1371 "#ATOMAND64 PSEUDO!",
1372 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1373 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1374 "#ATOMOR64 PSEUDO!",
1375 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1376 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1377 "#ATOMXOR64 PSEUDO!",
1378 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1379 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1380 "#ATOMNAND64 PSEUDO!",
1381 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1382 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1383 "#ATOMMIN64 PSEUDO!",
1384 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1385 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1386 "#ATOMMAX64 PSEUDO!",
1387 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1388 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1389 "#ATOMUMIN64 PSEUDO!",
1390 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1391 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1392 "#ATOMUMAX64 PSEUDO!",
1393 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1396 //===----------------------------------------------------------------------===//
1397 // Non-Instruction Patterns
1398 //===----------------------------------------------------------------------===//
1400 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
1401 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1402 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1403 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1404 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1405 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1406 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1407 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1408 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1410 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1411 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1412 Requires<[SmallCode, IsStatic]>;
1413 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1414 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1415 Requires<[SmallCode, IsStatic]>;
1416 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1417 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1418 Requires<[SmallCode, IsStatic]>;
1419 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1420 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1421 Requires<[SmallCode, IsStatic]>;
1424 // Direct PC relative function call for small code model. 32-bit displacement
1425 // sign extended to 64-bit.
1426 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1427 (CALL64pcrel32 tglobaladdr:$dst)>;
1428 def : Pat<(X86call (i64 texternalsym:$dst)),
1429 (CALL64pcrel32 texternalsym:$dst)>;
1431 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1432 (CALL64pcrel32 tglobaladdr:$dst)>;
1433 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1434 (CALL64pcrel32 texternalsym:$dst)>;
1436 def : Pat<(X86tailcall GR64:$dst),
1437 (CALL64r GR64:$dst)>;
1441 def : Pat<(X86tailcall GR32:$dst),
1443 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1445 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1448 def : Pat<(X86tcret GR64:$dst, imm:$off),
1449 (TCRETURNri64 GR64:$dst, imm:$off)>;
1451 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1452 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1454 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1455 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1459 // TEST R,R is smaller than CMP R,0
1460 def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
1461 (TEST64rr GR64:$src1, GR64:$src1)>;
1463 // Conditional moves with folded loads with operands swapped and conditions
1465 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1466 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1467 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1468 (CMOVB64rm GR64:$src2, addr:$src1)>;
1469 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1470 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1471 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1472 (CMOVE64rm GR64:$src2, addr:$src1)>;
1473 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1474 (CMOVA64rm GR64:$src2, addr:$src1)>;
1475 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1476 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1477 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1478 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1479 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1480 (CMOVL64rm GR64:$src2, addr:$src1)>;
1481 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1482 (CMOVG64rm GR64:$src2, addr:$src1)>;
1483 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1484 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1485 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1486 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1487 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1488 (CMOVP64rm GR64:$src2, addr:$src1)>;
1489 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1490 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1491 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1492 (CMOVS64rm GR64:$src2, addr:$src1)>;
1493 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1494 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1495 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1496 (CMOVO64rm GR64:$src2, addr:$src1)>;
1498 // zextload bool -> zextload byte
1499 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1502 // When extloading from 16-bit and smaller memory locations into 64-bit registers,
1503 // use zero-extending loads so that the entire 64-bit register is defined, avoiding
1504 // partial-register updates.
1505 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1506 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1507 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1508 // For other extloads, use subregs, since the high contents of the register are
1509 // defined after an extload.
1510 def : Pat<(extloadi64i32 addr:$src),
1511 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1513 def : Pat<(extloadi16i1 addr:$src),
1514 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1516 Requires<[In64BitMode]>;
1517 def : Pat<(extloadi16i8 addr:$src),
1518 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1520 Requires<[In64BitMode]>;
1523 def : Pat<(i64 (anyext GR8:$src)),
1524 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1525 def : Pat<(i64 (anyext GR16:$src)),
1526 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
1527 def : Pat<(i64 (anyext GR32:$src)),
1528 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
1529 def : Pat<(i16 (anyext GR8:$src)),
1530 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1531 Requires<[In64BitMode]>;
1532 def : Pat<(i32 (anyext GR8:$src)),
1533 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1534 Requires<[In64BitMode]>;
1536 //===----------------------------------------------------------------------===//
1538 //===----------------------------------------------------------------------===//
1540 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1541 // +128 doesn't, so in this special case use a sub instead of an add.
1542 def : Pat<(add GR64:$src1, 128),
1543 (SUB64ri8 GR64:$src1, -128)>;
1544 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1545 (SUB64mi8 addr:$dst, -128)>;
1547 // The same trick applies for 32-bit immediate fields in 64-bit
1549 def : Pat<(add GR64:$src1, 0x0000000080000000),
1550 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1551 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1552 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1554 // r & (2^32-1) ==> movz
1555 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1556 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1557 // r & (2^16-1) ==> movz
1558 def : Pat<(and GR64:$src, 0xffff),
1559 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1560 // r & (2^8-1) ==> movz
1561 def : Pat<(and GR64:$src, 0xff),
1562 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1563 // r & (2^8-1) ==> movz
1564 def : Pat<(and GR32:$src1, 0xff),
1565 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
1566 Requires<[In64BitMode]>;
1567 // r & (2^8-1) ==> movz
1568 def : Pat<(and GR16:$src1, 0xff),
1569 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1570 Requires<[In64BitMode]>;
1572 // sext_inreg patterns
1573 def : Pat<(sext_inreg GR64:$src, i32),
1574 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1575 def : Pat<(sext_inreg GR64:$src, i16),
1576 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1577 def : Pat<(sext_inreg GR64:$src, i8),
1578 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1579 def : Pat<(sext_inreg GR32:$src, i8),
1580 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1581 Requires<[In64BitMode]>;
1582 def : Pat<(sext_inreg GR16:$src, i8),
1583 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1584 Requires<[In64BitMode]>;
1587 def : Pat<(i32 (trunc GR64:$src)),
1588 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
1589 def : Pat<(i16 (trunc GR64:$src)),
1590 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
1591 def : Pat<(i8 (trunc GR64:$src)),
1592 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
1593 def : Pat<(i8 (trunc GR32:$src)),
1594 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
1595 Requires<[In64BitMode]>;
1596 def : Pat<(i8 (trunc GR16:$src)),
1597 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1598 Requires<[In64BitMode]>;
1600 // h-register tricks.
1601 // For now, be conservative on x86-64 and use an h-register extract only if the
1602 // value is immediately zero-extended or stored, which are somewhat common
1603 // cases. This uses a bunch of code to prevent a register requiring a REX prefix
1604 // from being allocated in the same instruction as the h register, as there's
1605 // currently no way to describe this requirement to the register allocator.
1607 // h-register extract and zero-extend.
1608 def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1612 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
1613 x86_subreg_8bit_hi)),
1615 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1617 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
1618 x86_subreg_8bit_hi))>,
1619 Requires<[In64BitMode]>;
1620 def : Pat<(srl_su GR16:$src, (i8 8)),
1623 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1624 x86_subreg_8bit_hi)),
1626 Requires<[In64BitMode]>;
1627 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1629 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1630 x86_subreg_8bit_hi))>,
1631 Requires<[In64BitMode]>;
1632 def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1636 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1637 x86_subreg_8bit_hi)),
1640 // h-register extract and store.
1641 def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1644 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
1645 x86_subreg_8bit_hi))>;
1646 def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1649 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
1650 x86_subreg_8bit_hi))>,
1651 Requires<[In64BitMode]>;
1652 def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1655 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1656 x86_subreg_8bit_hi))>,
1657 Requires<[In64BitMode]>;
1659 // (shl x, 1) ==> (add x, x)
1660 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1662 // (shl x (and y, 63)) ==> (shl x, y)
1663 def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1664 (SHL64rCL GR64:$src1)>;
1665 def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1666 (SHL64mCL addr:$dst)>;
1668 def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1669 (SHR64rCL GR64:$src1)>;
1670 def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1671 (SHR64mCL addr:$dst)>;
1673 def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1674 (SAR64rCL GR64:$src1)>;
1675 def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1676 (SAR64mCL addr:$dst)>;
1678 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1679 def : Pat<(or (srl GR64:$src1, CL:$amt),
1680 (shl GR64:$src2, (sub 64, CL:$amt))),
1681 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1683 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1684 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1685 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1687 def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1688 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1689 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1691 def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1692 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1694 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1696 def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1697 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1699 def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1700 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1701 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1703 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1704 def : Pat<(or (shl GR64:$src1, CL:$amt),
1705 (srl GR64:$src2, (sub 64, CL:$amt))),
1706 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1708 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1709 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1710 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1712 def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1713 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1714 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1716 def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1717 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1719 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1721 def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1722 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1724 def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1725 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1726 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1728 // X86 specific add which produces a flag.
1729 def : Pat<(addc GR64:$src1, GR64:$src2),
1730 (ADD64rr GR64:$src1, GR64:$src2)>;
1731 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1732 (ADD64rm GR64:$src1, addr:$src2)>;
1733 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1734 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1735 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1736 (ADD64ri32 GR64:$src1, imm:$src2)>;
1738 def : Pat<(subc GR64:$src1, GR64:$src2),
1739 (SUB64rr GR64:$src1, GR64:$src2)>;
1740 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1741 (SUB64rm GR64:$src1, addr:$src2)>;
1742 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1743 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1744 def : Pat<(subc GR64:$src1, imm:$src2),
1745 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1747 //===----------------------------------------------------------------------===//
1748 // EFLAGS-defining Patterns
1749 //===----------------------------------------------------------------------===//
1751 // Register-Register Addition with EFLAGS result
1752 def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
1754 (ADD64rr GR64:$src1, GR64:$src2)>;
1756 // Register-Integer Addition with EFLAGS result
1757 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
1759 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1760 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
1762 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
1764 // Register-Memory Addition with EFLAGS result
1765 def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
1767 (ADD64rm GR64:$src1, addr:$src2)>;
1769 // Memory-Register Addition with EFLAGS result
1770 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
1773 (ADD64mr addr:$dst, GR64:$src2)>;
1774 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1777 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
1778 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1781 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
1783 // Register-Register Subtraction with EFLAGS result
1784 def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
1786 (SUB64rr GR64:$src1, GR64:$src2)>;
1788 // Register-Memory Subtraction with EFLAGS result
1789 def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
1791 (SUB64rm GR64:$src1, addr:$src2)>;
1793 // Register-Integer Subtraction with EFLAGS result
1794 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
1796 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1797 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
1799 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1801 // Memory-Register Subtraction with EFLAGS result
1802 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
1805 (SUB64mr addr:$dst, GR64:$src2)>;
1807 // Memory-Integer Subtraction with EFLAGS result
1808 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1811 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
1812 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1815 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
1817 // Register-Register Signed Integer Multiplication with EFLAGS result
1818 def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
1820 (IMUL64rr GR64:$src1, GR64:$src2)>;
1822 // Register-Memory Signed Integer Multiplication with EFLAGS result
1823 def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
1825 (IMUL64rm GR64:$src1, addr:$src2)>;
1827 // Register-Integer Signed Integer Multiplication with EFLAGS result
1828 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
1830 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
1831 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
1833 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
1835 // Memory-Integer Signed Integer Multiplication with EFLAGS result
1836 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
1838 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
1839 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
1841 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
1843 // INC and DEC with EFLAGS result. Note that these do not set CF.
1844 def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1845 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1846 def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1848 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1849 def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1850 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1851 def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1853 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1855 def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1856 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1857 def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1859 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1860 def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1861 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1862 def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1864 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1866 def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1867 (INC64r GR64:$src)>;
1868 def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1870 (INC64m addr:$dst)>;
1871 def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1872 (DEC64r GR64:$src)>;
1873 def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1875 (DEC64m addr:$dst)>;
1877 //===----------------------------------------------------------------------===//
1878 // X86-64 SSE Instructions
1879 //===----------------------------------------------------------------------===//
1881 // Move instructions...
1883 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
1884 "mov{d|q}\t{$src, $dst|$dst, $src}",
1886 (v2i64 (scalar_to_vector GR64:$src)))]>;
1887 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
1888 "mov{d|q}\t{$src, $dst|$dst, $src}",
1889 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1892 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1893 "mov{d|q}\t{$src, $dst|$dst, $src}",
1894 [(set FR64:$dst, (bitconvert GR64:$src))]>;
1895 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1896 "movq\t{$src, $dst|$dst, $src}",
1897 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1899 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
1900 "mov{d|q}\t{$src, $dst|$dst, $src}",
1901 [(set GR64:$dst, (bitconvert FR64:$src))]>;
1902 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
1903 "movq\t{$src, $dst|$dst, $src}",
1904 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
1906 //===----------------------------------------------------------------------===//
1907 // X86-64 SSE4.1 Instructions
1908 //===----------------------------------------------------------------------===//
1910 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1911 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
1912 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
1913 (ins VR128:$src1, i32i8imm:$src2),
1914 !strconcat(OpcodeStr,
1915 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1917 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
1918 def mr : SS4AIi8<opc, MRMDestMem, (outs),
1919 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1920 !strconcat(OpcodeStr,
1921 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1922 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1923 addr:$dst)]>, OpSize, REX_W;
1926 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1928 let isTwoAddress = 1 in {
1929 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
1930 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
1931 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1932 !strconcat(OpcodeStr,
1933 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1935 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1937 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
1938 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1939 !strconcat(OpcodeStr,
1940 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1942 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1943 imm:$src3)))]>, OpSize, REX_W;
1947 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;