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