1 //====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the X86-64 instruction set, defining the instructions,
11 // and properties of the instructions which are needed for code generation,
12 // machine code emission, and analysis.
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
17 // Operand Definitions.
20 // 64-bits but only 32 bits are significant.
21 def i64i32imm : Operand<i64>;
22 // 64-bits but only 8 bits are significant.
23 def i64i8imm : Operand<i64>;
25 def lea64mem : Operand<i64> {
26 let PrintMethod = "printlea64mem";
27 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
30 def lea64_32mem : Operand<i32> {
31 let PrintMethod = "printlea64_32mem";
32 let 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 : Ii32<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], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
181 def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
182 "push{q}\t$imm", []>;
183 def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
184 "push{q}\t$imm", []>;
185 def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
186 "push{q}\t$imm", []>;
189 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
190 def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
191 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
192 def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
194 def LEA64_32r : I<0x8D, MRMSrcMem,
195 (outs GR32:$dst), (ins lea64_32mem:$src),
196 "lea{l}\t{$src|$dst}, {$dst|$src}",
197 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
199 let isReMaterializable = 1 in
200 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
201 "lea{q}\t{$src|$dst}, {$dst|$src}",
202 [(set GR64:$dst, lea64addr:$src)]>;
204 let isTwoAddress = 1 in
205 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
207 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
209 // Bit scan instructions.
210 let Defs = [EFLAGS] in {
211 def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
212 "bsf{q}\t{$src, $dst|$dst, $src}",
213 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
214 def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
215 "bsf{q}\t{$src, $dst|$dst, $src}",
216 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
217 (implicit EFLAGS)]>, TB;
219 def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
220 "bsr{q}\t{$src, $dst|$dst, $src}",
221 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
222 def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
223 "bsr{q}\t{$src, $dst|$dst, $src}",
224 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
225 (implicit EFLAGS)]>, TB;
229 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
230 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
231 [(X86rep_movs i64)]>, REP;
232 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
233 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
234 [(X86rep_stos i64)]>, REP;
236 //===----------------------------------------------------------------------===//
237 // Move Instructions...
240 let neverHasSideEffects = 1 in
241 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
242 "mov{q}\t{$src, $dst|$dst, $src}", []>;
244 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
245 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
246 "movabs{q}\t{$src, $dst|$dst, $src}",
247 [(set GR64:$dst, imm:$src)]>;
248 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
249 "mov{q}\t{$src, $dst|$dst, $src}",
250 [(set GR64:$dst, i64immSExt32:$src)]>;
253 let canFoldAsLoad = 1 in
254 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
255 "mov{q}\t{$src, $dst|$dst, $src}",
256 [(set GR64:$dst, (load addr:$src))]>;
258 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
259 "mov{q}\t{$src, $dst|$dst, $src}",
260 [(store GR64:$src, addr:$dst)]>;
261 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
262 "mov{q}\t{$src, $dst|$dst, $src}",
263 [(store i64immSExt32:$src, addr:$dst)]>;
265 // Sign/Zero extenders
267 // MOVSX64rr8 always has a REX prefix and it has an 8-bit register
268 // operand, which makes it a rare instruction with an 8-bit register
269 // operand that can never access an h register. If support for h registers
270 // were generalized, this would require a special register class.
271 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
272 "movs{bq|x}\t{$src, $dst|$dst, $src}",
273 [(set GR64:$dst, (sext GR8:$src))]>, TB;
274 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
275 "movs{bq|x}\t{$src, $dst|$dst, $src}",
276 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
277 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
278 "movs{wq|x}\t{$src, $dst|$dst, $src}",
279 [(set GR64:$dst, (sext GR16:$src))]>, TB;
280 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
281 "movs{wq|x}\t{$src, $dst|$dst, $src}",
282 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
283 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
284 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
285 [(set GR64:$dst, (sext GR32:$src))]>;
286 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
287 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
288 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
290 // Use movzbl instead of movzbq when the destination is a register; it's
291 // equivalent due to implicit zero-extending, and it has a smaller encoding.
292 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
293 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
294 [(set GR64:$dst, (zext GR8:$src))]>, TB;
295 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
296 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
297 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
298 // Use movzwl instead of movzwq when the destination is a register; it's
299 // equivalent due to implicit zero-extending, and it has a smaller encoding.
300 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
301 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
302 [(set GR64:$dst, (zext GR16:$src))]>, TB;
303 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
304 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
305 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
307 // There's no movzlq instruction, but movl can be used for this purpose, using
308 // implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
309 // extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
310 // zero-extension, however this isn't possible when the 32-bit value is
311 // defined by a truncate or is copied from something where the high bits aren't
312 // necessarily all zero. In such cases, we fall back to these explicit zext
314 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
315 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
316 [(set GR64:$dst, (zext GR32:$src))]>;
317 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
318 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
319 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
321 // Any instruction that defines a 32-bit result leaves the high half of the
322 // register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
323 // be copying from a truncate, but any other 32-bit operation will zero-extend
325 def def32 : PatLeaf<(i32 GR32:$src), [{
326 return N->getOpcode() != ISD::TRUNCATE &&
327 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
328 N->getOpcode() != ISD::CopyFromReg;
331 // In the case of a 32-bit def that is known to implicitly zero-extend,
332 // we can use a SUBREG_TO_REG.
333 def : Pat<(i64 (zext def32:$src)),
334 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
336 let neverHasSideEffects = 1 in {
337 let Defs = [RAX], Uses = [EAX] in
338 def CDQE : RI<0x98, RawFrm, (outs), (ins),
339 "{cltq|cdqe}", []>; // RAX = signext(EAX)
341 let Defs = [RAX,RDX], Uses = [RAX] in
342 def CQO : RI<0x99, RawFrm, (outs), (ins),
343 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
346 //===----------------------------------------------------------------------===//
347 // Arithmetic Instructions...
350 let Defs = [EFLAGS] in {
351 let isTwoAddress = 1 in {
352 let isConvertibleToThreeAddress = 1 in {
353 let isCommutable = 1 in
354 // Register-Register Addition
355 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
356 "add{q}\t{$src2, $dst|$dst, $src2}",
357 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
360 // Register-Integer Addition
361 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
362 "add{q}\t{$src2, $dst|$dst, $src2}",
363 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
365 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
366 "add{q}\t{$src2, $dst|$dst, $src2}",
367 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
369 } // isConvertibleToThreeAddress
371 // Register-Memory Addition
372 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
373 "add{q}\t{$src2, $dst|$dst, $src2}",
374 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
378 // Memory-Register Addition
379 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
380 "add{q}\t{$src2, $dst|$dst, $src2}",
381 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
383 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
384 "add{q}\t{$src2, $dst|$dst, $src2}",
385 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
387 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
388 "add{q}\t{$src2, $dst|$dst, $src2}",
389 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
392 let Uses = [EFLAGS] in {
393 let isTwoAddress = 1 in {
394 let isCommutable = 1 in
395 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
396 "adc{q}\t{$src2, $dst|$dst, $src2}",
397 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
399 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
400 "adc{q}\t{$src2, $dst|$dst, $src2}",
401 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
403 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
404 "adc{q}\t{$src2, $dst|$dst, $src2}",
405 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
406 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
407 "adc{q}\t{$src2, $dst|$dst, $src2}",
408 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
411 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
412 "adc{q}\t{$src2, $dst|$dst, $src2}",
413 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
414 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
415 "adc{q}\t{$src2, $dst|$dst, $src2}",
416 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
417 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
418 "adc{q}\t{$src2, $dst|$dst, $src2}",
419 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
422 let isTwoAddress = 1 in {
423 // Register-Register Subtraction
424 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
425 "sub{q}\t{$src2, $dst|$dst, $src2}",
426 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
429 // Register-Memory Subtraction
430 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
431 "sub{q}\t{$src2, $dst|$dst, $src2}",
432 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
435 // Register-Integer Subtraction
436 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
437 (ins GR64:$src1, i64i8imm:$src2),
438 "sub{q}\t{$src2, $dst|$dst, $src2}",
439 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
441 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
442 (ins GR64:$src1, i64i32imm:$src2),
443 "sub{q}\t{$src2, $dst|$dst, $src2}",
444 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
448 // Memory-Register Subtraction
449 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
450 "sub{q}\t{$src2, $dst|$dst, $src2}",
451 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
454 // Memory-Integer Subtraction
455 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
456 "sub{q}\t{$src2, $dst|$dst, $src2}",
457 [(store (sub (load addr:$dst), i64immSExt8:$src2),
460 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
461 "sub{q}\t{$src2, $dst|$dst, $src2}",
462 [(store (sub (load addr:$dst), i64immSExt32:$src2),
466 let Uses = [EFLAGS] in {
467 let isTwoAddress = 1 in {
468 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
469 "sbb{q}\t{$src2, $dst|$dst, $src2}",
470 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
472 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
473 "sbb{q}\t{$src2, $dst|$dst, $src2}",
474 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
476 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
477 "sbb{q}\t{$src2, $dst|$dst, $src2}",
478 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
479 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
480 "sbb{q}\t{$src2, $dst|$dst, $src2}",
481 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
484 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
485 "sbb{q}\t{$src2, $dst|$dst, $src2}",
486 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
487 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
488 "sbb{q}\t{$src2, $dst|$dst, $src2}",
489 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
490 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
491 "sbb{q}\t{$src2, $dst|$dst, $src2}",
492 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
496 // Unsigned multiplication
497 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
498 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
499 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
501 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
502 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
504 // Signed multiplication
505 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
506 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
508 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
509 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
512 let Defs = [EFLAGS] in {
513 let isTwoAddress = 1 in {
514 let isCommutable = 1 in
515 // Register-Register Signed Integer Multiplication
516 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
517 (ins GR64:$src1, GR64:$src2),
518 "imul{q}\t{$src2, $dst|$dst, $src2}",
519 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
520 (implicit EFLAGS)]>, TB;
522 // Register-Memory Signed Integer Multiplication
523 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
524 (ins GR64:$src1, i64mem:$src2),
525 "imul{q}\t{$src2, $dst|$dst, $src2}",
526 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
527 (implicit EFLAGS)]>, TB;
530 // Suprisingly enough, these are not two address instructions!
532 // Register-Integer Signed Integer Multiplication
533 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
534 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
535 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
536 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
538 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
539 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
540 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
541 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
544 // Memory-Integer Signed Integer Multiplication
545 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
546 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
547 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
548 [(set GR64:$dst, (mul (load addr:$src1),
551 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
552 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
553 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
554 [(set GR64:$dst, (mul (load addr:$src1),
555 i64immSExt32:$src2)),
559 // Unsigned division / remainder
560 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
561 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
563 // Signed division / remainder
564 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
565 "idiv{q}\t$src", []>;
567 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
569 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
570 "idiv{q}\t$src", []>;
574 // Unary instructions
575 let Defs = [EFLAGS], CodeSize = 2 in {
576 let isTwoAddress = 1 in
577 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
578 [(set GR64:$dst, (ineg GR64:$src)),
580 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
581 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
584 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
585 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
586 [(set GR64:$dst, (add GR64:$src, 1)),
588 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
589 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
592 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
593 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
594 [(set GR64:$dst, (add GR64:$src, -1)),
596 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
597 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
600 // In 64-bit mode, single byte INC and DEC cannot be encoded.
601 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
602 // Can transform into LEA.
603 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
604 [(set GR16:$dst, (add GR16:$src, 1)),
606 OpSize, Requires<[In64BitMode]>;
607 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
608 [(set GR32:$dst, (add GR32:$src, 1)),
610 Requires<[In64BitMode]>;
611 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
612 [(set GR16:$dst, (add GR16:$src, -1)),
614 OpSize, Requires<[In64BitMode]>;
615 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
616 [(set GR32:$dst, (add GR32:$src, -1)),
618 Requires<[In64BitMode]>;
619 } // isConvertibleToThreeAddress
621 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
622 // how to unfold them.
623 let isTwoAddress = 0, CodeSize = 2 in {
624 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
625 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
627 OpSize, Requires<[In64BitMode]>;
628 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
629 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
631 Requires<[In64BitMode]>;
632 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
633 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
635 OpSize, Requires<[In64BitMode]>;
636 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
637 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
639 Requires<[In64BitMode]>;
641 } // Defs = [EFLAGS], CodeSize
644 let Defs = [EFLAGS] in {
645 // Shift instructions
646 let isTwoAddress = 1 in {
648 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
649 "shl{q}\t{%cl, $dst|$dst, %CL}",
650 [(set GR64:$dst, (shl GR64:$src, CL))]>;
651 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
652 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
653 "shl{q}\t{$src2, $dst|$dst, $src2}",
654 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
655 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
660 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
661 "shl{q}\t{%cl, $dst|$dst, %CL}",
662 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
663 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
664 "shl{q}\t{$src, $dst|$dst, $src}",
665 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
666 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
668 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
670 let isTwoAddress = 1 in {
672 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
673 "shr{q}\t{%cl, $dst|$dst, %CL}",
674 [(set GR64:$dst, (srl GR64:$src, CL))]>;
675 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
676 "shr{q}\t{$src2, $dst|$dst, $src2}",
677 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
678 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
680 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
684 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
685 "shr{q}\t{%cl, $dst|$dst, %CL}",
686 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
687 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
688 "shr{q}\t{$src, $dst|$dst, $src}",
689 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
690 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
692 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
694 let isTwoAddress = 1 in {
696 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
697 "sar{q}\t{%cl, $dst|$dst, %CL}",
698 [(set GR64:$dst, (sra GR64:$src, CL))]>;
699 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
700 "sar{q}\t{$src2, $dst|$dst, $src2}",
701 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
702 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
704 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
708 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
709 "sar{q}\t{%cl, $dst|$dst, %CL}",
710 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
711 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
712 "sar{q}\t{$src, $dst|$dst, $src}",
713 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
714 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
716 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
718 // Rotate instructions
719 let isTwoAddress = 1 in {
721 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
722 "rol{q}\t{%cl, $dst|$dst, %CL}",
723 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
724 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
725 "rol{q}\t{$src2, $dst|$dst, $src2}",
726 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
727 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
729 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
733 def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
734 "rol{q}\t{%cl, $dst|$dst, %CL}",
735 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
736 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
737 "rol{q}\t{$src, $dst|$dst, $src}",
738 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
739 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
741 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
743 let isTwoAddress = 1 in {
745 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
746 "ror{q}\t{%cl, $dst|$dst, %CL}",
747 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
748 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
749 "ror{q}\t{$src2, $dst|$dst, $src2}",
750 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
751 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
753 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
757 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
758 "ror{q}\t{%cl, $dst|$dst, %CL}",
759 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
760 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
761 "ror{q}\t{$src, $dst|$dst, $src}",
762 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
763 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
765 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
767 // Double shift instructions (generalizations of rotate)
768 let isTwoAddress = 1 in {
770 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
771 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
772 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
773 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
774 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
775 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
778 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
779 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
780 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
781 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
782 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
785 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
786 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
787 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
788 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
795 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
796 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
797 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
799 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
800 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
801 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
804 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
805 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
806 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
807 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
808 (i8 imm:$src3)), addr:$dst)]>,
810 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
811 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
812 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
813 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
814 (i8 imm:$src3)), addr:$dst)]>,
818 //===----------------------------------------------------------------------===//
819 // Logical Instructions...
822 let isTwoAddress = 1 , AddedComplexity = 15 in
823 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
824 [(set GR64:$dst, (not GR64:$src))]>;
825 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
826 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
828 let Defs = [EFLAGS] in {
829 let isTwoAddress = 1 in {
830 let isCommutable = 1 in
831 def AND64rr : RI<0x21, MRMDestReg,
832 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
833 "and{q}\t{$src2, $dst|$dst, $src2}",
834 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
836 def AND64rm : RI<0x23, MRMSrcMem,
837 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
838 "and{q}\t{$src2, $dst|$dst, $src2}",
839 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
841 def AND64ri8 : RIi8<0x83, MRM4r,
842 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
843 "and{q}\t{$src2, $dst|$dst, $src2}",
844 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
846 def AND64ri32 : RIi32<0x81, MRM4r,
847 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
848 "and{q}\t{$src2, $dst|$dst, $src2}",
849 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
853 def AND64mr : RI<0x21, MRMDestMem,
854 (outs), (ins i64mem:$dst, GR64:$src),
855 "and{q}\t{$src, $dst|$dst, $src}",
856 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
858 def AND64mi8 : RIi8<0x83, MRM4m,
859 (outs), (ins i64mem:$dst, i64i8imm :$src),
860 "and{q}\t{$src, $dst|$dst, $src}",
861 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
863 def AND64mi32 : RIi32<0x81, MRM4m,
864 (outs), (ins i64mem:$dst, i64i32imm:$src),
865 "and{q}\t{$src, $dst|$dst, $src}",
866 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
869 let isTwoAddress = 1 in {
870 let isCommutable = 1 in
871 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
872 "or{q}\t{$src2, $dst|$dst, $src2}",
873 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
875 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
876 "or{q}\t{$src2, $dst|$dst, $src2}",
877 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
879 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
880 "or{q}\t{$src2, $dst|$dst, $src2}",
881 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
883 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
884 "or{q}\t{$src2, $dst|$dst, $src2}",
885 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
889 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
890 "or{q}\t{$src, $dst|$dst, $src}",
891 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
893 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
894 "or{q}\t{$src, $dst|$dst, $src}",
895 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
897 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
898 "or{q}\t{$src, $dst|$dst, $src}",
899 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
902 let isTwoAddress = 1 in {
903 let isCommutable = 1 in
904 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
905 "xor{q}\t{$src2, $dst|$dst, $src2}",
906 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
908 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
909 "xor{q}\t{$src2, $dst|$dst, $src2}",
910 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
912 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
913 "xor{q}\t{$src2, $dst|$dst, $src2}",
914 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
916 def XOR64ri32 : RIi32<0x81, MRM6r,
917 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
918 "xor{q}\t{$src2, $dst|$dst, $src2}",
919 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
923 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
924 "xor{q}\t{$src, $dst|$dst, $src}",
925 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
927 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
928 "xor{q}\t{$src, $dst|$dst, $src}",
929 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
931 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
932 "xor{q}\t{$src, $dst|$dst, $src}",
933 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
937 //===----------------------------------------------------------------------===//
938 // Comparison Instructions...
941 // Integer comparison
942 let Defs = [EFLAGS] in {
943 let isCommutable = 1 in
944 def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
945 "test{q}\t{$src2, $src1|$src1, $src2}",
946 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
948 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
949 "test{q}\t{$src2, $src1|$src1, $src2}",
950 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
952 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
953 (ins GR64:$src1, i64i32imm:$src2),
954 "test{q}\t{$src2, $src1|$src1, $src2}",
955 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
957 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
958 (ins i64mem:$src1, i64i32imm:$src2),
959 "test{q}\t{$src2, $src1|$src1, $src2}",
960 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
963 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
964 "cmp{q}\t{$src2, $src1|$src1, $src2}",
965 [(X86cmp GR64:$src1, GR64:$src2),
967 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
968 "cmp{q}\t{$src2, $src1|$src1, $src2}",
969 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
971 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
972 "cmp{q}\t{$src2, $src1|$src1, $src2}",
973 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
975 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
976 "cmp{q}\t{$src2, $src1|$src1, $src2}",
977 [(X86cmp GR64:$src1, i64immSExt8:$src2),
979 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
980 "cmp{q}\t{$src2, $src1|$src1, $src2}",
981 [(X86cmp GR64:$src1, i64immSExt32:$src2),
983 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
984 "cmp{q}\t{$src2, $src1|$src1, $src2}",
985 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
987 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
988 (ins i64mem:$src1, i64i32imm:$src2),
989 "cmp{q}\t{$src2, $src1|$src1, $src2}",
990 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
995 // TODO: BTC, BTR, and BTS
996 let Defs = [EFLAGS] in {
997 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
998 "bt{q}\t{$src2, $src1|$src1, $src2}",
999 [(X86bt GR64:$src1, GR64:$src2),
1000 (implicit EFLAGS)]>, TB;
1002 // Unlike with the register+register form, the memory+register form of the
1003 // bt instruction does not ignore the high bits of the index. From ISel's
1004 // perspective, this is pretty bizarre. Disable these instructions for now.
1005 //def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1006 // "bt{q}\t{$src2, $src1|$src1, $src2}",
1007 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
1008 // (implicit EFLAGS)]>, TB;
1010 def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1011 "bt{q}\t{$src2, $src1|$src1, $src2}",
1012 [(X86bt GR64:$src1, i64immSExt8:$src2),
1013 (implicit EFLAGS)]>, TB;
1014 // Note that these instructions don't need FastBTMem because that
1015 // only applies when the other operand is in a register. When it's
1016 // an immediate, bt is still fast.
1017 def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1018 "bt{q}\t{$src2, $src1|$src1, $src2}",
1019 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1020 (implicit EFLAGS)]>, TB;
1021 } // Defs = [EFLAGS]
1023 // Conditional moves
1024 let Uses = [EFLAGS], isTwoAddress = 1 in {
1025 let isCommutable = 1 in {
1026 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
1027 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1028 "cmovb\t{$src2, $dst|$dst, $src2}",
1029 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1030 X86_COND_B, EFLAGS))]>, TB;
1031 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
1032 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1033 "cmovae\t{$src2, $dst|$dst, $src2}",
1034 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1035 X86_COND_AE, EFLAGS))]>, TB;
1036 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
1037 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1038 "cmove\t{$src2, $dst|$dst, $src2}",
1039 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1040 X86_COND_E, EFLAGS))]>, TB;
1041 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
1042 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1043 "cmovne\t{$src2, $dst|$dst, $src2}",
1044 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1045 X86_COND_NE, EFLAGS))]>, TB;
1046 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
1047 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1048 "cmovbe\t{$src2, $dst|$dst, $src2}",
1049 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1050 X86_COND_BE, EFLAGS))]>, TB;
1051 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
1052 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1053 "cmova\t{$src2, $dst|$dst, $src2}",
1054 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1055 X86_COND_A, EFLAGS))]>, TB;
1056 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
1057 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1058 "cmovl\t{$src2, $dst|$dst, $src2}",
1059 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1060 X86_COND_L, EFLAGS))]>, TB;
1061 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
1062 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1063 "cmovge\t{$src2, $dst|$dst, $src2}",
1064 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1065 X86_COND_GE, EFLAGS))]>, TB;
1066 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
1067 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1068 "cmovle\t{$src2, $dst|$dst, $src2}",
1069 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1070 X86_COND_LE, EFLAGS))]>, TB;
1071 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
1072 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1073 "cmovg\t{$src2, $dst|$dst, $src2}",
1074 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1075 X86_COND_G, EFLAGS))]>, TB;
1076 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1077 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1078 "cmovs\t{$src2, $dst|$dst, $src2}",
1079 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1080 X86_COND_S, EFLAGS))]>, TB;
1081 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1082 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1083 "cmovns\t{$src2, $dst|$dst, $src2}",
1084 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1085 X86_COND_NS, EFLAGS))]>, TB;
1086 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1087 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1088 "cmovp\t{$src2, $dst|$dst, $src2}",
1089 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1090 X86_COND_P, EFLAGS))]>, TB;
1091 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1092 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1093 "cmovnp\t{$src2, $dst|$dst, $src2}",
1094 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1095 X86_COND_NP, EFLAGS))]>, TB;
1096 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1097 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1098 "cmovo\t{$src2, $dst|$dst, $src2}",
1099 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1100 X86_COND_O, EFLAGS))]>, TB;
1101 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1102 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1103 "cmovno\t{$src2, $dst|$dst, $src2}",
1104 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1105 X86_COND_NO, EFLAGS))]>, TB;
1106 } // isCommutable = 1
1108 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1109 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1110 "cmovb\t{$src2, $dst|$dst, $src2}",
1111 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1112 X86_COND_B, EFLAGS))]>, TB;
1113 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1114 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1115 "cmovae\t{$src2, $dst|$dst, $src2}",
1116 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1117 X86_COND_AE, EFLAGS))]>, TB;
1118 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1119 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1120 "cmove\t{$src2, $dst|$dst, $src2}",
1121 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1122 X86_COND_E, EFLAGS))]>, TB;
1123 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1124 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1125 "cmovne\t{$src2, $dst|$dst, $src2}",
1126 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1127 X86_COND_NE, EFLAGS))]>, TB;
1128 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1129 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1130 "cmovbe\t{$src2, $dst|$dst, $src2}",
1131 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1132 X86_COND_BE, EFLAGS))]>, TB;
1133 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1134 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1135 "cmova\t{$src2, $dst|$dst, $src2}",
1136 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1137 X86_COND_A, EFLAGS))]>, TB;
1138 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1139 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1140 "cmovl\t{$src2, $dst|$dst, $src2}",
1141 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1142 X86_COND_L, EFLAGS))]>, TB;
1143 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1144 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1145 "cmovge\t{$src2, $dst|$dst, $src2}",
1146 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1147 X86_COND_GE, EFLAGS))]>, TB;
1148 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1149 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1150 "cmovle\t{$src2, $dst|$dst, $src2}",
1151 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1152 X86_COND_LE, EFLAGS))]>, TB;
1153 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1154 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1155 "cmovg\t{$src2, $dst|$dst, $src2}",
1156 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1157 X86_COND_G, EFLAGS))]>, TB;
1158 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1159 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1160 "cmovs\t{$src2, $dst|$dst, $src2}",
1161 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1162 X86_COND_S, EFLAGS))]>, TB;
1163 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1164 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1165 "cmovns\t{$src2, $dst|$dst, $src2}",
1166 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1167 X86_COND_NS, EFLAGS))]>, TB;
1168 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1169 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1170 "cmovp\t{$src2, $dst|$dst, $src2}",
1171 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1172 X86_COND_P, EFLAGS))]>, TB;
1173 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1174 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1175 "cmovnp\t{$src2, $dst|$dst, $src2}",
1176 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1177 X86_COND_NP, EFLAGS))]>, TB;
1178 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1179 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1180 "cmovo\t{$src2, $dst|$dst, $src2}",
1181 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1182 X86_COND_O, EFLAGS))]>, TB;
1183 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1184 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1185 "cmovno\t{$src2, $dst|$dst, $src2}",
1186 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1187 X86_COND_NO, EFLAGS))]>, TB;
1190 //===----------------------------------------------------------------------===//
1191 // Conversion Instructions...
1194 // f64 -> signed i64
1195 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1196 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1198 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1199 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1200 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1201 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1202 (load addr:$src)))]>;
1203 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1204 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1205 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1206 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1207 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1208 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1209 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1210 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1212 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1213 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1214 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1216 (int_x86_sse2_cvttsd2si64
1217 (load addr:$src)))]>;
1219 // Signed i64 -> f64
1220 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1221 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1222 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1223 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1224 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1225 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1227 let isTwoAddress = 1 in {
1228 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1229 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1230 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1232 (int_x86_sse2_cvtsi642sd VR128:$src1,
1234 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1235 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1236 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1238 (int_x86_sse2_cvtsi642sd VR128:$src1,
1239 (loadi64 addr:$src2)))]>;
1242 // Signed i64 -> f32
1243 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1244 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1245 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1246 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1247 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1248 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1250 let isTwoAddress = 1 in {
1251 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1252 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1253 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1255 (int_x86_sse_cvtsi642ss VR128:$src1,
1257 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1258 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1259 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1261 (int_x86_sse_cvtsi642ss VR128:$src1,
1262 (loadi64 addr:$src2)))]>;
1265 // f32 -> signed i64
1266 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1267 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1269 (int_x86_sse_cvtss2si64 VR128:$src))]>;
1270 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1271 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1272 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1273 (load addr:$src)))]>;
1274 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1275 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1276 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1277 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1278 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1279 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1280 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1281 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1283 (int_x86_sse_cvttss2si64 VR128:$src))]>;
1284 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1285 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1287 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1289 //===----------------------------------------------------------------------===//
1290 // Alias Instructions
1291 //===----------------------------------------------------------------------===//
1293 // Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1294 // equivalent due to implicit zero-extending, and it sometimes has a smaller
1296 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1297 // FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1298 // when we have a better way to specify isel priority.
1299 let Defs = [EFLAGS], AddedComplexity = 1,
1300 isReMaterializable = 1, isAsCheapAsAMove = 1 in
1301 def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1302 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1303 [(set GR64:$dst, 0)]>;
1305 // Materialize i64 constant where top 32-bits are zero.
1306 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1307 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1308 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1309 [(set GR64:$dst, i64immZExt32:$src)]>;
1311 //===----------------------------------------------------------------------===//
1312 // Thread Local Storage Instructions
1313 //===----------------------------------------------------------------------===//
1315 // All calls clobber the non-callee saved registers. RSP is marked as
1316 // a use to prevent stack-pointer assignments that appear immediately
1317 // before calls from potentially appearing dead.
1318 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1319 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1320 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1321 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1322 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1324 def TLS_addr64 : I<0, Pseudo, (outs), (ins i64imm:$sym),
1326 "leaq\t${sym:mem}(%rip), %rdi; "
1329 "call\t__tls_get_addr@PLT",
1330 [(X86tlsaddr tglobaltlsaddr:$sym)]>,
1331 Requires<[In64BitMode]>;
1333 let AddedComplexity = 5 in
1334 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1335 "movq\t%gs:$src, $dst",
1336 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1338 let AddedComplexity = 5 in
1339 def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1340 "movq\t%fs:$src, $dst",
1341 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1343 //===----------------------------------------------------------------------===//
1344 // Atomic Instructions
1345 //===----------------------------------------------------------------------===//
1347 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1348 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1350 "cmpxchgq\t$swap,$ptr",
1351 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1354 let Constraints = "$val = $dst" in {
1355 let Defs = [EFLAGS] in
1356 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1359 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1361 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1363 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1366 // Atomic exchange, and, or, xor
1367 let Constraints = "$val = $dst", Defs = [EFLAGS],
1368 usesCustomDAGSchedInserter = 1 in {
1369 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1370 "#ATOMAND64 PSEUDO!",
1371 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1372 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1373 "#ATOMOR64 PSEUDO!",
1374 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1375 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1376 "#ATOMXOR64 PSEUDO!",
1377 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1378 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1379 "#ATOMNAND64 PSEUDO!",
1380 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1381 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1382 "#ATOMMIN64 PSEUDO!",
1383 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1384 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1385 "#ATOMMAX64 PSEUDO!",
1386 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1387 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1388 "#ATOMUMIN64 PSEUDO!",
1389 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1390 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1391 "#ATOMUMAX64 PSEUDO!",
1392 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1395 //===----------------------------------------------------------------------===//
1396 // Non-Instruction Patterns
1397 //===----------------------------------------------------------------------===//
1399 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
1400 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1401 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1402 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1403 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1404 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1405 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1406 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1407 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1409 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1410 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1411 Requires<[SmallCode, IsStatic]>;
1412 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1413 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1414 Requires<[SmallCode, IsStatic]>;
1415 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1416 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1417 Requires<[SmallCode, IsStatic]>;
1418 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1419 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1420 Requires<[SmallCode, IsStatic]>;
1423 // Direct PC relative function call for small code model. 32-bit displacement
1424 // sign extended to 64-bit.
1425 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1426 (CALL64pcrel32 tglobaladdr:$dst)>;
1427 def : Pat<(X86call (i64 texternalsym:$dst)),
1428 (CALL64pcrel32 texternalsym:$dst)>;
1430 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1431 (CALL64pcrel32 tglobaladdr:$dst)>;
1432 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1433 (CALL64pcrel32 texternalsym:$dst)>;
1435 def : Pat<(X86tailcall GR64:$dst),
1436 (CALL64r GR64:$dst)>;
1440 def : Pat<(X86tailcall GR32:$dst),
1442 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1444 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1447 def : Pat<(X86tcret GR64:$dst, imm:$off),
1448 (TCRETURNri64 GR64:$dst, imm:$off)>;
1450 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1451 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1453 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1454 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1458 // TEST R,R is smaller than CMP R,0
1459 def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
1460 (TEST64rr GR64:$src1, GR64:$src1)>;
1462 // Conditional moves with folded loads with operands swapped and conditions
1464 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1465 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1466 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1467 (CMOVB64rm GR64:$src2, addr:$src1)>;
1468 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1469 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1470 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1471 (CMOVE64rm GR64:$src2, addr:$src1)>;
1472 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1473 (CMOVA64rm GR64:$src2, addr:$src1)>;
1474 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1475 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1476 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1477 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1478 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1479 (CMOVL64rm GR64:$src2, addr:$src1)>;
1480 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1481 (CMOVG64rm GR64:$src2, addr:$src1)>;
1482 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1483 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1484 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1485 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1486 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1487 (CMOVP64rm GR64:$src2, addr:$src1)>;
1488 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1489 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1490 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1491 (CMOVS64rm GR64:$src2, addr:$src1)>;
1492 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1493 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1494 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1495 (CMOVO64rm GR64:$src2, addr:$src1)>;
1497 // zextload bool -> zextload byte
1498 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1501 // When extloading from 16-bit and smaller memory locations into 64-bit registers,
1502 // use zero-extending loads so that the entire 64-bit register is defined, avoiding
1503 // partial-register updates.
1504 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1505 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1506 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1507 // For other extloads, use subregs, since the high contents of the register are
1508 // defined after an extload.
1509 def : Pat<(extloadi64i32 addr:$src),
1510 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1512 def : Pat<(extloadi16i1 addr:$src),
1513 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1515 Requires<[In64BitMode]>;
1516 def : Pat<(extloadi16i8 addr:$src),
1517 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1519 Requires<[In64BitMode]>;
1522 def : Pat<(i64 (anyext GR8:$src)),
1523 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1524 def : Pat<(i64 (anyext GR16:$src)),
1525 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
1526 def : Pat<(i64 (anyext GR32:$src)),
1527 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
1528 def : Pat<(i16 (anyext GR8:$src)),
1529 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1530 Requires<[In64BitMode]>;
1531 def : Pat<(i32 (anyext GR8:$src)),
1532 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1533 Requires<[In64BitMode]>;
1535 //===----------------------------------------------------------------------===//
1537 //===----------------------------------------------------------------------===//
1539 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1540 // +128 doesn't, so in this special case use a sub instead of an add.
1541 def : Pat<(add GR64:$src1, 128),
1542 (SUB64ri8 GR64:$src1, -128)>;
1543 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1544 (SUB64mi8 addr:$dst, -128)>;
1546 // The same trick applies for 32-bit immediate fields in 64-bit
1548 def : Pat<(add GR64:$src1, 0x0000000080000000),
1549 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1550 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1551 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1553 // r & (2^32-1) ==> movz
1554 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1555 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1556 // r & (2^16-1) ==> movz
1557 def : Pat<(and GR64:$src, 0xffff),
1558 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1559 // r & (2^8-1) ==> movz
1560 def : Pat<(and GR64:$src, 0xff),
1561 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1562 // r & (2^8-1) ==> movz
1563 def : Pat<(and GR32:$src1, 0xff),
1564 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
1565 Requires<[In64BitMode]>;
1566 // r & (2^8-1) ==> movz
1567 def : Pat<(and GR16:$src1, 0xff),
1568 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1569 Requires<[In64BitMode]>;
1571 // sext_inreg patterns
1572 def : Pat<(sext_inreg GR64:$src, i32),
1573 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1574 def : Pat<(sext_inreg GR64:$src, i16),
1575 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1576 def : Pat<(sext_inreg GR64:$src, i8),
1577 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1578 def : Pat<(sext_inreg GR32:$src, i8),
1579 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1580 Requires<[In64BitMode]>;
1581 def : Pat<(sext_inreg GR16:$src, i8),
1582 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1583 Requires<[In64BitMode]>;
1586 def : Pat<(i32 (trunc GR64:$src)),
1587 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
1588 def : Pat<(i16 (trunc GR64:$src)),
1589 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
1590 def : Pat<(i8 (trunc GR64:$src)),
1591 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
1592 def : Pat<(i8 (trunc GR32:$src)),
1593 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
1594 Requires<[In64BitMode]>;
1595 def : Pat<(i8 (trunc GR16:$src)),
1596 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1597 Requires<[In64BitMode]>;
1599 // h-register tricks.
1600 // For now, be conservative on x86-64 and use an h-register extract only if the
1601 // value is immediately zero-extended or stored, which are somewhat common
1602 // cases. This uses a bunch of code to prevent a register requiring a REX prefix
1603 // from being allocated in the same instruction as the h register, as there's
1604 // currently no way to describe this requirement to the register allocator.
1606 // h-register extract and zero-extend.
1607 def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1611 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
1612 x86_subreg_8bit_hi)),
1614 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1616 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
1617 x86_subreg_8bit_hi))>,
1618 Requires<[In64BitMode]>;
1619 def : Pat<(srl_su GR16:$src, (i8 8)),
1622 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1623 x86_subreg_8bit_hi)),
1625 Requires<[In64BitMode]>;
1626 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1628 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1629 x86_subreg_8bit_hi))>,
1630 Requires<[In64BitMode]>;
1631 def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1635 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1636 x86_subreg_8bit_hi)),
1639 // h-register extract and store.
1640 def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1643 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
1644 x86_subreg_8bit_hi))>;
1645 def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1648 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
1649 x86_subreg_8bit_hi))>,
1650 Requires<[In64BitMode]>;
1651 def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1654 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1655 x86_subreg_8bit_hi))>,
1656 Requires<[In64BitMode]>;
1658 // (shl x, 1) ==> (add x, x)
1659 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1661 // (shl x (and y, 63)) ==> (shl x, y)
1662 def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1663 (SHL64rCL GR64:$src1)>;
1664 def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1665 (SHL64mCL addr:$dst)>;
1667 def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1668 (SHR64rCL GR64:$src1)>;
1669 def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1670 (SHR64mCL addr:$dst)>;
1672 def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1673 (SAR64rCL GR64:$src1)>;
1674 def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1675 (SAR64mCL addr:$dst)>;
1677 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1678 def : Pat<(or (srl GR64:$src1, CL:$amt),
1679 (shl GR64:$src2, (sub 64, CL:$amt))),
1680 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1682 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1683 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1684 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1686 def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1687 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1688 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1690 def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1691 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1693 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1695 def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1696 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1698 def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1699 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1700 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1702 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1703 def : Pat<(or (shl GR64:$src1, CL:$amt),
1704 (srl GR64:$src2, (sub 64, CL:$amt))),
1705 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1707 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1708 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1709 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1711 def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1712 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1713 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1715 def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1716 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1718 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1720 def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1721 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1723 def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1724 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1725 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1727 // X86 specific add which produces a flag.
1728 def : Pat<(addc GR64:$src1, GR64:$src2),
1729 (ADD64rr GR64:$src1, GR64:$src2)>;
1730 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1731 (ADD64rm GR64:$src1, addr:$src2)>;
1732 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1733 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1734 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1735 (ADD64ri32 GR64:$src1, imm:$src2)>;
1737 def : Pat<(subc GR64:$src1, GR64:$src2),
1738 (SUB64rr GR64:$src1, GR64:$src2)>;
1739 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1740 (SUB64rm GR64:$src1, addr:$src2)>;
1741 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1742 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1743 def : Pat<(subc GR64:$src1, imm:$src2),
1744 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1746 //===----------------------------------------------------------------------===//
1747 // EFLAGS-defining Patterns
1748 //===----------------------------------------------------------------------===//
1750 // Register-Register Addition with EFLAGS result
1751 def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
1753 (ADD64rr GR64:$src1, GR64:$src2)>;
1755 // Register-Integer Addition with EFLAGS result
1756 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
1758 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1759 def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
1761 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
1763 // Register-Memory Addition with EFLAGS result
1764 def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
1766 (ADD64rm GR64:$src1, addr:$src2)>;
1768 // Memory-Register Addition with EFLAGS result
1769 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
1772 (ADD64mr addr:$dst, GR64:$src2)>;
1773 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1776 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
1777 def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1780 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
1782 // Register-Register Subtraction with EFLAGS result
1783 def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
1785 (SUB64rr GR64:$src1, GR64:$src2)>;
1787 // Register-Memory Subtraction with EFLAGS result
1788 def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
1790 (SUB64rm GR64:$src1, addr:$src2)>;
1792 // Register-Integer Subtraction with EFLAGS result
1793 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
1795 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1796 def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
1798 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1800 // Memory-Register Subtraction with EFLAGS result
1801 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
1804 (SUB64mr addr:$dst, GR64:$src2)>;
1806 // Memory-Integer Subtraction with EFLAGS result
1807 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
1810 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
1811 def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
1814 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
1816 // Register-Register Signed Integer Multiplication with EFLAGS result
1817 def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
1819 (IMUL64rr GR64:$src1, GR64:$src2)>;
1821 // Register-Memory Signed Integer Multiplication with EFLAGS result
1822 def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
1824 (IMUL64rm GR64:$src1, addr:$src2)>;
1826 // Register-Integer Signed Integer Multiplication with EFLAGS result
1827 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
1829 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
1830 def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
1832 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
1834 // Memory-Integer Signed Integer Multiplication with EFLAGS result
1835 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
1837 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
1838 def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
1840 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
1842 // INC and DEC with EFLAGS result. Note that these do not set CF.
1843 def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1844 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1845 def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1847 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1848 def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1849 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1850 def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1852 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1854 def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1855 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1856 def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1858 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1859 def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1860 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1861 def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1863 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1865 def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1866 (INC64r GR64:$src)>;
1867 def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1869 (INC64m addr:$dst)>;
1870 def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1871 (DEC64r GR64:$src)>;
1872 def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1874 (DEC64m addr:$dst)>;
1876 //===----------------------------------------------------------------------===//
1877 // X86-64 SSE Instructions
1878 //===----------------------------------------------------------------------===//
1880 // Move instructions...
1882 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
1883 "mov{d|q}\t{$src, $dst|$dst, $src}",
1885 (v2i64 (scalar_to_vector GR64:$src)))]>;
1886 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
1887 "mov{d|q}\t{$src, $dst|$dst, $src}",
1888 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1891 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1892 "mov{d|q}\t{$src, $dst|$dst, $src}",
1893 [(set FR64:$dst, (bitconvert GR64:$src))]>;
1894 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1895 "movq\t{$src, $dst|$dst, $src}",
1896 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1898 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
1899 "mov{d|q}\t{$src, $dst|$dst, $src}",
1900 [(set GR64:$dst, (bitconvert FR64:$src))]>;
1901 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
1902 "movq\t{$src, $dst|$dst, $src}",
1903 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
1905 //===----------------------------------------------------------------------===//
1906 // X86-64 SSE4.1 Instructions
1907 //===----------------------------------------------------------------------===//
1909 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1910 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
1911 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
1912 (ins VR128:$src1, i32i8imm:$src2),
1913 !strconcat(OpcodeStr,
1914 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1916 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
1917 def mr : SS4AIi8<opc, MRMDestMem, (outs),
1918 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1919 !strconcat(OpcodeStr,
1920 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1921 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1922 addr:$dst)]>, OpSize, REX_W;
1925 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1927 let isTwoAddress = 1 in {
1928 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
1929 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
1930 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1931 !strconcat(OpcodeStr,
1932 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1934 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1936 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
1937 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1938 !strconcat(OpcodeStr,
1939 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1941 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1942 imm:$src3)))]>, OpSize, REX_W;
1946 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;