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