refactor .td files a bit, moving system instructions out to X86InstrSystem.td
[oota-llvm.git] / lib / Target / X86 / X86Instr64bit.td
1 //====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
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.
13 //
14 //===----------------------------------------------------------------------===//
15
16 //===----------------------------------------------------------------------===//
17 // Operand Definitions.
18 //
19
20 // 64-bits but only 32 bits are significant.
21 def i64i32imm  : Operand<i64> {
22   let ParserMatchClass = ImmSExti64i32AsmOperand;
23 }
24
25 // 64-bits but only 32 bits are significant, and those bits are treated as being
26 // pc relative.
27 def i64i32imm_pcrel : Operand<i64> {
28   let PrintMethod = "print_pcrel_imm";
29   let ParserMatchClass = X86AbsMemAsmOperand;
30 }
31
32
33 // 64-bits but only 8 bits are significant.
34 def i64i8imm   : Operand<i64> {
35   let ParserMatchClass = ImmSExti64i8AsmOperand;
36 }
37
38 def lea64_32mem : Operand<i32> {
39   let PrintMethod = "printi32mem";
40   let AsmOperandLowerMethod = "lower_lea64_32mem";
41   let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm, i8imm);
42   let ParserMatchClass = X86MemAsmOperand;
43 }
44
45
46 // Special i64mem for addresses of load folding tail calls. These are not
47 // allowed to use callee-saved registers since they must be scheduled
48 // after callee-saved register are popped.
49 def i64mem_TC : Operand<i64> {
50   let PrintMethod = "printi64mem";
51   let MIOperandInfo = (ops GR64_TC, i8imm, GR64_TC, i32imm, i8imm);
52   let ParserMatchClass = X86MemAsmOperand;
53 }
54
55 //===----------------------------------------------------------------------===//
56 // Complex Pattern Definitions.
57 //
58 def lea64addr : ComplexPattern<i64, 5, "SelectLEAAddr",
59                         [add, sub, mul, X86mul_imm, shl, or, frameindex,
60                          X86WrapperRIP], []>;
61
62 def tls64addr : ComplexPattern<i64, 5, "SelectTLSADDRAddr",
63                                [tglobaltlsaddr], []>;
64                                
65 //===----------------------------------------------------------------------===//
66 // Pattern fragments.
67 //
68
69 def i64immSExt8  : PatLeaf<(i64 immSext8)>;
70
71 def GetLo32XForm : SDNodeXForm<imm, [{
72   // Transformation function: get the low 32 bits.
73   return getI32Imm((unsigned)N->getZExtValue());
74 }]>;
75
76 def i64immSExt32  : PatLeaf<(i64 imm), [{ return i64immSExt32(N); }]>;
77
78
79 def i64immZExt32  : PatLeaf<(i64 imm), [{
80   // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
81   // unsignedsign extended field.
82   return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
83 }]>;
84
85 def sextloadi64i8  : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
86 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
87 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
88
89 def zextloadi64i1  : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
90 def zextloadi64i8  : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
91 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
92 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
93
94 def extloadi64i1   : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
95 def extloadi64i8   : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
96 def extloadi64i16  : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
97 def extloadi64i32  : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
98
99 //===----------------------------------------------------------------------===//
100 // Instruction list...
101 //
102
103 // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
104 // a stack adjustment and the codegen must know that they may modify the stack
105 // pointer before prolog-epilog rewriting occurs.
106 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
107 // sub / add which can clobber EFLAGS.
108 let Defs = [RSP, EFLAGS], Uses = [RSP] in {
109 def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
110                            "#ADJCALLSTACKDOWN",
111                            [(X86callseq_start timm:$amt)]>,
112                           Requires<[In64BitMode]>;
113 def ADJCALLSTACKUP64   : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
114                            "#ADJCALLSTACKUP",
115                            [(X86callseq_end timm:$amt1, timm:$amt2)]>,
116                           Requires<[In64BitMode]>;
117 }
118
119
120 //===----------------------------------------------------------------------===//
121 //  Call Instructions...
122 //
123 let isCall = 1 in
124   // All calls clobber the non-callee saved registers. RSP is marked as
125   // a use to prevent stack-pointer assignments that appear immediately
126   // before calls from potentially appearing dead. Uses for argument
127   // registers are added manually.
128   let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
129               FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
130               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
131               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
132               XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
133       Uses = [RSP] in {
134       
135     // NOTE: this pattern doesn't match "X86call imm", because we do not know
136     // that the offset between an arbitrary immediate and the call will fit in
137     // the 32-bit pcrel field that we have.
138     def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
139                           (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
140                           "call{q}\t$dst", []>,
141                         Requires<[In64BitMode, NotWin64]>;
142     def CALL64r       : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
143                           "call{q}\t{*}$dst", [(X86call GR64:$dst)]>,
144                         Requires<[In64BitMode, NotWin64]>;
145     def CALL64m       : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
146                           "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
147                         Requires<[In64BitMode, NotWin64]>;
148                         
149     def FARCALL64   : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
150                          "lcall{q}\t{*}$dst", []>;
151   }
152
153   // FIXME: We need to teach codegen about single list of call-clobbered 
154   // registers.
155 let isCall = 1, isCodeGenOnly = 1 in
156   // All calls clobber the non-callee saved registers. RSP is marked as
157   // a use to prevent stack-pointer assignments that appear immediately
158   // before calls from potentially appearing dead. Uses for argument
159   // registers are added manually.
160   let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
161               FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
162               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
163               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
164       Uses = [RSP] in {
165     def WINCALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
166                              (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
167                              "call{q}\t$dst", []>,
168                            Requires<[IsWin64]>;
169     def WINCALL64r       : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
170                              "call{q}\t{*}$dst",
171                              [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
172     def WINCALL64m       : I<0xFF, MRM2m, (outs), (ins i64mem:$dst,variable_ops),
173                              "call{q}\t{*}$dst",
174                              [(X86call (loadi64 addr:$dst))]>, 
175                            Requires<[IsWin64]>;
176   }
177
178
179 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
180     isCodeGenOnly = 1 in
181   let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
182               FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
183               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
184               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
185               XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
186       Uses = [RSP] in {
187   def TCRETURNdi64 : I<0, Pseudo, (outs),
188                          (ins i64i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
189                        "#TC_RETURN $dst $offset", []>;
190   def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64_TC:$dst, i32imm:$offset,
191                                            variable_ops),
192                        "#TC_RETURN $dst $offset", []>;
193   let mayLoad = 1 in
194   def TCRETURNmi64 : I<0, Pseudo, (outs), 
195                        (ins i64mem_TC:$dst, i32imm:$offset, variable_ops),
196                        "#TC_RETURN $dst $offset", []>;
197
198   def TAILJMPd64 : Ii32PCRel<0xE9, RawFrm, (outs),
199                                       (ins i64i32imm_pcrel:$dst, variable_ops),
200                    "jmp\t$dst  # TAILCALL", []>;
201   def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64_TC:$dst, variable_ops),
202                      "jmp{q}\t{*}$dst  # TAILCALL", []>;
203
204   let mayLoad = 1 in
205   def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst, variable_ops),
206                      "jmp{q}\t{*}$dst  # TAILCALL", []>;
207 }
208
209 // Branches
210 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
211   def JMP64pcrel32 : I<0xE9, RawFrm, (outs), (ins brtarget:$dst), 
212                        "jmp{q}\t$dst", []>;
213   def JMP64r     : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
214                      [(brind GR64:$dst)]>, Requires<[In64BitMode]>;
215   def JMP64m     : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
216                      [(brind (loadi64 addr:$dst))]>, Requires<[In64BitMode]>;
217   def FARJMP64   : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
218                       "ljmp{q}\t{*}$dst", []>;
219 }
220
221 //===----------------------------------------------------------------------===//
222 // EH Pseudo Instructions
223 //
224 let isTerminator = 1, isReturn = 1, isBarrier = 1,
225     hasCtrlDep = 1, isCodeGenOnly = 1 in {
226 def EH_RETURN64   : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
227                      "ret\t#eh_return, addr: $addr",
228                      [(X86ehret GR64:$addr)]>;
229
230 }
231
232 //===----------------------------------------------------------------------===//
233 //  Miscellaneous Instructions...
234 //
235
236 def POPCNT64rr : RI<0xB8, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
237                     "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
238 let mayLoad = 1 in
239 def POPCNT64rm : RI<0xB8, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
240                     "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
241
242 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
243 def LEAVE64  : I<0xC9, RawFrm,
244                  (outs), (ins), "leave", []>, Requires<[In64BitMode]>;
245 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
246 let mayLoad = 1 in {
247 def POP64r   : I<0x58, AddRegFrm,
248                  (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
249 def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
250 def POP64rmm: I<0x8F, MRM0m, (outs i64mem:$dst), (ins), "pop{q}\t$dst", []>;
251 }
252 let mayStore = 1 in {
253 def PUSH64r  : I<0x50, AddRegFrm,
254                  (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
255 def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
256 def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", []>;
257 }
258 }
259
260 let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
261 def PUSH64i8   : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm), 
262                      "push{q}\t$imm", []>;
263 def PUSH64i16  : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm), 
264                       "push{q}\t$imm", []>;
265 def PUSH64i32  : Ii32<0x68, RawFrm, (outs), (ins i64i32imm:$imm),
266                       "push{q}\t$imm", []>;
267 }
268
269 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1, neverHasSideEffects=1 in
270 def POPF64   : I<0x9D, RawFrm, (outs), (ins), "popfq", []>,
271                Requires<[In64BitMode]>;
272 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in
273 def PUSHF64    : I<0x9C, RawFrm, (outs), (ins), "pushfq", []>,
274                  Requires<[In64BitMode]>;
275
276 def LEA64_32r : I<0x8D, MRMSrcMem,
277                   (outs GR32:$dst), (ins lea64_32mem:$src),
278                   "lea{l}\t{$src|$dst}, {$dst|$src}",
279                   [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
280
281 let isReMaterializable = 1 in
282 def LEA64r   : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
283                   "lea{q}\t{$src|$dst}, {$dst|$src}",
284                   [(set GR64:$dst, lea64addr:$src)]>;
285
286 let Constraints = "$src = $dst" in
287 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
288                   "bswap{q}\t$dst", 
289                   [(set GR64:$dst, (bswap GR64:$src))]>, TB;
290
291 // Bit scan instructions.
292 let Defs = [EFLAGS] in {
293 def BSF64rr  : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
294                   "bsf{q}\t{$src, $dst|$dst, $src}",
295                   [(set GR64:$dst, EFLAGS, (X86bsf GR64:$src))]>, TB;
296 def BSF64rm  : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
297                   "bsf{q}\t{$src, $dst|$dst, $src}",
298                   [(set GR64:$dst, EFLAGS, (X86bsf (loadi64 addr:$src)))]>, TB;
299
300 def BSR64rr  : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
301                   "bsr{q}\t{$src, $dst|$dst, $src}",
302                   [(set GR64:$dst, EFLAGS, (X86bsr GR64:$src))]>, TB;
303 def BSR64rm  : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
304                   "bsr{q}\t{$src, $dst|$dst, $src}",
305                   [(set GR64:$dst, EFLAGS, (X86bsr (loadi64 addr:$src)))]>, TB;
306 } // Defs = [EFLAGS]
307
308 // Repeat string ops
309 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI], isCodeGenOnly = 1 in
310 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
311                    [(X86rep_movs i64)]>, REP;
312 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI], isCodeGenOnly = 1 in
313 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
314                    [(X86rep_stos i64)]>, REP;
315
316 let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in
317 def MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "movsq", []>;
318
319 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI,EFLAGS] in
320 def STOSQ : RI<0xAB, RawFrm, (outs), (ins), "stosq", []>;
321
322 def SCAS64 : RI<0xAF, RawFrm, (outs), (ins), "scasq", []>;
323
324 def CMPS64 : RI<0xA7, RawFrm, (outs), (ins), "cmpsq", []>;
325
326
327 //===----------------------------------------------------------------------===//
328 //  Move Instructions...
329 //
330
331 let neverHasSideEffects = 1 in
332 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
333                  "mov{q}\t{$src, $dst|$dst, $src}", []>;
334
335 let isReMaterializable = 1, isAsCheapAsAMove = 1  in {
336 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
337                     "movabs{q}\t{$src, $dst|$dst, $src}",
338                     [(set GR64:$dst, imm:$src)]>;
339 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
340                       "mov{q}\t{$src, $dst|$dst, $src}",
341                       [(set GR64:$dst, i64immSExt32:$src)]>;
342 }
343
344 // The assembler accepts movq of a 64-bit immediate as an alternate spelling of
345 // movabsq.
346 let isAsmParserOnly = 1 in {
347 def MOV64ri_alt : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
348                     "mov{q}\t{$src, $dst|$dst, $src}", []>;
349 }
350
351 let isCodeGenOnly = 1 in {
352 def MOV64rr_REV : RI<0x8B, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
353                      "mov{q}\t{$src, $dst|$dst, $src}", []>;
354 }
355
356 let canFoldAsLoad = 1, isReMaterializable = 1 in
357 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
358                  "mov{q}\t{$src, $dst|$dst, $src}",
359                  [(set GR64:$dst, (load addr:$src))]>;
360
361 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
362                  "mov{q}\t{$src, $dst|$dst, $src}",
363                  [(store GR64:$src, addr:$dst)]>;
364 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
365                       "mov{q}\t{$src, $dst|$dst, $src}",
366                       [(store i64immSExt32:$src, addr:$dst)]>;
367
368 /// Versions of MOV64rr, MOV64rm, and MOV64mr for i64mem_TC and GR64_TC.
369 let isCodeGenOnly = 1 in {
370 let neverHasSideEffects = 1 in
371 def MOV64rr_TC : RI<0x89, MRMDestReg, (outs GR64_TC:$dst), (ins GR64_TC:$src),
372                 "mov{q}\t{$src, $dst|$dst, $src}", []>;
373
374 let mayLoad = 1,
375     canFoldAsLoad = 1, isReMaterializable = 1 in
376 def MOV64rm_TC : RI<0x8B, MRMSrcMem, (outs GR64_TC:$dst), (ins i64mem_TC:$src),
377                 "mov{q}\t{$src, $dst|$dst, $src}",
378                 []>;
379
380 let mayStore = 1 in
381 def MOV64mr_TC : RI<0x89, MRMDestMem, (outs), (ins i64mem_TC:$dst, GR64_TC:$src),
382                 "mov{q}\t{$src, $dst|$dst, $src}",
383                 []>;
384 }
385
386 // FIXME: These definitions are utterly broken
387 // Just leave them commented out for now because they're useless outside
388 // of the large code model, and most compilers won't generate the instructions
389 // in question.
390 /*
391 def MOV64o8a : RIi8<0xA0, RawFrm, (outs), (ins offset8:$src),
392                       "mov{q}\t{$src, %rax|%rax, $src}", []>;
393 def MOV64o64a : RIi32<0xA1, RawFrm, (outs), (ins offset64:$src),
394                        "mov{q}\t{$src, %rax|%rax, $src}", []>;
395 def MOV64ao8 : RIi8<0xA2, RawFrm, (outs offset8:$dst), (ins),
396                        "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
397 def MOV64ao64 : RIi32<0xA3, RawFrm, (outs offset64:$dst), (ins),
398                        "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
399 */
400
401 // Moves to and from segment registers
402 def MOV64rs : RI<0x8C, MRMDestReg, (outs GR64:$dst), (ins SEGMENT_REG:$src),
403                  "mov{q}\t{$src, $dst|$dst, $src}", []>;
404 def MOV64ms : RI<0x8C, MRMDestMem, (outs i64mem:$dst), (ins SEGMENT_REG:$src),
405                  "mov{q}\t{$src, $dst|$dst, $src}", []>;
406 def MOV64sr : RI<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR64:$src),
407                  "mov{q}\t{$src, $dst|$dst, $src}", []>;
408 def MOV64sm : RI<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i64mem:$src),
409                  "mov{q}\t{$src, $dst|$dst, $src}", []>;
410
411 // Moves to and from debug registers
412 def MOV64rd : I<0x21, MRMDestReg, (outs GR64:$dst), (ins DEBUG_REG:$src),
413                 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
414 def MOV64dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR64:$src),
415                 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
416
417 // Moves to and from control registers
418 def MOV64rc : I<0x20, MRMDestReg, (outs GR64:$dst), (ins CONTROL_REG:$src),
419                 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
420 def MOV64cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR64:$src),
421                 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
422
423 // Sign/Zero extenders
424
425 // MOVSX64rr8 always has a REX prefix and it has an 8-bit register
426 // operand, which makes it a rare instruction with an 8-bit register
427 // operand that can never access an h register. If support for h registers
428 // were generalized, this would require a special register class.
429 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
430                     "movs{bq|x}\t{$src, $dst|$dst, $src}",
431                     [(set GR64:$dst, (sext GR8:$src))]>, TB;
432 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
433                     "movs{bq|x}\t{$src, $dst|$dst, $src}",
434                     [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
435 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
436                     "movs{wq|x}\t{$src, $dst|$dst, $src}",
437                     [(set GR64:$dst, (sext GR16:$src))]>, TB;
438 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
439                     "movs{wq|x}\t{$src, $dst|$dst, $src}",
440                     [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
441 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
442                     "movs{lq|xd}\t{$src, $dst|$dst, $src}",
443                     [(set GR64:$dst, (sext GR32:$src))]>;
444 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
445                     "movs{lq|xd}\t{$src, $dst|$dst, $src}",
446                     [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
447
448 // movzbq and movzwq encodings for the disassembler
449 def MOVZX64rr8_Q : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8:$src),
450                        "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
451 def MOVZX64rm8_Q : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem:$src),
452                        "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
453 def MOVZX64rr16_Q : RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
454                        "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
455 def MOVZX64rm16_Q : RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
456                        "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
457
458 // Use movzbl instead of movzbq when the destination is a register; it's
459 // equivalent due to implicit zero-extending, and it has a smaller encoding.
460 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
461                    "", [(set GR64:$dst, (zext GR8:$src))]>, TB;
462 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
463                    "", [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
464 // Use movzwl instead of movzwq when the destination is a register; it's
465 // equivalent due to implicit zero-extending, and it has a smaller encoding.
466 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
467                    "", [(set GR64:$dst, (zext GR16:$src))]>, TB;
468 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
469                    "", [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
470
471 // There's no movzlq instruction, but movl can be used for this purpose, using
472 // implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
473 // extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
474 // zero-extension, however this isn't possible when the 32-bit value is
475 // defined by a truncate or is copied from something where the high bits aren't
476 // necessarily all zero. In such cases, we fall back to these explicit zext
477 // instructions.
478 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
479                     "", [(set GR64:$dst, (zext GR32:$src))]>;
480 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
481                     "", [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
482
483 // Any instruction that defines a 32-bit result leaves the high half of the
484 // register. Truncate can be lowered to EXTRACT_SUBREG. CopyFromReg may
485 // be copying from a truncate. And x86's cmov doesn't do anything if the
486 // condition is false. But any other 32-bit operation will zero-extend
487 // up to 64 bits.
488 def def32 : PatLeaf<(i32 GR32:$src), [{
489   return N->getOpcode() != ISD::TRUNCATE &&
490          N->getOpcode() != TargetOpcode::EXTRACT_SUBREG &&
491          N->getOpcode() != ISD::CopyFromReg &&
492          N->getOpcode() != X86ISD::CMOV;
493 }]>;
494
495 // In the case of a 32-bit def that is known to implicitly zero-extend,
496 // we can use a SUBREG_TO_REG.
497 def : Pat<(i64 (zext def32:$src)),
498           (SUBREG_TO_REG (i64 0), GR32:$src, sub_32bit)>;
499
500 let neverHasSideEffects = 1 in {
501   let Defs = [RAX], Uses = [EAX] in
502   def CDQE : RI<0x98, RawFrm, (outs), (ins),
503                "{cltq|cdqe}", []>;     // RAX = signext(EAX)
504
505   let Defs = [RAX,RDX], Uses = [RAX] in
506   def CQO  : RI<0x99, RawFrm, (outs), (ins),
507                 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
508 }
509
510 //===----------------------------------------------------------------------===//
511 //  Arithmetic Instructions...
512 //
513
514 let Defs = [EFLAGS] in {
515
516 def ADD64i32 : RIi32<0x05, RawFrm, (outs), (ins i64i32imm:$src),
517                      "add{q}\t{$src, %rax|%rax, $src}", []>;
518
519 let Constraints = "$src1 = $dst" in {
520 let isConvertibleToThreeAddress = 1 in {
521 let isCommutable = 1 in
522 // Register-Register Addition
523 def ADD64rr    : RI<0x01, MRMDestReg, (outs GR64:$dst), 
524                     (ins GR64:$src1, GR64:$src2),
525                     "add{q}\t{$src2, $dst|$dst, $src2}",
526                     [(set GR64:$dst, EFLAGS,
527                           (X86add_flag GR64:$src1, GR64:$src2))]>;
528
529 // These are alternate spellings for use by the disassembler, we mark them as
530 // code gen only to ensure they aren't matched by the assembler.
531 let isCodeGenOnly = 1 in {
532   def ADD64rr_alt  : RI<0x03, MRMSrcReg, (outs GR64:$dst), 
533                        (ins GR64:$src1, GR64:$src2),
534                        "add{l}\t{$src2, $dst|$dst, $src2}", []>;
535 }
536
537 // Register-Integer Addition
538 def ADD64ri8  : RIi8<0x83, MRM0r, (outs GR64:$dst), 
539                      (ins GR64:$src1, i64i8imm:$src2),
540                      "add{q}\t{$src2, $dst|$dst, $src2}",
541                      [(set GR64:$dst, EFLAGS,
542                            (X86add_flag GR64:$src1, i64immSExt8:$src2))]>;
543 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), 
544                       (ins GR64:$src1, i64i32imm:$src2),
545                       "add{q}\t{$src2, $dst|$dst, $src2}",
546                       [(set GR64:$dst, EFLAGS,
547                             (X86add_flag GR64:$src1, i64immSExt32:$src2))]>;
548 } // isConvertibleToThreeAddress
549
550 // Register-Memory Addition
551 def ADD64rm     : RI<0x03, MRMSrcMem, (outs GR64:$dst), 
552                      (ins GR64:$src1, i64mem:$src2),
553                      "add{q}\t{$src2, $dst|$dst, $src2}",
554                      [(set GR64:$dst, EFLAGS,
555                            (X86add_flag GR64:$src1, (load addr:$src2)))]>;
556
557 } // Constraints = "$src1 = $dst"
558
559 // Memory-Register Addition
560 def ADD64mr  : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
561                   "add{q}\t{$src2, $dst|$dst, $src2}",
562                   [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
563                    (implicit EFLAGS)]>;
564 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
565                     "add{q}\t{$src2, $dst|$dst, $src2}",
566                 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
567                  (implicit EFLAGS)]>;
568 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
569                       "add{q}\t{$src2, $dst|$dst, $src2}",
570                [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
571                 (implicit EFLAGS)]>;
572
573 let Uses = [EFLAGS] in {
574
575 def ADC64i32 : RIi32<0x15, RawFrm, (outs), (ins i64i32imm:$src),
576                      "adc{q}\t{$src, %rax|%rax, $src}", []>;
577
578 let Constraints = "$src1 = $dst" in {
579 let isCommutable = 1 in
580 def ADC64rr  : RI<0x11, MRMDestReg, (outs GR64:$dst), 
581                   (ins GR64:$src1, GR64:$src2),
582                   "adc{q}\t{$src2, $dst|$dst, $src2}",
583                   [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
584
585 let isCodeGenOnly = 1 in {
586 def ADC64rr_REV : RI<0x13, MRMSrcReg , (outs GR32:$dst), 
587                      (ins GR64:$src1, GR64:$src2),
588                     "adc{q}\t{$src2, $dst|$dst, $src2}", []>;
589 }
590
591 def ADC64rm  : RI<0x13, MRMSrcMem , (outs GR64:$dst), 
592                   (ins GR64:$src1, i64mem:$src2),
593                   "adc{q}\t{$src2, $dst|$dst, $src2}",
594                   [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
595
596 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), 
597                     (ins GR64:$src1, i64i8imm:$src2),
598                     "adc{q}\t{$src2, $dst|$dst, $src2}",
599                     [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
600 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), 
601                       (ins GR64:$src1, i64i32imm:$src2),
602                       "adc{q}\t{$src2, $dst|$dst, $src2}",
603                       [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
604 } // Constraints = "$src1 = $dst"
605
606 def ADC64mr  : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
607                   "adc{q}\t{$src2, $dst|$dst, $src2}",
608                   [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
609 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
610                     "adc{q}\t{$src2, $dst|$dst, $src2}",
611                  [(store (adde (load addr:$dst), i64immSExt8:$src2), 
612                   addr:$dst)]>;
613 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
614                       "adc{q}\t{$src2, $dst|$dst, $src2}",
615                  [(store (adde (load addr:$dst), i64immSExt32:$src2), 
616                   addr:$dst)]>;
617 } // Uses = [EFLAGS]
618
619 let Constraints = "$src1 = $dst" in {
620 // Register-Register Subtraction
621 def SUB64rr  : RI<0x29, MRMDestReg, (outs GR64:$dst), 
622                   (ins GR64:$src1, GR64:$src2),
623                   "sub{q}\t{$src2, $dst|$dst, $src2}",
624                   [(set GR64:$dst, EFLAGS,
625                         (X86sub_flag GR64:$src1, GR64:$src2))]>;
626
627 let isCodeGenOnly = 1 in {
628 def SUB64rr_REV : RI<0x2B, MRMSrcReg, (outs GR64:$dst), 
629                      (ins GR64:$src1, GR64:$src2),
630                      "sub{q}\t{$src2, $dst|$dst, $src2}", []>;
631 }
632
633 // Register-Memory Subtraction
634 def SUB64rm  : RI<0x2B, MRMSrcMem, (outs GR64:$dst), 
635                   (ins GR64:$src1, i64mem:$src2),
636                   "sub{q}\t{$src2, $dst|$dst, $src2}",
637                   [(set GR64:$dst, EFLAGS, 
638                         (X86sub_flag GR64:$src1, (load addr:$src2)))]>;
639
640 // Register-Integer Subtraction
641 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
642                                  (ins GR64:$src1, i64i8imm:$src2),
643                     "sub{q}\t{$src2, $dst|$dst, $src2}",
644                     [(set GR64:$dst, EFLAGS,
645                           (X86sub_flag GR64:$src1, i64immSExt8:$src2))]>;
646 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
647                                    (ins GR64:$src1, i64i32imm:$src2),
648                       "sub{q}\t{$src2, $dst|$dst, $src2}",
649                       [(set GR64:$dst, EFLAGS,
650                             (X86sub_flag GR64:$src1, i64immSExt32:$src2))]>;
651 } // Constraints = "$src1 = $dst"
652
653 def SUB64i32 : RIi32<0x2D, RawFrm, (outs), (ins i64i32imm:$src),
654                      "sub{q}\t{$src, %rax|%rax, $src}", []>;
655
656 // Memory-Register Subtraction
657 def SUB64mr  : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2), 
658                   "sub{q}\t{$src2, $dst|$dst, $src2}",
659                   [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
660                    (implicit EFLAGS)]>;
661
662 // Memory-Integer Subtraction
663 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2), 
664                     "sub{q}\t{$src2, $dst|$dst, $src2}",
665                     [(store (sub (load addr:$dst), i64immSExt8:$src2),
666                             addr:$dst),
667                      (implicit EFLAGS)]>;
668 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
669                       "sub{q}\t{$src2, $dst|$dst, $src2}",
670                       [(store (sub (load addr:$dst), i64immSExt32:$src2),
671                               addr:$dst),
672                        (implicit EFLAGS)]>;
673
674 let Uses = [EFLAGS] in {
675 let Constraints = "$src1 = $dst" in {
676 def SBB64rr    : RI<0x19, MRMDestReg, (outs GR64:$dst), 
677                     (ins GR64:$src1, GR64:$src2),
678                     "sbb{q}\t{$src2, $dst|$dst, $src2}",
679                     [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
680
681 let isCodeGenOnly = 1 in {
682 def SBB64rr_REV : RI<0x1B, MRMSrcReg, (outs GR64:$dst), 
683                      (ins GR64:$src1, GR64:$src2),
684                      "sbb{q}\t{$src2, $dst|$dst, $src2}", []>;
685 }
686                      
687 def SBB64rm  : RI<0x1B, MRMSrcMem, (outs GR64:$dst), 
688                   (ins GR64:$src1, i64mem:$src2),
689                   "sbb{q}\t{$src2, $dst|$dst, $src2}",
690                   [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
691
692 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), 
693                     (ins GR64:$src1, i64i8imm:$src2),
694                     "sbb{q}\t{$src2, $dst|$dst, $src2}",
695                     [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
696 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), 
697                       (ins GR64:$src1, i64i32imm:$src2),
698                       "sbb{q}\t{$src2, $dst|$dst, $src2}",
699                       [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
700 } // Constraints = "$src1 = $dst"
701
702 def SBB64i32 : RIi32<0x1D, RawFrm, (outs), (ins i64i32imm:$src),
703                      "sbb{q}\t{$src, %rax|%rax, $src}", []>;
704
705 def SBB64mr  : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2), 
706                   "sbb{q}\t{$src2, $dst|$dst, $src2}",
707                   [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
708 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2), 
709                     "sbb{q}\t{$src2, $dst|$dst, $src2}",
710                [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
711 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2), 
712                       "sbb{q}\t{$src2, $dst|$dst, $src2}",
713               [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
714 } // Uses = [EFLAGS]
715 } // Defs = [EFLAGS]
716
717 // Unsigned multiplication
718 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
719 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
720                 "mul{q}\t$src", []>;         // RAX,RDX = RAX*GR64
721 let mayLoad = 1 in
722 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
723                 "mul{q}\t$src", []>;         // RAX,RDX = RAX*[mem64]
724
725 // Signed multiplication
726 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
727                  "imul{q}\t$src", []>;         // RAX,RDX = RAX*GR64
728 let mayLoad = 1 in
729 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
730                  "imul{q}\t$src", []>;         // RAX,RDX = RAX*[mem64]
731 }
732
733 let Defs = [EFLAGS] in {
734 let Constraints = "$src1 = $dst" in {
735 let isCommutable = 1 in
736 // Register-Register Signed Integer Multiplication
737 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
738                                    (ins GR64:$src1, GR64:$src2),
739                   "imul{q}\t{$src2, $dst|$dst, $src2}",
740                   [(set GR64:$dst, EFLAGS,
741                         (X86smul_flag GR64:$src1, GR64:$src2))]>, TB;
742
743 // Register-Memory Signed Integer Multiplication
744 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
745                                    (ins GR64:$src1, i64mem:$src2),
746                   "imul{q}\t{$src2, $dst|$dst, $src2}",
747                   [(set GR64:$dst, EFLAGS,
748                         (X86smul_flag GR64:$src1, (load addr:$src2)))]>, TB;
749 } // Constraints = "$src1 = $dst"
750
751 // Suprisingly enough, these are not two address instructions!
752
753 // Register-Integer Signed Integer Multiplication
754 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg,                      // GR64 = GR64*I8
755                       (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
756                       "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
757                       [(set GR64:$dst, EFLAGS,
758                             (X86smul_flag GR64:$src1, i64immSExt8:$src2))]>;
759 def IMUL64rri32 : RIi32<0x69, MRMSrcReg,                    // GR64 = GR64*I32
760                         (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
761                         "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
762                        [(set GR64:$dst, EFLAGS,
763                              (X86smul_flag GR64:$src1, i64immSExt32:$src2))]>;
764
765 // Memory-Integer Signed Integer Multiplication
766 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem,                      // GR64 = [mem64]*I8
767                       (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
768                       "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
769                       [(set GR64:$dst, EFLAGS,
770                             (X86smul_flag (load addr:$src1),
771                                           i64immSExt8:$src2))]>;
772 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem,                   // GR64 = [mem64]*I32
773                         (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
774                         "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
775                         [(set GR64:$dst, EFLAGS,
776                               (X86smul_flag (load addr:$src1),
777                                             i64immSExt32:$src2))]>;
778 } // Defs = [EFLAGS]
779
780 // Unsigned division / remainder
781 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
782 // RDX:RAX/r64 = RAX,RDX
783 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src),
784                 "div{q}\t$src", []>;
785 // Signed division / remainder
786 // RDX:RAX/r64 = RAX,RDX
787 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src),
788                 "idiv{q}\t$src", []>;
789 let mayLoad = 1 in {
790 // RDX:RAX/[mem64] = RAX,RDX
791 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src),
792                 "div{q}\t$src", []>;
793 // RDX:RAX/[mem64] = RAX,RDX
794 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src),
795                 "idiv{q}\t$src", []>;
796 }
797 }
798
799 // Unary instructions
800 let Defs = [EFLAGS], CodeSize = 2 in {
801 let Constraints = "$src = $dst" in
802 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
803                 [(set GR64:$dst, (ineg GR64:$src)),
804                  (implicit EFLAGS)]>;
805 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
806                 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
807                  (implicit EFLAGS)]>;
808
809 let Constraints = "$src = $dst", isConvertibleToThreeAddress = 1 in
810 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
811                 [(set GR64:$dst, EFLAGS, (X86inc_flag GR64:$src))]>;
812 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
813                 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
814                  (implicit EFLAGS)]>;
815
816 let Constraints = "$src = $dst", isConvertibleToThreeAddress = 1 in
817 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
818                 [(set GR64:$dst, EFLAGS, (X86dec_flag GR64:$src))]>;
819 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
820                 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
821                  (implicit EFLAGS)]>;
822
823 // In 64-bit mode, single byte INC and DEC cannot be encoded.
824 let Constraints = "$src = $dst", isConvertibleToThreeAddress = 1 in {
825 // Can transform into LEA.
826 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), 
827                   "inc{w}\t$dst",
828                   [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src))]>,
829                 OpSize, Requires<[In64BitMode]>;
830 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), 
831                   "inc{l}\t$dst",
832                   [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src))]>,
833                 Requires<[In64BitMode]>;
834 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), 
835                   "dec{w}\t$dst",
836                   [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src))]>,
837                 OpSize, Requires<[In64BitMode]>;
838 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), 
839                   "dec{l}\t$dst",
840                   [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src))]>,
841                 Requires<[In64BitMode]>;
842 } // Constraints = "$src = $dst", isConvertibleToThreeAddress
843
844 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
845 // how to unfold them.
846 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
847                   [(store (add (loadi16 addr:$dst), 1), addr:$dst),
848                     (implicit EFLAGS)]>,
849                 OpSize, Requires<[In64BitMode]>;
850 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
851                   [(store (add (loadi32 addr:$dst), 1), addr:$dst),
852                     (implicit EFLAGS)]>,
853                 Requires<[In64BitMode]>;
854 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
855                   [(store (add (loadi16 addr:$dst), -1), addr:$dst),
856                     (implicit EFLAGS)]>,
857                 OpSize, Requires<[In64BitMode]>;
858 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
859                   [(store (add (loadi32 addr:$dst), -1), addr:$dst),
860                     (implicit EFLAGS)]>,
861                 Requires<[In64BitMode]>;
862 } // Defs = [EFLAGS], CodeSize
863
864
865 let Defs = [EFLAGS] in {
866 // Shift instructions
867 let Constraints = "$src1 = $dst" in {
868 let Uses = [CL] in
869 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
870                   "shl{q}\t{%cl, $dst|$dst, %CL}",
871                   [(set GR64:$dst, (shl GR64:$src1, CL))]>;
872 let isConvertibleToThreeAddress = 1 in   // Can transform into LEA.
873 def SHL64ri  : RIi8<0xC1, MRM4r, (outs GR64:$dst), 
874                     (ins GR64:$src1, i8imm:$src2),
875                     "shl{q}\t{$src2, $dst|$dst, $src2}",
876                     [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
877 // NOTE: We don't include patterns for shifts of a register by one, because
878 // 'add reg,reg' is cheaper.
879 def SHL64r1  : RI<0xD1, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
880                  "shl{q}\t$dst", []>;
881 } // Constraints = "$src1 = $dst"
882
883 let Uses = [CL] in
884 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
885                   "shl{q}\t{%cl, $dst|$dst, %CL}",
886                   [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
887 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
888                   "shl{q}\t{$src, $dst|$dst, $src}",
889                  [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
890 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
891                   "shl{q}\t$dst",
892                  [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
893
894 let Constraints = "$src1 = $dst" in {
895 let Uses = [CL] in
896 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
897                   "shr{q}\t{%cl, $dst|$dst, %CL}",
898                   [(set GR64:$dst, (srl GR64:$src1, CL))]>;
899 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
900                   "shr{q}\t{$src2, $dst|$dst, $src2}",
901                   [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
902 def SHR64r1  : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
903                  "shr{q}\t$dst",
904                  [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
905 } // Constraints = "$src1 = $dst"
906
907 let Uses = [CL] in
908 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
909                   "shr{q}\t{%cl, $dst|$dst, %CL}",
910                   [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
911 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
912                   "shr{q}\t{$src, $dst|$dst, $src}",
913                  [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
914 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
915                   "shr{q}\t$dst",
916                  [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
917
918 let Constraints = "$src1 = $dst" in {
919 let Uses = [CL] in
920 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
921                  "sar{q}\t{%cl, $dst|$dst, %CL}",
922                  [(set GR64:$dst, (sra GR64:$src1, CL))]>;
923 def SAR64ri  : RIi8<0xC1, MRM7r, (outs GR64:$dst),
924                     (ins GR64:$src1, i8imm:$src2),
925                     "sar{q}\t{$src2, $dst|$dst, $src2}",
926                     [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
927 def SAR64r1  : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
928                  "sar{q}\t$dst",
929                  [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
930 } // Constraints = "$src = $dst"
931
932 let Uses = [CL] in
933 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst), 
934                  "sar{q}\t{%cl, $dst|$dst, %CL}",
935                  [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
936 def SAR64mi  : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
937                     "sar{q}\t{$src, $dst|$dst, $src}",
938                  [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
939 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
940                   "sar{q}\t$dst",
941                  [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
942
943 // Rotate instructions
944
945 let Constraints = "$src = $dst" in {
946 def RCL64r1 : RI<0xD1, MRM2r, (outs GR64:$dst), (ins GR64:$src),
947                  "rcl{q}\t{1, $dst|$dst, 1}", []>;
948 def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
949                    "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
950
951 def RCR64r1 : RI<0xD1, MRM3r, (outs GR64:$dst), (ins GR64:$src),
952                  "rcr{q}\t{1, $dst|$dst, 1}", []>;
953 def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
954                    "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
955
956 let Uses = [CL] in {
957 def RCL64rCL : RI<0xD3, MRM2r, (outs GR64:$dst), (ins GR64:$src),
958                   "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
959 def RCR64rCL : RI<0xD3, MRM3r, (outs GR64:$dst), (ins GR64:$src),
960                   "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
961 }
962 } // Constraints = "$src = $dst"
963
964 def RCL64m1 : RI<0xD1, MRM2m, (outs), (ins i64mem:$dst),
965                  "rcl{q}\t{1, $dst|$dst, 1}", []>;
966 def RCL64mi : RIi8<0xC1, MRM2m, (outs), (ins i64mem:$dst, i8imm:$cnt),
967                    "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
968 def RCR64m1 : RI<0xD1, MRM3m, (outs), (ins i64mem:$dst),
969                  "rcr{q}\t{1, $dst|$dst, 1}", []>;
970 def RCR64mi : RIi8<0xC1, MRM3m, (outs), (ins i64mem:$dst, i8imm:$cnt),
971                    "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
972
973 let Uses = [CL] in {
974 def RCL64mCL : RI<0xD3, MRM2m, (outs), (ins i64mem:$dst),
975                   "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
976 def RCR64mCL : RI<0xD3, MRM3m, (outs), (ins i64mem:$dst),
977                   "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
978 }
979
980 let Constraints = "$src1 = $dst" in {
981 let Uses = [CL] in
982 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
983                   "rol{q}\t{%cl, $dst|$dst, %CL}",
984                   [(set GR64:$dst, (rotl GR64:$src1, CL))]>;
985 def ROL64ri  : RIi8<0xC1, MRM0r, (outs GR64:$dst), 
986                     (ins GR64:$src1, i8imm:$src2),
987                     "rol{q}\t{$src2, $dst|$dst, $src2}",
988                     [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
989 def ROL64r1  : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
990                   "rol{q}\t$dst",
991                   [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
992 } // Constraints = "$src1 = $dst"
993
994 let Uses = [CL] in
995 def ROL64mCL :  RI<0xD3, MRM0m, (outs), (ins i64mem:$dst),
996                    "rol{q}\t{%cl, $dst|$dst, %CL}",
997                    [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
998 def ROL64mi  : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
999                     "rol{q}\t{$src, $dst|$dst, $src}",
1000                 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1001 def ROL64m1  : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
1002                  "rol{q}\t$dst",
1003                [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
1004
1005 let Constraints = "$src1 = $dst" in {
1006 let Uses = [CL] in
1007 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
1008                   "ror{q}\t{%cl, $dst|$dst, %CL}",
1009                   [(set GR64:$dst, (rotr GR64:$src1, CL))]>;
1010 def ROR64ri  : RIi8<0xC1, MRM1r, (outs GR64:$dst), 
1011                     (ins GR64:$src1, i8imm:$src2),
1012                     "ror{q}\t{$src2, $dst|$dst, $src2}",
1013                     [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
1014 def ROR64r1  : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
1015                   "ror{q}\t$dst",
1016                   [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
1017 } // Constraints = "$src1 = $dst"
1018
1019 let Uses = [CL] in
1020 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst), 
1021                   "ror{q}\t{%cl, $dst|$dst, %CL}",
1022                   [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
1023 def ROR64mi  : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
1024                     "ror{q}\t{$src, $dst|$dst, $src}",
1025                 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1026 def ROR64m1  : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
1027                  "ror{q}\t$dst",
1028                [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
1029
1030 // Double shift instructions (generalizations of rotate)
1031 let Constraints = "$src1 = $dst" in {
1032 let Uses = [CL] in {
1033 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), 
1034                     (ins GR64:$src1, GR64:$src2),
1035                     "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1036                     [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, 
1037                     TB;
1038 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), 
1039                     (ins GR64:$src1, GR64:$src2),
1040                     "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1041                     [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, 
1042                     TB;
1043 }
1044
1045 let isCommutable = 1 in {  // FIXME: Update X86InstrInfo::commuteInstruction
1046 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
1047                       (outs GR64:$dst), 
1048                       (ins GR64:$src1, GR64:$src2, i8imm:$src3),
1049                       "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1050                       [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
1051                                        (i8 imm:$src3)))]>,
1052                  TB;
1053 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
1054                       (outs GR64:$dst), 
1055                       (ins GR64:$src1, GR64:$src2, i8imm:$src3),
1056                       "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1057                       [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
1058                                        (i8 imm:$src3)))]>,
1059                  TB;
1060 } // isCommutable
1061 } // Constraints = "$src1 = $dst"
1062
1063 let Uses = [CL] in {
1064 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1065                     "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1066                     [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
1067                       addr:$dst)]>, TB;
1068 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1069                     "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1070                     [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
1071                       addr:$dst)]>, TB;
1072 }
1073 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
1074                       (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
1075                       "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1076                       [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
1077                                        (i8 imm:$src3)), addr:$dst)]>,
1078                  TB;
1079 def SHRD64mri8 : RIi8<0xAC, MRMDestMem, 
1080                       (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
1081                       "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1082                       [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
1083                                        (i8 imm:$src3)), addr:$dst)]>,
1084                  TB;
1085 } // Defs = [EFLAGS]
1086
1087 //===----------------------------------------------------------------------===//
1088 //  Logical Instructions...
1089 //
1090
1091 let Constraints = "$src = $dst" , AddedComplexity = 15 in
1092 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
1093                 [(set GR64:$dst, (not GR64:$src))]>;
1094 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
1095                 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
1096
1097 let Defs = [EFLAGS] in {
1098 def AND64i32 : RIi32<0x25, RawFrm, (outs), (ins i64i32imm:$src),
1099                      "and{q}\t{$src, %rax|%rax, $src}", []>;
1100
1101 let Constraints = "$src1 = $dst" in {
1102 let isCommutable = 1 in
1103 def AND64rr  : RI<0x21, MRMDestReg, 
1104                   (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1105                   "and{q}\t{$src2, $dst|$dst, $src2}",
1106                   [(set GR64:$dst, EFLAGS,
1107                         (X86and_flag GR64:$src1, GR64:$src2))]>;
1108 let isCodeGenOnly = 1 in {
1109 def AND64rr_REV : RI<0x23, MRMSrcReg, (outs GR64:$dst), 
1110                      (ins GR64:$src1, GR64:$src2),
1111                      "and{q}\t{$src2, $dst|$dst, $src2}", []>;
1112 }
1113 def AND64rm  : RI<0x23, MRMSrcMem,
1114                   (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1115                   "and{q}\t{$src2, $dst|$dst, $src2}",
1116                   [(set GR64:$dst, EFLAGS,
1117                         (X86and_flag GR64:$src1, (load addr:$src2)))]>;
1118 def AND64ri8 : RIi8<0x83, MRM4r, 
1119                     (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
1120                     "and{q}\t{$src2, $dst|$dst, $src2}",
1121                     [(set GR64:$dst, EFLAGS,
1122                           (X86and_flag GR64:$src1, i64immSExt8:$src2))]>;
1123 def AND64ri32  : RIi32<0x81, MRM4r, 
1124                        (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1125                        "and{q}\t{$src2, $dst|$dst, $src2}",
1126                        [(set GR64:$dst, EFLAGS,
1127                              (X86and_flag GR64:$src1, i64immSExt32:$src2))]>;
1128 } // Constraints = "$src1 = $dst"
1129
1130 def AND64mr  : RI<0x21, MRMDestMem,
1131                   (outs), (ins i64mem:$dst, GR64:$src),
1132                   "and{q}\t{$src, $dst|$dst, $src}",
1133                   [(store (and (load addr:$dst), GR64:$src), addr:$dst),
1134                    (implicit EFLAGS)]>;
1135 def AND64mi8 : RIi8<0x83, MRM4m,
1136                     (outs), (ins i64mem:$dst, i64i8imm :$src),
1137                     "and{q}\t{$src, $dst|$dst, $src}",
1138                  [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
1139                   (implicit EFLAGS)]>;
1140 def AND64mi32  : RIi32<0x81, MRM4m,
1141                        (outs), (ins i64mem:$dst, i64i32imm:$src),
1142                        "and{q}\t{$src, $dst|$dst, $src}",
1143              [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1144               (implicit EFLAGS)]>;
1145
1146 let Constraints = "$src1 = $dst" in {
1147 let isCommutable = 1 in
1148 def OR64rr   : RI<0x09, MRMDestReg, (outs GR64:$dst), 
1149                   (ins GR64:$src1, GR64:$src2),
1150                   "or{q}\t{$src2, $dst|$dst, $src2}",
1151                   [(set GR64:$dst, EFLAGS,
1152                         (X86or_flag GR64:$src1, GR64:$src2))]>;
1153 let isCodeGenOnly = 1 in {
1154 def OR64rr_REV : RI<0x0B, MRMSrcReg, (outs GR64:$dst), 
1155                     (ins GR64:$src1, GR64:$src2),
1156                     "or{q}\t{$src2, $dst|$dst, $src2}", []>;
1157 }
1158 def OR64rm   : RI<0x0B, MRMSrcMem , (outs GR64:$dst),
1159                   (ins GR64:$src1, i64mem:$src2),
1160                   "or{q}\t{$src2, $dst|$dst, $src2}",
1161                   [(set GR64:$dst, EFLAGS,
1162                         (X86or_flag GR64:$src1, (load addr:$src2)))]>;
1163 def OR64ri8  : RIi8<0x83, MRM1r, (outs GR64:$dst),
1164                     (ins GR64:$src1, i64i8imm:$src2),
1165                     "or{q}\t{$src2, $dst|$dst, $src2}",
1166                    [(set GR64:$dst, EFLAGS,
1167                          (X86or_flag GR64:$src1, i64immSExt8:$src2))]>;
1168 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst),
1169                      (ins GR64:$src1, i64i32imm:$src2),
1170                      "or{q}\t{$src2, $dst|$dst, $src2}",
1171                   [(set GR64:$dst, EFLAGS,
1172                         (X86or_flag GR64:$src1, i64immSExt32:$src2))]>;
1173 } // Constraints = "$src1 = $dst"
1174
1175 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1176                 "or{q}\t{$src, $dst|$dst, $src}",
1177                 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
1178                  (implicit EFLAGS)]>;
1179 def OR64mi8  : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
1180                     "or{q}\t{$src, $dst|$dst, $src}",
1181                   [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
1182                    (implicit EFLAGS)]>;
1183 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1184                      "or{q}\t{$src, $dst|$dst, $src}",
1185               [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1186                (implicit EFLAGS)]>;
1187
1188 def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i64i32imm:$src),
1189                     "or{q}\t{$src, %rax|%rax, $src}", []>;
1190
1191 let Constraints = "$src1 = $dst" in {
1192 let isCommutable = 1 in
1193 def XOR64rr  : RI<0x31, MRMDestReg,  (outs GR64:$dst), 
1194                   (ins GR64:$src1, GR64:$src2), 
1195                   "xor{q}\t{$src2, $dst|$dst, $src2}",
1196                   [(set GR64:$dst, EFLAGS,
1197                         (X86xor_flag GR64:$src1, GR64:$src2))]>;
1198 let isCodeGenOnly = 1 in {
1199 def XOR64rr_REV : RI<0x33, MRMSrcReg, (outs GR64:$dst), 
1200                      (ins GR64:$src1, GR64:$src2),
1201                     "xor{q}\t{$src2, $dst|$dst, $src2}", []>;
1202 }
1203 def XOR64rm  : RI<0x33, MRMSrcMem, (outs GR64:$dst), 
1204                   (ins GR64:$src1, i64mem:$src2), 
1205                   "xor{q}\t{$src2, $dst|$dst, $src2}",
1206                   [(set GR64:$dst, EFLAGS,
1207                         (X86xor_flag GR64:$src1, (load addr:$src2)))]>;
1208 def XOR64ri8 : RIi8<0x83, MRM6r,  (outs GR64:$dst), 
1209                     (ins GR64:$src1, i64i8imm:$src2),
1210                     "xor{q}\t{$src2, $dst|$dst, $src2}",
1211                     [(set GR64:$dst, EFLAGS,
1212                           (X86xor_flag GR64:$src1, i64immSExt8:$src2))]>;
1213 def XOR64ri32 : RIi32<0x81, MRM6r, 
1214                       (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2), 
1215                       "xor{q}\t{$src2, $dst|$dst, $src2}",
1216                       [(set GR64:$dst, EFLAGS,
1217                             (X86xor_flag GR64:$src1, i64immSExt32:$src2))]>;
1218 } // Constraints = "$src1 = $dst"
1219
1220 def XOR64mr  : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1221                   "xor{q}\t{$src, $dst|$dst, $src}",
1222                   [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1223                    (implicit EFLAGS)]>;
1224 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
1225                     "xor{q}\t{$src, $dst|$dst, $src}",
1226                  [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1227                   (implicit EFLAGS)]>;
1228 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1229                       "xor{q}\t{$src, $dst|$dst, $src}",
1230              [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1231               (implicit EFLAGS)]>;
1232               
1233 def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i64i32imm:$src),
1234                      "xor{q}\t{$src, %rax|%rax, $src}", []>;
1235
1236 } // Defs = [EFLAGS]
1237
1238 //===----------------------------------------------------------------------===//
1239 //  Comparison Instructions...
1240 //
1241
1242 // Integer comparison
1243 let Defs = [EFLAGS] in {
1244 def TEST64i32 : RIi32<0xa9, RawFrm, (outs), (ins i64i32imm:$src),
1245                       "test{q}\t{$src, %rax|%rax, $src}", []>;
1246 let isCommutable = 1 in
1247 def TEST64rr : RI<0x85, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1248                   "test{q}\t{$src2, $src1|$src1, $src2}",
1249                   [(set EFLAGS, (X86cmp (and GR64:$src1, GR64:$src2), 0))]>;
1250 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1251                   "test{q}\t{$src2, $src1|$src1, $src2}",
1252                   [(set EFLAGS, (X86cmp (and GR64:$src1, (loadi64 addr:$src2)),
1253                     0))]>;
1254 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1255                                         (ins GR64:$src1, i64i32imm:$src2),
1256                        "test{q}\t{$src2, $src1|$src1, $src2}",
1257                      [(set EFLAGS, (X86cmp (and GR64:$src1, i64immSExt32:$src2),
1258                       0))]>;
1259 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1260                                         (ins i64mem:$src1, i64i32imm:$src2),
1261                        "test{q}\t{$src2, $src1|$src1, $src2}",
1262                 [(set EFLAGS, (X86cmp (and (loadi64 addr:$src1),
1263                                            i64immSExt32:$src2), 0))]>;
1264
1265
1266 def CMP64i32 : RIi32<0x3D, RawFrm, (outs), (ins i64i32imm:$src),
1267                      "cmp{q}\t{$src, %rax|%rax, $src}", []>;
1268 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1269                  "cmp{q}\t{$src2, $src1|$src1, $src2}",
1270                  [(set EFLAGS, (X86cmp GR64:$src1, GR64:$src2))]>;
1271
1272 // These are alternate spellings for use by the disassembler, we mark them as
1273 // code gen only to ensure they aren't matched by the assembler.
1274 let isCodeGenOnly = 1 in {
1275   def CMP64mrmrr : RI<0x3B, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1276                       "cmp{q}\t{$src2, $src1|$src1, $src2}", []>;
1277 }
1278
1279 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1280                  "cmp{q}\t{$src2, $src1|$src1, $src2}",
1281                  [(set EFLAGS, (X86cmp (loadi64 addr:$src1), GR64:$src2))]>;
1282 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
1283                  "cmp{q}\t{$src2, $src1|$src1, $src2}",
1284                  [(set EFLAGS, (X86cmp GR64:$src1, (loadi64 addr:$src2)))]>;
1285 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1286                     "cmp{q}\t{$src2, $src1|$src1, $src2}",
1287                     [(set EFLAGS, (X86cmp GR64:$src1, i64immSExt8:$src2))]>;
1288 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
1289                       "cmp{q}\t{$src2, $src1|$src1, $src2}",
1290                       [(set EFLAGS, (X86cmp GR64:$src1, i64immSExt32:$src2))]>;
1291 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1292                     "cmp{q}\t{$src2, $src1|$src1, $src2}",
1293                     [(set EFLAGS, (X86cmp (loadi64 addr:$src1),
1294                                           i64immSExt8:$src2))]>;
1295 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1296                                        (ins i64mem:$src1, i64i32imm:$src2),
1297                       "cmp{q}\t{$src2, $src1|$src1, $src2}",
1298                       [(set EFLAGS, (X86cmp (loadi64 addr:$src1),
1299                                             i64immSExt32:$src2))]>;
1300 } // Defs = [EFLAGS]
1301
1302 // Bit tests.
1303 // TODO: BTC, BTR, and BTS
1304 let Defs = [EFLAGS] in {
1305 def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1306                "bt{q}\t{$src2, $src1|$src1, $src2}",
1307                [(set EFLAGS, (X86bt GR64:$src1, GR64:$src2))]>, TB;
1308
1309 // Unlike with the register+register form, the memory+register form of the
1310 // bt instruction does not ignore the high bits of the index. From ISel's
1311 // perspective, this is pretty bizarre. Disable these instructions for now.
1312 def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1313                "bt{q}\t{$src2, $src1|$src1, $src2}",
1314 //               [(X86bt (loadi64 addr:$src1), GR64:$src2),
1315 //                (implicit EFLAGS)]
1316                 []
1317                 >, TB;
1318
1319 def BT64ri8 : RIi8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1320                 "bt{q}\t{$src2, $src1|$src1, $src2}",
1321                 [(set EFLAGS, (X86bt GR64:$src1, i64immSExt8:$src2))]>, TB;
1322 // Note that these instructions don't need FastBTMem because that
1323 // only applies when the other operand is in a register. When it's
1324 // an immediate, bt is still fast.
1325 def BT64mi8 : RIi8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1326                 "bt{q}\t{$src2, $src1|$src1, $src2}",
1327                 [(set EFLAGS, (X86bt (loadi64 addr:$src1),
1328                                      i64immSExt8:$src2))]>, TB;
1329
1330 def BTC64rr : RI<0xBB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1331                  "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1332 def BTC64mr : RI<0xBB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1333                  "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1334 def BTC64ri8 : RIi8<0xBA, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1335                     "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1336 def BTC64mi8 : RIi8<0xBA, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1337                     "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1338
1339 def BTR64rr : RI<0xB3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1340                  "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1341 def BTR64mr : RI<0xB3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1342                  "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1343 def BTR64ri8 : RIi8<0xBA, MRM6r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1344                     "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1345 def BTR64mi8 : RIi8<0xBA, MRM6m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1346                     "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1347
1348 def BTS64rr : RI<0xAB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1349                  "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1350 def BTS64mr : RI<0xAB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1351                  "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1352 def BTS64ri8 : RIi8<0xBA, MRM5r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1353                     "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1354 def BTS64mi8 : RIi8<0xBA, MRM5m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1355                     "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1356 } // Defs = [EFLAGS]
1357
1358 // Conditional moves
1359 let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
1360 let isCommutable = 1 in {
1361 def CMOVB64rr : RI<0x42, MRMSrcReg,       // if <u, GR64 = GR64
1362                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1363                    "cmovb{q}\t{$src2, $dst|$dst, $src2}",
1364                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1365                                      X86_COND_B, EFLAGS))]>, TB;
1366 def CMOVAE64rr: RI<0x43, MRMSrcReg,       // if >=u, GR64 = GR64
1367                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1368                    "cmovae{q}\t{$src2, $dst|$dst, $src2}",
1369                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1370                                      X86_COND_AE, EFLAGS))]>, TB;
1371 def CMOVE64rr : RI<0x44, MRMSrcReg,       // if ==, GR64 = GR64
1372                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1373                    "cmove{q}\t{$src2, $dst|$dst, $src2}",
1374                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1375                                      X86_COND_E, EFLAGS))]>, TB;
1376 def CMOVNE64rr: RI<0x45, MRMSrcReg,       // if !=, GR64 = GR64
1377                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1378                    "cmovne{q}\t{$src2, $dst|$dst, $src2}",
1379                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1380                                     X86_COND_NE, EFLAGS))]>, TB;
1381 def CMOVBE64rr: RI<0x46, MRMSrcReg,       // if <=u, GR64 = GR64
1382                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1383                    "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
1384                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1385                                     X86_COND_BE, EFLAGS))]>, TB;
1386 def CMOVA64rr : RI<0x47, MRMSrcReg,       // if >u, GR64 = GR64
1387                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1388                    "cmova{q}\t{$src2, $dst|$dst, $src2}",
1389                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1390                                     X86_COND_A, EFLAGS))]>, TB;
1391 def CMOVL64rr : RI<0x4C, MRMSrcReg,       // if <s, GR64 = GR64
1392                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1393                    "cmovl{q}\t{$src2, $dst|$dst, $src2}",
1394                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1395                                     X86_COND_L, EFLAGS))]>, TB;
1396 def CMOVGE64rr: RI<0x4D, MRMSrcReg,       // if >=s, GR64 = GR64
1397                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1398                    "cmovge{q}\t{$src2, $dst|$dst, $src2}",
1399                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1400                                     X86_COND_GE, EFLAGS))]>, TB;
1401 def CMOVLE64rr: RI<0x4E, MRMSrcReg,       // if <=s, GR64 = GR64
1402                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1403                    "cmovle{q}\t{$src2, $dst|$dst, $src2}",
1404                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1405                                     X86_COND_LE, EFLAGS))]>, TB;
1406 def CMOVG64rr : RI<0x4F, MRMSrcReg,       // if >s, GR64 = GR64
1407                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1408                    "cmovg{q}\t{$src2, $dst|$dst, $src2}",
1409                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1410                                     X86_COND_G, EFLAGS))]>, TB;
1411 def CMOVS64rr : RI<0x48, MRMSrcReg,       // if signed, GR64 = GR64
1412                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1413                    "cmovs{q}\t{$src2, $dst|$dst, $src2}",
1414                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1415                                     X86_COND_S, EFLAGS))]>, TB;
1416 def CMOVNS64rr: RI<0x49, MRMSrcReg,       // if !signed, GR64 = GR64
1417                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1418                    "cmovns{q}\t{$src2, $dst|$dst, $src2}",
1419                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1420                                     X86_COND_NS, EFLAGS))]>, TB;
1421 def CMOVP64rr : RI<0x4A, MRMSrcReg,       // if parity, GR64 = GR64
1422                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1423                    "cmovp{q}\t{$src2, $dst|$dst, $src2}",
1424                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1425                                     X86_COND_P, EFLAGS))]>, TB;
1426 def CMOVNP64rr : RI<0x4B, MRMSrcReg,       // if !parity, GR64 = GR64
1427                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1428                    "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
1429                     [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1430                                      X86_COND_NP, EFLAGS))]>, TB;
1431 def CMOVO64rr : RI<0x40, MRMSrcReg,       // if overflow, GR64 = GR64
1432                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1433                    "cmovo{q}\t{$src2, $dst|$dst, $src2}",
1434                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1435                                     X86_COND_O, EFLAGS))]>, TB;
1436 def CMOVNO64rr : RI<0x41, MRMSrcReg,       // if !overflow, GR64 = GR64
1437                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1438                    "cmovno{q}\t{$src2, $dst|$dst, $src2}",
1439                     [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1440                                      X86_COND_NO, EFLAGS))]>, TB;
1441 } // isCommutable = 1
1442
1443 def CMOVB64rm : RI<0x42, MRMSrcMem,       // if <u, GR64 = [mem64]
1444                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1445                    "cmovb{q}\t{$src2, $dst|$dst, $src2}",
1446                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1447                                      X86_COND_B, EFLAGS))]>, TB;
1448 def CMOVAE64rm: RI<0x43, MRMSrcMem,       // if >=u, GR64 = [mem64]
1449                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1450                    "cmovae{q}\t{$src2, $dst|$dst, $src2}",
1451                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1452                                      X86_COND_AE, EFLAGS))]>, TB;
1453 def CMOVE64rm : RI<0x44, MRMSrcMem,       // if ==, GR64 = [mem64]
1454                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1455                    "cmove{q}\t{$src2, $dst|$dst, $src2}",
1456                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1457                                      X86_COND_E, EFLAGS))]>, TB;
1458 def CMOVNE64rm: RI<0x45, MRMSrcMem,       // if !=, GR64 = [mem64]
1459                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1460                    "cmovne{q}\t{$src2, $dst|$dst, $src2}",
1461                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1462                                     X86_COND_NE, EFLAGS))]>, TB;
1463 def CMOVBE64rm: RI<0x46, MRMSrcMem,       // if <=u, GR64 = [mem64]
1464                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1465                    "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
1466                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1467                                     X86_COND_BE, EFLAGS))]>, TB;
1468 def CMOVA64rm : RI<0x47, MRMSrcMem,       // if >u, GR64 = [mem64]
1469                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1470                    "cmova{q}\t{$src2, $dst|$dst, $src2}",
1471                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1472                                     X86_COND_A, EFLAGS))]>, TB;
1473 def CMOVL64rm : RI<0x4C, MRMSrcMem,       // if <s, GR64 = [mem64]
1474                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1475                    "cmovl{q}\t{$src2, $dst|$dst, $src2}",
1476                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1477                                     X86_COND_L, EFLAGS))]>, TB;
1478 def CMOVGE64rm: RI<0x4D, MRMSrcMem,       // if >=s, GR64 = [mem64]
1479                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1480                    "cmovge{q}\t{$src2, $dst|$dst, $src2}",
1481                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1482                                     X86_COND_GE, EFLAGS))]>, TB;
1483 def CMOVLE64rm: RI<0x4E, MRMSrcMem,       // if <=s, GR64 = [mem64]
1484                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1485                    "cmovle{q}\t{$src2, $dst|$dst, $src2}",
1486                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1487                                     X86_COND_LE, EFLAGS))]>, TB;
1488 def CMOVG64rm : RI<0x4F, MRMSrcMem,       // if >s, GR64 = [mem64]
1489                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1490                    "cmovg{q}\t{$src2, $dst|$dst, $src2}",
1491                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1492                                     X86_COND_G, EFLAGS))]>, TB;
1493 def CMOVS64rm : RI<0x48, MRMSrcMem,       // if signed, GR64 = [mem64]
1494                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1495                    "cmovs{q}\t{$src2, $dst|$dst, $src2}",
1496                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1497                                     X86_COND_S, EFLAGS))]>, TB;
1498 def CMOVNS64rm: RI<0x49, MRMSrcMem,       // if !signed, GR64 = [mem64]
1499                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1500                    "cmovns{q}\t{$src2, $dst|$dst, $src2}",
1501                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1502                                     X86_COND_NS, EFLAGS))]>, TB;
1503 def CMOVP64rm : RI<0x4A, MRMSrcMem,       // if parity, GR64 = [mem64]
1504                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1505                    "cmovp{q}\t{$src2, $dst|$dst, $src2}",
1506                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1507                                     X86_COND_P, EFLAGS))]>, TB;
1508 def CMOVNP64rm : RI<0x4B, MRMSrcMem,       // if !parity, GR64 = [mem64]
1509                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1510                    "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
1511                     [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1512                                      X86_COND_NP, EFLAGS))]>, TB;
1513 def CMOVO64rm : RI<0x40, MRMSrcMem,       // if overflow, GR64 = [mem64]
1514                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1515                    "cmovo{q}\t{$src2, $dst|$dst, $src2}",
1516                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1517                                     X86_COND_O, EFLAGS))]>, TB;
1518 def CMOVNO64rm : RI<0x41, MRMSrcMem,       // if !overflow, GR64 = [mem64]
1519                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1520                    "cmovno{q}\t{$src2, $dst|$dst, $src2}",
1521                     [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1522                                      X86_COND_NO, EFLAGS))]>, TB;
1523 } // Constraints = "$src1 = $dst"
1524
1525 // Use sbb to materialize carry flag into a GPR.
1526 // FIXME: This are pseudo ops that should be replaced with Pat<> patterns.
1527 // However, Pat<> can't replicate the destination reg into the inputs of the
1528 // result.
1529 // FIXME: Change this to have encoding Pseudo when X86MCCodeEmitter replaces
1530 // X86CodeEmitter.
1531 let Defs = [EFLAGS], Uses = [EFLAGS], isCodeGenOnly = 1 in
1532 def SETB_C64r : RI<0x19, MRMInitReg, (outs GR64:$dst), (ins), "",
1533                  [(set GR64:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
1534
1535 def : Pat<(i64 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
1536           (SETB_C64r)>;
1537
1538 //===----------------------------------------------------------------------===//
1539 // Descriptor-table support instructions
1540
1541 // LLDT is not interpreted specially in 64-bit mode because there is no sign
1542 //   extension.
1543 def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
1544                  "sldt{q}\t$dst", []>, TB;
1545 def SLDT64m : RI<0x00, MRM0m, (outs i16mem:$dst), (ins),
1546                  "sldt{q}\t$dst", []>, TB;
1547
1548 //===----------------------------------------------------------------------===//
1549 // Alias Instructions
1550 //===----------------------------------------------------------------------===//
1551
1552 // We want to rewrite MOV64r0 in terms of MOV32r0, because it's sometimes a
1553 // smaller encoding, but doing so at isel time interferes with rematerialization
1554 // in the current register allocator. For now, this is rewritten when the
1555 // instruction is lowered to an MCInst.
1556 // FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
1557 // when we have a better way to specify isel priority.
1558 let Defs = [EFLAGS],
1559     AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1560 def MOV64r0   : I<0x31, MRMInitReg, (outs GR64:$dst), (ins), "",
1561                  [(set GR64:$dst, 0)]>;
1562
1563 // Materialize i64 constant where top 32-bits are zero. This could theoretically
1564 // use MOV32ri with a SUBREG_TO_REG to represent the zero-extension, however
1565 // that would make it more difficult to rematerialize.
1566 let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1567 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1568                         "", [(set GR64:$dst, i64immZExt32:$src)]>;
1569
1570 //===----------------------------------------------------------------------===//
1571 // Thread Local Storage Instructions
1572 //===----------------------------------------------------------------------===//
1573
1574 // ELF TLS Support
1575 // All calls clobber the non-callee saved registers. RSP is marked as
1576 // a use to prevent stack-pointer assignments that appear immediately
1577 // before calls from potentially appearing dead.
1578 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1579             FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1580             MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1581             XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1582             XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1583     Uses = [RSP] in
1584 def TLS_addr64 : I<0, Pseudo, (outs), (ins i64mem:$sym),
1585                    ".byte\t0x66; "
1586                    "leaq\t$sym(%rip), %rdi; "
1587                    ".word\t0x6666; "
1588                    "rex64; "
1589                    "call\t__tls_get_addr@PLT",
1590                   [(X86tlsaddr tls64addr:$sym)]>,
1591                   Requires<[In64BitMode]>;
1592
1593 // Darwin TLS Support
1594 // For x86_64, the address of the thunk is passed in %rdi, on return 
1595 // the address of the variable is in %rax.  All other registers are preserved.
1596 let Defs = [RAX],
1597     Uses = [RDI],
1598     usesCustomInserter = 1 in
1599 def TLSCall_64 : I<0, Pseudo, (outs), (ins i64mem:$sym),
1600                   "# TLSCall_64",
1601                   [(X86TLSCall addr:$sym)]>,
1602                   Requires<[In64BitMode]>;
1603
1604 //===----------------------------------------------------------------------===//
1605 // Atomic Instructions
1606 //===----------------------------------------------------------------------===//
1607
1608 // TODO: Get this to fold the constant into the instruction.           
1609 let hasSideEffects = 1, Defs = [ESP] in
1610 def Int_MemBarrierNoSSE64  : RI<0x09, MRM1r, (outs), (ins GR64:$zero),
1611                            "lock\n\t"
1612                            "or{q}\t{$zero, (%rsp)|(%rsp), $zero}",
1613                            [(X86MemBarrierNoSSE GR64:$zero)]>,
1614                            Requires<[In64BitMode]>, LOCK;
1615
1616 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1617 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1618                "lock\n\t"
1619                "cmpxchgq\t$swap,$ptr",
1620                [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1621 }
1622
1623 let Constraints = "$val = $dst" in {
1624 let Defs = [EFLAGS] in
1625 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins GR64:$val,i64mem:$ptr),
1626                "lock\n\t"
1627                "xadd\t$val, $ptr",
1628                [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1629                 TB, LOCK;
1630
1631 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), 
1632                   (ins GR64:$val,i64mem:$ptr),
1633                   "xchg{q}\t{$val, $ptr|$ptr, $val}", 
1634                   [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1635
1636 def XCHG64rr : RI<0x87, MRMSrcReg, (outs GR64:$dst), (ins GR64:$val,GR64:$src),
1637                   "xchg{q}\t{$val, $src|$src, $val}", []>;
1638 }
1639
1640 def XADD64rr  : RI<0xC1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1641                    "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1642 let mayLoad = 1, mayStore = 1 in
1643 def XADD64rm  : RI<0xC1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1644                    "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1645                    
1646 def CMPXCHG64rr  : RI<0xB1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1647                       "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1648 let mayLoad = 1, mayStore = 1 in
1649 def CMPXCHG64rm  : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1650                       "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1651                       
1652 let Defs = [RAX, RDX, EFLAGS], Uses = [RAX, RBX, RCX, RDX] in
1653 def CMPXCHG16B : RI<0xC7, MRM1m, (outs), (ins i128mem:$dst),
1654                     "cmpxchg16b\t$dst", []>, TB;
1655
1656 def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src),
1657                   "xchg{q}\t{$src, %rax|%rax, $src}", []>;
1658
1659 // Optimized codegen when the non-memory output is not used.
1660 let Defs = [EFLAGS], mayLoad = 1, mayStore = 1 in {
1661 // FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1662 def LOCK_ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1663                       "lock\n\t"
1664                       "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1665 def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1666                                       (ins i64mem:$dst, i64i8imm :$src2),
1667                     "lock\n\t"
1668                     "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1669 def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1670                                         (ins i64mem:$dst, i64i32imm :$src2),
1671                       "lock\n\t"
1672                       "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1673 def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2), 
1674                       "lock\n\t"
1675                       "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1676 def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1677                                       (ins i64mem:$dst, i64i8imm :$src2), 
1678                       "lock\n\t"
1679                       "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1680 def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1681                                         (ins i64mem:$dst, i64i32imm:$src2),
1682                       "lock\n\t"
1683                       "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1684 def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1685                      "lock\n\t"
1686                      "inc{q}\t$dst", []>, LOCK;
1687 def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1688                       "lock\n\t"
1689                       "dec{q}\t$dst", []>, LOCK;
1690 }
1691 // Atomic exchange, and, or, xor
1692 let Constraints = "$val = $dst", Defs = [EFLAGS],
1693                   usesCustomInserter = 1 in {
1694 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1695                "#ATOMAND64 PSEUDO!", 
1696                [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1697 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1698                "#ATOMOR64 PSEUDO!", 
1699                [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1700 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1701                "#ATOMXOR64 PSEUDO!", 
1702                [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1703 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1704                "#ATOMNAND64 PSEUDO!", 
1705                [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1706 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1707                "#ATOMMIN64 PSEUDO!", 
1708                [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1709 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1710                "#ATOMMAX64 PSEUDO!", 
1711                [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1712 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1713                "#ATOMUMIN64 PSEUDO!", 
1714                [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1715 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1716                "#ATOMUMAX64 PSEUDO!", 
1717                [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1718 }
1719
1720 // Segmentation support instructions
1721
1722 // i16mem operand in LAR64rm and GR32 operand in LAR32rr is not a typo.
1723 def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src), 
1724                  "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1725 def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
1726                  "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1727                  
1728 def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1729                  "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB; 
1730 def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
1731                  "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1732
1733 def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", []>, TB;
1734
1735
1736 // String manipulation instructions
1737
1738 def LODSQ : RI<0xAD, RawFrm, (outs), (ins), "lodsq", []>;
1739
1740 //===----------------------------------------------------------------------===//
1741 // Non-Instruction Patterns
1742 //===----------------------------------------------------------------------===//
1743
1744 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1745 // code model mode, should use 'movabs'.  FIXME: This is really a hack, the
1746 //  'movabs' predicate should handle this sort of thing.
1747 def : Pat<(i64 (X86Wrapper tconstpool  :$dst)),
1748           (MOV64ri tconstpool  :$dst)>, Requires<[FarData]>;
1749 def : Pat<(i64 (X86Wrapper tjumptable  :$dst)),
1750           (MOV64ri tjumptable  :$dst)>, Requires<[FarData]>;
1751 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1752           (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
1753 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1754           (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
1755 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1756           (MOV64ri tblockaddress:$dst)>, Requires<[FarData]>;
1757
1758 // In static codegen with small code model, we can get the address of a label
1759 // into a register with 'movl'.  FIXME: This is a hack, the 'imm' predicate of
1760 // the MOV64ri64i32 should accept these.
1761 def : Pat<(i64 (X86Wrapper tconstpool  :$dst)),
1762           (MOV64ri64i32 tconstpool  :$dst)>, Requires<[SmallCode]>;
1763 def : Pat<(i64 (X86Wrapper tjumptable  :$dst)),
1764           (MOV64ri64i32 tjumptable  :$dst)>, Requires<[SmallCode]>;
1765 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1766           (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1767 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1768           (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1769 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1770           (MOV64ri64i32 tblockaddress:$dst)>, Requires<[SmallCode]>;
1771
1772 // In kernel code model, we can get the address of a label
1773 // into a register with 'movq'.  FIXME: This is a hack, the 'imm' predicate of
1774 // the MOV64ri32 should accept these.
1775 def : Pat<(i64 (X86Wrapper tconstpool  :$dst)),
1776           (MOV64ri32 tconstpool  :$dst)>, Requires<[KernelCode]>;
1777 def : Pat<(i64 (X86Wrapper tjumptable  :$dst)),
1778           (MOV64ri32 tjumptable  :$dst)>, Requires<[KernelCode]>;
1779 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1780           (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1781 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1782           (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
1783 def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1784           (MOV64ri32 tblockaddress:$dst)>, Requires<[KernelCode]>;
1785
1786 // If we have small model and -static mode, it is safe to store global addresses
1787 // directly as immediates.  FIXME: This is really a hack, the 'imm' predicate
1788 // for MOV64mi32 should handle this sort of thing.
1789 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1790           (MOV64mi32 addr:$dst, tconstpool:$src)>,
1791           Requires<[NearData, IsStatic]>;
1792 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1793           (MOV64mi32 addr:$dst, tjumptable:$src)>,
1794           Requires<[NearData, IsStatic]>;
1795 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1796           (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1797           Requires<[NearData, IsStatic]>;
1798 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1799           (MOV64mi32 addr:$dst, texternalsym:$src)>,
1800           Requires<[NearData, IsStatic]>;
1801 def : Pat<(store (i64 (X86Wrapper tblockaddress:$src)), addr:$dst),
1802           (MOV64mi32 addr:$dst, tblockaddress:$src)>,
1803           Requires<[NearData, IsStatic]>;
1804
1805 // Calls
1806 // Direct PC relative function call for small code model. 32-bit displacement
1807 // sign extended to 64-bit.
1808 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1809           (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
1810 def : Pat<(X86call (i64 texternalsym:$dst)),
1811           (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1812
1813 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1814           (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1815 def : Pat<(X86call (i64 texternalsym:$dst)),
1816           (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
1817
1818 // tailcall stuff
1819 def : Pat<(X86tcret GR64_TC:$dst, imm:$off),
1820           (TCRETURNri64 GR64_TC:$dst, imm:$off)>,
1821           Requires<[In64BitMode]>;
1822
1823 def : Pat<(X86tcret (load addr:$dst), imm:$off),
1824           (TCRETURNmi64 addr:$dst, imm:$off)>,
1825           Requires<[In64BitMode]>;
1826
1827 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1828           (TCRETURNdi64 tglobaladdr:$dst, imm:$off)>,
1829           Requires<[In64BitMode]>;
1830
1831 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1832           (TCRETURNdi64 texternalsym:$dst, imm:$off)>,
1833           Requires<[In64BitMode]>;
1834
1835 // tls has some funny stuff here...
1836 // This corresponds to movabs $foo@tpoff, %rax
1837 def : Pat<(i64 (X86Wrapper tglobaltlsaddr :$dst)),
1838           (MOV64ri tglobaltlsaddr :$dst)>;
1839 // This corresponds to add $foo@tpoff, %rax
1840 def : Pat<(add GR64:$src1, (X86Wrapper tglobaltlsaddr :$dst)),
1841           (ADD64ri32 GR64:$src1, tglobaltlsaddr :$dst)>;
1842 // This corresponds to mov foo@tpoff(%rbx), %eax
1843 def : Pat<(load (i64 (X86Wrapper tglobaltlsaddr :$dst))),
1844           (MOV64rm tglobaltlsaddr :$dst)>;
1845
1846 // Comparisons.
1847
1848 // TEST R,R is smaller than CMP R,0
1849 def : Pat<(X86cmp GR64:$src1, 0),
1850           (TEST64rr GR64:$src1, GR64:$src1)>;
1851
1852 // Conditional moves with folded loads with operands swapped and conditions
1853 // inverted.
1854 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1855           (CMOVAE64rm GR64:$src2, addr:$src1)>;
1856 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1857           (CMOVB64rm GR64:$src2, addr:$src1)>;
1858 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1859           (CMOVNE64rm GR64:$src2, addr:$src1)>;
1860 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1861           (CMOVE64rm GR64:$src2, addr:$src1)>;
1862 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1863           (CMOVA64rm GR64:$src2, addr:$src1)>;
1864 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1865           (CMOVBE64rm GR64:$src2, addr:$src1)>;
1866 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1867           (CMOVGE64rm GR64:$src2, addr:$src1)>;
1868 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1869           (CMOVL64rm GR64:$src2, addr:$src1)>;
1870 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1871           (CMOVG64rm GR64:$src2, addr:$src1)>;
1872 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1873           (CMOVLE64rm GR64:$src2, addr:$src1)>;
1874 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1875           (CMOVNP64rm GR64:$src2, addr:$src1)>;
1876 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1877           (CMOVP64rm GR64:$src2, addr:$src1)>;
1878 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1879           (CMOVNS64rm GR64:$src2, addr:$src1)>;
1880 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1881           (CMOVS64rm GR64:$src2, addr:$src1)>;
1882 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1883           (CMOVNO64rm GR64:$src2, addr:$src1)>;
1884 def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1885           (CMOVO64rm GR64:$src2, addr:$src1)>;
1886
1887 // zextload bool -> zextload byte
1888 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1889
1890 // extload
1891 // When extloading from 16-bit and smaller memory locations into 64-bit 
1892 // registers, use zero-extending loads so that the entire 64-bit register is 
1893 // defined, avoiding partial-register updates.
1894 def : Pat<(extloadi64i1 addr:$src),  (MOVZX64rm8  addr:$src)>;
1895 def : Pat<(extloadi64i8 addr:$src),  (MOVZX64rm8  addr:$src)>;
1896 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1897 // For other extloads, use subregs, since the high contents of the register are
1898 // defined after an extload.
1899 def : Pat<(extloadi64i32 addr:$src),
1900           (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
1901                          sub_32bit)>;
1902
1903 // anyext. Define these to do an explicit zero-extend to
1904 // avoid partial-register updates.
1905 def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8  GR8  :$src)>;
1906 def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1907 def : Pat<(i64 (anyext GR32:$src)),
1908           (SUBREG_TO_REG (i64 0), GR32:$src, sub_32bit)>;
1909
1910 //===----------------------------------------------------------------------===//
1911 // Some peepholes
1912 //===----------------------------------------------------------------------===//
1913
1914 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1915 // +128 doesn't, so in this special case use a sub instead of an add.
1916 def : Pat<(add GR64:$src1, 128),
1917           (SUB64ri8 GR64:$src1, -128)>;
1918 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1919           (SUB64mi8 addr:$dst, -128)>;
1920
1921 // The same trick applies for 32-bit immediate fields in 64-bit
1922 // instructions.
1923 def : Pat<(add GR64:$src1, 0x0000000080000000),
1924           (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1925 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1926           (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1927
1928 // Use a 32-bit and with implicit zero-extension instead of a 64-bit and if it
1929 // has an immediate with at least 32 bits of leading zeros, to avoid needing to
1930 // materialize that immediate in a register first.
1931 def : Pat<(and GR64:$src, i64immZExt32:$imm),
1932           (SUBREG_TO_REG
1933             (i64 0),
1934             (AND32ri
1935               (EXTRACT_SUBREG GR64:$src, sub_32bit),
1936               (i32 (GetLo32XForm imm:$imm))),
1937             sub_32bit)>;
1938
1939 // r & (2^32-1) ==> movz
1940 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1941           (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, sub_32bit))>;
1942 // r & (2^16-1) ==> movz
1943 def : Pat<(and GR64:$src, 0xffff),
1944           (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, sub_16bit)))>;
1945 // r & (2^8-1) ==> movz
1946 def : Pat<(and GR64:$src, 0xff),
1947           (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, sub_8bit)))>;
1948 // r & (2^8-1) ==> movz
1949 def : Pat<(and GR32:$src1, 0xff),
1950            (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, sub_8bit))>,
1951       Requires<[In64BitMode]>;
1952 // r & (2^8-1) ==> movz
1953 def : Pat<(and GR16:$src1, 0xff),
1954            (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, sub_8bit)))>,
1955       Requires<[In64BitMode]>;
1956
1957 // sext_inreg patterns
1958 def : Pat<(sext_inreg GR64:$src, i32),
1959           (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, sub_32bit))>;
1960 def : Pat<(sext_inreg GR64:$src, i16),
1961           (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, sub_16bit))>;
1962 def : Pat<(sext_inreg GR64:$src, i8),
1963           (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, sub_8bit))>;
1964 def : Pat<(sext_inreg GR32:$src, i8),
1965           (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, sub_8bit))>,
1966       Requires<[In64BitMode]>;
1967 def : Pat<(sext_inreg GR16:$src, i8),
1968           (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, sub_8bit)))>,
1969       Requires<[In64BitMode]>;
1970
1971 // trunc patterns
1972 def : Pat<(i32 (trunc GR64:$src)),
1973           (EXTRACT_SUBREG GR64:$src, sub_32bit)>;
1974 def : Pat<(i16 (trunc GR64:$src)),
1975           (EXTRACT_SUBREG GR64:$src, sub_16bit)>;
1976 def : Pat<(i8 (trunc GR64:$src)),
1977           (EXTRACT_SUBREG GR64:$src, sub_8bit)>;
1978 def : Pat<(i8 (trunc GR32:$src)),
1979           (EXTRACT_SUBREG GR32:$src, sub_8bit)>,
1980       Requires<[In64BitMode]>;
1981 def : Pat<(i8 (trunc GR16:$src)),
1982           (EXTRACT_SUBREG GR16:$src, sub_8bit)>,
1983       Requires<[In64BitMode]>;
1984
1985 // h-register tricks.
1986 // For now, be conservative on x86-64 and use an h-register extract only if the
1987 // value is immediately zero-extended or stored, which are somewhat common
1988 // cases. This uses a bunch of code to prevent a register requiring a REX prefix
1989 // from being allocated in the same instruction as the h register, as there's
1990 // currently no way to describe this requirement to the register allocator.
1991
1992 // h-register extract and zero-extend.
1993 def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1994           (SUBREG_TO_REG
1995             (i64 0),
1996             (MOVZX32_NOREXrr8
1997               (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
1998                               sub_8bit_hi)),
1999             sub_32bit)>;
2000 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
2001           (MOVZX32_NOREXrr8
2002             (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
2003                             sub_8bit_hi))>,
2004       Requires<[In64BitMode]>;
2005 def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)),
2006           (MOVZX32_NOREXrr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
2007                                                                    GR32_ABCD)),
2008                                              sub_8bit_hi))>,
2009       Requires<[In64BitMode]>;
2010 def : Pat<(srl GR16:$src, (i8 8)),
2011           (EXTRACT_SUBREG
2012             (MOVZX32_NOREXrr8
2013               (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2014                               sub_8bit_hi)),
2015             sub_16bit)>,
2016       Requires<[In64BitMode]>;
2017 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
2018           (MOVZX32_NOREXrr8
2019             (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2020                             sub_8bit_hi))>,
2021       Requires<[In64BitMode]>;
2022 def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
2023           (MOVZX32_NOREXrr8
2024             (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2025                             sub_8bit_hi))>,
2026       Requires<[In64BitMode]>;
2027 def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
2028           (SUBREG_TO_REG
2029             (i64 0),
2030             (MOVZX32_NOREXrr8
2031               (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2032                               sub_8bit_hi)),
2033             sub_32bit)>;
2034 def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
2035           (SUBREG_TO_REG
2036             (i64 0),
2037             (MOVZX32_NOREXrr8
2038               (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2039                               sub_8bit_hi)),
2040             sub_32bit)>;
2041
2042 // h-register extract and store.
2043 def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
2044           (MOV8mr_NOREX
2045             addr:$dst,
2046             (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
2047                             sub_8bit_hi))>;
2048 def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
2049           (MOV8mr_NOREX
2050             addr:$dst,
2051             (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
2052                             sub_8bit_hi))>,
2053       Requires<[In64BitMode]>;
2054 def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
2055           (MOV8mr_NOREX
2056             addr:$dst,
2057             (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
2058                             sub_8bit_hi))>,
2059       Requires<[In64BitMode]>;
2060
2061 // (shl x, 1) ==> (add x, x)
2062 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
2063
2064 // (shl x (and y, 63)) ==> (shl x, y)
2065 def : Pat<(shl GR64:$src1, (and CL, 63)),
2066           (SHL64rCL GR64:$src1)>;
2067 def : Pat<(store (shl (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2068           (SHL64mCL addr:$dst)>;
2069
2070 def : Pat<(srl GR64:$src1, (and CL, 63)),
2071           (SHR64rCL GR64:$src1)>;
2072 def : Pat<(store (srl (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2073           (SHR64mCL addr:$dst)>;
2074
2075 def : Pat<(sra GR64:$src1, (and CL, 63)),
2076           (SAR64rCL GR64:$src1)>;
2077 def : Pat<(store (sra (loadi64 addr:$dst), (and CL, 63)), addr:$dst),
2078           (SAR64mCL addr:$dst)>;
2079
2080 // (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
2081 let AddedComplexity = 5 in {  // Try this before the selecting to OR
2082 def : Pat<(or_is_add GR64:$src1, i64immSExt8:$src2),
2083           (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2084 def : Pat<(or_is_add GR64:$src1, i64immSExt32:$src2),
2085           (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
2086 def : Pat<(or_is_add GR64:$src1, GR64:$src2),
2087           (ADD64rr GR64:$src1, GR64:$src2)>;
2088 } // AddedComplexity
2089
2090 // X86 specific add which produces a flag.
2091 def : Pat<(addc GR64:$src1, GR64:$src2),
2092           (ADD64rr GR64:$src1, GR64:$src2)>;
2093 def : Pat<(addc GR64:$src1, (load addr:$src2)),
2094           (ADD64rm GR64:$src1, addr:$src2)>;
2095 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
2096           (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2097 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
2098           (ADD64ri32 GR64:$src1, imm:$src2)>;
2099
2100 def : Pat<(subc GR64:$src1, GR64:$src2),
2101           (SUB64rr GR64:$src1, GR64:$src2)>;
2102 def : Pat<(subc GR64:$src1, (load addr:$src2)),
2103           (SUB64rm GR64:$src1, addr:$src2)>;
2104 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
2105           (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
2106 def : Pat<(subc GR64:$src1, imm:$src2),
2107           (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
2108
2109 //===----------------------------------------------------------------------===//
2110 // EFLAGS-defining Patterns
2111 //===----------------------------------------------------------------------===//
2112
2113 // addition
2114 def : Pat<(add GR64:$src1, GR64:$src2),
2115           (ADD64rr GR64:$src1, GR64:$src2)>;
2116 def : Pat<(add GR64:$src1, i64immSExt8:$src2),
2117           (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2118 def : Pat<(add GR64:$src1, i64immSExt32:$src2),
2119           (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
2120 def : Pat<(add GR64:$src1, (loadi64 addr:$src2)),
2121           (ADD64rm GR64:$src1, addr:$src2)>;
2122
2123 // subtraction
2124 def : Pat<(sub GR64:$src1, GR64:$src2),
2125           (SUB64rr GR64:$src1, GR64:$src2)>;
2126 def : Pat<(sub GR64:$src1, (loadi64 addr:$src2)),
2127           (SUB64rm GR64:$src1, addr:$src2)>;
2128 def : Pat<(sub GR64:$src1, i64immSExt8:$src2),
2129           (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
2130 def : Pat<(sub GR64:$src1, i64immSExt32:$src2),
2131           (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
2132
2133 // Multiply
2134 def : Pat<(mul GR64:$src1, GR64:$src2),
2135           (IMUL64rr GR64:$src1, GR64:$src2)>;
2136 def : Pat<(mul GR64:$src1, (loadi64 addr:$src2)),
2137           (IMUL64rm GR64:$src1, addr:$src2)>;
2138 def : Pat<(mul GR64:$src1, i64immSExt8:$src2),
2139           (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
2140 def : Pat<(mul GR64:$src1, i64immSExt32:$src2),
2141           (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
2142 def : Pat<(mul (loadi64 addr:$src1), i64immSExt8:$src2),
2143           (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
2144 def : Pat<(mul (loadi64 addr:$src1), i64immSExt32:$src2),
2145           (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
2146
2147 // inc/dec
2148 def : Pat<(add GR16:$src, 1),  (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2149 def : Pat<(add GR16:$src, -1), (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2150 def : Pat<(add GR32:$src, 1),  (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2151 def : Pat<(add GR32:$src, -1), (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2152 def : Pat<(add GR64:$src, 1),  (INC64r GR64:$src)>;
2153 def : Pat<(add GR64:$src, -1), (DEC64r GR64:$src)>;
2154
2155 // or
2156 def : Pat<(or GR64:$src1, GR64:$src2),
2157           (OR64rr GR64:$src1, GR64:$src2)>;
2158 def : Pat<(or GR64:$src1, i64immSExt8:$src2),
2159           (OR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2160 def : Pat<(or GR64:$src1, i64immSExt32:$src2),
2161           (OR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2162 def : Pat<(or GR64:$src1, (loadi64 addr:$src2)),
2163           (OR64rm GR64:$src1, addr:$src2)>;
2164
2165 // xor
2166 def : Pat<(xor GR64:$src1, GR64:$src2),
2167           (XOR64rr GR64:$src1, GR64:$src2)>;
2168 def : Pat<(xor GR64:$src1, i64immSExt8:$src2),
2169           (XOR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2170 def : Pat<(xor GR64:$src1, i64immSExt32:$src2),
2171           (XOR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2172 def : Pat<(xor GR64:$src1, (loadi64 addr:$src2)),
2173           (XOR64rm GR64:$src1, addr:$src2)>;
2174
2175 // and
2176 def : Pat<(and GR64:$src1, GR64:$src2),
2177           (AND64rr GR64:$src1, GR64:$src2)>;
2178 def : Pat<(and GR64:$src1, i64immSExt8:$src2),
2179           (AND64ri8 GR64:$src1, i64immSExt8:$src2)>;
2180 def : Pat<(and GR64:$src1, i64immSExt32:$src2),
2181           (AND64ri32 GR64:$src1, i64immSExt32:$src2)>;
2182 def : Pat<(and GR64:$src1, (loadi64 addr:$src2)),
2183           (AND64rm GR64:$src1, addr:$src2)>;
2184
2185 //===----------------------------------------------------------------------===//
2186 // X86-64 SSE Instructions
2187 //===----------------------------------------------------------------------===//
2188
2189 // Move instructions...
2190
2191 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2192                         "mov{d|q}\t{$src, $dst|$dst, $src}",
2193                         [(set VR128:$dst,
2194                           (v2i64 (scalar_to_vector GR64:$src)))]>;
2195 def MOVPQIto64rr  : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
2196                          "mov{d|q}\t{$src, $dst|$dst, $src}",
2197                          [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2198                                            (iPTR 0)))]>;
2199
2200 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
2201                        "mov{d|q}\t{$src, $dst|$dst, $src}",
2202                        [(set FR64:$dst, (bitconvert GR64:$src))]>;
2203 def MOV64toSDrm : S3SI<0x7E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
2204                        "movq\t{$src, $dst|$dst, $src}",
2205                        [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2206
2207 def MOVSDto64rr  : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
2208                         "mov{d|q}\t{$src, $dst|$dst, $src}",
2209                         [(set GR64:$dst, (bitconvert FR64:$src))]>;
2210 def MOVSDto64mr  : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
2211                         "movq\t{$src, $dst|$dst, $src}",
2212                         [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
2213