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