77533188e4a4c1d80a0ba841b8cf5909de81b587
[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 // 64-bits but only 8 bits are significant.
23 def i64i8imm   : Operand<i64>;
24
25 def lea64mem : Operand<i64> {
26   let PrintMethod = "printi64mem";
27   let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
28 }
29
30 def lea64_32mem : Operand<i32> {
31   let PrintMethod = "printlea64_32mem";
32   let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
33 }
34
35 //===----------------------------------------------------------------------===//
36 // Complex Pattern Definitions.
37 //
38 def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
39                                [add, mul, shl, or, frameindex, X86Wrapper],
40                                []>;
41
42 //===----------------------------------------------------------------------===//
43 // Pattern fragments.
44 //
45
46 def i64immSExt32  : PatLeaf<(i64 imm), [{
47   // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
48   // sign extended field.
49   return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
50 }]>;
51
52 def i64immZExt32  : PatLeaf<(i64 imm), [{
53   // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
54   // unsignedsign extended field.
55   return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
56 }]>;
57
58 def i64immSExt8  : PatLeaf<(i64 imm), [{
59   // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
60   // sign extended field.
61   return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
62 }]>;
63
64 def sextloadi64i8  : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
65 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
66 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
67
68 def zextloadi64i1  : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
69 def zextloadi64i8  : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
70 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
71 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
72
73 def extloadi64i1   : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
74 def extloadi64i8   : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
75 def extloadi64i16  : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
76 def extloadi64i32  : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
77
78 //===----------------------------------------------------------------------===//
79 // Instruction list...
80 //
81
82 // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
83 // a stack adjustment and the codegen must know that they may modify the stack
84 // pointer before prolog-epilog rewriting occurs.
85 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
86 // sub / add which can clobber EFLAGS.
87 let Defs = [RSP, EFLAGS], Uses = [RSP] in {
88 def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
89                            "#ADJCALLSTACKDOWN",
90                            [(X86callseq_start timm:$amt)]>,
91                           Requires<[In64BitMode]>;
92 def ADJCALLSTACKUP64   : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
93                            "#ADJCALLSTACKUP",
94                            [(X86callseq_end timm:$amt1, timm:$amt2)]>,
95                           Requires<[In64BitMode]>;
96 }
97
98 //===----------------------------------------------------------------------===//
99 //  Call Instructions...
100 //
101 let isCall = 1 in
102   // All calls clobber the non-callee saved registers. RSP is marked as
103   // a use to prevent stack-pointer assignments that appear immediately
104   // before calls from potentially appearing dead. Uses for argument
105   // registers are added manually.
106   let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
107               FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
108               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
109               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
110               XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
111       Uses = [RSP] in {
112     def CALL64pcrel32 : I<0xE8, RawFrm, (outs), (ins i64imm:$dst, variable_ops),
113                           "call\t${dst:call}", []>;
114     def CALL64r       : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
115                           "call\t{*}$dst", [(X86call GR64:$dst)]>;
116     def CALL64m       : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
117                           "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
118   }
119
120
121
122 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
123 def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset, variable_ops),
124                  "#TC_RETURN $dst $offset",
125                  []>;
126
127 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
128 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset, variable_ops),
129                  "#TC_RETURN $dst $offset",
130                  []>;
131
132
133 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
134   def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst  # TAILCALL",
135                  []>;     
136
137 // Branches
138 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
139   def JMP64r     : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
140                      [(brind GR64:$dst)]>;
141   def JMP64m     : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
142                      [(brind (loadi64 addr:$dst))]>;
143 }
144
145 //===----------------------------------------------------------------------===//
146 // EH Pseudo Instructions
147 //
148 let isTerminator = 1, isReturn = 1, isBarrier = 1,
149     hasCtrlDep = 1 in {
150 def EH_RETURN64   : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
151                      "ret\t#eh_return, addr: $addr",
152                      [(X86ehret GR64:$addr)]>;
153
154 }
155
156 //===----------------------------------------------------------------------===//
157 //  Miscellaneous Instructions...
158 //
159 let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
160 def LEAVE64  : I<0xC9, RawFrm,
161                  (outs), (ins), "leave", []>;
162 let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
163 let mayLoad = 1 in
164 def POP64r   : I<0x58, AddRegFrm,
165                  (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
166 let mayStore = 1 in
167 def PUSH64r  : I<0x50, AddRegFrm,
168                  (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
169 }
170
171 let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
172 def POPFQ    : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
173 let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
174 def PUSHFQ   : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
175
176 def LEA64_32r : I<0x8D, MRMSrcMem,
177                   (outs GR32:$dst), (ins lea64_32mem:$src),
178                   "lea{l}\t{$src|$dst}, {$dst|$src}",
179                   [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
180
181 let isReMaterializable = 1 in
182 def LEA64r   : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
183                   "lea{q}\t{$src|$dst}, {$dst|$src}",
184                   [(set GR64:$dst, lea64addr:$src)]>;
185
186 let isTwoAddress = 1 in
187 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
188                   "bswap{q}\t$dst", 
189                   [(set GR64:$dst, (bswap GR64:$src))]>, TB;
190
191 // Bit scan instructions.
192 let Defs = [EFLAGS] in {
193 def BSF64rr  : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
194                   "bsf{q}\t{$src, $dst|$dst, $src}",
195                   [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
196 def BSF64rm  : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
197                   "bsf{q}\t{$src, $dst|$dst, $src}",
198                   [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
199                    (implicit EFLAGS)]>, TB;
200
201 def BSR64rr  : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
202                   "bsr{q}\t{$src, $dst|$dst, $src}",
203                   [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
204 def BSR64rm  : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
205                   "bsr{q}\t{$src, $dst|$dst, $src}",
206                   [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
207                    (implicit EFLAGS)]>, TB;
208 } // Defs = [EFLAGS]
209
210 // Repeat string ops
211 let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
212 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
213                    [(X86rep_movs i64)]>, REP;
214 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
215 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
216                    [(X86rep_stos i64)]>, REP;
217
218 //===----------------------------------------------------------------------===//
219 //  Move Instructions...
220 //
221
222 let neverHasSideEffects = 1 in
223 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
224                  "mov{q}\t{$src, $dst|$dst, $src}", []>;
225
226 let isReMaterializable = 1, isAsCheapAsAMove = 1  in {
227 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
228                     "movabs{q}\t{$src, $dst|$dst, $src}",
229                     [(set GR64:$dst, imm:$src)]>;
230 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
231                       "mov{q}\t{$src, $dst|$dst, $src}",
232                       [(set GR64:$dst, i64immSExt32:$src)]>;
233 }
234
235 let isSimpleLoad = 1 in
236 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
237                  "mov{q}\t{$src, $dst|$dst, $src}",
238                  [(set GR64:$dst, (load addr:$src))]>;
239
240 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
241                  "mov{q}\t{$src, $dst|$dst, $src}",
242                  [(store GR64:$src, addr:$dst)]>;
243 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
244                       "mov{q}\t{$src, $dst|$dst, $src}",
245                       [(store i64immSExt32:$src, addr:$dst)]>;
246
247 // Sign/Zero extenders
248
249 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
250                     "movs{bq|x}\t{$src, $dst|$dst, $src}",
251                     [(set GR64:$dst, (sext GR8:$src))]>, TB;
252 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
253                     "movs{bq|x}\t{$src, $dst|$dst, $src}",
254                     [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
255 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
256                     "movs{wq|x}\t{$src, $dst|$dst, $src}",
257                     [(set GR64:$dst, (sext GR16:$src))]>, TB;
258 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
259                     "movs{wq|x}\t{$src, $dst|$dst, $src}",
260                     [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
261 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
262                     "movs{lq|xd}\t{$src, $dst|$dst, $src}",
263                     [(set GR64:$dst, (sext GR32:$src))]>;
264 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
265                     "movs{lq|xd}\t{$src, $dst|$dst, $src}",
266                     [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
267
268 // Use movzbl instead of movzbq when the destination is a register; it's
269 // equivalent due to implicit zero-extending, and it has a smaller encoding.
270 def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
271                    "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
272                    [(set GR64:$dst, (zext GR8:$src))]>, TB;
273 def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
274                    "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
275                    [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
276 // Use movzwl instead of movzwq when the destination is a register; it's
277 // equivalent due to implicit zero-extending, and it has a smaller encoding.
278 def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
279                    "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
280                    [(set GR64:$dst, (zext GR16:$src))]>, TB;
281 def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
282                    "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
283                    [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
284
285 // There's no movzlq instruction, but movl can be used for this purpose, using
286 // implicit zero-extension. We need this because the seeming alternative for
287 // implementing zext from 32 to 64, an EXTRACT_SUBREG/SUBREG_TO_REG pair, isn't
288 // safe because both instructions could be optimized away in the
289 // register-to-register case, leaving nothing behind to do the zero extension.
290 def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
291                     "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
292                     [(set GR64:$dst, (zext GR32:$src))]>;
293 def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
294                     "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
295                     [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
296
297 let neverHasSideEffects = 1 in {
298   let Defs = [RAX], Uses = [EAX] in
299   def CDQE : RI<0x98, RawFrm, (outs), (ins),
300                "{cltq|cdqe}", []>;     // RAX = signext(EAX)
301
302   let Defs = [RAX,RDX], Uses = [RAX] in
303   def CQO  : RI<0x99, RawFrm, (outs), (ins),
304                 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
305 }
306
307 //===----------------------------------------------------------------------===//
308 //  Arithmetic Instructions...
309 //
310
311 let Defs = [EFLAGS] in {
312 let isTwoAddress = 1 in {
313 let isConvertibleToThreeAddress = 1 in {
314 let isCommutable = 1 in
315 def ADD64rr  : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
316                   "add{q}\t{$src2, $dst|$dst, $src2}",
317                   [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
318                    (implicit EFLAGS)]>;
319
320 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
321                       "add{q}\t{$src2, $dst|$dst, $src2}",
322                       [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
323                        (implicit EFLAGS)]>;
324 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
325                     "add{q}\t{$src2, $dst|$dst, $src2}",
326                     [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
327                      (implicit EFLAGS)]>;
328 } // isConvertibleToThreeAddress
329
330 def ADD64rm  : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
331                   "add{q}\t{$src2, $dst|$dst, $src2}",
332                   [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
333                    (implicit EFLAGS)]>;
334 } // isTwoAddress
335
336 def ADD64mr  : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
337                   "add{q}\t{$src2, $dst|$dst, $src2}",
338                   [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
339                    (implicit EFLAGS)]>;
340 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
341                       "add{q}\t{$src2, $dst|$dst, $src2}",
342                [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
343                 (implicit EFLAGS)]>;
344 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
345                     "add{q}\t{$src2, $dst|$dst, $src2}",
346                 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
347                  (implicit EFLAGS)]>;
348
349 let Uses = [EFLAGS] in {
350 let isTwoAddress = 1 in {
351 let isCommutable = 1 in
352 def ADC64rr  : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
353                   "adc{q}\t{$src2, $dst|$dst, $src2}",
354                   [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
355
356 def ADC64rm  : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
357                   "adc{q}\t{$src2, $dst|$dst, $src2}",
358                   [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
359
360 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
361                       "adc{q}\t{$src2, $dst|$dst, $src2}",
362                       [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
363 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
364                     "adc{q}\t{$src2, $dst|$dst, $src2}",
365                     [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
366 } // isTwoAddress
367
368 def ADC64mr  : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
369                   "adc{q}\t{$src2, $dst|$dst, $src2}",
370                   [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
371 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
372                       "adc{q}\t{$src2, $dst|$dst, $src2}",
373                  [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
374 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
375                     "adc{q}\t{$src2, $dst|$dst, $src2}",
376                  [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
377 } // Uses = [EFLAGS]
378
379 let isTwoAddress = 1 in {
380 def SUB64rr  : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
381                   "sub{q}\t{$src2, $dst|$dst, $src2}",
382                   [(set GR64:$dst, (sub GR64:$src1, GR64:$src2))]>;
383
384 def SUB64rm  : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
385                   "sub{q}\t{$src2, $dst|$dst, $src2}",
386                   [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2)))]>;
387
388 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
389                       "sub{q}\t{$src2, $dst|$dst, $src2}",
390                       [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2))]>;
391 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
392                     "sub{q}\t{$src2, $dst|$dst, $src2}",
393                     [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2))]>;
394 } // isTwoAddress
395
396 def SUB64mr  : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2), 
397                   "sub{q}\t{$src2, $dst|$dst, $src2}",
398                   [(store (sub (load addr:$dst), GR64:$src2), addr:$dst)]>;
399 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2), 
400                       "sub{q}\t{$src2, $dst|$dst, $src2}",
401                [(store (sub (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
402 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2), 
403                     "sub{q}\t{$src2, $dst|$dst, $src2}",
404                 [(store (sub (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
405
406 let Uses = [EFLAGS] in {
407 let isTwoAddress = 1 in {
408 def SBB64rr    : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
409                     "sbb{q}\t{$src2, $dst|$dst, $src2}",
410                     [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
411
412 def SBB64rm  : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
413                   "sbb{q}\t{$src2, $dst|$dst, $src2}",
414                   [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
415
416 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
417                       "sbb{q}\t{$src2, $dst|$dst, $src2}",
418                       [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
419 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
420                     "sbb{q}\t{$src2, $dst|$dst, $src2}",
421                     [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
422 } // isTwoAddress
423
424 def SBB64mr  : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2), 
425                   "sbb{q}\t{$src2, $dst|$dst, $src2}",
426                   [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
427 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2), 
428                       "sbb{q}\t{$src2, $dst|$dst, $src2}",
429               [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
430 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2), 
431                     "sbb{q}\t{$src2, $dst|$dst, $src2}",
432                [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
433 } // Uses = [EFLAGS]
434 } // Defs = [EFLAGS]
435
436 // Unsigned multiplication
437 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
438 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
439                 "mul{q}\t$src", []>;         // RAX,RDX = RAX*GR64
440 let mayLoad = 1 in
441 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
442                 "mul{q}\t$src", []>;         // RAX,RDX = RAX*[mem64]
443
444 // Signed multiplication
445 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
446                  "imul{q}\t$src", []>;         // RAX,RDX = RAX*GR64
447 let mayLoad = 1 in
448 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
449                  "imul{q}\t$src", []>;         // RAX,RDX = RAX*[mem64]
450 }
451
452 let Defs = [EFLAGS] in {
453 let isTwoAddress = 1 in {
454 let isCommutable = 1 in
455 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
456                   "imul{q}\t{$src2, $dst|$dst, $src2}",
457                   [(set GR64:$dst, (mul GR64:$src1, GR64:$src2))]>, TB;
458
459 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
460                   "imul{q}\t{$src2, $dst|$dst, $src2}",
461                  [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2)))]>, TB;
462 } // isTwoAddress
463
464 // Suprisingly enough, these are not two address instructions!
465 def IMUL64rri32 : RIi32<0x69, MRMSrcReg,                    // GR64 = GR64*I32
466                         (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
467                         "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
468                        [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2))]>;
469 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg,                      // GR64 = GR64*I8
470                       (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
471                       "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
472                       [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2))]>;
473 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem,                   // GR64 = [mem64]*I32
474                         (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
475                         "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
476                 [(set GR64:$dst, (mul (load addr:$src1), i64immSExt32:$src2))]>;
477 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem,                      // GR64 = [mem64]*I8
478                       (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
479                       "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
480                  [(set GR64:$dst, (mul (load addr:$src1), i64immSExt8:$src2))]>;
481 } // Defs = [EFLAGS]
482
483 // Unsigned division / remainder
484 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
485 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src),        // RDX:RAX/r64 = RAX,RDX
486                 "div{q}\t$src", []>;
487 // Signed division / remainder
488 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src),        // RDX:RAX/r64 = RAX,RDX
489                 "idiv{q}\t$src", []>;
490 let mayLoad = 1 in {
491 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src),      // RDX:RAX/[mem64] = RAX,RDX
492                 "div{q}\t$src", []>;
493 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src),      // RDX:RAX/[mem64] = RAX,RDX
494                 "idiv{q}\t$src", []>;
495 }
496 }
497
498 // Unary instructions
499 let Defs = [EFLAGS], CodeSize = 2 in {
500 let isTwoAddress = 1 in
501 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
502                 [(set GR64:$dst, (ineg GR64:$src))]>;
503 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
504                 [(store (ineg (loadi64 addr:$dst)), addr:$dst)]>;
505
506 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
507 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
508                 [(set GR64:$dst, (add GR64:$src, 1))]>;
509 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
510                 [(store (add (loadi64 addr:$dst), 1), addr:$dst)]>;
511
512 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
513 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
514                 [(set GR64:$dst, (add GR64:$src, -1))]>;
515 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
516                 [(store (add (loadi64 addr:$dst), -1), addr:$dst)]>;
517
518 // In 64-bit mode, single byte INC and DEC cannot be encoded.
519 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
520 // Can transform into LEA.
521 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
522                   [(set GR16:$dst, (add GR16:$src, 1))]>,
523                 OpSize, Requires<[In64BitMode]>;
524 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
525                   [(set GR32:$dst, (add GR32:$src, 1))]>,
526                 Requires<[In64BitMode]>;
527 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
528                   [(set GR16:$dst, (add GR16:$src, -1))]>,
529                 OpSize, Requires<[In64BitMode]>;
530 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
531                   [(set GR32:$dst, (add GR32:$src, -1))]>,
532                 Requires<[In64BitMode]>;
533 } // isConvertibleToThreeAddress
534
535 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
536 // how to unfold them.
537 let isTwoAddress = 0, CodeSize = 2 in {
538   def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
539                     [(store (add (loadi16 addr:$dst), 1), addr:$dst)]>,
540                   OpSize, Requires<[In64BitMode]>;
541   def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
542                     [(store (add (loadi32 addr:$dst), 1), addr:$dst)]>,
543                   Requires<[In64BitMode]>;
544   def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
545                     [(store (add (loadi16 addr:$dst), -1), addr:$dst)]>,
546                   OpSize, Requires<[In64BitMode]>;
547   def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
548                     [(store (add (loadi32 addr:$dst), -1), addr:$dst)]>,
549                   Requires<[In64BitMode]>;
550 }
551 } // Defs = [EFLAGS], CodeSize
552
553
554 let Defs = [EFLAGS] in {
555 // Shift instructions
556 let isTwoAddress = 1 in {
557 let Uses = [CL] in
558 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
559                   "shl{q}\t{%cl, $dst|$dst, %CL}",
560                   [(set GR64:$dst, (shl GR64:$src, CL))]>;
561 let isConvertibleToThreeAddress = 1 in   // Can transform into LEA.
562 def SHL64ri  : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
563                     "shl{q}\t{$src2, $dst|$dst, $src2}",
564                     [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
565 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
566 // cheaper.
567 } // isTwoAddress
568
569 let Uses = [CL] in
570 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
571                   "shl{q}\t{%cl, $dst|$dst, %CL}",
572                   [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
573 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
574                   "shl{q}\t{$src, $dst|$dst, $src}",
575                  [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
576 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
577                   "shl{q}\t$dst",
578                  [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
579
580 let isTwoAddress = 1 in {
581 let Uses = [CL] in
582 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
583                   "shr{q}\t{%cl, $dst|$dst, %CL}",
584                   [(set GR64:$dst, (srl GR64:$src, CL))]>;
585 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
586                   "shr{q}\t{$src2, $dst|$dst, $src2}",
587                   [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
588 def SHR64r1  : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
589                  "shr{q}\t$dst",
590                  [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
591 } // isTwoAddress
592
593 let Uses = [CL] in
594 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
595                   "shr{q}\t{%cl, $dst|$dst, %CL}",
596                   [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
597 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
598                   "shr{q}\t{$src, $dst|$dst, $src}",
599                  [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
600 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
601                   "shr{q}\t$dst",
602                  [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
603
604 let isTwoAddress = 1 in {
605 let Uses = [CL] in
606 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
607                  "sar{q}\t{%cl, $dst|$dst, %CL}",
608                  [(set GR64:$dst, (sra GR64:$src, CL))]>;
609 def SAR64ri  : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
610                    "sar{q}\t{$src2, $dst|$dst, $src2}",
611                    [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
612 def SAR64r1  : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
613                  "sar{q}\t$dst",
614                  [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
615 } // isTwoAddress
616
617 let Uses = [CL] in
618 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst), 
619                  "sar{q}\t{%cl, $dst|$dst, %CL}",
620                  [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
621 def SAR64mi  : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
622                     "sar{q}\t{$src, $dst|$dst, $src}",
623                  [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
624 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
625                   "sar{q}\t$dst",
626                  [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
627
628 // Rotate instructions
629 let isTwoAddress = 1 in {
630 let Uses = [CL] in
631 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
632                   "rol{q}\t{%cl, $dst|$dst, %CL}",
633                   [(set GR64:$dst, (rotl GR64:$src, CL))]>;
634 def ROL64ri  : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
635                     "rol{q}\t{$src2, $dst|$dst, $src2}",
636                     [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
637 def ROL64r1  : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
638                   "rol{q}\t$dst",
639                   [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
640 } // isTwoAddress
641
642 let Uses = [CL] in
643 def ROL64mCL :  I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
644                   "rol{q}\t{%cl, $dst|$dst, %CL}",
645                   [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
646 def ROL64mi  : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
647                     "rol{q}\t{$src, $dst|$dst, $src}",
648                 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
649 def ROL64m1  : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
650                  "rol{q}\t$dst",
651                [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
652
653 let isTwoAddress = 1 in {
654 let Uses = [CL] in
655 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
656                   "ror{q}\t{%cl, $dst|$dst, %CL}",
657                   [(set GR64:$dst, (rotr GR64:$src, CL))]>;
658 def ROR64ri  : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
659                     "ror{q}\t{$src2, $dst|$dst, $src2}",
660                     [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
661 def ROR64r1  : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
662                   "ror{q}\t$dst",
663                   [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
664 } // isTwoAddress
665
666 let Uses = [CL] in
667 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst), 
668                   "ror{q}\t{%cl, $dst|$dst, %CL}",
669                   [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
670 def ROR64mi  : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
671                     "ror{q}\t{$src, $dst|$dst, $src}",
672                 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
673 def ROR64m1  : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
674                  "ror{q}\t$dst",
675                [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
676
677 // Double shift instructions (generalizations of rotate)
678 let isTwoAddress = 1 in {
679 let Uses = [CL] in {
680 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
681                     "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
682                     [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
683 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
684                     "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
685                     [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
686 }
687
688 let isCommutable = 1 in {  // FIXME: Update X86InstrInfo::commuteInstruction
689 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
690                       (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
691                       "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
692                       [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
693                                        (i8 imm:$src3)))]>,
694                  TB;
695 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
696                       (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
697                       "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
698                       [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
699                                        (i8 imm:$src3)))]>,
700                  TB;
701 } // isCommutable
702 } // isTwoAddress
703
704 let Uses = [CL] in {
705 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
706                     "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
707                     [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
708                       addr:$dst)]>, TB;
709 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
710                     "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
711                     [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
712                       addr:$dst)]>, TB;
713 }
714 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
715                       (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
716                       "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
717                       [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
718                                        (i8 imm:$src3)), addr:$dst)]>,
719                  TB;
720 def SHRD64mri8 : RIi8<0xAC, MRMDestMem, 
721                       (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
722                       "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
723                       [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
724                                        (i8 imm:$src3)), addr:$dst)]>,
725                  TB;
726 } // Defs = [EFLAGS]
727
728 //===----------------------------------------------------------------------===//
729 //  Logical Instructions...
730 //
731
732 let isTwoAddress = 1 in
733 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
734                 [(set GR64:$dst, (not GR64:$src))]>;
735 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
736                 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
737
738 let Defs = [EFLAGS] in {
739 let isTwoAddress = 1 in {
740 let isCommutable = 1 in
741 def AND64rr  : RI<0x21, MRMDestReg, 
742                   (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
743                   "and{q}\t{$src2, $dst|$dst, $src2}",
744                   [(set GR64:$dst, (and GR64:$src1, GR64:$src2))]>;
745 def AND64rm  : RI<0x23, MRMSrcMem,
746                   (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
747                   "and{q}\t{$src2, $dst|$dst, $src2}",
748                   [(set GR64:$dst, (and GR64:$src1, (load addr:$src2)))]>;
749 def AND64ri32  : RIi32<0x81, MRM4r, 
750                        (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
751                        "and{q}\t{$src2, $dst|$dst, $src2}",
752                        [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2))]>;
753 def AND64ri8 : RIi8<0x83, MRM4r, 
754                     (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
755                     "and{q}\t{$src2, $dst|$dst, $src2}",
756                     [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2))]>;
757 } // isTwoAddress
758
759 def AND64mr  : RI<0x21, MRMDestMem,
760                   (outs), (ins i64mem:$dst, GR64:$src),
761                   "and{q}\t{$src, $dst|$dst, $src}",
762                   [(store (and (load addr:$dst), GR64:$src), addr:$dst)]>;
763 def AND64mi32  : RIi32<0x81, MRM4m,
764                        (outs), (ins i64mem:$dst, i64i32imm:$src),
765                        "and{q}\t{$src, $dst|$dst, $src}",
766              [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
767 def AND64mi8 : RIi8<0x83, MRM4m,
768                     (outs), (ins i64mem:$dst, i64i8imm :$src),
769                     "and{q}\t{$src, $dst|$dst, $src}",
770                  [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
771
772 let isTwoAddress = 1 in {
773 let isCommutable = 1 in
774 def OR64rr   : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
775                   "or{q}\t{$src2, $dst|$dst, $src2}",
776                   [(set GR64:$dst, (or GR64:$src1, GR64:$src2))]>;
777 def OR64rm   : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
778                   "or{q}\t{$src2, $dst|$dst, $src2}",
779                   [(set GR64:$dst, (or GR64:$src1, (load addr:$src2)))]>;
780 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
781                      "or{q}\t{$src2, $dst|$dst, $src2}",
782                      [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2))]>;
783 def OR64ri8  : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
784                     "or{q}\t{$src2, $dst|$dst, $src2}",
785                     [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2))]>;
786 } // isTwoAddress
787
788 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
789                 "or{q}\t{$src, $dst|$dst, $src}",
790                 [(store (or (load addr:$dst), GR64:$src), addr:$dst)]>;
791 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
792                      "or{q}\t{$src, $dst|$dst, $src}",
793               [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
794 def OR64mi8  : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
795                     "or{q}\t{$src, $dst|$dst, $src}",
796                   [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
797
798 let isTwoAddress = 1 in {
799 let isCommutable = 1 in
800 def XOR64rr  : RI<0x31, MRMDestReg,  (outs GR64:$dst), (ins GR64:$src1, GR64:$src2), 
801                   "xor{q}\t{$src2, $dst|$dst, $src2}",
802                   [(set GR64:$dst, (xor GR64:$src1, GR64:$src2))]>;
803 def XOR64rm  : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2), 
804                   "xor{q}\t{$src2, $dst|$dst, $src2}",
805                   [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2)))]>;
806 def XOR64ri32 : RIi32<0x81, MRM6r, 
807                       (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2), 
808                       "xor{q}\t{$src2, $dst|$dst, $src2}",
809                       [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2))]>;
810 def XOR64ri8 : RIi8<0x83, MRM6r,  (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
811                     "xor{q}\t{$src2, $dst|$dst, $src2}",
812                     [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2))]>;
813 } // isTwoAddress
814
815 def XOR64mr  : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
816                   "xor{q}\t{$src, $dst|$dst, $src}",
817                   [(store (xor (load addr:$dst), GR64:$src), addr:$dst)]>;
818 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
819                       "xor{q}\t{$src, $dst|$dst, $src}",
820              [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
821 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
822                     "xor{q}\t{$src, $dst|$dst, $src}",
823                  [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
824 } // Defs = [EFLAGS]
825
826 //===----------------------------------------------------------------------===//
827 //  Comparison Instructions...
828 //
829
830 // Integer comparison
831 let Defs = [EFLAGS] in {
832 let isCommutable = 1 in
833 def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
834                   "test{q}\t{$src2, $src1|$src1, $src2}",
835                   [(X86cmp (and GR64:$src1, GR64:$src2), 0),
836                    (implicit EFLAGS)]>;
837 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
838                   "test{q}\t{$src2, $src1|$src1, $src2}",
839                   [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
840                    (implicit EFLAGS)]>;
841 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
842                                         (ins GR64:$src1, i64i32imm:$src2),
843                        "test{q}\t{$src2, $src1|$src1, $src2}",
844                      [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
845                       (implicit EFLAGS)]>;
846 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
847                                         (ins i64mem:$src1, i64i32imm:$src2),
848                        "test{q}\t{$src2, $src1|$src1, $src2}",
849                 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
850                  (implicit EFLAGS)]>;
851
852 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
853                  "cmp{q}\t{$src2, $src1|$src1, $src2}",
854                  [(X86cmp GR64:$src1, GR64:$src2),
855                   (implicit EFLAGS)]>;
856 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
857                  "cmp{q}\t{$src2, $src1|$src1, $src2}",
858                  [(X86cmp (loadi64 addr:$src1), GR64:$src2),
859                    (implicit EFLAGS)]>;
860 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
861                  "cmp{q}\t{$src2, $src1|$src1, $src2}",
862                  [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
863                   (implicit EFLAGS)]>;
864 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
865                       "cmp{q}\t{$src2, $src1|$src1, $src2}",
866                       [(X86cmp GR64:$src1, i64immSExt32:$src2),
867                        (implicit EFLAGS)]>;
868 def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
869                                        (ins i64mem:$src1, i64i32imm:$src2),
870                       "cmp{q}\t{$src2, $src1|$src1, $src2}",
871                       [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
872                        (implicit EFLAGS)]>;
873 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
874                     "cmp{q}\t{$src2, $src1|$src1, $src2}",
875                     [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
876                      (implicit EFLAGS)]>;
877 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
878                     "cmp{q}\t{$src2, $src1|$src1, $src2}",
879                     [(X86cmp GR64:$src1, i64immSExt8:$src2),
880                      (implicit EFLAGS)]>;
881 } // Defs = [EFLAGS]
882
883 // Conditional moves
884 let Uses = [EFLAGS], isTwoAddress = 1 in {
885 let isCommutable = 1 in {
886 def CMOVB64rr : RI<0x42, MRMSrcReg,       // if <u, GR64 = GR64
887                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
888                    "cmovb\t{$src2, $dst|$dst, $src2}",
889                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
890                                      X86_COND_B, EFLAGS))]>, TB;
891 def CMOVAE64rr: RI<0x43, MRMSrcReg,       // if >=u, GR64 = GR64
892                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
893                    "cmovae\t{$src2, $dst|$dst, $src2}",
894                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
895                                      X86_COND_AE, EFLAGS))]>, TB;
896 def CMOVE64rr : RI<0x44, MRMSrcReg,       // if ==, GR64 = GR64
897                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
898                    "cmove\t{$src2, $dst|$dst, $src2}",
899                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
900                                      X86_COND_E, EFLAGS))]>, TB;
901 def CMOVNE64rr: RI<0x45, MRMSrcReg,       // if !=, GR64 = GR64
902                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
903                    "cmovne\t{$src2, $dst|$dst, $src2}",
904                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
905                                     X86_COND_NE, EFLAGS))]>, TB;
906 def CMOVBE64rr: RI<0x46, MRMSrcReg,       // if <=u, GR64 = GR64
907                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
908                    "cmovbe\t{$src2, $dst|$dst, $src2}",
909                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
910                                     X86_COND_BE, EFLAGS))]>, TB;
911 def CMOVA64rr : RI<0x47, MRMSrcReg,       // if >u, GR64 = GR64
912                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
913                    "cmova\t{$src2, $dst|$dst, $src2}",
914                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
915                                     X86_COND_A, EFLAGS))]>, TB;
916 def CMOVL64rr : RI<0x4C, MRMSrcReg,       // if <s, GR64 = GR64
917                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
918                    "cmovl\t{$src2, $dst|$dst, $src2}",
919                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
920                                     X86_COND_L, EFLAGS))]>, TB;
921 def CMOVGE64rr: RI<0x4D, MRMSrcReg,       // if >=s, GR64 = GR64
922                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
923                    "cmovge\t{$src2, $dst|$dst, $src2}",
924                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
925                                     X86_COND_GE, EFLAGS))]>, TB;
926 def CMOVLE64rr: RI<0x4E, MRMSrcReg,       // if <=s, GR64 = GR64
927                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
928                    "cmovle\t{$src2, $dst|$dst, $src2}",
929                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
930                                     X86_COND_LE, EFLAGS))]>, TB;
931 def CMOVG64rr : RI<0x4F, MRMSrcReg,       // if >s, GR64 = GR64
932                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
933                    "cmovg\t{$src2, $dst|$dst, $src2}",
934                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
935                                     X86_COND_G, EFLAGS))]>, TB;
936 def CMOVS64rr : RI<0x48, MRMSrcReg,       // if signed, GR64 = GR64
937                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
938                    "cmovs\t{$src2, $dst|$dst, $src2}",
939                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
940                                     X86_COND_S, EFLAGS))]>, TB;
941 def CMOVNS64rr: RI<0x49, MRMSrcReg,       // if !signed, GR64 = GR64
942                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
943                    "cmovns\t{$src2, $dst|$dst, $src2}",
944                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
945                                     X86_COND_NS, EFLAGS))]>, TB;
946 def CMOVP64rr : RI<0x4A, MRMSrcReg,       // if parity, GR64 = GR64
947                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
948                    "cmovp\t{$src2, $dst|$dst, $src2}",
949                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
950                                     X86_COND_P, EFLAGS))]>, TB;
951 def CMOVNP64rr : RI<0x4B, MRMSrcReg,       // if !parity, GR64 = GR64
952                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
953                    "cmovnp\t{$src2, $dst|$dst, $src2}",
954                     [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
955                                      X86_COND_NP, EFLAGS))]>, TB;
956 } // isCommutable = 1
957
958 def CMOVB64rm : RI<0x42, MRMSrcMem,       // if <u, GR64 = [mem64]
959                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
960                    "cmovb\t{$src2, $dst|$dst, $src2}",
961                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
962                                      X86_COND_B, EFLAGS))]>, TB;
963 def CMOVAE64rm: RI<0x43, MRMSrcMem,       // if >=u, GR64 = [mem64]
964                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
965                    "cmovae\t{$src2, $dst|$dst, $src2}",
966                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
967                                      X86_COND_AE, EFLAGS))]>, TB;
968 def CMOVE64rm : RI<0x44, MRMSrcMem,       // if ==, GR64 = [mem64]
969                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
970                    "cmove\t{$src2, $dst|$dst, $src2}",
971                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
972                                      X86_COND_E, EFLAGS))]>, TB;
973 def CMOVNE64rm: RI<0x45, MRMSrcMem,       // if !=, GR64 = [mem64]
974                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
975                    "cmovne\t{$src2, $dst|$dst, $src2}",
976                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
977                                     X86_COND_NE, EFLAGS))]>, TB;
978 def CMOVBE64rm: RI<0x46, MRMSrcMem,       // if <=u, GR64 = [mem64]
979                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
980                    "cmovbe\t{$src2, $dst|$dst, $src2}",
981                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
982                                     X86_COND_BE, EFLAGS))]>, TB;
983 def CMOVA64rm : RI<0x47, MRMSrcMem,       // if >u, GR64 = [mem64]
984                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
985                    "cmova\t{$src2, $dst|$dst, $src2}",
986                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
987                                     X86_COND_A, EFLAGS))]>, TB;
988 def CMOVL64rm : RI<0x4C, MRMSrcMem,       // if <s, GR64 = [mem64]
989                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
990                    "cmovl\t{$src2, $dst|$dst, $src2}",
991                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
992                                     X86_COND_L, EFLAGS))]>, TB;
993 def CMOVGE64rm: RI<0x4D, MRMSrcMem,       // if >=s, GR64 = [mem64]
994                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
995                    "cmovge\t{$src2, $dst|$dst, $src2}",
996                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
997                                     X86_COND_GE, EFLAGS))]>, TB;
998 def CMOVLE64rm: RI<0x4E, MRMSrcMem,       // if <=s, GR64 = [mem64]
999                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1000                    "cmovle\t{$src2, $dst|$dst, $src2}",
1001                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1002                                     X86_COND_LE, EFLAGS))]>, TB;
1003 def CMOVG64rm : RI<0x4F, MRMSrcMem,       // if >s, GR64 = [mem64]
1004                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1005                    "cmovg\t{$src2, $dst|$dst, $src2}",
1006                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1007                                     X86_COND_G, EFLAGS))]>, TB;
1008 def CMOVS64rm : RI<0x48, MRMSrcMem,       // if signed, GR64 = [mem64]
1009                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1010                    "cmovs\t{$src2, $dst|$dst, $src2}",
1011                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1012                                     X86_COND_S, EFLAGS))]>, TB;
1013 def CMOVNS64rm: RI<0x49, MRMSrcMem,       // if !signed, GR64 = [mem64]
1014                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1015                    "cmovns\t{$src2, $dst|$dst, $src2}",
1016                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1017                                     X86_COND_NS, EFLAGS))]>, TB;
1018 def CMOVP64rm : RI<0x4A, MRMSrcMem,       // if parity, GR64 = [mem64]
1019                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1020                    "cmovp\t{$src2, $dst|$dst, $src2}",
1021                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1022                                     X86_COND_P, EFLAGS))]>, TB;
1023 def CMOVNP64rm : RI<0x4B, MRMSrcMem,       // if !parity, GR64 = [mem64]
1024                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1025                    "cmovnp\t{$src2, $dst|$dst, $src2}",
1026                     [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1027                                      X86_COND_NP, EFLAGS))]>, TB;
1028 } // isTwoAddress
1029
1030 //===----------------------------------------------------------------------===//
1031 //  Conversion Instructions...
1032 //
1033
1034 // f64 -> signed i64
1035 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1036                            "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1037                            [(set GR64:$dst,
1038                              (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1039 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1040                            "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1041                            [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1042                                              (load addr:$src)))]>;
1043 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1044                         "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1045                         [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1046 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1047                         "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1048                         [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1049 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1050                             "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1051                             [(set GR64:$dst,
1052                               (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1053 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1054                             "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1055                             [(set GR64:$dst,
1056                               (int_x86_sse2_cvttsd2si64
1057                                (load addr:$src)))]>;
1058
1059 // Signed i64 -> f64
1060 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1061                        "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1062                        [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1063 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1064                        "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1065                        [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1066
1067 let isTwoAddress = 1 in {
1068 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1069                            (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1070                            "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1071                            [(set VR128:$dst,
1072                              (int_x86_sse2_cvtsi642sd VR128:$src1,
1073                               GR64:$src2))]>;
1074 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1075                            (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1076                            "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1077                            [(set VR128:$dst,
1078                              (int_x86_sse2_cvtsi642sd VR128:$src1,
1079                               (loadi64 addr:$src2)))]>;
1080 } // isTwoAddress
1081
1082 // Signed i64 -> f32
1083 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1084                        "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1085                        [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1086 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1087                        "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1088                        [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1089
1090 let isTwoAddress = 1 in {
1091   def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1092                               (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1093                               "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1094                               [(set VR128:$dst,
1095                                 (int_x86_sse_cvtsi642ss VR128:$src1,
1096                                  GR64:$src2))]>;
1097   def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1098                               (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1099                               "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1100                               [(set VR128:$dst,
1101                                 (int_x86_sse_cvtsi642ss VR128:$src1,
1102                                  (loadi64 addr:$src2)))]>;
1103 }
1104
1105 // f32 -> signed i64
1106 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1107                            "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1108                            [(set GR64:$dst,
1109                              (int_x86_sse_cvtss2si64 VR128:$src))]>;
1110 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1111                            "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1112                            [(set GR64:$dst, (int_x86_sse_cvtss2si64
1113                                              (load addr:$src)))]>;
1114 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1115                         "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1116                         [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1117 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1118                         "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1119                         [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1120 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1121                             "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1122                             [(set GR64:$dst,
1123                               (int_x86_sse_cvttss2si64 VR128:$src))]>;
1124 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1125                             "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1126                             [(set GR64:$dst,
1127                               (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1128
1129 //===----------------------------------------------------------------------===//
1130 // Alias Instructions
1131 //===----------------------------------------------------------------------===//
1132
1133 // Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1134 // equivalent due to implicit zero-extending, and it sometimes has a smaller
1135 // encoding.
1136 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1137 // FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1138 // when we have a better way to specify isel priority.
1139 let Defs = [EFLAGS], AddedComplexity = 1,
1140     isReMaterializable = 1, isAsCheapAsAMove = 1 in
1141 def MOV64r0  : I<0x31, MRMInitReg,  (outs GR64:$dst), (ins),
1142                 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1143                 [(set GR64:$dst, 0)]>;
1144
1145 // Materialize i64 constant where top 32-bits are zero.
1146 let AddedComplexity = 1, isReMaterializable = 1 in
1147 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1148                         "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1149                         [(set GR64:$dst, i64immZExt32:$src)]>;
1150
1151 //===----------------------------------------------------------------------===//
1152 // Thread Local Storage Instructions
1153 //===----------------------------------------------------------------------===//
1154
1155 def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
1156               ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
1157                   [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
1158
1159 //===----------------------------------------------------------------------===//
1160 // Atomic Instructions
1161 //===----------------------------------------------------------------------===//
1162
1163 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1164 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1165                "lock\n\tcmpxchgq\t$swap,$ptr",
1166                [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1167 }
1168
1169 let Constraints = "$val = $dst" in {
1170 let Defs = [EFLAGS] in
1171 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1172                "lock\n\txadd\t$val, $ptr", 
1173                [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1174                 TB, LOCK;
1175 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1176                   "xchg\t$val, $ptr", 
1177                   [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1178 }
1179
1180 // Atomic exchange, and, or, xor
1181 let Constraints = "$val = $dst", Defs = [EFLAGS],
1182                   usesCustomDAGSchedInserter = 1 in {
1183 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1184                "#ATOMAND64 PSUEDO!", 
1185                [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1186 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1187                "#ATOMOR64 PSUEDO!", 
1188                [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1189 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1190                "#ATOMXOR64 PSUEDO!", 
1191                [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1192 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1193                "#ATOMNAND64 PSUEDO!", 
1194                [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1195 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1196                "#ATOMMIN64 PSUEDO!", 
1197                [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1198 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1199                "#ATOMMAX64 PSUEDO!", 
1200                [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1201 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1202                "#ATOMUMIN64 PSUEDO!", 
1203                [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1204 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1205                "#ATOMUMAX64 PSUEDO!", 
1206                [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1207 }
1208
1209 //===----------------------------------------------------------------------===//
1210 // Non-Instruction Patterns
1211 //===----------------------------------------------------------------------===//
1212
1213 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
1214 def : Pat<(i64 (X86Wrapper tconstpool  :$dst)),
1215           (MOV64ri tconstpool  :$dst)>, Requires<[NotSmallCode]>;
1216 def : Pat<(i64 (X86Wrapper tjumptable  :$dst)),
1217           (MOV64ri tjumptable  :$dst)>, Requires<[NotSmallCode]>;
1218 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1219           (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1220 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1221           (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1222
1223 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1224           (MOV64mi32 addr:$dst, tconstpool:$src)>,
1225           Requires<[SmallCode, IsStatic]>;
1226 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1227           (MOV64mi32 addr:$dst, tjumptable:$src)>,
1228           Requires<[SmallCode, IsStatic]>;
1229 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1230           (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1231           Requires<[SmallCode, IsStatic]>;
1232 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1233           (MOV64mi32 addr:$dst, texternalsym:$src)>,
1234           Requires<[SmallCode, IsStatic]>;
1235
1236 // Calls
1237 // Direct PC relative function call for small code model. 32-bit displacement
1238 // sign extended to 64-bit.
1239 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1240           (CALL64pcrel32 tglobaladdr:$dst)>;
1241 def : Pat<(X86call (i64 texternalsym:$dst)),
1242           (CALL64pcrel32 texternalsym:$dst)>;
1243
1244 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1245           (CALL64pcrel32 tglobaladdr:$dst)>;
1246 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1247           (CALL64pcrel32 texternalsym:$dst)>;
1248
1249 def : Pat<(X86tailcall GR64:$dst),
1250           (CALL64r GR64:$dst)>;
1251
1252
1253 // tailcall stuff
1254 def : Pat<(X86tailcall GR32:$dst),
1255           (TAILCALL)>;
1256 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1257           (TAILCALL)>;
1258 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1259           (TAILCALL)>;
1260
1261 def : Pat<(X86tcret GR64:$dst, imm:$off),
1262           (TCRETURNri64 GR64:$dst, imm:$off)>;
1263
1264 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1265           (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1266
1267 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1268           (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1269
1270 // Comparisons.
1271
1272 // TEST R,R is smaller than CMP R,0
1273 def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
1274           (TEST64rr GR64:$src1, GR64:$src1)>;
1275
1276
1277
1278 // Zero-extension
1279 def : Pat<(i64 (zext GR32:$src)), 
1280           (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
1281
1282 // zextload bool -> zextload byte
1283 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1284
1285 // extload
1286 // When extloading from 16-bit and smaller memory locations into 64-bit registers,
1287 // use zero-extending loads so that the entire 64-bit register is defined, avoiding
1288 // partial-register updates.
1289 def : Pat<(extloadi64i1 addr:$src),  (MOVZX64rm8  addr:$src)>;
1290 def : Pat<(extloadi64i8 addr:$src),  (MOVZX64rm8  addr:$src)>;
1291 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1292 // For other extloads, use subregs, since the high contents of the register are
1293 // defined after an extload.
1294 def : Pat<(extloadi64i32 addr:$src),
1295           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1296                          x86_subreg_32bit)>;
1297 def : Pat<(extloadi16i1 addr:$src), 
1298           (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src), 
1299                          x86_subreg_8bit)>,
1300          Requires<[In64BitMode]>;
1301 def : Pat<(extloadi16i8 addr:$src), 
1302           (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src), 
1303                          x86_subreg_8bit)>,
1304          Requires<[In64BitMode]>;
1305
1306 // anyext
1307 def : Pat<(i64 (anyext GR8:$src)),
1308           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1309 def : Pat<(i64 (anyext GR16:$src)),
1310           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
1311 def : Pat<(i64 (anyext GR32:$src)), 
1312           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
1313 def : Pat<(i16 (anyext GR8:$src)),
1314           (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1315          Requires<[In64BitMode]>;
1316 def : Pat<(i32 (anyext GR8:$src)),
1317           (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1318          Requires<[In64BitMode]>;
1319
1320 //===----------------------------------------------------------------------===//
1321 // Some peepholes
1322 //===----------------------------------------------------------------------===//
1323
1324 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1325 // +128 doesn't, so in this special case use a sub instead of an add.
1326 def : Pat<(add GR64:$src1, 128),
1327           (SUB64ri8 GR64:$src1, -128)>;
1328 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1329           (SUB64mi8 addr:$dst, -128)>;
1330
1331 // The same trick applies for 32-bit immediate fields in 64-bit
1332 // instructions.
1333 def : Pat<(add GR64:$src1, 0x0000000080000000),
1334           (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1335 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1336           (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1337
1338 // r & (2^32-1) ==> movz
1339 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1340           (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1341 // r & (2^16-1) ==> movz
1342 def : Pat<(and GR64:$src, 0xffff),
1343           (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1344 // r & (2^8-1) ==> movz
1345 def : Pat<(and GR64:$src, 0xff),
1346           (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1347 // r & (2^8-1) ==> movz
1348 def : Pat<(and GR32:$src1, 0xff),
1349            (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1350       Requires<[In64BitMode]>;
1351 // r & (2^8-1) ==> movz
1352 def : Pat<(and GR16:$src1, 0xff),
1353            (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1354       Requires<[In64BitMode]>;
1355
1356 // sext_inreg patterns
1357 def : Pat<(sext_inreg GR64:$src, i32),
1358           (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1359 def : Pat<(sext_inreg GR64:$src, i16),
1360           (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1361 def : Pat<(sext_inreg GR64:$src, i8),
1362           (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1363 def : Pat<(sext_inreg GR32:$src, i8),
1364           (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1365       Requires<[In64BitMode]>;
1366 def : Pat<(sext_inreg GR16:$src, i8),
1367           (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1368       Requires<[In64BitMode]>;
1369
1370 // trunc patterns
1371 def : Pat<(i32 (trunc GR64:$src)),
1372           (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1373 def : Pat<(i16 (trunc GR64:$src)),
1374           (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1375 def : Pat<(i8 (trunc GR64:$src)),
1376           (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1377 def : Pat<(i8 (trunc GR32:$src)),
1378           (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1379       Requires<[In64BitMode]>;
1380 def : Pat<(i8 (trunc GR16:$src)),
1381           (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1382       Requires<[In64BitMode]>;
1383
1384 // (shl x, 1) ==> (add x, x)
1385 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1386
1387 // (shl x (and y, 63)) ==> (shl x, y)
1388 def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1389           (SHL64rCL GR64:$src1)>;
1390 def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1391           (SHL64mCL addr:$dst)>;
1392
1393 def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1394           (SHR64rCL GR64:$src1)>;
1395 def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1396           (SHR64mCL addr:$dst)>;
1397
1398 def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1399           (SAR64rCL GR64:$src1)>;
1400 def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1401           (SAR64mCL addr:$dst)>;
1402
1403 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1404 def : Pat<(or (srl GR64:$src1, CL:$amt),
1405               (shl GR64:$src2, (sub 64, CL:$amt))),
1406           (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1407
1408 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1409                      (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1410           (SHRD64mrCL addr:$dst, GR64:$src2)>;
1411
1412 def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1413               (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1414           (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1415
1416 def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1417                      (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1418                  addr:$dst),
1419           (SHRD64mrCL addr:$dst, GR64:$src2)>;
1420
1421 def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1422           (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1423
1424 def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1425                        GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1426           (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1427
1428 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1429 def : Pat<(or (shl GR64:$src1, CL:$amt),
1430               (srl GR64:$src2, (sub 64, CL:$amt))),
1431           (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1432
1433 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1434                      (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1435           (SHLD64mrCL addr:$dst, GR64:$src2)>;
1436
1437 def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1438               (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1439           (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1440
1441 def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1442                      (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1443                  addr:$dst),
1444           (SHLD64mrCL addr:$dst, GR64:$src2)>;
1445
1446 def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1447           (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1448
1449 def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1450                        GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1451           (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1452
1453 // X86 specific add which produces a flag.
1454 def : Pat<(addc GR64:$src1, GR64:$src2),
1455           (ADD64rr GR64:$src1, GR64:$src2)>;
1456 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1457           (ADD64rm GR64:$src1, addr:$src2)>;
1458 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1459           (ADD64ri32 GR64:$src1, imm:$src2)>;
1460 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1461           (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1462
1463 def : Pat<(subc GR64:$src1, GR64:$src2),
1464           (SUB64rr GR64:$src1, GR64:$src2)>;
1465 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1466           (SUB64rm GR64:$src1, addr:$src2)>;
1467 def : Pat<(subc GR64:$src1, imm:$src2),
1468           (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1469 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1470           (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1471
1472
1473 //===----------------------------------------------------------------------===//
1474 // X86-64 SSE Instructions
1475 //===----------------------------------------------------------------------===//
1476
1477 // Move instructions...
1478
1479 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
1480                         "mov{d|q}\t{$src, $dst|$dst, $src}",
1481                         [(set VR128:$dst,
1482                           (v2i64 (scalar_to_vector GR64:$src)))]>;
1483 def MOVPQIto64rr  : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
1484                          "mov{d|q}\t{$src, $dst|$dst, $src}",
1485                          [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1486                                            (iPTR 0)))]>;
1487
1488 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1489                        "mov{d|q}\t{$src, $dst|$dst, $src}",
1490                        [(set FR64:$dst, (bitconvert GR64:$src))]>;
1491 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1492                        "movq\t{$src, $dst|$dst, $src}",
1493                        [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1494
1495 def MOVSDto64rr  : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
1496                         "mov{d|q}\t{$src, $dst|$dst, $src}",
1497                         [(set GR64:$dst, (bitconvert FR64:$src))]>;
1498 def MOVSDto64mr  : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
1499                         "movq\t{$src, $dst|$dst, $src}",
1500                         [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
1501
1502 //===----------------------------------------------------------------------===//
1503 // X86-64 SSE4.1 Instructions
1504 //===----------------------------------------------------------------------===//
1505
1506 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1507 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
1508   def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
1509                  (ins VR128:$src1, i32i8imm:$src2),
1510                  !strconcat(OpcodeStr, 
1511                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1512                  [(set GR64:$dst,
1513                   (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
1514   def mr : SS4AIi8<opc, MRMDestMem, (outs),
1515                  (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1516                  !strconcat(OpcodeStr, 
1517                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1518                  [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1519                           addr:$dst)]>, OpSize, REX_W;
1520 }
1521
1522 defm PEXTRQ      : SS41I_extract64<0x16, "pextrq">;
1523
1524 let isTwoAddress = 1 in {
1525   multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
1526     def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
1527                    (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1528                    !strconcat(OpcodeStr, 
1529                     "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1530                    [(set VR128:$dst, 
1531                      (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1532                    OpSize, REX_W;
1533     def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
1534                    (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1535                    !strconcat(OpcodeStr,
1536                     "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1537                    [(set VR128:$dst, 
1538                      (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1539                                        imm:$src3)))]>, OpSize, REX_W;
1540   }
1541 }
1542
1543 defm PINSRQ      : SS41I_insert64<0x22, "pinsrq">;