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, 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],
112 def CALL64pcrel32 : I<0xE8, RawFrm, (outs), (ins i64imm:$dst, variable_ops),
113 "call\t${dst:call}", []>;
114 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
115 "call\t{*}$dst", [(X86call GR64:$dst)]>;
116 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
117 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
122 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
123 def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset, variable_ops),
124 "#TC_RETURN $dst $offset",
127 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
128 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset, variable_ops),
129 "#TC_RETURN $dst $offset",
133 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
134 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst # TAILCALL",
138 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
139 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
140 [(brind GR64:$dst)]>;
141 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
142 [(brind (loadi64 addr:$dst))]>;
145 //===----------------------------------------------------------------------===//
146 // EH Pseudo Instructions
148 let isTerminator = 1, isReturn = 1, isBarrier = 1,
150 def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
151 "ret\t#eh_return, addr: $addr",
152 [(X86ehret GR64:$addr)]>;
156 //===----------------------------------------------------------------------===//
157 // Miscellaneous Instructions...
159 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
160 def LEAVE64 : I<0xC9, RawFrm,
161 (outs), (ins), "leave", []>;
162 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
164 def POP64r : I<0x58, AddRegFrm,
165 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
167 def PUSH64r : I<0x50, AddRegFrm,
168 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
171 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
172 def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
173 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
174 def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
176 def LEA64_32r : I<0x8D, MRMSrcMem,
177 (outs GR32:$dst), (ins lea64_32mem:$src),
178 "lea{l}\t{$src|$dst}, {$dst|$src}",
179 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
181 let isReMaterializable = 1 in
182 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
183 "lea{q}\t{$src|$dst}, {$dst|$src}",
184 [(set GR64:$dst, lea64addr:$src)]>;
186 let isTwoAddress = 1 in
187 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
189 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
191 // Bit scan instructions.
192 let Defs = [EFLAGS] in {
193 def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
194 "bsf{q}\t{$src, $dst|$dst, $src}",
195 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
196 def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
197 "bsf{q}\t{$src, $dst|$dst, $src}",
198 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
199 (implicit EFLAGS)]>, TB;
201 def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
202 "bsr{q}\t{$src, $dst|$dst, $src}",
203 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
204 def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
205 "bsr{q}\t{$src, $dst|$dst, $src}",
206 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
207 (implicit EFLAGS)]>, TB;
211 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
212 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
213 [(X86rep_movs i64)]>, REP;
214 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
215 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
216 [(X86rep_stos i64)]>, REP;
218 //===----------------------------------------------------------------------===//
219 // Move Instructions...
222 let neverHasSideEffects = 1 in
223 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
224 "mov{q}\t{$src, $dst|$dst, $src}", []>;
226 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
227 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
228 "movabs{q}\t{$src, $dst|$dst, $src}",
229 [(set GR64:$dst, imm:$src)]>;
230 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
231 "mov{q}\t{$src, $dst|$dst, $src}",
232 [(set GR64:$dst, i64immSExt32:$src)]>;
235 let canFoldAsLoad = 1 in
236 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
237 "mov{q}\t{$src, $dst|$dst, $src}",
238 [(set GR64:$dst, (load addr:$src))]>;
240 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
241 "mov{q}\t{$src, $dst|$dst, $src}",
242 [(store GR64:$src, addr:$dst)]>;
243 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
244 "mov{q}\t{$src, $dst|$dst, $src}",
245 [(store i64immSExt32:$src, addr:$dst)]>;
247 // Sign/Zero extenders
249 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
250 "movs{bq|x}\t{$src, $dst|$dst, $src}",
251 [(set GR64:$dst, (sext GR8:$src))]>, TB;
252 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
253 "movs{bq|x}\t{$src, $dst|$dst, $src}",
254 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
255 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
256 "movs{wq|x}\t{$src, $dst|$dst, $src}",
257 [(set GR64:$dst, (sext GR16:$src))]>, TB;
258 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
259 "movs{wq|x}\t{$src, $dst|$dst, $src}",
260 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
261 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
262 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
263 [(set GR64:$dst, (sext GR32:$src))]>;
264 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
265 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
266 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
268 // Use movzbl instead of movzbq when the destination is a register; it's
269 // equivalent due to implicit zero-extending, and it has a smaller encoding.
270 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
271 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
272 [(set GR64:$dst, (zext GR8:$src))]>, TB;
273 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
274 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
275 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
276 // Use movzwl instead of movzwq when the destination is a register; it's
277 // equivalent due to implicit zero-extending, and it has a smaller encoding.
278 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
279 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
280 [(set GR64:$dst, (zext GR16:$src))]>, TB;
281 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
282 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
283 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
285 // There's no movzlq instruction, but movl can be used for this purpose, using
286 // implicit zero-extension. We need this because the seeming alternative for
287 // implementing zext from 32 to 64, an EXTRACT_SUBREG/SUBREG_TO_REG pair, isn't
288 // safe because both instructions could be optimized away in the
289 // register-to-register case, leaving nothing behind to do the zero extension.
290 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
291 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
292 [(set GR64:$dst, (zext GR32:$src))]>;
293 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
294 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
295 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
297 let neverHasSideEffects = 1 in {
298 let Defs = [RAX], Uses = [EAX] in
299 def CDQE : RI<0x98, RawFrm, (outs), (ins),
300 "{cltq|cdqe}", []>; // RAX = signext(EAX)
302 let Defs = [RAX,RDX], Uses = [RAX] in
303 def CQO : RI<0x99, RawFrm, (outs), (ins),
304 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
307 //===----------------------------------------------------------------------===//
308 // Arithmetic Instructions...
311 let Defs = [EFLAGS] in {
312 let isTwoAddress = 1 in {
313 let isConvertibleToThreeAddress = 1 in {
314 let isCommutable = 1 in
315 // Register-Register Addition
316 def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
317 "add{q}\t{$src2, $dst|$dst, $src2}",
318 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
321 // Register-Integer Addition
322 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
323 "add{q}\t{$src2, $dst|$dst, $src2}",
324 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
326 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
327 "add{q}\t{$src2, $dst|$dst, $src2}",
328 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
330 } // isConvertibleToThreeAddress
332 // Register-Memory Addition
333 def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
334 "add{q}\t{$src2, $dst|$dst, $src2}",
335 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
339 // Memory-Register Addition
340 def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
341 "add{q}\t{$src2, $dst|$dst, $src2}",
342 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
344 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
345 "add{q}\t{$src2, $dst|$dst, $src2}",
346 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
348 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
349 "add{q}\t{$src2, $dst|$dst, $src2}",
350 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
353 let Uses = [EFLAGS] in {
354 let isTwoAddress = 1 in {
355 let isCommutable = 1 in
356 def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
357 "adc{q}\t{$src2, $dst|$dst, $src2}",
358 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
360 def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
361 "adc{q}\t{$src2, $dst|$dst, $src2}",
362 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
364 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
365 "adc{q}\t{$src2, $dst|$dst, $src2}",
366 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
367 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
368 "adc{q}\t{$src2, $dst|$dst, $src2}",
369 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
372 def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
373 "adc{q}\t{$src2, $dst|$dst, $src2}",
374 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
375 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
376 "adc{q}\t{$src2, $dst|$dst, $src2}",
377 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
378 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
379 "adc{q}\t{$src2, $dst|$dst, $src2}",
380 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
383 let isTwoAddress = 1 in {
384 // Register-Register Subtraction
385 def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
386 "sub{q}\t{$src2, $dst|$dst, $src2}",
387 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
390 // Register-Memory Subtraction
391 def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
392 "sub{q}\t{$src2, $dst|$dst, $src2}",
393 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
396 // Register-Integer Subtraction
397 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
398 (ins GR64:$src1, i64i8imm:$src2),
399 "sub{q}\t{$src2, $dst|$dst, $src2}",
400 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
402 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
403 (ins GR64:$src1, i64i32imm:$src2),
404 "sub{q}\t{$src2, $dst|$dst, $src2}",
405 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
409 // Memory-Register Subtraction
410 def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
411 "sub{q}\t{$src2, $dst|$dst, $src2}",
412 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
415 // Memory-Integer Subtraction
416 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
417 "sub{q}\t{$src2, $dst|$dst, $src2}",
418 [(store (sub (load addr:$dst), i64immSExt8:$src2),
421 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
422 "sub{q}\t{$src2, $dst|$dst, $src2}",
423 [(store (sub (load addr:$dst), i64immSExt32:$src2),
427 let Uses = [EFLAGS] in {
428 let isTwoAddress = 1 in {
429 def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
430 "sbb{q}\t{$src2, $dst|$dst, $src2}",
431 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
433 def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
434 "sbb{q}\t{$src2, $dst|$dst, $src2}",
435 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
437 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
438 "sbb{q}\t{$src2, $dst|$dst, $src2}",
439 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
440 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
441 "sbb{q}\t{$src2, $dst|$dst, $src2}",
442 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
445 def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
446 "sbb{q}\t{$src2, $dst|$dst, $src2}",
447 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
448 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
449 "sbb{q}\t{$src2, $dst|$dst, $src2}",
450 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
451 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
452 "sbb{q}\t{$src2, $dst|$dst, $src2}",
453 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
457 // Unsigned multiplication
458 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
459 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
460 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
462 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
463 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
465 // Signed multiplication
466 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
467 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
469 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
470 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
473 let Defs = [EFLAGS] in {
474 let isTwoAddress = 1 in {
475 let isCommutable = 1 in
476 // Register-Register Signed Integer Multiplication
477 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
478 (ins GR64:$src1, GR64:$src2),
479 "imul{q}\t{$src2, $dst|$dst, $src2}",
480 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
481 (implicit EFLAGS)]>, TB;
483 // Register-Memory Signed Integer Multiplication
484 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
485 (ins GR64:$src1, i64mem:$src2),
486 "imul{q}\t{$src2, $dst|$dst, $src2}",
487 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
488 (implicit EFLAGS)]>, TB;
491 // Suprisingly enough, these are not two address instructions!
493 // Register-Integer Signed Integer Multiplication
494 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
495 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
496 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
497 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
499 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
500 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
501 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
502 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
505 // Memory-Integer Signed Integer Multiplication
506 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
507 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
508 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
509 [(set GR64:$dst, (mul (load addr:$src1),
512 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
513 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
514 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
515 [(set GR64:$dst, (mul (load addr:$src1),
516 i64immSExt32:$src2)),
520 // Unsigned division / remainder
521 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
522 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
524 // Signed division / remainder
525 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
526 "idiv{q}\t$src", []>;
528 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
530 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
531 "idiv{q}\t$src", []>;
535 // Unary instructions
536 let Defs = [EFLAGS], CodeSize = 2 in {
537 let isTwoAddress = 1 in
538 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
539 [(set GR64:$dst, (ineg GR64:$src))]>;
540 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
541 [(store (ineg (loadi64 addr:$dst)), addr:$dst)]>;
543 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
544 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
545 [(set GR64:$dst, (add GR64:$src, 1))]>;
546 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
547 [(store (add (loadi64 addr:$dst), 1), addr:$dst)]>;
549 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
550 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
551 [(set GR64:$dst, (add GR64:$src, -1))]>;
552 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
553 [(store (add (loadi64 addr:$dst), -1), addr:$dst)]>;
555 // In 64-bit mode, single byte INC and DEC cannot be encoded.
556 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
557 // Can transform into LEA.
558 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
559 [(set GR16:$dst, (add GR16:$src, 1))]>,
560 OpSize, Requires<[In64BitMode]>;
561 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
562 [(set GR32:$dst, (add GR32:$src, 1))]>,
563 Requires<[In64BitMode]>;
564 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
565 [(set GR16:$dst, (add GR16:$src, -1))]>,
566 OpSize, Requires<[In64BitMode]>;
567 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
568 [(set GR32:$dst, (add GR32:$src, -1))]>,
569 Requires<[In64BitMode]>;
570 } // isConvertibleToThreeAddress
572 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
573 // how to unfold them.
574 let isTwoAddress = 0, CodeSize = 2 in {
575 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
576 [(store (add (loadi16 addr:$dst), 1), addr:$dst)]>,
577 OpSize, Requires<[In64BitMode]>;
578 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
579 [(store (add (loadi32 addr:$dst), 1), addr:$dst)]>,
580 Requires<[In64BitMode]>;
581 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
582 [(store (add (loadi16 addr:$dst), -1), addr:$dst)]>,
583 OpSize, Requires<[In64BitMode]>;
584 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
585 [(store (add (loadi32 addr:$dst), -1), addr:$dst)]>,
586 Requires<[In64BitMode]>;
588 } // Defs = [EFLAGS], CodeSize
591 let Defs = [EFLAGS] in {
592 // Shift instructions
593 let isTwoAddress = 1 in {
595 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
596 "shl{q}\t{%cl, $dst|$dst, %CL}",
597 [(set GR64:$dst, (shl GR64:$src, CL))]>;
598 let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
599 def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
600 "shl{q}\t{$src2, $dst|$dst, $src2}",
601 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
602 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
607 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
608 "shl{q}\t{%cl, $dst|$dst, %CL}",
609 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
610 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
611 "shl{q}\t{$src, $dst|$dst, $src}",
612 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
613 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
615 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
617 let isTwoAddress = 1 in {
619 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
620 "shr{q}\t{%cl, $dst|$dst, %CL}",
621 [(set GR64:$dst, (srl GR64:$src, CL))]>;
622 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
623 "shr{q}\t{$src2, $dst|$dst, $src2}",
624 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
625 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
627 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
631 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
632 "shr{q}\t{%cl, $dst|$dst, %CL}",
633 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
634 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
635 "shr{q}\t{$src, $dst|$dst, $src}",
636 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
637 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
639 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
641 let isTwoAddress = 1 in {
643 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
644 "sar{q}\t{%cl, $dst|$dst, %CL}",
645 [(set GR64:$dst, (sra GR64:$src, CL))]>;
646 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
647 "sar{q}\t{$src2, $dst|$dst, $src2}",
648 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
649 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
651 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
655 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
656 "sar{q}\t{%cl, $dst|$dst, %CL}",
657 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
658 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
659 "sar{q}\t{$src, $dst|$dst, $src}",
660 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
661 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
663 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
665 // Rotate instructions
666 let isTwoAddress = 1 in {
668 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
669 "rol{q}\t{%cl, $dst|$dst, %CL}",
670 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
671 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
672 "rol{q}\t{$src2, $dst|$dst, $src2}",
673 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
674 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
676 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
680 def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
681 "rol{q}\t{%cl, $dst|$dst, %CL}",
682 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
683 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
684 "rol{q}\t{$src, $dst|$dst, $src}",
685 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
686 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
688 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
690 let isTwoAddress = 1 in {
692 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
693 "ror{q}\t{%cl, $dst|$dst, %CL}",
694 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
695 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
696 "ror{q}\t{$src2, $dst|$dst, $src2}",
697 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
698 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
700 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
704 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
705 "ror{q}\t{%cl, $dst|$dst, %CL}",
706 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
707 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
708 "ror{q}\t{$src, $dst|$dst, $src}",
709 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
710 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
712 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
714 // Double shift instructions (generalizations of rotate)
715 let isTwoAddress = 1 in {
717 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
718 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
719 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
720 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
721 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
722 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
725 let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
726 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
727 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
728 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
729 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
732 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
733 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
734 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
735 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
742 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
743 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
744 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
746 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
747 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
748 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
751 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
752 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
753 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
754 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
755 (i8 imm:$src3)), addr:$dst)]>,
757 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
758 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
759 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
760 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
761 (i8 imm:$src3)), addr:$dst)]>,
765 //===----------------------------------------------------------------------===//
766 // Logical Instructions...
769 let isTwoAddress = 1 , AddedComplexity = 15 in
770 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
771 [(set GR64:$dst, (not GR64:$src))]>;
772 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
773 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
775 let Defs = [EFLAGS] in {
776 let isTwoAddress = 1 in {
777 let isCommutable = 1 in
778 def AND64rr : RI<0x21, MRMDestReg,
779 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
780 "and{q}\t{$src2, $dst|$dst, $src2}",
781 [(set GR64:$dst, (and GR64:$src1, GR64:$src2))]>;
782 def AND64rm : RI<0x23, MRMSrcMem,
783 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
784 "and{q}\t{$src2, $dst|$dst, $src2}",
785 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2)))]>;
786 def AND64ri8 : RIi8<0x83, MRM4r,
787 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
788 "and{q}\t{$src2, $dst|$dst, $src2}",
789 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2))]>;
790 def AND64ri32 : RIi32<0x81, MRM4r,
791 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
792 "and{q}\t{$src2, $dst|$dst, $src2}",
793 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2))]>;
796 def AND64mr : RI<0x21, MRMDestMem,
797 (outs), (ins i64mem:$dst, GR64:$src),
798 "and{q}\t{$src, $dst|$dst, $src}",
799 [(store (and (load addr:$dst), GR64:$src), addr:$dst)]>;
800 def AND64mi8 : RIi8<0x83, MRM4m,
801 (outs), (ins i64mem:$dst, i64i8imm :$src),
802 "and{q}\t{$src, $dst|$dst, $src}",
803 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
804 def AND64mi32 : RIi32<0x81, MRM4m,
805 (outs), (ins i64mem:$dst, i64i32imm:$src),
806 "and{q}\t{$src, $dst|$dst, $src}",
807 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
809 let isTwoAddress = 1 in {
810 let isCommutable = 1 in
811 def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
812 "or{q}\t{$src2, $dst|$dst, $src2}",
813 [(set GR64:$dst, (or GR64:$src1, GR64:$src2))]>;
814 def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
815 "or{q}\t{$src2, $dst|$dst, $src2}",
816 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2)))]>;
817 def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
818 "or{q}\t{$src2, $dst|$dst, $src2}",
819 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2))]>;
820 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
821 "or{q}\t{$src2, $dst|$dst, $src2}",
822 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2))]>;
825 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
826 "or{q}\t{$src, $dst|$dst, $src}",
827 [(store (or (load addr:$dst), GR64:$src), addr:$dst)]>;
828 def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
829 "or{q}\t{$src, $dst|$dst, $src}",
830 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
831 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
832 "or{q}\t{$src, $dst|$dst, $src}",
833 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
835 let isTwoAddress = 1 in {
836 let isCommutable = 1 in
837 def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
838 "xor{q}\t{$src2, $dst|$dst, $src2}",
839 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2))]>;
840 def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
841 "xor{q}\t{$src2, $dst|$dst, $src2}",
842 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2)))]>;
843 def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
844 "xor{q}\t{$src2, $dst|$dst, $src2}",
845 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2))]>;
846 def XOR64ri32 : RIi32<0x81, MRM6r,
847 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
848 "xor{q}\t{$src2, $dst|$dst, $src2}",
849 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2))]>;
852 def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
853 "xor{q}\t{$src, $dst|$dst, $src}",
854 [(store (xor (load addr:$dst), GR64:$src), addr:$dst)]>;
855 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
856 "xor{q}\t{$src, $dst|$dst, $src}",
857 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
858 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
859 "xor{q}\t{$src, $dst|$dst, $src}",
860 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
863 //===----------------------------------------------------------------------===//
864 // Comparison Instructions...
867 // Integer comparison
868 let Defs = [EFLAGS] in {
869 let isCommutable = 1 in
870 def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
871 "test{q}\t{$src2, $src1|$src1, $src2}",
872 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
874 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
875 "test{q}\t{$src2, $src1|$src1, $src2}",
876 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
878 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
879 (ins GR64:$src1, i64i32imm:$src2),
880 "test{q}\t{$src2, $src1|$src1, $src2}",
881 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
883 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
884 (ins i64mem:$src1, i64i32imm:$src2),
885 "test{q}\t{$src2, $src1|$src1, $src2}",
886 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
889 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
890 "cmp{q}\t{$src2, $src1|$src1, $src2}",
891 [(X86cmp GR64:$src1, GR64:$src2),
893 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
894 "cmp{q}\t{$src2, $src1|$src1, $src2}",
895 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
897 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
898 "cmp{q}\t{$src2, $src1|$src1, $src2}",
899 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
901 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
902 "cmp{q}\t{$src2, $src1|$src1, $src2}",
903 [(X86cmp GR64:$src1, i64immSExt8:$src2),
905 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
906 "cmp{q}\t{$src2, $src1|$src1, $src2}",
907 [(X86cmp GR64:$src1, i64immSExt32:$src2),
909 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
910 "cmp{q}\t{$src2, $src1|$src1, $src2}",
911 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
913 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
914 (ins i64mem:$src1, i64i32imm:$src2),
915 "cmp{q}\t{$src2, $src1|$src1, $src2}",
916 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
921 // TODO: BTC, BTR, and BTS
922 let Defs = [EFLAGS] in {
923 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
924 "bt{q}\t{$src2, $src1|$src1, $src2}",
925 [(X86bt GR64:$src1, GR64:$src2),
926 (implicit EFLAGS)]>, TB;
928 // Unlike with the register+register form, the memory+register form of the
929 // bt instruction does not ignore the high bits of the index. From ISel's
930 // perspective, this is pretty bizarre. Disable these instructions for now.
931 //def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
932 // "bt{q}\t{$src2, $src1|$src1, $src2}",
933 // [(X86bt (loadi64 addr:$src1), GR64:$src2),
934 // (implicit EFLAGS)]>, TB;
936 def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
937 "bt{q}\t{$src2, $src1|$src1, $src2}",
938 [(X86bt GR64:$src1, i64immSExt8:$src2),
939 (implicit EFLAGS)]>, TB;
940 // Note that these instructions don't need FastBTMem because that
941 // only applies when the other operand is in a register. When it's
942 // an immediate, bt is still fast.
943 def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
944 "bt{q}\t{$src2, $src1|$src1, $src2}",
945 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
946 (implicit EFLAGS)]>, TB;
950 let Uses = [EFLAGS], isTwoAddress = 1 in {
951 let isCommutable = 1 in {
952 def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
953 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
954 "cmovb\t{$src2, $dst|$dst, $src2}",
955 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
956 X86_COND_B, EFLAGS))]>, TB;
957 def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
958 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
959 "cmovae\t{$src2, $dst|$dst, $src2}",
960 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
961 X86_COND_AE, EFLAGS))]>, TB;
962 def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
963 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
964 "cmove\t{$src2, $dst|$dst, $src2}",
965 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
966 X86_COND_E, EFLAGS))]>, TB;
967 def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
968 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
969 "cmovne\t{$src2, $dst|$dst, $src2}",
970 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
971 X86_COND_NE, EFLAGS))]>, TB;
972 def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
973 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
974 "cmovbe\t{$src2, $dst|$dst, $src2}",
975 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
976 X86_COND_BE, EFLAGS))]>, TB;
977 def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
978 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
979 "cmova\t{$src2, $dst|$dst, $src2}",
980 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
981 X86_COND_A, EFLAGS))]>, TB;
982 def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
983 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
984 "cmovl\t{$src2, $dst|$dst, $src2}",
985 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
986 X86_COND_L, EFLAGS))]>, TB;
987 def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
988 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
989 "cmovge\t{$src2, $dst|$dst, $src2}",
990 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
991 X86_COND_GE, EFLAGS))]>, TB;
992 def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
993 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
994 "cmovle\t{$src2, $dst|$dst, $src2}",
995 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
996 X86_COND_LE, EFLAGS))]>, TB;
997 def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
998 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
999 "cmovg\t{$src2, $dst|$dst, $src2}",
1000 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1001 X86_COND_G, EFLAGS))]>, TB;
1002 def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
1003 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1004 "cmovs\t{$src2, $dst|$dst, $src2}",
1005 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1006 X86_COND_S, EFLAGS))]>, TB;
1007 def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
1008 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1009 "cmovns\t{$src2, $dst|$dst, $src2}",
1010 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1011 X86_COND_NS, EFLAGS))]>, TB;
1012 def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
1013 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1014 "cmovp\t{$src2, $dst|$dst, $src2}",
1015 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1016 X86_COND_P, EFLAGS))]>, TB;
1017 def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
1018 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1019 "cmovnp\t{$src2, $dst|$dst, $src2}",
1020 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1021 X86_COND_NP, EFLAGS))]>, TB;
1022 def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1023 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1024 "cmovo\t{$src2, $dst|$dst, $src2}",
1025 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1026 X86_COND_O, EFLAGS))]>, TB;
1027 def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1028 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1029 "cmovno\t{$src2, $dst|$dst, $src2}",
1030 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1031 X86_COND_NO, EFLAGS))]>, TB;
1032 } // isCommutable = 1
1034 def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1035 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1036 "cmovb\t{$src2, $dst|$dst, $src2}",
1037 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1038 X86_COND_B, EFLAGS))]>, TB;
1039 def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1040 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1041 "cmovae\t{$src2, $dst|$dst, $src2}",
1042 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1043 X86_COND_AE, EFLAGS))]>, TB;
1044 def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1045 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1046 "cmove\t{$src2, $dst|$dst, $src2}",
1047 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1048 X86_COND_E, EFLAGS))]>, TB;
1049 def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1050 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1051 "cmovne\t{$src2, $dst|$dst, $src2}",
1052 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1053 X86_COND_NE, EFLAGS))]>, TB;
1054 def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1055 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1056 "cmovbe\t{$src2, $dst|$dst, $src2}",
1057 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1058 X86_COND_BE, EFLAGS))]>, TB;
1059 def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1060 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1061 "cmova\t{$src2, $dst|$dst, $src2}",
1062 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1063 X86_COND_A, EFLAGS))]>, TB;
1064 def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1065 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1066 "cmovl\t{$src2, $dst|$dst, $src2}",
1067 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1068 X86_COND_L, EFLAGS))]>, TB;
1069 def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1070 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1071 "cmovge\t{$src2, $dst|$dst, $src2}",
1072 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1073 X86_COND_GE, EFLAGS))]>, TB;
1074 def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1075 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1076 "cmovle\t{$src2, $dst|$dst, $src2}",
1077 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1078 X86_COND_LE, EFLAGS))]>, TB;
1079 def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1080 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1081 "cmovg\t{$src2, $dst|$dst, $src2}",
1082 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1083 X86_COND_G, EFLAGS))]>, TB;
1084 def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1085 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1086 "cmovs\t{$src2, $dst|$dst, $src2}",
1087 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1088 X86_COND_S, EFLAGS))]>, TB;
1089 def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1090 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1091 "cmovns\t{$src2, $dst|$dst, $src2}",
1092 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1093 X86_COND_NS, EFLAGS))]>, TB;
1094 def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1095 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1096 "cmovp\t{$src2, $dst|$dst, $src2}",
1097 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1098 X86_COND_P, EFLAGS))]>, TB;
1099 def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
1100 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1101 "cmovnp\t{$src2, $dst|$dst, $src2}",
1102 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1103 X86_COND_NP, EFLAGS))]>, TB;
1104 def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1105 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1106 "cmovo\t{$src2, $dst|$dst, $src2}",
1107 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1108 X86_COND_O, EFLAGS))]>, TB;
1109 def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1110 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1111 "cmovno\t{$src2, $dst|$dst, $src2}",
1112 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1113 X86_COND_NO, EFLAGS))]>, TB;
1116 //===----------------------------------------------------------------------===//
1117 // Conversion Instructions...
1120 // f64 -> signed i64
1121 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1122 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1124 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1125 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1126 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1127 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1128 (load addr:$src)))]>;
1129 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1130 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1131 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1132 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1133 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1134 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1135 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1136 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1138 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1139 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1140 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1142 (int_x86_sse2_cvttsd2si64
1143 (load addr:$src)))]>;
1145 // Signed i64 -> f64
1146 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1147 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1148 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1149 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1150 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1151 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1153 let isTwoAddress = 1 in {
1154 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1155 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1156 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1158 (int_x86_sse2_cvtsi642sd VR128:$src1,
1160 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1161 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1162 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1164 (int_x86_sse2_cvtsi642sd VR128:$src1,
1165 (loadi64 addr:$src2)))]>;
1168 // Signed i64 -> f32
1169 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1170 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1171 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1172 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1173 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1174 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1176 let isTwoAddress = 1 in {
1177 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1178 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1179 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1181 (int_x86_sse_cvtsi642ss VR128:$src1,
1183 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1184 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1185 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1187 (int_x86_sse_cvtsi642ss VR128:$src1,
1188 (loadi64 addr:$src2)))]>;
1191 // f32 -> signed i64
1192 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1193 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1195 (int_x86_sse_cvtss2si64 VR128:$src))]>;
1196 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1197 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1198 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1199 (load addr:$src)))]>;
1200 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1201 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1202 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1203 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1204 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1205 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1206 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1207 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1209 (int_x86_sse_cvttss2si64 VR128:$src))]>;
1210 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1211 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1213 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1215 //===----------------------------------------------------------------------===//
1216 // Alias Instructions
1217 //===----------------------------------------------------------------------===//
1219 // Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1220 // equivalent due to implicit zero-extending, and it sometimes has a smaller
1222 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1223 // FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1224 // when we have a better way to specify isel priority.
1225 let Defs = [EFLAGS], AddedComplexity = 1,
1226 isReMaterializable = 1, isAsCheapAsAMove = 1 in
1227 def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1228 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1229 [(set GR64:$dst, 0)]>;
1231 // Materialize i64 constant where top 32-bits are zero.
1232 let AddedComplexity = 1, isReMaterializable = 1 in
1233 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1234 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1235 [(set GR64:$dst, i64immZExt32:$src)]>;
1237 //===----------------------------------------------------------------------===//
1238 // Thread Local Storage Instructions
1239 //===----------------------------------------------------------------------===//
1241 def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
1242 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
1243 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
1245 let AddedComplexity = 5 in
1246 def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1247 "movq\t%gs:$src, $dst",
1248 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1250 //===----------------------------------------------------------------------===//
1251 // Atomic Instructions
1252 //===----------------------------------------------------------------------===//
1254 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1255 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1256 "lock\n\tcmpxchgq\t$swap,$ptr",
1257 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1260 let Constraints = "$val = $dst" in {
1261 let Defs = [EFLAGS] in
1262 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1263 "lock\n\txadd\t$val, $ptr",
1264 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1266 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1268 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1271 // Atomic exchange, and, or, xor
1272 let Constraints = "$val = $dst", Defs = [EFLAGS],
1273 usesCustomDAGSchedInserter = 1 in {
1274 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1275 "#ATOMAND64 PSEUDO!",
1276 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1277 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1278 "#ATOMOR64 PSEUDO!",
1279 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1280 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1281 "#ATOMXOR64 PSEUDO!",
1282 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1283 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1284 "#ATOMNAND64 PSEUDO!",
1285 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1286 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1287 "#ATOMMIN64 PSEUDO!",
1288 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1289 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1290 "#ATOMMAX64 PSEUDO!",
1291 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1292 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1293 "#ATOMUMIN64 PSEUDO!",
1294 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1295 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1296 "#ATOMUMAX64 PSEUDO!",
1297 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1300 //===----------------------------------------------------------------------===//
1301 // Non-Instruction Patterns
1302 //===----------------------------------------------------------------------===//
1304 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
1305 def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1306 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1307 def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1308 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1309 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1310 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1311 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1312 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1314 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1315 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1316 Requires<[SmallCode, IsStatic]>;
1317 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1318 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1319 Requires<[SmallCode, IsStatic]>;
1320 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1321 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1322 Requires<[SmallCode, IsStatic]>;
1323 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1324 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1325 Requires<[SmallCode, IsStatic]>;
1328 // Direct PC relative function call for small code model. 32-bit displacement
1329 // sign extended to 64-bit.
1330 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1331 (CALL64pcrel32 tglobaladdr:$dst)>;
1332 def : Pat<(X86call (i64 texternalsym:$dst)),
1333 (CALL64pcrel32 texternalsym:$dst)>;
1335 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1336 (CALL64pcrel32 tglobaladdr:$dst)>;
1337 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1338 (CALL64pcrel32 texternalsym:$dst)>;
1340 def : Pat<(X86tailcall GR64:$dst),
1341 (CALL64r GR64:$dst)>;
1345 def : Pat<(X86tailcall GR32:$dst),
1347 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1349 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1352 def : Pat<(X86tcret GR64:$dst, imm:$off),
1353 (TCRETURNri64 GR64:$dst, imm:$off)>;
1355 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1356 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1358 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1359 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1363 // TEST R,R is smaller than CMP R,0
1364 def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
1365 (TEST64rr GR64:$src1, GR64:$src1)>;
1367 // Conditional moves with folded loads with operands swapped and conditions
1369 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1370 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1371 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1372 (CMOVB64rm GR64:$src2, addr:$src1)>;
1373 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1374 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1375 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1376 (CMOVE64rm GR64:$src2, addr:$src1)>;
1377 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1378 (CMOVA64rm GR64:$src2, addr:$src1)>;
1379 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1380 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1381 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1382 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1383 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1384 (CMOVL64rm GR64:$src2, addr:$src1)>;
1385 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1386 (CMOVG64rm GR64:$src2, addr:$src1)>;
1387 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1388 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1389 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1390 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1391 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1392 (CMOVP64rm GR64:$src2, addr:$src1)>;
1393 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1394 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1395 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1396 (CMOVS64rm GR64:$src2, addr:$src1)>;
1397 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1398 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1399 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1400 (CMOVO64rm GR64:$src2, addr:$src1)>;
1403 def : Pat<(i64 (zext GR32:$src)),
1404 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
1406 // zextload bool -> zextload byte
1407 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1410 // When extloading from 16-bit and smaller memory locations into 64-bit registers,
1411 // use zero-extending loads so that the entire 64-bit register is defined, avoiding
1412 // partial-register updates.
1413 def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1414 def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1415 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1416 // For other extloads, use subregs, since the high contents of the register are
1417 // defined after an extload.
1418 def : Pat<(extloadi64i32 addr:$src),
1419 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1421 def : Pat<(extloadi16i1 addr:$src),
1422 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1424 Requires<[In64BitMode]>;
1425 def : Pat<(extloadi16i8 addr:$src),
1426 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1428 Requires<[In64BitMode]>;
1431 def : Pat<(i64 (anyext GR8:$src)),
1432 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1433 def : Pat<(i64 (anyext GR16:$src)),
1434 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
1435 def : Pat<(i64 (anyext GR32:$src)),
1436 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
1437 def : Pat<(i16 (anyext GR8:$src)),
1438 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1439 Requires<[In64BitMode]>;
1440 def : Pat<(i32 (anyext GR8:$src)),
1441 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1442 Requires<[In64BitMode]>;
1444 //===----------------------------------------------------------------------===//
1446 //===----------------------------------------------------------------------===//
1448 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1449 // +128 doesn't, so in this special case use a sub instead of an add.
1450 def : Pat<(add GR64:$src1, 128),
1451 (SUB64ri8 GR64:$src1, -128)>;
1452 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1453 (SUB64mi8 addr:$dst, -128)>;
1455 // The same trick applies for 32-bit immediate fields in 64-bit
1457 def : Pat<(add GR64:$src1, 0x0000000080000000),
1458 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1459 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1460 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1462 // r & (2^32-1) ==> movz
1463 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1464 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1465 // r & (2^16-1) ==> movz
1466 def : Pat<(and GR64:$src, 0xffff),
1467 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1468 // r & (2^8-1) ==> movz
1469 def : Pat<(and GR64:$src, 0xff),
1470 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1471 // r & (2^8-1) ==> movz
1472 def : Pat<(and GR32:$src1, 0xff),
1473 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1474 Requires<[In64BitMode]>;
1475 // r & (2^8-1) ==> movz
1476 def : Pat<(and GR16:$src1, 0xff),
1477 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1478 Requires<[In64BitMode]>;
1480 // sext_inreg patterns
1481 def : Pat<(sext_inreg GR64:$src, i32),
1482 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1483 def : Pat<(sext_inreg GR64:$src, i16),
1484 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1485 def : Pat<(sext_inreg GR64:$src, i8),
1486 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1487 def : Pat<(sext_inreg GR32:$src, i8),
1488 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1489 Requires<[In64BitMode]>;
1490 def : Pat<(sext_inreg GR16:$src, i8),
1491 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1492 Requires<[In64BitMode]>;
1495 def : Pat<(i32 (trunc GR64:$src)),
1496 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1497 def : Pat<(i16 (trunc GR64:$src)),
1498 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1499 def : Pat<(i8 (trunc GR64:$src)),
1500 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1501 def : Pat<(i8 (trunc GR32:$src)),
1502 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1503 Requires<[In64BitMode]>;
1504 def : Pat<(i8 (trunc GR16:$src)),
1505 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1506 Requires<[In64BitMode]>;
1508 // (shl x, 1) ==> (add x, x)
1509 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1511 // (shl x (and y, 63)) ==> (shl x, y)
1512 def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1513 (SHL64rCL GR64:$src1)>;
1514 def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1515 (SHL64mCL addr:$dst)>;
1517 def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1518 (SHR64rCL GR64:$src1)>;
1519 def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1520 (SHR64mCL addr:$dst)>;
1522 def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1523 (SAR64rCL GR64:$src1)>;
1524 def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1525 (SAR64mCL addr:$dst)>;
1527 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1528 def : Pat<(or (srl GR64:$src1, CL:$amt),
1529 (shl GR64:$src2, (sub 64, CL:$amt))),
1530 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1532 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1533 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1534 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1536 def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1537 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1538 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1540 def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1541 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1543 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1545 def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1546 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1548 def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1549 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1550 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1552 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1553 def : Pat<(or (shl GR64:$src1, CL:$amt),
1554 (srl GR64:$src2, (sub 64, CL:$amt))),
1555 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1557 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1558 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1559 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1561 def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1562 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1563 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1565 def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1566 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1568 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1570 def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1571 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1573 def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1574 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1575 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1577 // X86 specific add which produces a flag.
1578 def : Pat<(addc GR64:$src1, GR64:$src2),
1579 (ADD64rr GR64:$src1, GR64:$src2)>;
1580 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1581 (ADD64rm GR64:$src1, addr:$src2)>;
1582 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1583 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1584 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1585 (ADD64ri32 GR64:$src1, imm:$src2)>;
1587 def : Pat<(subc GR64:$src1, GR64:$src2),
1588 (SUB64rr GR64:$src1, GR64:$src2)>;
1589 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1590 (SUB64rm GR64:$src1, addr:$src2)>;
1591 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1592 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1593 def : Pat<(subc GR64:$src1, imm:$src2),
1594 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1596 //===----------------------------------------------------------------------===//
1597 // Overflow Patterns
1598 //===----------------------------------------------------------------------===//
1600 // Register-Register Addition with Overflow
1601 def : Pat<(parallel (X86add_ovf GR64:$src1, GR64:$src2),
1603 (ADD64rr GR64:$src1, GR64:$src2)>;
1605 // Register-Integer Addition with Overflow
1606 def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt8:$src2),
1608 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1609 def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt32:$src2),
1611 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
1613 // Register-Memory Addition with Overflow
1614 def : Pat<(parallel (X86add_ovf GR64:$src1, (load addr:$src2)),
1616 (ADD64rm GR64:$src1, addr:$src2)>;
1618 // Memory-Register Addition with Overflow
1619 def : Pat<(parallel (store (X86add_ovf (load addr:$dst), GR64:$src2),
1622 (ADD64mr addr:$dst, GR64:$src2)>;
1623 def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt8:$src2),
1626 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
1627 def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt32:$src2),
1630 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
1632 // Register-Register Subtraction with Overflow
1633 def : Pat<(parallel (X86sub_ovf GR64:$src1, GR64:$src2),
1635 (SUB64rr GR64:$src1, GR64:$src2)>;
1637 // Register-Memory Subtraction with Overflow
1638 def : Pat<(parallel (X86sub_ovf GR64:$src1, (load addr:$src2)),
1640 (SUB64rm GR64:$src1, addr:$src2)>;
1642 // Register-Integer Subtraction with Overflow
1643 def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt8:$src2),
1645 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1646 def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt32:$src2),
1648 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1650 // Memory-Register Subtraction with Overflow
1651 def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), GR64:$src2),
1654 (SUB64mr addr:$dst, GR64:$src2)>;
1656 // Memory-Integer Subtraction with Overflow
1657 def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt8:$src2),
1660 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
1661 def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt32:$src2),
1664 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
1666 // Register-Register Signed Integer Multiplication with Overflow
1667 def : Pat<(parallel (X86smul_ovf GR64:$src1, GR64:$src2),
1669 (IMUL64rr GR64:$src1, GR64:$src2)>;
1671 // Register-Memory Signed Integer Multiplication with Overflow
1672 def : Pat<(parallel (X86smul_ovf GR64:$src1, (load addr:$src2)),
1674 (IMUL64rm GR64:$src1, addr:$src2)>;
1676 // Register-Integer Signed Integer Multiplication with Overflow
1677 def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt8:$src2),
1679 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
1680 def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt32:$src2),
1682 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
1684 // Memory-Integer Signed Integer Multiplication with Overflow
1685 def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt8:$src2),
1687 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
1688 def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt32:$src2),
1690 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
1692 //===----------------------------------------------------------------------===//
1693 // X86-64 SSE Instructions
1694 //===----------------------------------------------------------------------===//
1696 // Move instructions...
1698 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
1699 "mov{d|q}\t{$src, $dst|$dst, $src}",
1701 (v2i64 (scalar_to_vector GR64:$src)))]>;
1702 def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
1703 "mov{d|q}\t{$src, $dst|$dst, $src}",
1704 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1707 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1708 "mov{d|q}\t{$src, $dst|$dst, $src}",
1709 [(set FR64:$dst, (bitconvert GR64:$src))]>;
1710 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1711 "movq\t{$src, $dst|$dst, $src}",
1712 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1714 def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
1715 "mov{d|q}\t{$src, $dst|$dst, $src}",
1716 [(set GR64:$dst, (bitconvert FR64:$src))]>;
1717 def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
1718 "movq\t{$src, $dst|$dst, $src}",
1719 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
1721 //===----------------------------------------------------------------------===//
1722 // X86-64 SSE4.1 Instructions
1723 //===----------------------------------------------------------------------===//
1725 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1726 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
1727 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
1728 (ins VR128:$src1, i32i8imm:$src2),
1729 !strconcat(OpcodeStr,
1730 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1732 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
1733 def mr : SS4AIi8<opc, MRMDestMem, (outs),
1734 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1735 !strconcat(OpcodeStr,
1736 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1737 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1738 addr:$dst)]>, OpSize, REX_W;
1741 defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1743 let isTwoAddress = 1 in {
1744 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
1745 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
1746 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1747 !strconcat(OpcodeStr,
1748 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1750 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1752 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
1753 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1754 !strconcat(OpcodeStr,
1755 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1757 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1758 imm:$src3)))]>, OpSize, REX_W;
1762 defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;