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