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