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. We need this because the seeming alternative for
296 // implementing zext from 32 to 64, an EXTRACT_SUBREG/SUBREG_TO_REG pair, isn't
297 // safe because both instructions could be optimized away in the
298 // register-to-register case, leaving nothing behind to do the zero extension.
299 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
300 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
301 [(set GR64:$dst, (zext GR32:$src))]>;
302 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
303 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
304 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
306 let neverHasSideEffects = 1 in {
307 let Defs = [RAX], Uses = [EAX] in
308 def CDQE : RI<0x98, RawFrm, (outs), (ins),
309 "{cltq|cdqe}", []>; // RAX = signext(EAX)
311 let Defs = [RAX,RDX], Uses = [RAX] in
312 def CQO : RI<0x99, RawFrm, (outs), (ins),
313 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
316 //===----------------------------------------------------------------------===//
317 // Arithmetic Instructions...
320 let Defs = [EFLAGS] in {
321 let isTwoAddress = 1 in {
322 let isConvertibleToThreeAddress = 1 in {
323 let isCommutable = 1 in
324 // Register-Register Addition
325 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
326 "add{q}\t{$src2, $dst|$dst, $src2}",
327 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
330 // Register-Integer Addition
331 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
332 "add{q}\t{$src2, $dst|$dst, $src2}",
333 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
335 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
336 "add{q}\t{$src2, $dst|$dst, $src2}",
337 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
339 } // isConvertibleToThreeAddress
341 // Register-Memory Addition
342 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
343 "add{q}\t{$src2, $dst|$dst, $src2}",
344 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
348 // Memory-Register Addition
349 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
350 "add{q}\t{$src2, $dst|$dst, $src2}",
351 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
353 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
354 "add{q}\t{$src2, $dst|$dst, $src2}",
355 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
357 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
358 "add{q}\t{$src2, $dst|$dst, $src2}",
359 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
362 let Uses = [EFLAGS] in {
363 let isTwoAddress = 1 in {
364 let isCommutable = 1 in
365 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
366 "adc{q}\t{$src2, $dst|$dst, $src2}",
367 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
369 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
370 "adc{q}\t{$src2, $dst|$dst, $src2}",
371 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
373 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
374 "adc{q}\t{$src2, $dst|$dst, $src2}",
375 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
376 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
377 "adc{q}\t{$src2, $dst|$dst, $src2}",
378 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
381 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
382 "adc{q}\t{$src2, $dst|$dst, $src2}",
383 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
384 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
385 "adc{q}\t{$src2, $dst|$dst, $src2}",
386 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
387 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
388 "adc{q}\t{$src2, $dst|$dst, $src2}",
389 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
392 let isTwoAddress = 1 in {
393 // Register-Register Subtraction
394 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
395 "sub{q}\t{$src2, $dst|$dst, $src2}",
396 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
399 // Register-Memory Subtraction
400 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
401 "sub{q}\t{$src2, $dst|$dst, $src2}",
402 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
405 // Register-Integer Subtraction
406 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
407 (ins GR64:$src1, i64i8imm:$src2),
408 "sub{q}\t{$src2, $dst|$dst, $src2}",
409 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
411 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
412 (ins GR64:$src1, i64i32imm:$src2),
413 "sub{q}\t{$src2, $dst|$dst, $src2}",
414 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
418 // Memory-Register Subtraction
419 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
420 "sub{q}\t{$src2, $dst|$dst, $src2}",
421 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
424 // Memory-Integer Subtraction
425 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
426 "sub{q}\t{$src2, $dst|$dst, $src2}",
427 [(store (sub (load addr:$dst), i64immSExt8:$src2),
430 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
431 "sub{q}\t{$src2, $dst|$dst, $src2}",
432 [(store (sub (load addr:$dst), i64immSExt32:$src2),
436 let Uses = [EFLAGS] in {
437 let isTwoAddress = 1 in {
438 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
439 "sbb{q}\t{$src2, $dst|$dst, $src2}",
440 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
442 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
443 "sbb{q}\t{$src2, $dst|$dst, $src2}",
444 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
446 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
447 "sbb{q}\t{$src2, $dst|$dst, $src2}",
448 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
449 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
450 "sbb{q}\t{$src2, $dst|$dst, $src2}",
451 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
454 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
455 "sbb{q}\t{$src2, $dst|$dst, $src2}",
456 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
457 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
458 "sbb{q}\t{$src2, $dst|$dst, $src2}",
459 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
460 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
461 "sbb{q}\t{$src2, $dst|$dst, $src2}",
462 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
466 // Unsigned multiplication
467 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
468 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
469 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
471 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
472 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
474 // Signed multiplication
475 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
476 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
478 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
479 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
482 let Defs = [EFLAGS] in {
483 let isTwoAddress = 1 in {
484 let isCommutable = 1 in
485 // Register-Register Signed Integer Multiplication
486 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
487 (ins GR64:$src1, GR64:$src2),
488 "imul{q}\t{$src2, $dst|$dst, $src2}",
489 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
490 (implicit EFLAGS)]>, TB;
492 // Register-Memory Signed Integer Multiplication
493 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
494 (ins GR64:$src1, i64mem:$src2),
495 "imul{q}\t{$src2, $dst|$dst, $src2}",
496 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
497 (implicit EFLAGS)]>, TB;
500 // Suprisingly enough, these are not two address instructions!
502 // Register-Integer Signed Integer Multiplication
503 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
504 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
505 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
506 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
508 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
509 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
510 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
511 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
514 // Memory-Integer Signed Integer Multiplication
515 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
516 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
517 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
518 [(set GR64:$dst, (mul (load addr:$src1),
521 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
522 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
523 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
524 [(set GR64:$dst, (mul (load addr:$src1),
525 i64immSExt32:$src2)),
529 // Unsigned division / remainder
530 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
531 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
533 // Signed division / remainder
534 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
535 "idiv{q}\t$src", []>;
537 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
539 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
540 "idiv{q}\t$src", []>;
544 // Unary instructions
545 let Defs = [EFLAGS], CodeSize = 2 in {
546 let isTwoAddress = 1 in
547 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
548 [(set GR64:$dst, (ineg GR64:$src)),
550 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
551 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
554 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
555 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
556 [(set GR64:$dst, (add GR64:$src, 1)),
558 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
559 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
562 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
563 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
564 [(set GR64:$dst, (add GR64:$src, -1)),
566 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
567 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
570 // In 64-bit mode, single byte INC and DEC cannot be encoded.
571 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
572 // Can transform into LEA.
573 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
574 [(set GR16:$dst, (add GR16:$src, 1)),
576 OpSize, Requires<[In64BitMode]>;
577 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
578 [(set GR32:$dst, (add GR32:$src, 1)),
580 Requires<[In64BitMode]>;
581 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
582 [(set GR16:$dst, (add GR16:$src, -1)),
584 OpSize, Requires<[In64BitMode]>;
585 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
586 [(set GR32:$dst, (add GR32:$src, -1)),
588 Requires<[In64BitMode]>;
589 } // isConvertibleToThreeAddress
591 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
592 // how to unfold them.
593 let isTwoAddress = 0, CodeSize = 2 in {
594 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
595 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
597 OpSize, Requires<[In64BitMode]>;
598 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
599 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
601 Requires<[In64BitMode]>;
602 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
603 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
605 OpSize, Requires<[In64BitMode]>;
606 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
607 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
609 Requires<[In64BitMode]>;
611 } // Defs = [EFLAGS], CodeSize
614 let Defs = [EFLAGS] in {
615 // Shift instructions
616 let isTwoAddress = 1 in {
618 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
619 "shl{q}\t{%cl, $dst|$dst, %CL}",
620 [(set GR64:$dst, (shl GR64:$src, CL))]>;
621 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
622 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
623 "shl{q}\t{$src2, $dst|$dst, $src2}",
624 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
625 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
630 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
631 "shl{q}\t{%cl, $dst|$dst, %CL}",
632 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
633 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
634 "shl{q}\t{$src, $dst|$dst, $src}",
635 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
636 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
638 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
640 let isTwoAddress = 1 in {
642 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
643 "shr{q}\t{%cl, $dst|$dst, %CL}",
644 [(set GR64:$dst, (srl GR64:$src, CL))]>;
645 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
646 "shr{q}\t{$src2, $dst|$dst, $src2}",
647 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
648 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
650 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
654 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
655 "shr{q}\t{%cl, $dst|$dst, %CL}",
656 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
657 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
658 "shr{q}\t{$src, $dst|$dst, $src}",
659 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
660 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
662 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
664 let isTwoAddress = 1 in {
666 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
667 "sar{q}\t{%cl, $dst|$dst, %CL}",
668 [(set GR64:$dst, (sra GR64:$src, CL))]>;
669 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
670 "sar{q}\t{$src2, $dst|$dst, $src2}",
671 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
672 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
674 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
678 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
679 "sar{q}\t{%cl, $dst|$dst, %CL}",
680 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
681 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
682 "sar{q}\t{$src, $dst|$dst, $src}",
683 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
684 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
686 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
688 // Rotate instructions
689 let isTwoAddress = 1 in {
691 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
692 "rol{q}\t{%cl, $dst|$dst, %CL}",
693 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
694 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
695 "rol{q}\t{$src2, $dst|$dst, $src2}",
696 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
697 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
699 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
703 def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
704 "rol{q}\t{%cl, $dst|$dst, %CL}",
705 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
706 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
707 "rol{q}\t{$src, $dst|$dst, $src}",
708 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
709 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
711 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
713 let isTwoAddress = 1 in {
715 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
716 "ror{q}\t{%cl, $dst|$dst, %CL}",
717 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
718 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
719 "ror{q}\t{$src2, $dst|$dst, $src2}",
720 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
721 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
723 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
727 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
728 "ror{q}\t{%cl, $dst|$dst, %CL}",
729 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
730 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
731 "ror{q}\t{$src, $dst|$dst, $src}",
732 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
733 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
735 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
737 // Double shift instructions (generalizations of rotate)
738 let isTwoAddress = 1 in {
740 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
741 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
742 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
743 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
744 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
745 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
748 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
749 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
750 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
751 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
752 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
755 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
756 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
757 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
758 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
765 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
766 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
767 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
769 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
770 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
771 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
774 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
775 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
776 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
777 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
778 (i8 imm:$src3)), addr:$dst)]>,
780 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
781 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
782 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
783 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
784 (i8 imm:$src3)), addr:$dst)]>,
788 //===----------------------------------------------------------------------===//
789 // Logical Instructions...
792 let isTwoAddress = 1 , AddedComplexity = 15 in
793 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
794 [(set GR64:$dst, (not GR64:$src))]>;
795 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
796 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
798 let Defs = [EFLAGS] in {
799 let isTwoAddress = 1 in {
800 let isCommutable = 1 in
801 def AND64rr : RI<0x21, MRMDestReg,
802 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
803 "and{q}\t{$src2, $dst|$dst, $src2}",
804 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
806 def AND64rm : RI<0x23, MRMSrcMem,
807 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
808 "and{q}\t{$src2, $dst|$dst, $src2}",
809 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
811 def AND64ri8 : RIi8<0x83, MRM4r,
812 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
813 "and{q}\t{$src2, $dst|$dst, $src2}",
814 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
816 def AND64ri32 : RIi32<0x81, MRM4r,
817 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
818 "and{q}\t{$src2, $dst|$dst, $src2}",
819 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
823 def AND64mr : RI<0x21, MRMDestMem,
824 (outs), (ins i64mem:$dst, GR64:$src),
825 "and{q}\t{$src, $dst|$dst, $src}",
826 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
828 def AND64mi8 : RIi8<0x83, MRM4m,
829 (outs), (ins i64mem:$dst, i64i8imm :$src),
830 "and{q}\t{$src, $dst|$dst, $src}",
831 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
833 def AND64mi32 : RIi32<0x81, MRM4m,
834 (outs), (ins i64mem:$dst, i64i32imm:$src),
835 "and{q}\t{$src, $dst|$dst, $src}",
836 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
839 let isTwoAddress = 1 in {
840 let isCommutable = 1 in
841 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
842 "or{q}\t{$src2, $dst|$dst, $src2}",
843 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
845 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
846 "or{q}\t{$src2, $dst|$dst, $src2}",
847 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
849 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
850 "or{q}\t{$src2, $dst|$dst, $src2}",
851 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
853 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
854 "or{q}\t{$src2, $dst|$dst, $src2}",
855 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
859 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
860 "or{q}\t{$src, $dst|$dst, $src}",
861 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
863 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
864 "or{q}\t{$src, $dst|$dst, $src}",
865 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
867 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
868 "or{q}\t{$src, $dst|$dst, $src}",
869 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
872 let isTwoAddress = 1 in {
873 let isCommutable = 1 in
874 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
875 "xor{q}\t{$src2, $dst|$dst, $src2}",
876 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
878 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
879 "xor{q}\t{$src2, $dst|$dst, $src2}",
880 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
882 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
883 "xor{q}\t{$src2, $dst|$dst, $src2}",
884 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
886 def XOR64ri32 : RIi32<0x81, MRM6r,
887 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
888 "xor{q}\t{$src2, $dst|$dst, $src2}",
889 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
893 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
894 "xor{q}\t{$src, $dst|$dst, $src}",
895 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
897 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
898 "xor{q}\t{$src, $dst|$dst, $src}",
899 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
901 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
902 "xor{q}\t{$src, $dst|$dst, $src}",
903 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
907 //===----------------------------------------------------------------------===//
908 // Comparison Instructions...
911 // Integer comparison
912 let Defs = [EFLAGS] in {
913 let isCommutable = 1 in
914 def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
915 "test{q}\t{$src2, $src1|$src1, $src2}",
916 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
918 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
919 "test{q}\t{$src2, $src1|$src1, $src2}",
920 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
922 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
923 (ins GR64:$src1, i64i32imm:$src2),
924 "test{q}\t{$src2, $src1|$src1, $src2}",
925 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
927 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
928 (ins i64mem:$src1, i64i32imm:$src2),
929 "test{q}\t{$src2, $src1|$src1, $src2}",
930 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
933 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
934 "cmp{q}\t{$src2, $src1|$src1, $src2}",
935 [(X86cmp GR64:$src1, GR64:$src2),
937 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
938 "cmp{q}\t{$src2, $src1|$src1, $src2}",
939 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
941 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
942 "cmp{q}\t{$src2, $src1|$src1, $src2}",
943 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
945 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
946 "cmp{q}\t{$src2, $src1|$src1, $src2}",
947 [(X86cmp GR64:$src1, i64immSExt8:$src2),
949 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
950 "cmp{q}\t{$src2, $src1|$src1, $src2}",
951 [(X86cmp GR64:$src1, i64immSExt32:$src2),
953 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
954 "cmp{q}\t{$src2, $src1|$src1, $src2}",
955 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
957 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
958 (ins i64mem:$src1, i64i32imm:$src2),
959 "cmp{q}\t{$src2, $src1|$src1, $src2}",
960 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
965 // TODO: BTC, BTR, and BTS
966 let Defs = [EFLAGS] in {
967 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
968 "bt{q}\t{$src2, $src1|$src1, $src2}",
969 [(X86bt GR64:$src1, GR64:$src2),
970 (implicit EFLAGS)]>, TB;
972 // Unlike with the register+register form, the memory+register form of the
973 // bt instruction does not ignore the high bits of the index. From ISel's
974 // perspective, this is pretty bizarre. Disable these instructions for now.
975 //def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
976 // "bt{q}\t{$src2, $src1|$src1, $src2}",
977 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
978 // (implicit EFLAGS)]>, TB;
980 def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
981 "bt{q}\t{$src2, $src1|$src1, $src2}",
982 [(X86bt GR64:$src1, i64immSExt8:$src2),
983 (implicit EFLAGS)]>, TB;
984 // Note that these instructions don't need FastBTMem because that
985 // only applies when the other operand is in a register. When it's
986 // an immediate, bt is still fast.
987 def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
988 "bt{q}\t{$src2, $src1|$src1, $src2}",
989 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
990 (implicit EFLAGS)]>, TB;
994 let Uses = [EFLAGS], isTwoAddress = 1 in {
995 let isCommutable = 1 in {
996 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
997 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
998 "cmovb\t{$src2, $dst|$dst, $src2}",
999 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1000 X86_COND_B, EFLAGS))]>, TB;
1001 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
1002 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1003 "cmovae\t{$src2, $dst|$dst, $src2}",
1004 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1005 X86_COND_AE, EFLAGS))]>, TB;
1006 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
1007 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1008 "cmove\t{$src2, $dst|$dst, $src2}",
1009 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1010 X86_COND_E, EFLAGS))]>, TB;
1011 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
1012 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1013 "cmovne\t{$src2, $dst|$dst, $src2}",
1014 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1015 X86_COND_NE, EFLAGS))]>, TB;
1016 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
1017 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1018 "cmovbe\t{$src2, $dst|$dst, $src2}",
1019 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1020 X86_COND_BE, EFLAGS))]>, TB;
1021 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
1022 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1023 "cmova\t{$src2, $dst|$dst, $src2}",
1024 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1025 X86_COND_A, EFLAGS))]>, TB;
1026 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
1027 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1028 "cmovl\t{$src2, $dst|$dst, $src2}",
1029 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1030 X86_COND_L, EFLAGS))]>, TB;
1031 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
1032 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1033 "cmovge\t{$src2, $dst|$dst, $src2}",
1034 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1035 X86_COND_GE, EFLAGS))]>, TB;
1036 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
1037 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1038 "cmovle\t{$src2, $dst|$dst, $src2}",
1039 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1040 X86_COND_LE, EFLAGS))]>, TB;
1041 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
1042 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1043 "cmovg\t{$src2, $dst|$dst, $src2}",
1044 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1045 X86_COND_G, EFLAGS))]>, TB;
1046 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1047 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1048 "cmovs\t{$src2, $dst|$dst, $src2}",
1049 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1050 X86_COND_S, EFLAGS))]>, TB;
1051 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1052 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1053 "cmovns\t{$src2, $dst|$dst, $src2}",
1054 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1055 X86_COND_NS, EFLAGS))]>, TB;
1056 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1057 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1058 "cmovp\t{$src2, $dst|$dst, $src2}",
1059 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1060 X86_COND_P, EFLAGS))]>, TB;
1061 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1062 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1063 "cmovnp\t{$src2, $dst|$dst, $src2}",
1064 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1065 X86_COND_NP, EFLAGS))]>, TB;
1066 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1067 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1068 "cmovo\t{$src2, $dst|$dst, $src2}",
1069 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1070 X86_COND_O, EFLAGS))]>, TB;
1071 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1072 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1073 "cmovno\t{$src2, $dst|$dst, $src2}",
1074 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1075 X86_COND_NO, EFLAGS))]>, TB;
1076 } // isCommutable = 1
1078 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1079 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1080 "cmovb\t{$src2, $dst|$dst, $src2}",
1081 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1082 X86_COND_B, EFLAGS))]>, TB;
1083 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1084 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1085 "cmovae\t{$src2, $dst|$dst, $src2}",
1086 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1087 X86_COND_AE, EFLAGS))]>, TB;
1088 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1089 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1090 "cmove\t{$src2, $dst|$dst, $src2}",
1091 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1092 X86_COND_E, EFLAGS))]>, TB;
1093 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1094 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1095 "cmovne\t{$src2, $dst|$dst, $src2}",
1096 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1097 X86_COND_NE, EFLAGS))]>, TB;
1098 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1099 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1100 "cmovbe\t{$src2, $dst|$dst, $src2}",
1101 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1102 X86_COND_BE, EFLAGS))]>, TB;
1103 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1104 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1105 "cmova\t{$src2, $dst|$dst, $src2}",
1106 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1107 X86_COND_A, EFLAGS))]>, TB;
1108 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1109 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1110 "cmovl\t{$src2, $dst|$dst, $src2}",
1111 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1112 X86_COND_L, EFLAGS))]>, TB;
1113 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1114 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1115 "cmovge\t{$src2, $dst|$dst, $src2}",
1116 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1117 X86_COND_GE, EFLAGS))]>, TB;
1118 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1119 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1120 "cmovle\t{$src2, $dst|$dst, $src2}",
1121 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1122 X86_COND_LE, EFLAGS))]>, TB;
1123 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1124 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1125 "cmovg\t{$src2, $dst|$dst, $src2}",
1126 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1127 X86_COND_G, EFLAGS))]>, TB;
1128 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1129 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1130 "cmovs\t{$src2, $dst|$dst, $src2}",
1131 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1132 X86_COND_S, EFLAGS))]>, TB;
1133 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1134 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1135 "cmovns\t{$src2, $dst|$dst, $src2}",
1136 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1137 X86_COND_NS, EFLAGS))]>, TB;
1138 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1139 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1140 "cmovp\t{$src2, $dst|$dst, $src2}",
1141 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1142 X86_COND_P, EFLAGS))]>, TB;
1143 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1144 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1145 "cmovnp\t{$src2, $dst|$dst, $src2}",
1146 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1147 X86_COND_NP, EFLAGS))]>, TB;
1148 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1149 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1150 "cmovo\t{$src2, $dst|$dst, $src2}",
1151 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1152 X86_COND_O, EFLAGS))]>, TB;
1153 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1154 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1155 "cmovno\t{$src2, $dst|$dst, $src2}",
1156 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1157 X86_COND_NO, EFLAGS))]>, TB;
1160 //===----------------------------------------------------------------------===//
1161 // Conversion Instructions...
1164 // f64 -> signed i64
1165 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1166 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1168 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1169 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1170 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1171 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1172 (load addr:$src)))]>;
1173 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1174 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1175 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1176 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1177 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1178 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1179 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1180 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1182 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1183 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1184 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1186 (int_x86_sse2_cvttsd2si64
1187 (load addr:$src)))]>;
1189 // Signed i64 -> f64
1190 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1191 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1192 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1193 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1194 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1195 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1197 let isTwoAddress = 1 in {
1198 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1199 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1200 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1202 (int_x86_sse2_cvtsi642sd VR128:$src1,
1204 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1205 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1206 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1208 (int_x86_sse2_cvtsi642sd VR128:$src1,
1209 (loadi64 addr:$src2)))]>;
1212 // Signed i64 -> f32
1213 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1214 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1215 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1216 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1217 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1218 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1220 let isTwoAddress = 1 in {
1221 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1222 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1223 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1225 (int_x86_sse_cvtsi642ss VR128:$src1,
1227 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1228 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1229 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1231 (int_x86_sse_cvtsi642ss VR128:$src1,
1232 (loadi64 addr:$src2)))]>;
1235 // f32 -> signed i64
1236 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1237 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1239 (int_x86_sse_cvtss2si64 VR128:$src))]>;
1240 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1241 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1242 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1243 (load addr:$src)))]>;
1244 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1245 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1246 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1247 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1248 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1249 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1250 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1251 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1253 (int_x86_sse_cvttss2si64 VR128:$src))]>;
1254 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1255 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1257 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1259 //===----------------------------------------------------------------------===//
1260 // Alias Instructions
1261 //===----------------------------------------------------------------------===//
1263 // Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1264 // equivalent due to implicit zero-extending, and it sometimes has a smaller
1266 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1267 // FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1268 // when we have a better way to specify isel priority.
1269 let Defs = [EFLAGS], AddedComplexity = 1,
1270 isReMaterializable = 1, isAsCheapAsAMove = 1 in
1271 def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1272 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1273 [(set GR64:$dst, 0)]>;
1275 // Materialize i64 constant where top 32-bits are zero.
1276 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1277 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1278 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1279 [(set GR64:$dst, i64immZExt32:$src)]>;
1281 //===----------------------------------------------------------------------===//
1282 // Thread Local Storage Instructions
1283 //===----------------------------------------------------------------------===//
1285 def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
1286 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
1287 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
1289 let AddedComplexity = 5 in
1290 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1291 "movq\t%gs:$src, $dst",
1292 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1294 //===----------------------------------------------------------------------===//
1295 // Atomic Instructions
1296 //===----------------------------------------------------------------------===//
1298 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1299 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1300 "lock\n\tcmpxchgq\t$swap,$ptr",
1301 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1304 let Constraints = "$val = $dst" in {
1305 let Defs = [EFLAGS] in
1306 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1307 "lock\n\txadd\t$val, $ptr",
1308 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1310 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1312 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1315 // Atomic exchange, and, or, xor
1316 let Constraints = "$val = $dst", Defs = [EFLAGS],
1317 usesCustomDAGSchedInserter = 1 in {
1318 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1319 "#ATOMAND64 PSEUDO!",
1320 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1321 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1322 "#ATOMOR64 PSEUDO!",
1323 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1324 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1325 "#ATOMXOR64 PSEUDO!",
1326 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1327 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1328 "#ATOMNAND64 PSEUDO!",
1329 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1330 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1331 "#ATOMMIN64 PSEUDO!",
1332 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1333 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1334 "#ATOMMAX64 PSEUDO!",
1335 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1336 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1337 "#ATOMUMIN64 PSEUDO!",
1338 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1339 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1340 "#ATOMUMAX64 PSEUDO!",
1341 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1344 //===----------------------------------------------------------------------===//
1345 // Non-Instruction Patterns
1346 //===----------------------------------------------------------------------===//
1348 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
1349 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1350 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1351 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1352 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1353 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1354 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1355 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1356 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1358 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1359 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1360 Requires<[SmallCode, IsStatic]>;
1361 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1362 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1363 Requires<[SmallCode, IsStatic]>;
1364 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1365 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1366 Requires<[SmallCode, IsStatic]>;
1367 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1368 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1369 Requires<[SmallCode, IsStatic]>;
1372 // Direct PC relative function call for small code model. 32-bit displacement
1373 // sign extended to 64-bit.
1374 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1375 (CALL64pcrel32 tglobaladdr:$dst)>;
1376 def : Pat<(X86call (i64 texternalsym:$dst)),
1377 (CALL64pcrel32 texternalsym:$dst)>;
1379 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1380 (CALL64pcrel32 tglobaladdr:$dst)>;
1381 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1382 (CALL64pcrel32 texternalsym:$dst)>;
1384 def : Pat<(X86tailcall GR64:$dst),
1385 (CALL64r GR64:$dst)>;
1389 def : Pat<(X86tailcall GR32:$dst),
1391 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1393 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1396 def : Pat<(X86tcret GR64:$dst, imm:$off),
1397 (TCRETURNri64 GR64:$dst, imm:$off)>;
1399 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1400 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1402 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1403 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1407 // TEST R,R is smaller than CMP R,0
1408 def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
1409 (TEST64rr GR64:$src1, GR64:$src1)>;
1411 // Conditional moves with folded loads with operands swapped and conditions
1413 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1414 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1415 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1416 (CMOVB64rm GR64:$src2, addr:$src1)>;
1417 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1418 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1419 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1420 (CMOVE64rm GR64:$src2, addr:$src1)>;
1421 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1422 (CMOVA64rm GR64:$src2, addr:$src1)>;
1423 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1424 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1425 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1426 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1427 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1428 (CMOVL64rm GR64:$src2, addr:$src1)>;
1429 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1430 (CMOVG64rm GR64:$src2, addr:$src1)>;
1431 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1432 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1433 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1434 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1435 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1436 (CMOVP64rm GR64:$src2, addr:$src1)>;
1437 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1438 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1439 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1440 (CMOVS64rm GR64:$src2, addr:$src1)>;
1441 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1442 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1443 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1444 (CMOVO64rm GR64:$src2, addr:$src1)>;
1447 def : Pat<(i64 (zext GR32:$src)),
1448 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
1450 // zextload bool -> zextload byte
1451 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1454 // When extloading from 16-bit and smaller memory locations into 64-bit registers,
1455 // use zero-extending loads so that the entire 64-bit register is defined, avoiding
1456 // partial-register updates.
1457 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1458 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1459 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1460 // For other extloads, use subregs, since the high contents of the register are
1461 // defined after an extload.
1462 def : Pat<(extloadi64i32 addr:$src),
1463 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1465 def : Pat<(extloadi16i1 addr:$src),
1466 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1468 Requires<[In64BitMode]>;
1469 def : Pat<(extloadi16i8 addr:$src),
1470 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1472 Requires<[In64BitMode]>;
1475 def : Pat<(i64 (anyext GR8:$src)),
1476 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1477 def : Pat<(i64 (anyext GR16:$src)),
1478 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
1479 def : Pat<(i64 (anyext GR32:$src)),
1480 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
1481 def : Pat<(i16 (anyext GR8:$src)),
1482 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1483 Requires<[In64BitMode]>;
1484 def : Pat<(i32 (anyext GR8:$src)),
1485 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1486 Requires<[In64BitMode]>;
1488 //===----------------------------------------------------------------------===//
1490 //===----------------------------------------------------------------------===//
1492 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1493 // +128 doesn't, so in this special case use a sub instead of an add.
1494 def : Pat<(add GR64:$src1, 128),
1495 (SUB64ri8 GR64:$src1, -128)>;
1496 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1497 (SUB64mi8 addr:$dst, -128)>;
1499 // The same trick applies for 32-bit immediate fields in 64-bit
1501 def : Pat<(add GR64:$src1, 0x0000000080000000),
1502 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1503 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1504 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1506 // r & (2^32-1) ==> movz
1507 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1508 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1509 // r & (2^16-1) ==> movz
1510 def : Pat<(and GR64:$src, 0xffff),
1511 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1512 // r & (2^8-1) ==> movz
1513 def : Pat<(and GR64:$src, 0xff),
1514 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1515 // r & (2^8-1) ==> movz
1516 def : Pat<(and GR32:$src1, 0xff),
1517 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1518 Requires<[In64BitMode]>;
1519 // r & (2^8-1) ==> movz
1520 def : Pat<(and GR16:$src1, 0xff),
1521 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1522 Requires<[In64BitMode]>;
1524 // sext_inreg patterns
1525 def : Pat<(sext_inreg GR64:$src, i32),
1526 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1527 def : Pat<(sext_inreg GR64:$src, i16),
1528 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1529 def : Pat<(sext_inreg GR64:$src, i8),
1530 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1531 def : Pat<(sext_inreg GR32:$src, i8),
1532 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1533 Requires<[In64BitMode]>;
1534 def : Pat<(sext_inreg GR16:$src, i8),
1535 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1536 Requires<[In64BitMode]>;
1539 def : Pat<(i32 (trunc GR64:$src)),
1540 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1541 def : Pat<(i16 (trunc GR64:$src)),
1542 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1543 def : Pat<(i8 (trunc GR64:$src)),
1544 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1545 def : Pat<(i8 (trunc GR32:$src)),
1546 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1547 Requires<[In64BitMode]>;
1548 def : Pat<(i8 (trunc GR16:$src)),
1549 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1550 Requires<[In64BitMode]>;
1552 // (shl x, 1) ==> (add x, x)
1553 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1555 // (shl x (and y, 63)) ==> (shl x, y)
1556 def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1557 (SHL64rCL GR64:$src1)>;
1558 def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1559 (SHL64mCL addr:$dst)>;
1561 def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1562 (SHR64rCL GR64:$src1)>;
1563 def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1564 (SHR64mCL addr:$dst)>;
1566 def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1567 (SAR64rCL GR64:$src1)>;
1568 def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1569 (SAR64mCL addr:$dst)>;
1571 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1572 def : Pat<(or (srl GR64:$src1, CL:$amt),
1573 (shl GR64:$src2, (sub 64, CL:$amt))),
1574 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1576 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1577 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1578 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1580 def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1581 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1582 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1584 def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1585 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1587 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1589 def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1590 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1592 def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1593 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1594 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1596 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1597 def : Pat<(or (shl GR64:$src1, CL:$amt),
1598 (srl GR64:$src2, (sub 64, CL:$amt))),
1599 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1601 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1602 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1603 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1605 def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1606 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1607 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1609 def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1610 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1612 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1614 def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1615 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1617 def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1618 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1619 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1621 // X86 specific add which produces a flag.
1622 def : Pat<(addc GR64:$src1, GR64:$src2),
1623 (ADD64rr GR64:$src1, GR64:$src2)>;
1624 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1625 (ADD64rm GR64:$src1, addr:$src2)>;
1626 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1627 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1628 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1629 (ADD64ri32 GR64:$src1, imm:$src2)>;
1631 def : Pat<(subc GR64:$src1, GR64:$src2),
1632 (SUB64rr GR64:$src1, GR64:$src2)>;
1633 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1634 (SUB64rm GR64:$src1, addr:$src2)>;
1635 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1636 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1637 def : Pat<(subc GR64:$src1, imm:$src2),
1638 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1640 //===----------------------------------------------------------------------===//
1641 // EFLAGS-defining Patterns
1642 //===----------------------------------------------------------------------===//
1644 // Register-Register Addition with EFLAGS result
1645 def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
1647 (ADD64rr GR64:$src1, GR64:$src2)>;
1649 // Register-Integer Addition with EFLAGS result
1650 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
1652 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1653 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
1655 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
1657 // Register-Memory Addition with EFLAGS result
1658 def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
1660 (ADD64rm GR64:$src1, addr:$src2)>;
1662 // Memory-Register Addition with EFLAGS result
1663 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
1666 (ADD64mr addr:$dst, GR64:$src2)>;
1667 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1670 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
1671 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1674 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
1676 // Register-Register Subtraction with EFLAGS result
1677 def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
1679 (SUB64rr GR64:$src1, GR64:$src2)>;
1681 // Register-Memory Subtraction with EFLAGS result
1682 def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
1684 (SUB64rm GR64:$src1, addr:$src2)>;
1686 // Register-Integer Subtraction with EFLAGS result
1687 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
1689 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1690 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
1692 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1694 // Memory-Register Subtraction with EFLAGS result
1695 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
1698 (SUB64mr addr:$dst, GR64:$src2)>;
1700 // Memory-Integer Subtraction with EFLAGS result
1701 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1704 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
1705 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1708 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
1710 // Register-Register Signed Integer Multiplication with EFLAGS result
1711 def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
1713 (IMUL64rr GR64:$src1, GR64:$src2)>;
1715 // Register-Memory Signed Integer Multiplication with EFLAGS result
1716 def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
1718 (IMUL64rm GR64:$src1, addr:$src2)>;
1720 // Register-Integer Signed Integer Multiplication with EFLAGS result
1721 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
1723 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
1724 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
1726 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
1728 // Memory-Integer Signed Integer Multiplication with EFLAGS result
1729 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
1731 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
1732 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
1734 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
1736 // INC and DEC with EFLAGS result. Note that these do not set CF.
1737 def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1738 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1739 def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1741 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1742 def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1743 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1744 def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1746 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1748 def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1749 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1750 def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1752 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1753 def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1754 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1755 def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1757 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1759 def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1760 (INC64r GR64:$src)>;
1761 def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1763 (INC64m addr:$dst)>;
1764 def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1765 (DEC64r GR64:$src)>;
1766 def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1768 (DEC64m addr:$dst)>;
1770 //===----------------------------------------------------------------------===//
1771 // X86-64 SSE Instructions
1772 //===----------------------------------------------------------------------===//
1774 // Move instructions...
1776 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
1777 "mov{d|q}\t{$src, $dst|$dst, $src}",
1779 (v2i64 (scalar_to_vector GR64:$src)))]>;
1780 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
1781 "mov{d|q}\t{$src, $dst|$dst, $src}",
1782 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1785 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1786 "mov{d|q}\t{$src, $dst|$dst, $src}",
1787 [(set FR64:$dst, (bitconvert GR64:$src))]>;
1788 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1789 "movq\t{$src, $dst|$dst, $src}",
1790 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1792 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
1793 "mov{d|q}\t{$src, $dst|$dst, $src}",
1794 [(set GR64:$dst, (bitconvert FR64:$src))]>;
1795 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
1796 "movq\t{$src, $dst|$dst, $src}",
1797 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
1799 //===----------------------------------------------------------------------===//
1800 // X86-64 SSE4.1 Instructions
1801 //===----------------------------------------------------------------------===//
1803 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1804 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
1805 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
1806 (ins VR128:$src1, i32i8imm:$src2),
1807 !strconcat(OpcodeStr,
1808 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1810 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
1811 def mr : SS4AIi8<opc, MRMDestMem, (outs),
1812 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1813 !strconcat(OpcodeStr,
1814 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1815 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1816 addr:$dst)]>, OpSize, REX_W;
1819 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1821 let isTwoAddress = 1 in {
1822 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
1823 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
1824 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1825 !strconcat(OpcodeStr,
1826 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1828 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1830 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
1831 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1832 !strconcat(OpcodeStr,
1833 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1835 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1836 imm:$src3)))]>, OpSize, REX_W;
1840 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;