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