Redo and generalize previously removed opt for pinsrw: (vextract (v4i32 bc (v4f32...
[oota-llvm.git] / lib / Target / X86 / X86InstrX86-64.td
1 //====- X86InstrX86-64.td - Describe the X86 Instruction Set ----*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the Evan Cheng and is distributed under
6 // the University of Illinois Open Source 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->getValue() == (int32_t)N->getValue();
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->getValue() == (uint32_t)N->getValue();
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->getValue() == (int8_t)N->getValue();
62 }]>;
63
64 def sextloadi64i1  : PatFrag<(ops node:$ptr), (i64 (sextloadi1 node:$ptr))>;
65 def sextloadi64i8  : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
66 def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
67 def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
68
69 def zextloadi64i1  : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
70 def zextloadi64i8  : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
71 def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
72 def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
73
74 def extloadi64i1   : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
75 def extloadi64i8   : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
76 def extloadi64i16  : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
77 def extloadi64i32  : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
78
79 //===----------------------------------------------------------------------===//
80 // Instruction list...
81 //
82
83 def IMPLICIT_DEF_GR64  : I<0, Pseudo, (outs GR64:$dst), (ins),
84                          "#IMPLICIT_DEF $dst",
85                          [(set GR64:$dst, (undef))]>;
86
87 //===----------------------------------------------------------------------===//
88 //  Call Instructions...
89 //
90 let isCall = 1 in
91   // All calls clobber the non-callee saved registers...
92   let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
93               FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
94               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
95               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
96               XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15] in {
97     def CALL64pcrel32 : I<0xE8, RawFrm, (outs), (ins i64imm:$dst, variable_ops),
98                           "call ${dst:call}", []>;
99     def CALL64r       : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
100                           "call {*}$dst", [(X86call GR64:$dst)]>;
101     def CALL64m       : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
102                           "call {*}$dst", []>;
103   }
104
105 // Branches
106 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
107   def JMP64r     : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q} {*}$dst",
108                      [(brind GR64:$dst)]>;
109   def JMP64m     : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q} {*}$dst",
110                      [(brind (loadi64 addr:$dst))]>;
111 }
112
113 //===----------------------------------------------------------------------===//
114 //  Miscellaneous Instructions...
115 //
116 def LEAVE64  : I<0xC9, RawFrm,
117                  (outs), (ins), "leave", []>, Imp<[RBP,RSP],[RBP,RSP]>;
118 def POP64r   : I<0x58, AddRegFrm,
119                  (outs GR64:$reg), (ins), "pop{q} $reg", []>, Imp<[RSP],[RSP]>;
120 def PUSH64r  : I<0x50, AddRegFrm,
121                  (outs), (ins GR64:$reg), "push{q} $reg", []>, Imp<[RSP],[RSP]>;
122
123 def LEA64_32r : I<0x8D, MRMSrcMem,
124                   (outs GR32:$dst), (ins lea64_32mem:$src),
125                   "lea{l} {$src|$dst}, {$dst|$src}",
126                   [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
127
128 def LEA64r   : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
129                   "lea{q} {$src|$dst}, {$dst|$src}",
130                   [(set GR64:$dst, lea64addr:$src)]>;
131
132 let isTwoAddress = 1 in
133 def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
134                   "bswap{q} $dst", 
135                   [(set GR64:$dst, (bswap GR64:$src))]>, TB;
136 // Exchange
137 def XCHG64rr : RI<0x87, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
138                   "xchg{q} {$src2|$src1}, {$src1|$src2}", []>;
139 def XCHG64mr : RI<0x87, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
140                   "xchg{q} {$src2|$src1}, {$src1|$src2}", []>;
141 def XCHG64rm : RI<0x87, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
142                   "xchg{q} {$src2|$src1}, {$src1|$src2}", []>;
143
144 // Repeat string ops
145 def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
146                    [(X86rep_movs i64)]>,
147                 Imp<[RCX,RDI,RSI], [RCX,RDI,RSI]>, REP;
148 def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
149                    [(X86rep_stos i64)]>,
150                 Imp<[RAX,RCX,RDI], [RCX,RDI]>, REP;
151
152 //===----------------------------------------------------------------------===//
153 //  Move Instructions...
154 //
155
156 def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
157                  "mov{q} {$src, $dst|$dst, $src}", []>;
158
159 def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
160                     "movabs{q} {$src, $dst|$dst, $src}",
161                     [(set GR64:$dst, imm:$src)]>;
162 def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
163                       "mov{q} {$src, $dst|$dst, $src}",
164                       [(set GR64:$dst, i64immSExt32:$src)]>;
165
166 def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
167                  "mov{q} {$src, $dst|$dst, $src}",
168                  [(set GR64:$dst, (load addr:$src))]>;
169
170 def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
171                  "mov{q} {$src, $dst|$dst, $src}",
172                  [(store GR64:$src, addr:$dst)]>;
173 def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
174                       "mov{q} {$src, $dst|$dst, $src}",
175                       [(store i64immSExt32:$src, addr:$dst)]>;
176
177 // Sign/Zero extenders
178
179 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
180                     "movs{bq|x} {$src, $dst|$dst, $src}",
181                     [(set GR64:$dst, (sext GR8:$src))]>, TB;
182 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
183                     "movs{bq|x} {$src, $dst|$dst, $src}",
184                     [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
185 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
186                     "movs{wq|x} {$src, $dst|$dst, $src}",
187                     [(set GR64:$dst, (sext GR16:$src))]>, TB;
188 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
189                     "movs{wq|x} {$src, $dst|$dst, $src}",
190                     [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
191 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
192                     "movs{lq|xd} {$src, $dst|$dst, $src}",
193                     [(set GR64:$dst, (sext GR32:$src))]>;
194 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
195                     "movs{lq|xd} {$src, $dst|$dst, $src}",
196                     [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
197
198 def MOVZX64rr8 : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
199                     "movz{bq|x} {$src, $dst|$dst, $src}",
200                     [(set GR64:$dst, (zext GR8:$src))]>, TB;
201 def MOVZX64rm8 : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
202                     "movz{bq|x} {$src, $dst|$dst, $src}",
203                     [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
204 def MOVZX64rr16: RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
205                     "movz{wq|x} {$src, $dst|$dst, $src}",
206                     [(set GR64:$dst, (zext GR16:$src))]>, TB;
207 def MOVZX64rm16: RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
208                     "movz{wq|x} {$src, $dst|$dst, $src}",
209                     [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
210
211 def CDQE : RI<0x98, RawFrm, (outs), (ins),
212              "{cltq|cdqe}", []>, Imp<[EAX],[RAX]>;     // RAX = signext(EAX)
213
214 def CQO  : RI<0x99, RawFrm, (outs), (ins),
215               "{cqto|cqo}", []>, Imp<[RAX],[RAX,RDX]>; // RDX:RAX = signext(RAX)
216
217 //===----------------------------------------------------------------------===//
218 //  Arithmetic Instructions...
219 //
220
221 let isTwoAddress = 1 in {
222 let isConvertibleToThreeAddress = 1 in {
223 let isCommutable = 1 in
224 def ADD64rr  : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
225                   "add{q} {$src2, $dst|$dst, $src2}",
226                   [(set GR64:$dst, (add GR64:$src1, GR64:$src2))]>;
227
228 def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
229                       "add{q} {$src2, $dst|$dst, $src2}",
230                       [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2))]>;
231 def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
232                     "add{q} {$src2, $dst|$dst, $src2}",
233                     [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2))]>;
234 } // isConvertibleToThreeAddress
235
236 def ADD64rm  : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
237                   "add{q} {$src2, $dst|$dst, $src2}",
238                   [(set GR64:$dst, (add GR64:$src1, (load addr:$src2)))]>;
239 } // isTwoAddress
240
241 def ADD64mr  : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
242                   "add{q} {$src2, $dst|$dst, $src2}",
243                   [(store (add (load addr:$dst), GR64:$src2), addr:$dst)]>;
244 def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
245                       "add{q} {$src2, $dst|$dst, $src2}",
246                [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
247 def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
248                     "add{q} {$src2, $dst|$dst, $src2}",
249                 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
250
251 let isTwoAddress = 1 in {
252 let isCommutable = 1 in
253 def ADC64rr  : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
254                   "adc{q} {$src2, $dst|$dst, $src2}",
255                   [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
256
257 def ADC64rm  : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
258                   "adc{q} {$src2, $dst|$dst, $src2}",
259                   [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
260
261 def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
262                       "adc{q} {$src2, $dst|$dst, $src2}",
263                       [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
264 def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
265                     "adc{q} {$src2, $dst|$dst, $src2}",
266                     [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
267 } // isTwoAddress
268
269 def ADC64mr  : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
270                   "adc{q} {$src2, $dst|$dst, $src2}",
271                   [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
272 def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
273                       "adc{q} {$src2, $dst|$dst, $src2}",
274                [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
275 def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
276                     "adc{q} {$src2, $dst|$dst, $src2}",
277                [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
278
279 let isTwoAddress = 1 in {
280 def SUB64rr  : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
281                   "sub{q} {$src2, $dst|$dst, $src2}",
282                   [(set GR64:$dst, (sub GR64:$src1, GR64:$src2))]>;
283
284 def SUB64rm  : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
285                   "sub{q} {$src2, $dst|$dst, $src2}",
286                   [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2)))]>;
287
288 def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
289                       "sub{q} {$src2, $dst|$dst, $src2}",
290                       [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2))]>;
291 def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
292                     "sub{q} {$src2, $dst|$dst, $src2}",
293                     [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2))]>;
294 } // isTwoAddress
295
296 def SUB64mr  : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2), 
297                   "sub{q} {$src2, $dst|$dst, $src2}",
298                   [(store (sub (load addr:$dst), GR64:$src2), addr:$dst)]>;
299 def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2), 
300                       "sub{q} {$src2, $dst|$dst, $src2}",
301                [(store (sub (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
302 def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2), 
303                     "sub{q} {$src2, $dst|$dst, $src2}",
304                 [(store (sub (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
305
306 let isTwoAddress = 1 in {
307 def SBB64rr    : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
308                     "sbb{q} {$src2, $dst|$dst, $src2}",
309                     [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
310
311 def SBB64rm  : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
312                   "sbb{q} {$src2, $dst|$dst, $src2}",
313                   [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
314
315 def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
316                       "sbb{q} {$src2, $dst|$dst, $src2}",
317                       [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
318 def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
319                     "sbb{q} {$src2, $dst|$dst, $src2}",
320                     [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
321 } // isTwoAddress
322
323 def SBB64mr  : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2), 
324                   "sbb{q} {$src2, $dst|$dst, $src2}",
325                   [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
326 def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2), 
327                       "sbb{q} {$src2, $dst|$dst, $src2}",
328               [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
329 def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2), 
330                     "sbb{q} {$src2, $dst|$dst, $src2}",
331                [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
332
333 // Unsigned multiplication
334 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
335                 "mul{q} $src", []>,
336              Imp<[RAX],[RAX,RDX]>;         // RAX,RDX = RAX*GR64
337 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
338                 "mul{q} $src", []>,
339              Imp<[RAX],[RAX,RDX]>;         // RAX,RDX = RAX*[mem64]
340
341 // Signed multiplication
342 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
343                  "imul{q} $src", []>,
344               Imp<[RAX],[RAX,RDX]>;         // RAX,RDX = RAX*GR64
345 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
346                  "imul{q} $src", []>,
347               Imp<[RAX],[RAX,RDX]>;         // RAX,RDX = RAX*[mem64]
348
349 let isTwoAddress = 1 in {
350 let isCommutable = 1 in
351 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
352                   "imul{q} {$src2, $dst|$dst, $src2}",
353                   [(set GR64:$dst, (mul GR64:$src1, GR64:$src2))]>, TB;
354
355 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
356                   "imul{q} {$src2, $dst|$dst, $src2}",
357                  [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2)))]>, TB;
358 } // isTwoAddress
359
360 // Suprisingly enough, these are not two address instructions!
361 def IMUL64rri32 : RIi32<0x69, MRMSrcReg,                    // GR64 = GR64*I32
362                         (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
363                         "imul{q} {$src2, $src1, $dst|$dst, $src1, $src2}",
364                        [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2))]>;
365 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg,                      // GR64 = GR64*I8
366                       (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
367                       "imul{q} {$src2, $src1, $dst|$dst, $src1, $src2}",
368                       [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2))]>;
369 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem,                   // GR64 = [mem64]*I32
370                         (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
371                         "imul{q} {$src2, $src1, $dst|$dst, $src1, $src2}",
372                 [(set GR64:$dst, (mul (load addr:$src1), i64immSExt32:$src2))]>;
373 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem,                      // GR64 = [mem64]*I8
374                       (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
375                       "imul{q} {$src2, $src1, $dst|$dst, $src1, $src2}",
376                  [(set GR64:$dst, (mul (load addr:$src1), i64immSExt8:$src2))]>;
377
378 // Unsigned division / remainder
379 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src),        // RDX:RAX/r64 = RAX,RDX
380                 "div{q} $src", []>, Imp<[RAX,RDX],[RAX,RDX]>;
381 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src),      // RDX:RAX/[mem64] = RAX,RDX
382                 "div{q} $src", []>, Imp<[RAX,RDX],[RAX,RDX]>;
383
384 // Signed division / remainder
385 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src),        // RDX:RAX/r64 = RAX,RDX
386                 "idiv{q} $src", []>, Imp<[RAX,RDX],[RAX,RDX]>;
387 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src),      // RDX:RAX/[mem64] = RAX,RDX
388                 "idiv{q} $src", []>, Imp<[RAX,RDX],[RAX,RDX]>;
389
390 // Unary instructions
391 let CodeSize = 2 in {
392 let isTwoAddress = 1 in
393 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q} $dst",
394                 [(set GR64:$dst, (ineg GR64:$src))]>;
395 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q} $dst",
396                 [(store (ineg (loadi64 addr:$dst)), addr:$dst)]>;
397
398 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
399 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q} $dst",
400                 [(set GR64:$dst, (add GR64:$src, 1))]>;
401 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q} $dst",
402                 [(store (add (loadi64 addr:$dst), 1), addr:$dst)]>;
403
404 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
405 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q} $dst",
406                 [(set GR64:$dst, (add GR64:$src, -1))]>;
407 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q} $dst",
408                 [(store (add (loadi64 addr:$dst), -1), addr:$dst)]>;
409
410 // In 64-bit mode, single byte INC and DEC cannot be encoded.
411 let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
412 // Can transform into LEA.
413 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w} $dst",
414                   [(set GR16:$dst, (add GR16:$src, 1))]>,
415                 OpSize, Requires<[In64BitMode]>;
416 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l} $dst",
417                   [(set GR32:$dst, (add GR32:$src, 1))]>,
418                 Requires<[In64BitMode]>;
419 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w} $dst",
420                   [(set GR16:$dst, (add GR16:$src, -1))]>,
421                 OpSize, Requires<[In64BitMode]>;
422 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l} $dst",
423                   [(set GR32:$dst, (add GR32:$src, -1))]>,
424                 Requires<[In64BitMode]>;
425 } // isConvertibleToThreeAddress
426 } // CodeSize
427
428
429 // Shift instructions
430 let isTwoAddress = 1 in {
431 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
432                   "shl{q} {%cl, $dst|$dst, %CL}",
433                   [(set GR64:$dst, (shl GR64:$src, CL))]>,
434                Imp<[CL],[]>;
435 def SHL64ri  : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
436                     "shl{q} {$src2, $dst|$dst, $src2}",
437                     [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
438 def SHL64r1  : RI<0xD1, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
439                  "shl{q} $dst", []>;
440 } // isTwoAddress
441
442 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
443                   "shl{q} {%cl, $dst|$dst, %CL}",
444                   [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>,
445                Imp<[CL],[]>;
446 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
447                   "shl{q} {$src, $dst|$dst, $src}",
448                  [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
449 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
450                   "shl{q} $dst",
451                  [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
452
453 let isTwoAddress = 1 in {
454 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
455                   "shr{q} {%cl, $dst|$dst, %CL}",
456                   [(set GR64:$dst, (srl GR64:$src, CL))]>,
457                Imp<[CL],[]>;
458 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
459                   "shr{q} {$src2, $dst|$dst, $src2}",
460                   [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
461 def SHR64r1  : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
462                  "shr{q} $dst",
463                  [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
464 } // isTwoAddress
465
466 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
467                   "shr{q} {%cl, $dst|$dst, %CL}",
468                   [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>,
469                Imp<[CL],[]>;
470 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
471                   "shr{q} {$src, $dst|$dst, $src}",
472                  [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
473 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
474                   "shr{q} $dst",
475                  [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
476
477 let isTwoAddress = 1 in {
478 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
479                  "sar{q} {%cl, $dst|$dst, %CL}",
480                  [(set GR64:$dst, (sra GR64:$src, CL))]>, Imp<[CL],[]>;
481 def SAR64ri  : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
482                    "sar{q} {$src2, $dst|$dst, $src2}",
483                    [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
484 def SAR64r1  : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
485                  "sar{q} $dst",
486                  [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
487 } // isTwoAddress
488
489 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst), 
490                  "sar{q} {%cl, $dst|$dst, %CL}",
491                  [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>,
492                Imp<[CL],[]>;
493 def SAR64mi  : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
494                     "sar{q} {$src, $dst|$dst, $src}",
495                  [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
496 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
497                   "sar{q} $dst",
498                  [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
499
500 // Rotate instructions
501 let isTwoAddress = 1 in {
502 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
503                   "rol{q} {%cl, $dst|$dst, %CL}",
504                   [(set GR64:$dst, (rotl GR64:$src, CL))]>, Imp<[CL],[]>;
505 def ROL64ri  : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
506                     "rol{q} {$src2, $dst|$dst, $src2}",
507                     [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
508 def ROL64r1  : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
509                   "rol{q} $dst",
510                   [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
511 } // isTwoAddress
512
513 def ROL64mCL :  I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
514                   "rol{q} {%cl, $dst|$dst, %CL}",
515                   [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>,
516                Imp<[CL],[]>;
517 def ROL64mi  : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
518                     "rol{q} {$src, $dst|$dst, $src}",
519                 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
520 def ROL64m1  : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
521                  "rol{q} $dst",
522                [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
523
524 let isTwoAddress = 1 in {
525 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
526                   "ror{q} {%cl, $dst|$dst, %CL}",
527                   [(set GR64:$dst, (rotr GR64:$src, CL))]>, Imp<[CL],[]>;
528 def ROR64ri  : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
529                     "ror{q} {$src2, $dst|$dst, $src2}",
530                     [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
531 def ROR64r1  : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
532                   "ror{q} $dst",
533                   [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
534 } // isTwoAddress
535
536 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst), 
537                   "ror{q} {%cl, $dst|$dst, %CL}",
538                   [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>,
539                Imp<[CL],[]>;
540 def ROR64mi  : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
541                     "ror{q} {$src, $dst|$dst, $src}",
542                 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
543 def ROR64m1  : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
544                  "ror{q} $dst",
545                [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
546
547 // Double shift instructions (generalizations of rotate)
548 let isTwoAddress = 1 in {
549 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
550                     "shld{q} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
551                  Imp<[CL],[]>, TB;
552 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
553                     "shrd{q} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
554                  Imp<[CL],[]>, TB;
555
556 let isCommutable = 1 in {  // FIXME: Update X86InstrInfo::commuteInstruction
557 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
558                       (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
559                       "shld{q} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
560                       TB;
561 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
562                       (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
563                       "shrd{q} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
564                  TB;
565 } // isCommutable
566 } // isTwoAddress
567
568 // Temporary hack: there is no patterns associated with these instructions
569 // so we have to tell tblgen that these do not produce results.
570 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
571                     "shld{q} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
572                  Imp<[CL],[]>, TB;
573 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
574                     "shrd{q} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
575                  Imp<[CL],[]>, TB;
576 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
577                       (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
578                       "shld{q} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
579                  TB;
580 def SHRD64mri8 : RIi8<0xAC, MRMDestMem, 
581                       (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
582                       "shrd{q} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
583                  TB;
584
585 //===----------------------------------------------------------------------===//
586 //  Logical Instructions...
587 //
588
589 let isTwoAddress = 1 in
590 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q} $dst",
591                 [(set GR64:$dst, (not GR64:$src))]>;
592 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q} $dst",
593                 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
594
595 let isTwoAddress = 1 in {
596 let isCommutable = 1 in
597 def AND64rr  : RI<0x21, MRMDestReg, 
598                   (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
599                   "and{q} {$src2, $dst|$dst, $src2}",
600                   [(set GR64:$dst, (and GR64:$src1, GR64:$src2))]>;
601 def AND64rm  : RI<0x23, MRMSrcMem,
602                   (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
603                   "and{q} {$src2, $dst|$dst, $src2}",
604                   [(set GR64:$dst, (and GR64:$src1, (load addr:$src2)))]>;
605 def AND64ri32  : RIi32<0x81, MRM4r, 
606                        (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
607                        "and{q} {$src2, $dst|$dst, $src2}",
608                        [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2))]>;
609 def AND64ri8 : RIi8<0x83, MRM4r, 
610                     (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
611                     "and{q} {$src2, $dst|$dst, $src2}",
612                     [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2))]>;
613 } // isTwoAddress
614
615 def AND64mr  : RI<0x21, MRMDestMem,
616                   (outs), (ins i64mem:$dst, GR64:$src),
617                   "and{q} {$src, $dst|$dst, $src}",
618                   [(store (and (load addr:$dst), GR64:$src), addr:$dst)]>;
619 def AND64mi32  : RIi32<0x81, MRM4m,
620                        (outs), (ins i64mem:$dst, i64i32imm:$src),
621                        "and{q} {$src, $dst|$dst, $src}",
622              [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
623 def AND64mi8 : RIi8<0x83, MRM4m,
624                     (outs), (ins i64mem:$dst, i64i8imm :$src),
625                     "and{q} {$src, $dst|$dst, $src}",
626                  [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
627
628 let isTwoAddress = 1 in {
629 let isCommutable = 1 in
630 def OR64rr   : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
631                   "or{q} {$src2, $dst|$dst, $src2}",
632                   [(set GR64:$dst, (or GR64:$src1, GR64:$src2))]>;
633 def OR64rm   : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
634                   "or{q} {$src2, $dst|$dst, $src2}",
635                   [(set GR64:$dst, (or GR64:$src1, (load addr:$src2)))]>;
636 def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
637                      "or{q} {$src2, $dst|$dst, $src2}",
638                      [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2))]>;
639 def OR64ri8  : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
640                     "or{q} {$src2, $dst|$dst, $src2}",
641                     [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2))]>;
642 } // isTwoAddress
643
644 def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
645                 "or{q} {$src, $dst|$dst, $src}",
646                 [(store (or (load addr:$dst), GR64:$src), addr:$dst)]>;
647 def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
648                      "or{q} {$src, $dst|$dst, $src}",
649               [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
650 def OR64mi8  : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
651                     "or{q} {$src, $dst|$dst, $src}",
652                   [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
653
654 let isTwoAddress = 1 in {
655 let isCommutable = 1 in
656 def XOR64rr  : RI<0x31, MRMDestReg,  (outs GR64:$dst), (ins GR64:$src1, GR64:$src2), 
657                   "xor{q} {$src2, $dst|$dst, $src2}",
658                   [(set GR64:$dst, (xor GR64:$src1, GR64:$src2))]>;
659 def XOR64rm  : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2), 
660                   "xor{q} {$src2, $dst|$dst, $src2}",
661                   [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2)))]>;
662 def XOR64ri32 : RIi32<0x81, MRM6r, 
663                       (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2), 
664                       "xor{q} {$src2, $dst|$dst, $src2}",
665                       [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2))]>;
666 def XOR64ri8 : RIi8<0x83, MRM6r,  (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
667                     "xor{q} {$src2, $dst|$dst, $src2}",
668                     [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2))]>;
669 } // isTwoAddress
670
671 def XOR64mr  : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
672                   "xor{q} {$src, $dst|$dst, $src}",
673                   [(store (xor (load addr:$dst), GR64:$src), addr:$dst)]>;
674 def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
675                       "xor{q} {$src, $dst|$dst, $src}",
676              [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
677 def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
678                     "xor{q} {$src, $dst|$dst, $src}",
679                  [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
680
681 //===----------------------------------------------------------------------===//
682 //  Comparison Instructions...
683 //
684
685 // Integer comparison
686 let isCommutable = 1 in
687 def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
688                   "test{q} {$src2, $src1|$src1, $src2}",
689                   [(X86cmp (and GR64:$src1, GR64:$src2), 0)]>;
690 def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
691                   "test{q} {$src2, $src1|$src1, $src2}",
692                   [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0)]>;
693 def TEST64ri32 : RIi32<0xF7, MRM0r, (outs), (ins GR64:$src1, i64i32imm:$src2),
694                        "test{q} {$src2, $src1|$src1, $src2}",
695                        [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0)]>;
696 def TEST64mi32 : RIi32<0xF7, MRM0m, (outs), (ins i64mem:$src1, i64i32imm:$src2),
697                        "test{q} {$src2, $src1|$src1, $src2}",
698                   [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0)]>;
699
700 def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
701                  "cmp{q} {$src2, $src1|$src1, $src2}",
702                  [(X86cmp GR64:$src1, GR64:$src2)]>;
703 def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
704                  "cmp{q} {$src2, $src1|$src1, $src2}",
705                  [(X86cmp (loadi64 addr:$src1), GR64:$src2)]>;
706 def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
707                  "cmp{q} {$src2, $src1|$src1, $src2}",
708                  [(X86cmp GR64:$src1, (loadi64 addr:$src2))]>;
709 def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
710                       "cmp{q} {$src2, $src1|$src1, $src2}",
711                       [(X86cmp GR64:$src1, i64immSExt32:$src2)]>;
712 def CMP64mi32 : RIi32<0x81, MRM7m, (outs), (ins i64mem:$src1, i64i32imm:$src2),
713                       "cmp{q} {$src2, $src1|$src1, $src2}",
714                       [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2)]>;
715 def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
716                     "cmp{q} {$src2, $src1|$src1, $src2}",
717                     [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2)]>;
718 def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
719                     "cmp{q} {$src2, $src1|$src1, $src2}",
720                     [(X86cmp GR64:$src1, i64immSExt8:$src2)]>;
721
722 // Conditional moves
723 let isTwoAddress = 1 in {
724 def CMOVB64rr : RI<0x42, MRMSrcReg,       // if <u, GR64 = GR64
725                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
726                    "cmovb {$src2, $dst|$dst, $src2}",
727                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
728                                      X86_COND_B))]>, TB;
729 def CMOVB64rm : RI<0x42, MRMSrcMem,       // if <u, GR64 = [mem64]
730                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
731                    "cmovb {$src2, $dst|$dst, $src2}",
732                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
733                                      X86_COND_B))]>, TB;
734 def CMOVAE64rr: RI<0x43, MRMSrcReg,       // if >=u, GR64 = GR64
735                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
736                    "cmovae {$src2, $dst|$dst, $src2}",
737                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
738                                      X86_COND_AE))]>, TB;
739 def CMOVAE64rm: RI<0x43, MRMSrcMem,       // if >=u, GR64 = [mem64]
740                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
741                    "cmovae {$src2, $dst|$dst, $src2}",
742                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
743                                      X86_COND_AE))]>, TB;
744 def CMOVE64rr : RI<0x44, MRMSrcReg,       // if ==, GR64 = GR64
745                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
746                    "cmove {$src2, $dst|$dst, $src2}",
747                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
748                                      X86_COND_E))]>, TB;
749 def CMOVE64rm : RI<0x44, MRMSrcMem,       // if ==, GR64 = [mem64]
750                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
751                    "cmove {$src2, $dst|$dst, $src2}",
752                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
753                                      X86_COND_E))]>, TB;
754 def CMOVNE64rr: RI<0x45, MRMSrcReg,       // if !=, GR64 = GR64
755                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
756                    "cmovne {$src2, $dst|$dst, $src2}",
757                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
758                                     X86_COND_NE))]>, TB;
759 def CMOVNE64rm: RI<0x45, MRMSrcMem,       // if !=, GR64 = [mem64]
760                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
761                    "cmovne {$src2, $dst|$dst, $src2}",
762                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
763                                     X86_COND_NE))]>, TB;
764 def CMOVBE64rr: RI<0x46, MRMSrcReg,       // if <=u, GR64 = GR64
765                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
766                    "cmovbe {$src2, $dst|$dst, $src2}",
767                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
768                                     X86_COND_BE))]>, TB;
769 def CMOVBE64rm: RI<0x46, MRMSrcMem,       // if <=u, GR64 = [mem64]
770                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
771                    "cmovbe {$src2, $dst|$dst, $src2}",
772                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
773                                     X86_COND_BE))]>, TB;
774 def CMOVA64rr : RI<0x47, MRMSrcReg,       // if >u, GR64 = GR64
775                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
776                    "cmova {$src2, $dst|$dst, $src2}",
777                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
778                                     X86_COND_A))]>, TB;
779 def CMOVA64rm : RI<0x47, MRMSrcMem,       // if >u, GR64 = [mem64]
780                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
781                    "cmova {$src2, $dst|$dst, $src2}",
782                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
783                                     X86_COND_A))]>, TB;
784 def CMOVL64rr : RI<0x4C, MRMSrcReg,       // if <s, GR64 = GR64
785                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
786                    "cmovl {$src2, $dst|$dst, $src2}",
787                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
788                                     X86_COND_L))]>, TB;
789 def CMOVL64rm : RI<0x4C, MRMSrcMem,       // if <s, GR64 = [mem64]
790                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
791                    "cmovl {$src2, $dst|$dst, $src2}",
792                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
793                                     X86_COND_L))]>, TB;
794 def CMOVGE64rr: RI<0x4D, MRMSrcReg,       // if >=s, GR64 = GR64
795                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
796                    "cmovge {$src2, $dst|$dst, $src2}",
797                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
798                                     X86_COND_GE))]>, TB;
799 def CMOVGE64rm: RI<0x4D, MRMSrcMem,       // if >=s, GR64 = [mem64]
800                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
801                    "cmovge {$src2, $dst|$dst, $src2}",
802                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
803                                     X86_COND_GE))]>, TB;
804 def CMOVLE64rr: RI<0x4E, MRMSrcReg,       // if <=s, GR64 = GR64
805                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
806                    "cmovle {$src2, $dst|$dst, $src2}",
807                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
808                                     X86_COND_LE))]>, TB;
809 def CMOVLE64rm: RI<0x4E, MRMSrcMem,       // if <=s, GR64 = [mem64]
810                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
811                    "cmovle {$src2, $dst|$dst, $src2}",
812                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
813                                     X86_COND_LE))]>, TB;
814 def CMOVG64rr : RI<0x4F, MRMSrcReg,       // if >s, GR64 = GR64
815                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
816                    "cmovg {$src2, $dst|$dst, $src2}",
817                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
818                                     X86_COND_G))]>, TB;
819 def CMOVG64rm : RI<0x4F, MRMSrcMem,       // if >s, GR64 = [mem64]
820                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
821                    "cmovg {$src2, $dst|$dst, $src2}",
822                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
823                                     X86_COND_G))]>, TB;
824 def CMOVS64rr : RI<0x48, MRMSrcReg,       // if signed, GR64 = GR64
825                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
826                    "cmovs {$src2, $dst|$dst, $src2}",
827                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
828                                     X86_COND_S))]>, TB;
829 def CMOVS64rm : RI<0x48, MRMSrcMem,       // if signed, GR64 = [mem64]
830                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
831                    "cmovs {$src2, $dst|$dst, $src2}",
832                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
833                                     X86_COND_S))]>, TB;
834 def CMOVNS64rr: RI<0x49, MRMSrcReg,       // if !signed, GR64 = GR64
835                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
836                    "cmovns {$src2, $dst|$dst, $src2}",
837                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
838                                     X86_COND_NS))]>, TB;
839 def CMOVNS64rm: RI<0x49, MRMSrcMem,       // if !signed, GR64 = [mem64]
840                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
841                    "cmovns {$src2, $dst|$dst, $src2}",
842                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
843                                     X86_COND_NS))]>, TB;
844 def CMOVP64rr : RI<0x4A, MRMSrcReg,       // if parity, GR64 = GR64
845                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
846                    "cmovp {$src2, $dst|$dst, $src2}",
847                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
848                                     X86_COND_P))]>, TB;
849 def CMOVP64rm : RI<0x4A, MRMSrcMem,       // if parity, GR64 = [mem64]
850                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
851                    "cmovp {$src2, $dst|$dst, $src2}",
852                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
853                                     X86_COND_P))]>, TB;
854 def CMOVNP64rr : RI<0x4B, MRMSrcReg,       // if !parity, GR64 = GR64
855                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
856                    "cmovnp {$src2, $dst|$dst, $src2}",
857                     [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
858                                      X86_COND_NP))]>, TB;
859 def CMOVNP64rm : RI<0x4B, MRMSrcMem,       // if !parity, GR64 = [mem64]
860                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
861                    "cmovnp {$src2, $dst|$dst, $src2}",
862                     [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
863                                      X86_COND_NP))]>, TB;
864 } // isTwoAddress
865
866 //===----------------------------------------------------------------------===//
867 //  Conversion Instructions...
868 //
869
870 // f64 -> signed i64
871 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
872                            "cvtsd2si{q} {$src, $dst|$dst, $src}",
873                            [(set GR64:$dst,
874                              (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
875 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
876                            "cvtsd2si{q} {$src, $dst|$dst, $src}",
877                            [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
878                                              (load addr:$src)))]>;
879 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
880                         "cvttsd2si{q} {$src, $dst|$dst, $src}",
881                         [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
882 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
883                         "cvttsd2si{q} {$src, $dst|$dst, $src}",
884                         [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
885 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
886                             "cvttsd2si{q} {$src, $dst|$dst, $src}",
887                             [(set GR64:$dst,
888                               (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
889 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
890                             "cvttsd2si{q} {$src, $dst|$dst, $src}",
891                             [(set GR64:$dst,
892                               (int_x86_sse2_cvttsd2si64
893                                (load addr:$src)))]>;
894
895 // Signed i64 -> f64
896 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
897                        "cvtsi2sd{q} {$src, $dst|$dst, $src}",
898                        [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
899 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
900                        "cvtsi2sd{q} {$src, $dst|$dst, $src}",
901                        [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
902 let isTwoAddress = 1 in {
903 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
904                            (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
905                            "cvtsi2sd{q} {$src2, $dst|$dst, $src2}",
906                            [(set VR128:$dst,
907                              (int_x86_sse2_cvtsi642sd VR128:$src1,
908                               GR64:$src2))]>;
909 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
910                            (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
911                            "cvtsi2sd{q} {$src2, $dst|$dst, $src2}",
912                            [(set VR128:$dst,
913                              (int_x86_sse2_cvtsi642sd VR128:$src1,
914                               (loadi64 addr:$src2)))]>;
915 } // isTwoAddress
916
917 // Signed i64 -> f32
918 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
919                        "cvtsi2ss{q} {$src, $dst|$dst, $src}",
920                        [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
921 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
922                        "cvtsi2ss{q} {$src, $dst|$dst, $src}",
923                        [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
924 let isTwoAddress = 1 in {
925 def Int_CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg,
926                            (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
927                            "cvtsi2ss{q} {$src2, $dst|$dst, $src2}",
928                            []>; // TODO: add intrinsic
929 def Int_CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem,
930                            (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
931                            "cvtsi2ss{q} {$src2, $dst|$dst, $src2}",
932                            []>; // TODO: add intrinsic
933 } // isTwoAddress
934
935 // f32 -> signed i64
936 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
937                            "cvtss2si{q} {$src, $dst|$dst, $src}",
938                            [(set GR64:$dst,
939                              (int_x86_sse_cvtss2si64 VR128:$src))]>;
940 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
941                            "cvtss2si{q} {$src, $dst|$dst, $src}",
942                            [(set GR64:$dst, (int_x86_sse_cvtss2si64
943                                              (load addr:$src)))]>;
944 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
945                         "cvttss2si{q} {$src, $dst|$dst, $src}",
946                         [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
947 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
948                         "cvttss2si{q} {$src, $dst|$dst, $src}",
949                         [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
950 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
951                             "cvttss2si{q} {$src, $dst|$dst, $src}",
952                             [(set GR64:$dst,
953                               (int_x86_sse_cvttss2si64 VR128:$src))]>;
954 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
955                             "cvttss2si{q} {$src, $dst|$dst, $src}",
956                             [(set GR64:$dst,
957                               (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
958
959 let isTwoAddress = 1 in {
960   def Int_CVTSI642SSrr : RSSI<0x2A, MRMSrcReg,
961                               (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
962                               "cvtsi2ss{q} {$src2, $dst|$dst, $src2}",
963                               [(set VR128:$dst,
964                                 (int_x86_sse_cvtsi642ss VR128:$src1,
965                                  GR64:$src2))]>;
966   def Int_CVTSI642SSrm : RSSI<0x2A, MRMSrcMem,
967                               (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
968                               "cvtsi2ss{q} {$src2, $dst|$dst, $src2}",
969                               [(set VR128:$dst,
970                                 (int_x86_sse_cvtsi642ss VR128:$src1,
971                                  (loadi64 addr:$src2)))]>;
972 }
973
974 //===----------------------------------------------------------------------===//
975 // Alias Instructions
976 //===----------------------------------------------------------------------===//
977
978 // Zero-extension
979 // TODO: Remove this after proper i32 -> i64 zext support.
980 def PsMOVZX64rr32: I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
981                      "mov{l} {$src, ${dst:subreg32}|${dst:subreg32}, $src}",
982                      [(set GR64:$dst, (zext GR32:$src))]>;
983 def PsMOVZX64rm32: I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
984                      "mov{l} {$src, ${dst:subreg32}|${dst:subreg32}, $src}",
985                      [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
986
987
988 // Alias instructions that map movr0 to xor.
989 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
990 // FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
991 // when we have a better way to specify isel priority.
992 let AddedComplexity = 1 in
993 def MOV64r0  : RI<0x31, MRMInitReg,  (outs GR64:$dst), (ins),
994                  "xor{q} $dst, $dst",
995                  [(set GR64:$dst, 0)]>;
996
997 // Materialize i64 constant where top 32-bits are zero.
998 let AddedComplexity = 1 in
999 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1000                         "mov{l} {$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1001                         [(set GR64:$dst, i64immZExt32:$src)]>;
1002
1003 //===----------------------------------------------------------------------===//
1004 // Non-Instruction Patterns
1005 //===----------------------------------------------------------------------===//
1006
1007 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
1008 def : Pat<(i64 (X86Wrapper tconstpool  :$dst)),
1009           (MOV64ri tconstpool  :$dst)>, Requires<[NotSmallCode]>;
1010 def : Pat<(i64 (X86Wrapper tjumptable  :$dst)),
1011           (MOV64ri tjumptable  :$dst)>, Requires<[NotSmallCode]>;
1012 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1013           (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1014 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1015           (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1016
1017 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1018           (MOV64mi32 addr:$dst, tconstpool:$src)>,
1019           Requires<[SmallCode, IsStatic]>;
1020 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1021           (MOV64mi32 addr:$dst, tjumptable:$src)>,
1022           Requires<[SmallCode, IsStatic]>;
1023 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1024           (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1025           Requires<[SmallCode, IsStatic]>;
1026 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1027           (MOV64mi32 addr:$dst, texternalsym:$src)>,
1028           Requires<[SmallCode, IsStatic]>;
1029
1030 // Calls
1031 // Direct PC relative function call for small code model. 32-bit displacement
1032 // sign extended to 64-bit.
1033 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1034           (CALL64pcrel32 tglobaladdr:$dst)>;
1035 def : Pat<(X86call (i64 texternalsym:$dst)),
1036           (CALL64pcrel32 texternalsym:$dst)>;
1037
1038 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1039           (CALL64pcrel32 tglobaladdr:$dst)>;
1040 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1041           (CALL64pcrel32 texternalsym:$dst)>;
1042
1043 def : Pat<(X86tailcall GR64:$dst),
1044           (CALL64r GR64:$dst)>;
1045
1046 // {s|z}extload bool -> {s|z}extload byte
1047 def : Pat<(sextloadi64i1 addr:$src), (MOVSX64rm8 addr:$src)>;
1048 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1049
1050 // extload
1051 def : Pat<(extloadi64i1 addr:$src),  (MOVZX64rm8  addr:$src)>;
1052 def : Pat<(extloadi64i8 addr:$src),  (MOVZX64rm8  addr:$src)>;
1053 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1054 def : Pat<(extloadi64i32 addr:$src), (PsMOVZX64rm32 addr:$src)>;
1055
1056 // anyext -> zext
1057 def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8  GR8 :$src)>;
1058 def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16:$src)>;
1059 def : Pat<(i64 (anyext GR32:$src)), (PsMOVZX64rr32 GR32:$src)>;
1060 def : Pat<(i64 (anyext (loadi8  addr:$src))), (MOVZX64rm8  addr:$src)>;
1061 def : Pat<(i64 (anyext (loadi16 addr:$src))), (MOVZX64rm16 addr:$src)>;
1062 def : Pat<(i64 (anyext (loadi32 addr:$src))), (PsMOVZX64rm32 addr:$src)>;
1063
1064 //===----------------------------------------------------------------------===//
1065 // Some peepholes
1066 //===----------------------------------------------------------------------===//
1067
1068 // (shl x, 1) ==> (add x, x)
1069 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1070
1071 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1072 def : Pat<(or (srl GR64:$src1, CL:$amt),
1073               (shl GR64:$src2, (sub 64, CL:$amt))),
1074           (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1075
1076 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1077                      (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1078           (SHRD64mrCL addr:$dst, GR64:$src2)>;
1079
1080 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1081 def : Pat<(or (shl GR64:$src1, CL:$amt),
1082               (srl GR64:$src2, (sub 64, CL:$amt))),
1083           (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1084
1085 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1086                      (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1087           (SHLD64mrCL addr:$dst, GR64:$src2)>;
1088
1089 // X86 specific add which produces a flag.
1090 def : Pat<(addc GR64:$src1, GR64:$src2),
1091           (ADD64rr GR64:$src1, GR64:$src2)>;
1092 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1093           (ADD64rm GR64:$src1, addr:$src2)>;
1094 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1095           (ADD64ri32 GR64:$src1, imm:$src2)>;
1096 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1097           (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1098
1099 def : Pat<(subc GR64:$src1, GR64:$src2),
1100           (SUB64rr GR64:$src1, GR64:$src2)>;
1101 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1102           (SUB64rm GR64:$src1, addr:$src2)>;
1103 def : Pat<(subc GR64:$src1, imm:$src2),
1104           (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1105 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1106           (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1107
1108
1109 //===----------------------------------------------------------------------===//
1110 // X86-64 SSE Instructions
1111 //===----------------------------------------------------------------------===//
1112
1113 // Move instructions...
1114
1115 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
1116                         "mov{d|q} {$src, $dst|$dst, $src}",
1117                         [(set VR128:$dst,
1118                           (v2i64 (scalar_to_vector GR64:$src)))]>;
1119 def MOV64toPQIrm : RPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1120                         "mov{d|q} {$src, $dst|$dst, $src}",
1121                         [(set VR128:$dst,
1122                           (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>;
1123
1124 def MOVPQIto64rr  : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
1125                          "mov{d|q} {$src, $dst|$dst, $src}",
1126                          [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1127                                            (iPTR 0)))]>;
1128 def MOVPQIto64mr  : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
1129                          "mov{d|q} {$src, $dst|$dst, $src}",
1130                          [(store (i64 (vector_extract (v2i64 VR128:$src),
1131                                        (iPTR 0))), addr:$dst)]>;
1132
1133 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1134                        "mov{d|q} {$src, $dst|$dst, $src}",
1135                        [(set FR64:$dst, (bitconvert GR64:$src))]>;
1136 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1137                        "mov{d|q} {$src, $dst|$dst, $src}",
1138                        [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1139
1140 def MOVSDto64rr  : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
1141                         "mov{d|q} {$src, $dst|$dst, $src}",
1142                         [(set GR64:$dst, (bitconvert FR64:$src))]>;
1143 def MOVSDto64mr  : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
1144                         "mov{d|q} {$src, $dst|$dst, $src}",
1145                         [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;