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 = "printi64mem";
27 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
30 def lea64_32mem : Operand<i32> {
31 let PrintMethod = "printlea64_32mem";
32 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
35 //===----------------------------------------------------------------------===//
36 // Complex Pattern Definitions.
38 def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
39 [add, mul, X86mul_imm, shl, or, frameindex, X86Wrapper],
42 //===----------------------------------------------------------------------===//
46 def i64immSExt8 : PatLeaf<(i64 imm), [{
47 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
48 // sign extended field.
49 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
52 def i64immSExt32 : PatLeaf<(i64 imm), [{
53 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
54 // sign extended field.
55 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
58 def i64immZExt32 : PatLeaf<(i64 imm), [{
59 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
60 // unsignedsign extended field.
61 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
64 def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
65 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
66 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
68 def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
69 def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
70 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
71 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
73 def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
74 def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
75 def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
76 def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
78 //===----------------------------------------------------------------------===//
79 // Instruction list...
82 // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
83 // a stack adjustment and the codegen must know that they may modify the stack
84 // pointer before prolog-epilog rewriting occurs.
85 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
86 // sub / add which can clobber EFLAGS.
87 let Defs = [RSP, EFLAGS], Uses = [RSP] in {
88 def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
90 [(X86callseq_start timm:$amt)]>,
91 Requires<[In64BitMode]>;
92 def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
94 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
95 Requires<[In64BitMode]>;
98 //===----------------------------------------------------------------------===//
99 // Call Instructions...
102 // All calls clobber the non-callee saved registers. RSP is marked as
103 // a use to prevent stack-pointer assignments that appear immediately
104 // before calls from potentially appearing dead. Uses for argument
105 // registers are added manually.
106 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
107 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
108 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
109 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
110 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
113 // NOTE: this pattern doesn't match "X86call imm", because we do not know
114 // that the offset between an arbitrary immediate and the call will fit in
115 // the 32-bit pcrel field that we have.
116 def CALL64pcrel32 : I<0xE8, RawFrm,
117 (outs), (ins i64i32imm:$dst, variable_ops),
118 "call\t${dst:call}", []>,
119 Requires<[In64BitMode]>;
120 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
121 "call\t{*}$dst", [(X86call GR64:$dst)]>;
122 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
123 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
128 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
129 def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
131 "#TC_RETURN $dst $offset",
134 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
135 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
137 "#TC_RETURN $dst $offset",
141 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
142 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
143 "jmp{q}\t{*}$dst # TAILCALL",
147 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
148 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
149 [(brind GR64:$dst)]>;
150 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
151 [(brind (loadi64 addr:$dst))]>;
154 //===----------------------------------------------------------------------===//
155 // EH Pseudo Instructions
157 let isTerminator = 1, isReturn = 1, isBarrier = 1,
159 def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
160 "ret\t#eh_return, addr: $addr",
161 [(X86ehret GR64:$addr)]>;
165 //===----------------------------------------------------------------------===//
166 // Miscellaneous Instructions...
168 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
169 def LEAVE64 : I<0xC9, RawFrm,
170 (outs), (ins), "leave", []>;
171 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
173 def POP64r : I<0x58, AddRegFrm,
174 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
176 def PUSH64r : I<0x50, AddRegFrm,
177 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
180 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
181 def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
182 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
183 def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
185 def LEA64_32r : I<0x8D, MRMSrcMem,
186 (outs GR32:$dst), (ins lea64_32mem:$src),
187 "lea{l}\t{$src|$dst}, {$dst|$src}",
188 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
190 let isReMaterializable = 1 in
191 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
192 "lea{q}\t{$src|$dst}, {$dst|$src}",
193 [(set GR64:$dst, lea64addr:$src)]>;
195 let isTwoAddress = 1 in
196 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
198 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
200 // Bit scan instructions.
201 let Defs = [EFLAGS] in {
202 def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
203 "bsf{q}\t{$src, $dst|$dst, $src}",
204 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
205 def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
206 "bsf{q}\t{$src, $dst|$dst, $src}",
207 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
208 (implicit EFLAGS)]>, TB;
210 def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
211 "bsr{q}\t{$src, $dst|$dst, $src}",
212 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
213 def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
214 "bsr{q}\t{$src, $dst|$dst, $src}",
215 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
216 (implicit EFLAGS)]>, TB;
220 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
221 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
222 [(X86rep_movs i64)]>, REP;
223 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
224 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
225 [(X86rep_stos i64)]>, REP;
227 //===----------------------------------------------------------------------===//
228 // Move Instructions...
231 let neverHasSideEffects = 1 in
232 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
233 "mov{q}\t{$src, $dst|$dst, $src}", []>;
235 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
236 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
237 "movabs{q}\t{$src, $dst|$dst, $src}",
238 [(set GR64:$dst, imm:$src)]>;
239 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
240 "mov{q}\t{$src, $dst|$dst, $src}",
241 [(set GR64:$dst, i64immSExt32:$src)]>;
244 let canFoldAsLoad = 1 in
245 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
246 "mov{q}\t{$src, $dst|$dst, $src}",
247 [(set GR64:$dst, (load addr:$src))]>;
249 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
250 "mov{q}\t{$src, $dst|$dst, $src}",
251 [(store GR64:$src, addr:$dst)]>;
252 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
253 "mov{q}\t{$src, $dst|$dst, $src}",
254 [(store i64immSExt32:$src, addr:$dst)]>;
256 // Sign/Zero extenders
258 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
259 "movs{bq|x}\t{$src, $dst|$dst, $src}",
260 [(set GR64:$dst, (sext GR8:$src))]>, TB;
261 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
262 "movs{bq|x}\t{$src, $dst|$dst, $src}",
263 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
264 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
265 "movs{wq|x}\t{$src, $dst|$dst, $src}",
266 [(set GR64:$dst, (sext GR16:$src))]>, TB;
267 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
268 "movs{wq|x}\t{$src, $dst|$dst, $src}",
269 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
270 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
271 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
272 [(set GR64:$dst, (sext GR32:$src))]>;
273 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
274 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
275 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
277 // Use movzbl instead of movzbq when the destination is a register; it's
278 // equivalent due to implicit zero-extending, and it has a smaller encoding.
279 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
280 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
281 [(set GR64:$dst, (zext GR8:$src))]>, TB;
282 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
283 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
284 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
285 // Use movzwl instead of movzwq when the destination is a register; it's
286 // equivalent due to implicit zero-extending, and it has a smaller encoding.
287 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
288 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
289 [(set GR64:$dst, (zext GR16:$src))]>, TB;
290 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
291 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
292 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
294 // There's no movzlq instruction, but movl can be used for this purpose, using
295 // implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
296 // extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
297 // zero-extension, however this isn't possible when the 32-bit value is
298 // defined by a truncate or is copied from something where the high bits aren't
299 // necessarily all zero. In such cases, we fall back to these explicit zext
301 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
302 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
303 [(set GR64:$dst, (zext GR32:$src))]>;
304 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
305 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
306 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
308 // Any instruction that defines a 32-bit result leaves the high half of the
309 // register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
310 // be copying from a truncate, but any other 32-bit operation will zero-extend
312 def def32 : PatLeaf<(i32 GR32:$src), [{
313 return N->getOpcode() != ISD::TRUNCATE &&
314 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
315 N->getOpcode() != ISD::CopyFromReg;
318 // In the case of a 32-bit def that is known to implicitly zero-extend,
319 // we can use a SUBREG_TO_REG.
320 def : Pat<(i64 (zext def32:$src)),
321 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
323 let neverHasSideEffects = 1 in {
324 let Defs = [RAX], Uses = [EAX] in
325 def CDQE : RI<0x98, RawFrm, (outs), (ins),
326 "{cltq|cdqe}", []>; // RAX = signext(EAX)
328 let Defs = [RAX,RDX], Uses = [RAX] in
329 def CQO : RI<0x99, RawFrm, (outs), (ins),
330 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
333 //===----------------------------------------------------------------------===//
334 // Arithmetic Instructions...
337 let Defs = [EFLAGS] in {
338 let isTwoAddress = 1 in {
339 let isConvertibleToThreeAddress = 1 in {
340 let isCommutable = 1 in
341 // Register-Register Addition
342 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
343 "add{q}\t{$src2, $dst|$dst, $src2}",
344 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
347 // Register-Integer Addition
348 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
349 "add{q}\t{$src2, $dst|$dst, $src2}",
350 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
352 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
353 "add{q}\t{$src2, $dst|$dst, $src2}",
354 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
356 } // isConvertibleToThreeAddress
358 // Register-Memory Addition
359 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
360 "add{q}\t{$src2, $dst|$dst, $src2}",
361 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
365 // Memory-Register Addition
366 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
367 "add{q}\t{$src2, $dst|$dst, $src2}",
368 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
370 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
371 "add{q}\t{$src2, $dst|$dst, $src2}",
372 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
374 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
375 "add{q}\t{$src2, $dst|$dst, $src2}",
376 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
379 let Uses = [EFLAGS] in {
380 let isTwoAddress = 1 in {
381 let isCommutable = 1 in
382 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
383 "adc{q}\t{$src2, $dst|$dst, $src2}",
384 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
386 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
387 "adc{q}\t{$src2, $dst|$dst, $src2}",
388 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
390 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
391 "adc{q}\t{$src2, $dst|$dst, $src2}",
392 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
393 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
394 "adc{q}\t{$src2, $dst|$dst, $src2}",
395 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
398 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
399 "adc{q}\t{$src2, $dst|$dst, $src2}",
400 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
401 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
402 "adc{q}\t{$src2, $dst|$dst, $src2}",
403 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
404 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
405 "adc{q}\t{$src2, $dst|$dst, $src2}",
406 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
409 let isTwoAddress = 1 in {
410 // Register-Register Subtraction
411 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
412 "sub{q}\t{$src2, $dst|$dst, $src2}",
413 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
416 // Register-Memory Subtraction
417 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
418 "sub{q}\t{$src2, $dst|$dst, $src2}",
419 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
422 // Register-Integer Subtraction
423 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
424 (ins GR64:$src1, i64i8imm:$src2),
425 "sub{q}\t{$src2, $dst|$dst, $src2}",
426 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
428 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
429 (ins GR64:$src1, i64i32imm:$src2),
430 "sub{q}\t{$src2, $dst|$dst, $src2}",
431 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
435 // Memory-Register Subtraction
436 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
437 "sub{q}\t{$src2, $dst|$dst, $src2}",
438 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
441 // Memory-Integer Subtraction
442 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
443 "sub{q}\t{$src2, $dst|$dst, $src2}",
444 [(store (sub (load addr:$dst), i64immSExt8:$src2),
447 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
448 "sub{q}\t{$src2, $dst|$dst, $src2}",
449 [(store (sub (load addr:$dst), i64immSExt32:$src2),
453 let Uses = [EFLAGS] in {
454 let isTwoAddress = 1 in {
455 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
456 "sbb{q}\t{$src2, $dst|$dst, $src2}",
457 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
459 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
460 "sbb{q}\t{$src2, $dst|$dst, $src2}",
461 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
463 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
464 "sbb{q}\t{$src2, $dst|$dst, $src2}",
465 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
466 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
467 "sbb{q}\t{$src2, $dst|$dst, $src2}",
468 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
471 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
472 "sbb{q}\t{$src2, $dst|$dst, $src2}",
473 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
474 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
475 "sbb{q}\t{$src2, $dst|$dst, $src2}",
476 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
477 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
478 "sbb{q}\t{$src2, $dst|$dst, $src2}",
479 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
483 // Unsigned multiplication
484 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
485 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
486 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
488 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
489 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
491 // Signed multiplication
492 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
493 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
495 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
496 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
499 let Defs = [EFLAGS] in {
500 let isTwoAddress = 1 in {
501 let isCommutable = 1 in
502 // Register-Register Signed Integer Multiplication
503 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
504 (ins GR64:$src1, GR64:$src2),
505 "imul{q}\t{$src2, $dst|$dst, $src2}",
506 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
507 (implicit EFLAGS)]>, TB;
509 // Register-Memory Signed Integer Multiplication
510 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
511 (ins GR64:$src1, i64mem:$src2),
512 "imul{q}\t{$src2, $dst|$dst, $src2}",
513 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
514 (implicit EFLAGS)]>, TB;
517 // Suprisingly enough, these are not two address instructions!
519 // Register-Integer Signed Integer Multiplication
520 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
521 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
522 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
523 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
525 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
526 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
527 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
528 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
531 // Memory-Integer Signed Integer Multiplication
532 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
533 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
534 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
535 [(set GR64:$dst, (mul (load addr:$src1),
538 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
539 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
540 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
541 [(set GR64:$dst, (mul (load addr:$src1),
542 i64immSExt32:$src2)),
546 // Unsigned division / remainder
547 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
548 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
550 // Signed division / remainder
551 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
552 "idiv{q}\t$src", []>;
554 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
556 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
557 "idiv{q}\t$src", []>;
561 // Unary instructions
562 let Defs = [EFLAGS], CodeSize = 2 in {
563 let isTwoAddress = 1 in
564 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
565 [(set GR64:$dst, (ineg GR64:$src)),
567 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
568 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
571 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
572 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
573 [(set GR64:$dst, (add GR64:$src, 1)),
575 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
576 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
579 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
580 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
581 [(set GR64:$dst, (add GR64:$src, -1)),
583 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
584 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
587 // In 64-bit mode, single byte INC and DEC cannot be encoded.
588 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
589 // Can transform into LEA.
590 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
591 [(set GR16:$dst, (add GR16:$src, 1)),
593 OpSize, Requires<[In64BitMode]>;
594 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
595 [(set GR32:$dst, (add GR32:$src, 1)),
597 Requires<[In64BitMode]>;
598 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
599 [(set GR16:$dst, (add GR16:$src, -1)),
601 OpSize, Requires<[In64BitMode]>;
602 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
603 [(set GR32:$dst, (add GR32:$src, -1)),
605 Requires<[In64BitMode]>;
606 } // isConvertibleToThreeAddress
608 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
609 // how to unfold them.
610 let isTwoAddress = 0, CodeSize = 2 in {
611 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
612 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
614 OpSize, Requires<[In64BitMode]>;
615 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
616 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
618 Requires<[In64BitMode]>;
619 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
620 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
622 OpSize, Requires<[In64BitMode]>;
623 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
624 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
626 Requires<[In64BitMode]>;
628 } // Defs = [EFLAGS], CodeSize
631 let Defs = [EFLAGS] in {
632 // Shift instructions
633 let isTwoAddress = 1 in {
635 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
636 "shl{q}\t{%cl, $dst|$dst, %CL}",
637 [(set GR64:$dst, (shl GR64:$src, CL))]>;
638 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
639 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
640 "shl{q}\t{$src2, $dst|$dst, $src2}",
641 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
642 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
647 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
648 "shl{q}\t{%cl, $dst|$dst, %CL}",
649 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
650 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
651 "shl{q}\t{$src, $dst|$dst, $src}",
652 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
653 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
655 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
657 let isTwoAddress = 1 in {
659 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
660 "shr{q}\t{%cl, $dst|$dst, %CL}",
661 [(set GR64:$dst, (srl GR64:$src, CL))]>;
662 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
663 "shr{q}\t{$src2, $dst|$dst, $src2}",
664 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
665 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
667 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
671 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
672 "shr{q}\t{%cl, $dst|$dst, %CL}",
673 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
674 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
675 "shr{q}\t{$src, $dst|$dst, $src}",
676 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
677 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
679 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
681 let isTwoAddress = 1 in {
683 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
684 "sar{q}\t{%cl, $dst|$dst, %CL}",
685 [(set GR64:$dst, (sra GR64:$src, CL))]>;
686 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
687 "sar{q}\t{$src2, $dst|$dst, $src2}",
688 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
689 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
691 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
695 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
696 "sar{q}\t{%cl, $dst|$dst, %CL}",
697 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
698 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
699 "sar{q}\t{$src, $dst|$dst, $src}",
700 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
701 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
703 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
705 // Rotate instructions
706 let isTwoAddress = 1 in {
708 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
709 "rol{q}\t{%cl, $dst|$dst, %CL}",
710 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
711 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
712 "rol{q}\t{$src2, $dst|$dst, $src2}",
713 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
714 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
716 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
720 def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
721 "rol{q}\t{%cl, $dst|$dst, %CL}",
722 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
723 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
724 "rol{q}\t{$src, $dst|$dst, $src}",
725 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
726 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
728 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
730 let isTwoAddress = 1 in {
732 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
733 "ror{q}\t{%cl, $dst|$dst, %CL}",
734 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
735 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
736 "ror{q}\t{$src2, $dst|$dst, $src2}",
737 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
738 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
740 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
744 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
745 "ror{q}\t{%cl, $dst|$dst, %CL}",
746 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
747 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
748 "ror{q}\t{$src, $dst|$dst, $src}",
749 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
750 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
752 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
754 // Double shift instructions (generalizations of rotate)
755 let isTwoAddress = 1 in {
757 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
758 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
759 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
760 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
761 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
762 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
765 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
766 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
767 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
768 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
769 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
772 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
773 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
774 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
775 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
782 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
783 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
784 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
786 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
787 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
788 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
791 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
792 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
793 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
794 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
795 (i8 imm:$src3)), addr:$dst)]>,
797 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
798 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
799 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
800 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
801 (i8 imm:$src3)), addr:$dst)]>,
805 //===----------------------------------------------------------------------===//
806 // Logical Instructions...
809 let isTwoAddress = 1 , AddedComplexity = 15 in
810 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
811 [(set GR64:$dst, (not GR64:$src))]>;
812 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
813 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
815 let Defs = [EFLAGS] in {
816 let isTwoAddress = 1 in {
817 let isCommutable = 1 in
818 def AND64rr : RI<0x21, MRMDestReg,
819 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
820 "and{q}\t{$src2, $dst|$dst, $src2}",
821 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
823 def AND64rm : RI<0x23, MRMSrcMem,
824 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
825 "and{q}\t{$src2, $dst|$dst, $src2}",
826 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
828 def AND64ri8 : RIi8<0x83, MRM4r,
829 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
830 "and{q}\t{$src2, $dst|$dst, $src2}",
831 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
833 def AND64ri32 : RIi32<0x81, MRM4r,
834 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
835 "and{q}\t{$src2, $dst|$dst, $src2}",
836 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
840 def AND64mr : RI<0x21, MRMDestMem,
841 (outs), (ins i64mem:$dst, GR64:$src),
842 "and{q}\t{$src, $dst|$dst, $src}",
843 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
845 def AND64mi8 : RIi8<0x83, MRM4m,
846 (outs), (ins i64mem:$dst, i64i8imm :$src),
847 "and{q}\t{$src, $dst|$dst, $src}",
848 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
850 def AND64mi32 : RIi32<0x81, MRM4m,
851 (outs), (ins i64mem:$dst, i64i32imm:$src),
852 "and{q}\t{$src, $dst|$dst, $src}",
853 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
856 let isTwoAddress = 1 in {
857 let isCommutable = 1 in
858 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
859 "or{q}\t{$src2, $dst|$dst, $src2}",
860 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
862 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
863 "or{q}\t{$src2, $dst|$dst, $src2}",
864 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
866 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
867 "or{q}\t{$src2, $dst|$dst, $src2}",
868 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
870 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
871 "or{q}\t{$src2, $dst|$dst, $src2}",
872 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
876 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
877 "or{q}\t{$src, $dst|$dst, $src}",
878 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
880 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
881 "or{q}\t{$src, $dst|$dst, $src}",
882 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
884 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
885 "or{q}\t{$src, $dst|$dst, $src}",
886 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
889 let isTwoAddress = 1 in {
890 let isCommutable = 1 in
891 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
892 "xor{q}\t{$src2, $dst|$dst, $src2}",
893 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
895 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
896 "xor{q}\t{$src2, $dst|$dst, $src2}",
897 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
899 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
900 "xor{q}\t{$src2, $dst|$dst, $src2}",
901 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
903 def XOR64ri32 : RIi32<0x81, MRM6r,
904 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
905 "xor{q}\t{$src2, $dst|$dst, $src2}",
906 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
910 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
911 "xor{q}\t{$src, $dst|$dst, $src}",
912 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
914 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
915 "xor{q}\t{$src, $dst|$dst, $src}",
916 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
918 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
919 "xor{q}\t{$src, $dst|$dst, $src}",
920 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
924 //===----------------------------------------------------------------------===//
925 // Comparison Instructions...
928 // Integer comparison
929 let Defs = [EFLAGS] in {
930 let isCommutable = 1 in
931 def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
932 "test{q}\t{$src2, $src1|$src1, $src2}",
933 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
935 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
936 "test{q}\t{$src2, $src1|$src1, $src2}",
937 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
939 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
940 (ins GR64:$src1, i64i32imm:$src2),
941 "test{q}\t{$src2, $src1|$src1, $src2}",
942 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
944 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
945 (ins i64mem:$src1, i64i32imm:$src2),
946 "test{q}\t{$src2, $src1|$src1, $src2}",
947 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
950 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
951 "cmp{q}\t{$src2, $src1|$src1, $src2}",
952 [(X86cmp GR64:$src1, GR64:$src2),
954 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
955 "cmp{q}\t{$src2, $src1|$src1, $src2}",
956 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
958 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
959 "cmp{q}\t{$src2, $src1|$src1, $src2}",
960 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
962 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
963 "cmp{q}\t{$src2, $src1|$src1, $src2}",
964 [(X86cmp GR64:$src1, i64immSExt8:$src2),
966 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
967 "cmp{q}\t{$src2, $src1|$src1, $src2}",
968 [(X86cmp GR64:$src1, i64immSExt32:$src2),
970 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
971 "cmp{q}\t{$src2, $src1|$src1, $src2}",
972 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
974 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
975 (ins i64mem:$src1, i64i32imm:$src2),
976 "cmp{q}\t{$src2, $src1|$src1, $src2}",
977 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
982 // TODO: BTC, BTR, and BTS
983 let Defs = [EFLAGS] in {
984 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
985 "bt{q}\t{$src2, $src1|$src1, $src2}",
986 [(X86bt GR64:$src1, GR64:$src2),
987 (implicit EFLAGS)]>, TB;
989 // Unlike with the register+register form, the memory+register form of the
990 // bt instruction does not ignore the high bits of the index. From ISel's
991 // perspective, this is pretty bizarre. Disable these instructions for now.
992 //def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
993 // "bt{q}\t{$src2, $src1|$src1, $src2}",
994 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
995 // (implicit EFLAGS)]>, TB;
997 def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
998 "bt{q}\t{$src2, $src1|$src1, $src2}",
999 [(X86bt GR64:$src1, i64immSExt8:$src2),
1000 (implicit EFLAGS)]>, TB;
1001 // Note that these instructions don't need FastBTMem because that
1002 // only applies when the other operand is in a register. When it's
1003 // an immediate, bt is still fast.
1004 def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1005 "bt{q}\t{$src2, $src1|$src1, $src2}",
1006 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1007 (implicit EFLAGS)]>, TB;
1008 } // Defs = [EFLAGS]
1010 // Conditional moves
1011 let Uses = [EFLAGS], isTwoAddress = 1 in {
1012 let isCommutable = 1 in {
1013 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
1014 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1015 "cmovb\t{$src2, $dst|$dst, $src2}",
1016 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1017 X86_COND_B, EFLAGS))]>, TB;
1018 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
1019 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1020 "cmovae\t{$src2, $dst|$dst, $src2}",
1021 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1022 X86_COND_AE, EFLAGS))]>, TB;
1023 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
1024 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1025 "cmove\t{$src2, $dst|$dst, $src2}",
1026 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1027 X86_COND_E, EFLAGS))]>, TB;
1028 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
1029 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1030 "cmovne\t{$src2, $dst|$dst, $src2}",
1031 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1032 X86_COND_NE, EFLAGS))]>, TB;
1033 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
1034 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1035 "cmovbe\t{$src2, $dst|$dst, $src2}",
1036 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1037 X86_COND_BE, EFLAGS))]>, TB;
1038 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
1039 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1040 "cmova\t{$src2, $dst|$dst, $src2}",
1041 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1042 X86_COND_A, EFLAGS))]>, TB;
1043 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
1044 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1045 "cmovl\t{$src2, $dst|$dst, $src2}",
1046 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1047 X86_COND_L, EFLAGS))]>, TB;
1048 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
1049 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1050 "cmovge\t{$src2, $dst|$dst, $src2}",
1051 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1052 X86_COND_GE, EFLAGS))]>, TB;
1053 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
1054 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1055 "cmovle\t{$src2, $dst|$dst, $src2}",
1056 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1057 X86_COND_LE, EFLAGS))]>, TB;
1058 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
1059 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1060 "cmovg\t{$src2, $dst|$dst, $src2}",
1061 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1062 X86_COND_G, EFLAGS))]>, TB;
1063 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1064 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1065 "cmovs\t{$src2, $dst|$dst, $src2}",
1066 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1067 X86_COND_S, EFLAGS))]>, TB;
1068 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1069 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1070 "cmovns\t{$src2, $dst|$dst, $src2}",
1071 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1072 X86_COND_NS, EFLAGS))]>, TB;
1073 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1074 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1075 "cmovp\t{$src2, $dst|$dst, $src2}",
1076 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1077 X86_COND_P, EFLAGS))]>, TB;
1078 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1079 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1080 "cmovnp\t{$src2, $dst|$dst, $src2}",
1081 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1082 X86_COND_NP, EFLAGS))]>, TB;
1083 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1084 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1085 "cmovo\t{$src2, $dst|$dst, $src2}",
1086 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1087 X86_COND_O, EFLAGS))]>, TB;
1088 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1089 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1090 "cmovno\t{$src2, $dst|$dst, $src2}",
1091 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1092 X86_COND_NO, EFLAGS))]>, TB;
1093 } // isCommutable = 1
1095 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1096 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1097 "cmovb\t{$src2, $dst|$dst, $src2}",
1098 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1099 X86_COND_B, EFLAGS))]>, TB;
1100 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1101 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1102 "cmovae\t{$src2, $dst|$dst, $src2}",
1103 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1104 X86_COND_AE, EFLAGS))]>, TB;
1105 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1106 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1107 "cmove\t{$src2, $dst|$dst, $src2}",
1108 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1109 X86_COND_E, EFLAGS))]>, TB;
1110 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1111 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1112 "cmovne\t{$src2, $dst|$dst, $src2}",
1113 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1114 X86_COND_NE, EFLAGS))]>, TB;
1115 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1116 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1117 "cmovbe\t{$src2, $dst|$dst, $src2}",
1118 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1119 X86_COND_BE, EFLAGS))]>, TB;
1120 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1121 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1122 "cmova\t{$src2, $dst|$dst, $src2}",
1123 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1124 X86_COND_A, EFLAGS))]>, TB;
1125 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1126 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1127 "cmovl\t{$src2, $dst|$dst, $src2}",
1128 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1129 X86_COND_L, EFLAGS))]>, TB;
1130 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1131 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1132 "cmovge\t{$src2, $dst|$dst, $src2}",
1133 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1134 X86_COND_GE, EFLAGS))]>, TB;
1135 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1136 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1137 "cmovle\t{$src2, $dst|$dst, $src2}",
1138 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1139 X86_COND_LE, EFLAGS))]>, TB;
1140 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1141 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1142 "cmovg\t{$src2, $dst|$dst, $src2}",
1143 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1144 X86_COND_G, EFLAGS))]>, TB;
1145 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1146 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1147 "cmovs\t{$src2, $dst|$dst, $src2}",
1148 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1149 X86_COND_S, EFLAGS))]>, TB;
1150 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1151 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1152 "cmovns\t{$src2, $dst|$dst, $src2}",
1153 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1154 X86_COND_NS, EFLAGS))]>, TB;
1155 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1156 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1157 "cmovp\t{$src2, $dst|$dst, $src2}",
1158 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1159 X86_COND_P, EFLAGS))]>, TB;
1160 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1161 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1162 "cmovnp\t{$src2, $dst|$dst, $src2}",
1163 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1164 X86_COND_NP, EFLAGS))]>, TB;
1165 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1166 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1167 "cmovo\t{$src2, $dst|$dst, $src2}",
1168 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1169 X86_COND_O, EFLAGS))]>, TB;
1170 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1171 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1172 "cmovno\t{$src2, $dst|$dst, $src2}",
1173 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1174 X86_COND_NO, EFLAGS))]>, TB;
1177 //===----------------------------------------------------------------------===//
1178 // Conversion Instructions...
1181 // f64 -> signed i64
1182 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1183 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1185 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1186 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1187 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1188 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1189 (load addr:$src)))]>;
1190 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1191 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1192 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1193 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1194 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1195 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1196 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1197 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1199 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1200 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1201 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1203 (int_x86_sse2_cvttsd2si64
1204 (load addr:$src)))]>;
1206 // Signed i64 -> f64
1207 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1208 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1209 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1210 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1211 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1212 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1214 let isTwoAddress = 1 in {
1215 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1216 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1217 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1219 (int_x86_sse2_cvtsi642sd VR128:$src1,
1221 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1222 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1223 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1225 (int_x86_sse2_cvtsi642sd VR128:$src1,
1226 (loadi64 addr:$src2)))]>;
1229 // Signed i64 -> f32
1230 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1231 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1232 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1233 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1234 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1235 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1237 let isTwoAddress = 1 in {
1238 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1239 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1240 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1242 (int_x86_sse_cvtsi642ss VR128:$src1,
1244 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1245 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1246 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1248 (int_x86_sse_cvtsi642ss VR128:$src1,
1249 (loadi64 addr:$src2)))]>;
1252 // f32 -> signed i64
1253 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1254 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1256 (int_x86_sse_cvtss2si64 VR128:$src))]>;
1257 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1258 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1259 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1260 (load addr:$src)))]>;
1261 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1262 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1263 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1264 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1265 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1266 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1267 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1268 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1270 (int_x86_sse_cvttss2si64 VR128:$src))]>;
1271 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1272 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1274 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1276 //===----------------------------------------------------------------------===//
1277 // Alias Instructions
1278 //===----------------------------------------------------------------------===//
1280 // Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1281 // equivalent due to implicit zero-extending, and it sometimes has a smaller
1283 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1284 // FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1285 // when we have a better way to specify isel priority.
1286 let Defs = [EFLAGS], AddedComplexity = 1,
1287 isReMaterializable = 1, isAsCheapAsAMove = 1 in
1288 def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1289 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1290 [(set GR64:$dst, 0)]>;
1292 // Materialize i64 constant where top 32-bits are zero.
1293 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1294 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1295 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1296 [(set GR64:$dst, i64immZExt32:$src)]>;
1298 //===----------------------------------------------------------------------===//
1299 // Thread Local Storage Instructions
1300 //===----------------------------------------------------------------------===//
1302 def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
1303 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
1304 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
1306 let AddedComplexity = 5 in
1307 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1308 "movq\t%gs:$src, $dst",
1309 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1311 //===----------------------------------------------------------------------===//
1312 // Atomic Instructions
1313 //===----------------------------------------------------------------------===//
1315 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1316 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1317 "lock\n\tcmpxchgq\t$swap,$ptr",
1318 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1321 let Constraints = "$val = $dst" in {
1322 let Defs = [EFLAGS] in
1323 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1324 "lock\n\txadd\t$val, $ptr",
1325 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1327 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1329 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1332 // Atomic exchange, and, or, xor
1333 let Constraints = "$val = $dst", Defs = [EFLAGS],
1334 usesCustomDAGSchedInserter = 1 in {
1335 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1336 "#ATOMAND64 PSEUDO!",
1337 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1338 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1339 "#ATOMOR64 PSEUDO!",
1340 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1341 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1342 "#ATOMXOR64 PSEUDO!",
1343 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1344 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1345 "#ATOMNAND64 PSEUDO!",
1346 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1347 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1348 "#ATOMMIN64 PSEUDO!",
1349 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1350 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1351 "#ATOMMAX64 PSEUDO!",
1352 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1353 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1354 "#ATOMUMIN64 PSEUDO!",
1355 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1356 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1357 "#ATOMUMAX64 PSEUDO!",
1358 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1361 //===----------------------------------------------------------------------===//
1362 // Non-Instruction Patterns
1363 //===----------------------------------------------------------------------===//
1365 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
1366 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1367 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1368 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1369 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1370 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1371 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1372 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1373 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1375 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1376 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1377 Requires<[SmallCode, IsStatic]>;
1378 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1379 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1380 Requires<[SmallCode, IsStatic]>;
1381 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1382 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1383 Requires<[SmallCode, IsStatic]>;
1384 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1385 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1386 Requires<[SmallCode, IsStatic]>;
1389 // Direct PC relative function call for small code model. 32-bit displacement
1390 // sign extended to 64-bit.
1391 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1392 (CALL64pcrel32 tglobaladdr:$dst)>;
1393 def : Pat<(X86call (i64 texternalsym:$dst)),
1394 (CALL64pcrel32 texternalsym:$dst)>;
1396 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1397 (CALL64pcrel32 tglobaladdr:$dst)>;
1398 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1399 (CALL64pcrel32 texternalsym:$dst)>;
1401 def : Pat<(X86tailcall GR64:$dst),
1402 (CALL64r GR64:$dst)>;
1406 def : Pat<(X86tailcall GR32:$dst),
1408 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1410 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1413 def : Pat<(X86tcret GR64:$dst, imm:$off),
1414 (TCRETURNri64 GR64:$dst, imm:$off)>;
1416 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1417 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1419 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1420 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1424 // TEST R,R is smaller than CMP R,0
1425 def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
1426 (TEST64rr GR64:$src1, GR64:$src1)>;
1428 // Conditional moves with folded loads with operands swapped and conditions
1430 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1431 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1432 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1433 (CMOVB64rm GR64:$src2, addr:$src1)>;
1434 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1435 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1436 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1437 (CMOVE64rm GR64:$src2, addr:$src1)>;
1438 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1439 (CMOVA64rm GR64:$src2, addr:$src1)>;
1440 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1441 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1442 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1443 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1444 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1445 (CMOVL64rm GR64:$src2, addr:$src1)>;
1446 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1447 (CMOVG64rm GR64:$src2, addr:$src1)>;
1448 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1449 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1450 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1451 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1452 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1453 (CMOVP64rm GR64:$src2, addr:$src1)>;
1454 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1455 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1456 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1457 (CMOVS64rm GR64:$src2, addr:$src1)>;
1458 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1459 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1460 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1461 (CMOVO64rm GR64:$src2, addr:$src1)>;
1463 // zextload bool -> zextload byte
1464 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1467 // When extloading from 16-bit and smaller memory locations into 64-bit registers,
1468 // use zero-extending loads so that the entire 64-bit register is defined, avoiding
1469 // partial-register updates.
1470 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1471 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1472 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1473 // For other extloads, use subregs, since the high contents of the register are
1474 // defined after an extload.
1475 def : Pat<(extloadi64i32 addr:$src),
1476 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1478 def : Pat<(extloadi16i1 addr:$src),
1479 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1481 Requires<[In64BitMode]>;
1482 def : Pat<(extloadi16i8 addr:$src),
1483 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1485 Requires<[In64BitMode]>;
1488 def : Pat<(i64 (anyext GR8:$src)),
1489 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1490 def : Pat<(i64 (anyext GR16:$src)),
1491 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
1492 def : Pat<(i64 (anyext GR32:$src)),
1493 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
1494 def : Pat<(i16 (anyext GR8:$src)),
1495 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1496 Requires<[In64BitMode]>;
1497 def : Pat<(i32 (anyext GR8:$src)),
1498 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1499 Requires<[In64BitMode]>;
1501 //===----------------------------------------------------------------------===//
1503 //===----------------------------------------------------------------------===//
1505 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1506 // +128 doesn't, so in this special case use a sub instead of an add.
1507 def : Pat<(add GR64:$src1, 128),
1508 (SUB64ri8 GR64:$src1, -128)>;
1509 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1510 (SUB64mi8 addr:$dst, -128)>;
1512 // The same trick applies for 32-bit immediate fields in 64-bit
1514 def : Pat<(add GR64:$src1, 0x0000000080000000),
1515 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1516 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1517 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1519 // r & (2^32-1) ==> movz
1520 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1521 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1522 // r & (2^16-1) ==> movz
1523 def : Pat<(and GR64:$src, 0xffff),
1524 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1525 // r & (2^8-1) ==> movz
1526 def : Pat<(and GR64:$src, 0xff),
1527 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1528 // r & (2^8-1) ==> movz
1529 def : Pat<(and GR32:$src1, 0xff),
1530 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1531 Requires<[In64BitMode]>;
1532 // r & (2^8-1) ==> movz
1533 def : Pat<(and GR16:$src1, 0xff),
1534 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1535 Requires<[In64BitMode]>;
1537 // sext_inreg patterns
1538 def : Pat<(sext_inreg GR64:$src, i32),
1539 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1540 def : Pat<(sext_inreg GR64:$src, i16),
1541 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1542 def : Pat<(sext_inreg GR64:$src, i8),
1543 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1544 def : Pat<(sext_inreg GR32:$src, i8),
1545 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1546 Requires<[In64BitMode]>;
1547 def : Pat<(sext_inreg GR16:$src, i8),
1548 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1549 Requires<[In64BitMode]>;
1552 def : Pat<(i32 (trunc GR64:$src)),
1553 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1554 def : Pat<(i16 (trunc GR64:$src)),
1555 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1556 def : Pat<(i8 (trunc GR64:$src)),
1557 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1558 def : Pat<(i8 (trunc GR32:$src)),
1559 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1560 Requires<[In64BitMode]>;
1561 def : Pat<(i8 (trunc GR16:$src)),
1562 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1563 Requires<[In64BitMode]>;
1565 // (shl x, 1) ==> (add x, x)
1566 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1568 // (shl x (and y, 63)) ==> (shl x, y)
1569 def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1570 (SHL64rCL GR64:$src1)>;
1571 def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1572 (SHL64mCL addr:$dst)>;
1574 def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1575 (SHR64rCL GR64:$src1)>;
1576 def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1577 (SHR64mCL addr:$dst)>;
1579 def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1580 (SAR64rCL GR64:$src1)>;
1581 def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1582 (SAR64mCL addr:$dst)>;
1584 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1585 def : Pat<(or (srl GR64:$src1, CL:$amt),
1586 (shl GR64:$src2, (sub 64, CL:$amt))),
1587 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1589 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1590 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1591 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1593 def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1594 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1595 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1597 def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1598 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1600 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1602 def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1603 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1605 def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1606 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1607 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1609 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1610 def : Pat<(or (shl GR64:$src1, CL:$amt),
1611 (srl GR64:$src2, (sub 64, CL:$amt))),
1612 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1614 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1615 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1616 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1618 def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1619 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1620 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1622 def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1623 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1625 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1627 def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1628 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1630 def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1631 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1632 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1634 // X86 specific add which produces a flag.
1635 def : Pat<(addc GR64:$src1, GR64:$src2),
1636 (ADD64rr GR64:$src1, GR64:$src2)>;
1637 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1638 (ADD64rm GR64:$src1, addr:$src2)>;
1639 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1640 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1641 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1642 (ADD64ri32 GR64:$src1, imm:$src2)>;
1644 def : Pat<(subc GR64:$src1, GR64:$src2),
1645 (SUB64rr GR64:$src1, GR64:$src2)>;
1646 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1647 (SUB64rm GR64:$src1, addr:$src2)>;
1648 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1649 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1650 def : Pat<(subc GR64:$src1, imm:$src2),
1651 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1653 //===----------------------------------------------------------------------===//
1654 // EFLAGS-defining Patterns
1655 //===----------------------------------------------------------------------===//
1657 // Register-Register Addition with EFLAGS result
1658 def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
1660 (ADD64rr GR64:$src1, GR64:$src2)>;
1662 // Register-Integer Addition with EFLAGS result
1663 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
1665 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1666 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
1668 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
1670 // Register-Memory Addition with EFLAGS result
1671 def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
1673 (ADD64rm GR64:$src1, addr:$src2)>;
1675 // Memory-Register Addition with EFLAGS result
1676 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
1679 (ADD64mr addr:$dst, GR64:$src2)>;
1680 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1683 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
1684 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1687 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
1689 // Register-Register Subtraction with EFLAGS result
1690 def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
1692 (SUB64rr GR64:$src1, GR64:$src2)>;
1694 // Register-Memory Subtraction with EFLAGS result
1695 def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
1697 (SUB64rm GR64:$src1, addr:$src2)>;
1699 // Register-Integer Subtraction with EFLAGS result
1700 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
1702 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1703 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
1705 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1707 // Memory-Register Subtraction with EFLAGS result
1708 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
1711 (SUB64mr addr:$dst, GR64:$src2)>;
1713 // Memory-Integer Subtraction with EFLAGS result
1714 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1717 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
1718 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1721 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
1723 // Register-Register Signed Integer Multiplication with EFLAGS result
1724 def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
1726 (IMUL64rr GR64:$src1, GR64:$src2)>;
1728 // Register-Memory Signed Integer Multiplication with EFLAGS result
1729 def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
1731 (IMUL64rm GR64:$src1, addr:$src2)>;
1733 // Register-Integer Signed Integer Multiplication with EFLAGS result
1734 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
1736 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
1737 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
1739 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
1741 // Memory-Integer Signed Integer Multiplication with EFLAGS result
1742 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
1744 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
1745 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
1747 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
1749 // INC and DEC with EFLAGS result. Note that these do not set CF.
1750 def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1751 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1752 def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1754 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1755 def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1756 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1757 def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1759 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1761 def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1762 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1763 def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1765 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1766 def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1767 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1768 def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1770 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1772 def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1773 (INC64r GR64:$src)>;
1774 def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1776 (INC64m addr:$dst)>;
1777 def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1778 (DEC64r GR64:$src)>;
1779 def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1781 (DEC64m addr:$dst)>;
1783 //===----------------------------------------------------------------------===//
1784 // X86-64 SSE Instructions
1785 //===----------------------------------------------------------------------===//
1787 // Move instructions...
1789 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
1790 "mov{d|q}\t{$src, $dst|$dst, $src}",
1792 (v2i64 (scalar_to_vector GR64:$src)))]>;
1793 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
1794 "mov{d|q}\t{$src, $dst|$dst, $src}",
1795 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1798 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1799 "mov{d|q}\t{$src, $dst|$dst, $src}",
1800 [(set FR64:$dst, (bitconvert GR64:$src))]>;
1801 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1802 "movq\t{$src, $dst|$dst, $src}",
1803 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1805 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
1806 "mov{d|q}\t{$src, $dst|$dst, $src}",
1807 [(set GR64:$dst, (bitconvert FR64:$src))]>;
1808 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
1809 "movq\t{$src, $dst|$dst, $src}",
1810 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
1812 //===----------------------------------------------------------------------===//
1813 // X86-64 SSE4.1 Instructions
1814 //===----------------------------------------------------------------------===//
1816 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1817 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
1818 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
1819 (ins VR128:$src1, i32i8imm:$src2),
1820 !strconcat(OpcodeStr,
1821 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1823 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
1824 def mr : SS4AIi8<opc, MRMDestMem, (outs),
1825 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1826 !strconcat(OpcodeStr,
1827 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1828 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1829 addr:$dst)]>, OpSize, REX_W;
1832 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1834 let isTwoAddress = 1 in {
1835 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
1836 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
1837 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1838 !strconcat(OpcodeStr,
1839 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1841 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1843 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
1844 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1845 !strconcat(OpcodeStr,
1846 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1848 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1849 imm:$src3)))]>, OpSize, REX_W;
1853 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;