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