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