b5fe4659bc3472fa066253725140a7831d96db2b
[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 def CMOVO64rr : RI<0x40, MRMSrcReg,       // if overflow, GR64 = GR64
1008                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1009                    "cmovo\t{$src2, $dst|$dst, $src2}",
1010                    [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1011                                     X86_COND_O, EFLAGS))]>, TB;
1012 def CMOVNO64rr : RI<0x41, MRMSrcReg,       // if !overflow, GR64 = GR64
1013                    (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1014                    "cmovno\t{$src2, $dst|$dst, $src2}",
1015                     [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1016                                      X86_COND_NO, EFLAGS))]>, TB;
1017 } // isCommutable = 1
1018
1019 def CMOVB64rm : RI<0x42, MRMSrcMem,       // if <u, GR64 = [mem64]
1020                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1021                    "cmovb\t{$src2, $dst|$dst, $src2}",
1022                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1023                                      X86_COND_B, EFLAGS))]>, TB;
1024 def CMOVAE64rm: RI<0x43, MRMSrcMem,       // if >=u, GR64 = [mem64]
1025                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1026                    "cmovae\t{$src2, $dst|$dst, $src2}",
1027                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1028                                      X86_COND_AE, EFLAGS))]>, TB;
1029 def CMOVE64rm : RI<0x44, MRMSrcMem,       // if ==, GR64 = [mem64]
1030                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1031                    "cmove\t{$src2, $dst|$dst, $src2}",
1032                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1033                                      X86_COND_E, EFLAGS))]>, TB;
1034 def CMOVNE64rm: RI<0x45, MRMSrcMem,       // if !=, GR64 = [mem64]
1035                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1036                    "cmovne\t{$src2, $dst|$dst, $src2}",
1037                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1038                                     X86_COND_NE, EFLAGS))]>, TB;
1039 def CMOVBE64rm: RI<0x46, MRMSrcMem,       // if <=u, GR64 = [mem64]
1040                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1041                    "cmovbe\t{$src2, $dst|$dst, $src2}",
1042                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1043                                     X86_COND_BE, EFLAGS))]>, TB;
1044 def CMOVA64rm : RI<0x47, MRMSrcMem,       // if >u, GR64 = [mem64]
1045                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1046                    "cmova\t{$src2, $dst|$dst, $src2}",
1047                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1048                                     X86_COND_A, EFLAGS))]>, TB;
1049 def CMOVL64rm : RI<0x4C, MRMSrcMem,       // if <s, GR64 = [mem64]
1050                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1051                    "cmovl\t{$src2, $dst|$dst, $src2}",
1052                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1053                                     X86_COND_L, EFLAGS))]>, TB;
1054 def CMOVGE64rm: RI<0x4D, MRMSrcMem,       // if >=s, GR64 = [mem64]
1055                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1056                    "cmovge\t{$src2, $dst|$dst, $src2}",
1057                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1058                                     X86_COND_GE, EFLAGS))]>, TB;
1059 def CMOVLE64rm: RI<0x4E, MRMSrcMem,       // if <=s, GR64 = [mem64]
1060                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1061                    "cmovle\t{$src2, $dst|$dst, $src2}",
1062                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1063                                     X86_COND_LE, EFLAGS))]>, TB;
1064 def CMOVG64rm : RI<0x4F, MRMSrcMem,       // if >s, GR64 = [mem64]
1065                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1066                    "cmovg\t{$src2, $dst|$dst, $src2}",
1067                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1068                                     X86_COND_G, EFLAGS))]>, TB;
1069 def CMOVS64rm : RI<0x48, MRMSrcMem,       // if signed, GR64 = [mem64]
1070                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1071                    "cmovs\t{$src2, $dst|$dst, $src2}",
1072                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1073                                     X86_COND_S, EFLAGS))]>, TB;
1074 def CMOVNS64rm: RI<0x49, MRMSrcMem,       // if !signed, GR64 = [mem64]
1075                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1076                    "cmovns\t{$src2, $dst|$dst, $src2}",
1077                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1078                                     X86_COND_NS, EFLAGS))]>, TB;
1079 def CMOVP64rm : RI<0x4A, MRMSrcMem,       // if parity, GR64 = [mem64]
1080                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1081                    "cmovp\t{$src2, $dst|$dst, $src2}",
1082                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1083                                     X86_COND_P, EFLAGS))]>, TB;
1084 def CMOVNP64rm : RI<0x4B, MRMSrcMem,       // if !parity, GR64 = [mem64]
1085                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1086                    "cmovnp\t{$src2, $dst|$dst, $src2}",
1087                     [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1088                                      X86_COND_NP, EFLAGS))]>, TB;
1089 def CMOVO64rm : RI<0x40, MRMSrcMem,       // if overflow, GR64 = [mem64]
1090                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1091                    "cmovo\t{$src2, $dst|$dst, $src2}",
1092                    [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1093                                     X86_COND_O, EFLAGS))]>, TB;
1094 def CMOVNO64rm : RI<0x41, MRMSrcMem,       // if !overflow, GR64 = [mem64]
1095                    (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1096                    "cmovno\t{$src2, $dst|$dst, $src2}",
1097                     [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1098                                      X86_COND_NO, EFLAGS))]>, TB;
1099 } // isTwoAddress
1100
1101 //===----------------------------------------------------------------------===//
1102 //  Conversion Instructions...
1103 //
1104
1105 // f64 -> signed i64
1106 def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1107                            "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1108                            [(set GR64:$dst,
1109                              (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
1110 def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1111                            "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
1112                            [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1113                                              (load addr:$src)))]>;
1114 def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1115                         "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1116                         [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
1117 def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1118                         "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1119                         [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
1120 def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1121                             "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1122                             [(set GR64:$dst,
1123                               (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
1124 def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
1125                             "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
1126                             [(set GR64:$dst,
1127                               (int_x86_sse2_cvttsd2si64
1128                                (load addr:$src)))]>;
1129
1130 // Signed i64 -> f64
1131 def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1132                        "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1133                        [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
1134 def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1135                        "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
1136                        [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1137
1138 let isTwoAddress = 1 in {
1139 def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
1140                            (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1141                            "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1142                            [(set VR128:$dst,
1143                              (int_x86_sse2_cvtsi642sd VR128:$src1,
1144                               GR64:$src2))]>;
1145 def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
1146                            (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1147                            "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
1148                            [(set VR128:$dst,
1149                              (int_x86_sse2_cvtsi642sd VR128:$src1,
1150                               (loadi64 addr:$src2)))]>;
1151 } // isTwoAddress
1152
1153 // Signed i64 -> f32
1154 def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
1155                        "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1156                        [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
1157 def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
1158                        "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
1159                        [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
1160
1161 let isTwoAddress = 1 in {
1162   def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1163                               (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1164                               "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1165                               [(set VR128:$dst,
1166                                 (int_x86_sse_cvtsi642ss VR128:$src1,
1167                                  GR64:$src2))]>;
1168   def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1169                               (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1170                               "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1171                               [(set VR128:$dst,
1172                                 (int_x86_sse_cvtsi642ss VR128:$src1,
1173                                  (loadi64 addr:$src2)))]>;
1174 }
1175
1176 // f32 -> signed i64
1177 def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1178                            "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1179                            [(set GR64:$dst,
1180                              (int_x86_sse_cvtss2si64 VR128:$src))]>;
1181 def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1182                            "cvtss2si{q}\t{$src, $dst|$dst, $src}",
1183                            [(set GR64:$dst, (int_x86_sse_cvtss2si64
1184                                              (load addr:$src)))]>;
1185 def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1186                         "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1187                         [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
1188 def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1189                         "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1190                         [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
1191 def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
1192                             "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1193                             [(set GR64:$dst,
1194                               (int_x86_sse_cvttss2si64 VR128:$src))]>;
1195 def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1196                             "cvttss2si{q}\t{$src, $dst|$dst, $src}",
1197                             [(set GR64:$dst,
1198                               (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1199
1200 //===----------------------------------------------------------------------===//
1201 // Alias Instructions
1202 //===----------------------------------------------------------------------===//
1203
1204 // Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1205 // equivalent due to implicit zero-extending, and it sometimes has a smaller
1206 // encoding.
1207 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1208 // FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1209 // when we have a better way to specify isel priority.
1210 let Defs = [EFLAGS], AddedComplexity = 1,
1211     isReMaterializable = 1, isAsCheapAsAMove = 1 in
1212 def MOV64r0  : I<0x31, MRMInitReg,  (outs GR64:$dst), (ins),
1213                 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1214                 [(set GR64:$dst, 0)]>;
1215
1216 // Materialize i64 constant where top 32-bits are zero.
1217 let AddedComplexity = 1, isReMaterializable = 1 in
1218 def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
1219                         "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1220                         [(set GR64:$dst, i64immZExt32:$src)]>;
1221
1222 //===----------------------------------------------------------------------===//
1223 // Thread Local Storage Instructions
1224 //===----------------------------------------------------------------------===//
1225
1226 def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
1227               ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
1228                   [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
1229
1230 //===----------------------------------------------------------------------===//
1231 // Atomic Instructions
1232 //===----------------------------------------------------------------------===//
1233
1234 let Defs = [RAX, EFLAGS], Uses = [RAX] in {
1235 def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
1236                "lock\n\tcmpxchgq\t$swap,$ptr",
1237                [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1238 }
1239
1240 let Constraints = "$val = $dst" in {
1241 let Defs = [EFLAGS] in
1242 def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1243                "lock\n\txadd\t$val, $ptr", 
1244                [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
1245                 TB, LOCK;
1246 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
1247                   "xchg\t$val, $ptr", 
1248                   [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
1249 }
1250
1251 // Atomic exchange, and, or, xor
1252 let Constraints = "$val = $dst", Defs = [EFLAGS],
1253                   usesCustomDAGSchedInserter = 1 in {
1254 def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1255                "#ATOMAND64 PSEUDO!", 
1256                [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
1257 def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1258                "#ATOMOR64 PSEUDO!", 
1259                [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
1260 def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1261                "#ATOMXOR64 PSEUDO!", 
1262                [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
1263 def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1264                "#ATOMNAND64 PSEUDO!", 
1265                [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
1266 def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
1267                "#ATOMMIN64 PSEUDO!", 
1268                [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
1269 def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1270                "#ATOMMAX64 PSEUDO!", 
1271                [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
1272 def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1273                "#ATOMUMIN64 PSEUDO!", 
1274                [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
1275 def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
1276                "#ATOMUMAX64 PSEUDO!", 
1277                [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
1278 }
1279
1280 //===----------------------------------------------------------------------===//
1281 // Non-Instruction Patterns
1282 //===----------------------------------------------------------------------===//
1283
1284 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
1285 def : Pat<(i64 (X86Wrapper tconstpool  :$dst)),
1286           (MOV64ri tconstpool  :$dst)>, Requires<[NotSmallCode]>;
1287 def : Pat<(i64 (X86Wrapper tjumptable  :$dst)),
1288           (MOV64ri tjumptable  :$dst)>, Requires<[NotSmallCode]>;
1289 def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1290           (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1291 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1292           (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1293
1294 def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1295           (MOV64mi32 addr:$dst, tconstpool:$src)>,
1296           Requires<[SmallCode, IsStatic]>;
1297 def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1298           (MOV64mi32 addr:$dst, tjumptable:$src)>,
1299           Requires<[SmallCode, IsStatic]>;
1300 def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1301           (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1302           Requires<[SmallCode, IsStatic]>;
1303 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1304           (MOV64mi32 addr:$dst, texternalsym:$src)>,
1305           Requires<[SmallCode, IsStatic]>;
1306
1307 // Calls
1308 // Direct PC relative function call for small code model. 32-bit displacement
1309 // sign extended to 64-bit.
1310 def : Pat<(X86call (i64 tglobaladdr:$dst)),
1311           (CALL64pcrel32 tglobaladdr:$dst)>;
1312 def : Pat<(X86call (i64 texternalsym:$dst)),
1313           (CALL64pcrel32 texternalsym:$dst)>;
1314
1315 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1316           (CALL64pcrel32 tglobaladdr:$dst)>;
1317 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1318           (CALL64pcrel32 texternalsym:$dst)>;
1319
1320 def : Pat<(X86tailcall GR64:$dst),
1321           (CALL64r GR64:$dst)>;
1322
1323
1324 // tailcall stuff
1325 def : Pat<(X86tailcall GR32:$dst),
1326           (TAILCALL)>;
1327 def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1328           (TAILCALL)>;
1329 def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1330           (TAILCALL)>;
1331
1332 def : Pat<(X86tcret GR64:$dst, imm:$off),
1333           (TCRETURNri64 GR64:$dst, imm:$off)>;
1334
1335 def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1336           (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1337
1338 def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1339           (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1340
1341 // Comparisons.
1342
1343 // TEST R,R is smaller than CMP R,0
1344 def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
1345           (TEST64rr GR64:$src1, GR64:$src1)>;
1346
1347
1348
1349 // Zero-extension
1350 def : Pat<(i64 (zext GR32:$src)), 
1351           (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
1352
1353 // zextload bool -> zextload byte
1354 def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1355
1356 // extload
1357 // When extloading from 16-bit and smaller memory locations into 64-bit registers,
1358 // use zero-extending loads so that the entire 64-bit register is defined, avoiding
1359 // partial-register updates.
1360 def : Pat<(extloadi64i1 addr:$src),  (MOVZX64rm8  addr:$src)>;
1361 def : Pat<(extloadi64i8 addr:$src),  (MOVZX64rm8  addr:$src)>;
1362 def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1363 // For other extloads, use subregs, since the high contents of the register are
1364 // defined after an extload.
1365 def : Pat<(extloadi64i32 addr:$src),
1366           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1367                          x86_subreg_32bit)>;
1368 def : Pat<(extloadi16i1 addr:$src), 
1369           (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src), 
1370                          x86_subreg_8bit)>,
1371          Requires<[In64BitMode]>;
1372 def : Pat<(extloadi16i8 addr:$src), 
1373           (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src), 
1374                          x86_subreg_8bit)>,
1375          Requires<[In64BitMode]>;
1376
1377 // anyext
1378 def : Pat<(i64 (anyext GR8:$src)),
1379           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1380 def : Pat<(i64 (anyext GR16:$src)),
1381           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
1382 def : Pat<(i64 (anyext GR32:$src)), 
1383           (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
1384 def : Pat<(i16 (anyext GR8:$src)),
1385           (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1386          Requires<[In64BitMode]>;
1387 def : Pat<(i32 (anyext GR8:$src)),
1388           (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1389          Requires<[In64BitMode]>;
1390
1391 //===----------------------------------------------------------------------===//
1392 // Some peepholes
1393 //===----------------------------------------------------------------------===//
1394
1395 // Odd encoding trick: -128 fits into an 8-bit immediate field while
1396 // +128 doesn't, so in this special case use a sub instead of an add.
1397 def : Pat<(add GR64:$src1, 128),
1398           (SUB64ri8 GR64:$src1, -128)>;
1399 def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1400           (SUB64mi8 addr:$dst, -128)>;
1401
1402 // The same trick applies for 32-bit immediate fields in 64-bit
1403 // instructions.
1404 def : Pat<(add GR64:$src1, 0x0000000080000000),
1405           (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1406 def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1407           (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1408
1409 // r & (2^32-1) ==> movz
1410 def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
1411           (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1412 // r & (2^16-1) ==> movz
1413 def : Pat<(and GR64:$src, 0xffff),
1414           (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1415 // r & (2^8-1) ==> movz
1416 def : Pat<(and GR64:$src, 0xff),
1417           (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1418 // r & (2^8-1) ==> movz
1419 def : Pat<(and GR32:$src1, 0xff),
1420            (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1421       Requires<[In64BitMode]>;
1422 // r & (2^8-1) ==> movz
1423 def : Pat<(and GR16:$src1, 0xff),
1424            (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1425       Requires<[In64BitMode]>;
1426
1427 // sext_inreg patterns
1428 def : Pat<(sext_inreg GR64:$src, i32),
1429           (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1430 def : Pat<(sext_inreg GR64:$src, i16),
1431           (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1432 def : Pat<(sext_inreg GR64:$src, i8),
1433           (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1434 def : Pat<(sext_inreg GR32:$src, i8),
1435           (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1436       Requires<[In64BitMode]>;
1437 def : Pat<(sext_inreg GR16:$src, i8),
1438           (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1439       Requires<[In64BitMode]>;
1440
1441 // trunc patterns
1442 def : Pat<(i32 (trunc GR64:$src)),
1443           (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1444 def : Pat<(i16 (trunc GR64:$src)),
1445           (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1446 def : Pat<(i8 (trunc GR64:$src)),
1447           (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1448 def : Pat<(i8 (trunc GR32:$src)),
1449           (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1450       Requires<[In64BitMode]>;
1451 def : Pat<(i8 (trunc GR16:$src)),
1452           (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1453       Requires<[In64BitMode]>;
1454
1455 // (shl x, 1) ==> (add x, x)
1456 def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1457
1458 // (shl x (and y, 63)) ==> (shl x, y)
1459 def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1460           (SHL64rCL GR64:$src1)>;
1461 def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1462           (SHL64mCL addr:$dst)>;
1463
1464 def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1465           (SHR64rCL GR64:$src1)>;
1466 def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1467           (SHR64mCL addr:$dst)>;
1468
1469 def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1470           (SAR64rCL GR64:$src1)>;
1471 def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1472           (SAR64mCL addr:$dst)>;
1473
1474 // (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1475 def : Pat<(or (srl GR64:$src1, CL:$amt),
1476               (shl GR64:$src2, (sub 64, CL:$amt))),
1477           (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1478
1479 def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1480                      (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1481           (SHRD64mrCL addr:$dst, GR64:$src2)>;
1482
1483 def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1484               (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1485           (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1486
1487 def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1488                      (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1489                  addr:$dst),
1490           (SHRD64mrCL addr:$dst, GR64:$src2)>;
1491
1492 def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1493           (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1494
1495 def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1496                        GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1497           (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1498
1499 // (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1500 def : Pat<(or (shl GR64:$src1, CL:$amt),
1501               (srl GR64:$src2, (sub 64, CL:$amt))),
1502           (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1503
1504 def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1505                      (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1506           (SHLD64mrCL addr:$dst, GR64:$src2)>;
1507
1508 def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1509               (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1510           (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1511
1512 def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1513                      (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1514                  addr:$dst),
1515           (SHLD64mrCL addr:$dst, GR64:$src2)>;
1516
1517 def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1518           (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1519
1520 def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1521                        GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1522           (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1523
1524 // X86 specific add which produces a flag.
1525 def : Pat<(addc GR64:$src1, GR64:$src2),
1526           (ADD64rr GR64:$src1, GR64:$src2)>;
1527 def : Pat<(addc GR64:$src1, (load addr:$src2)),
1528           (ADD64rm GR64:$src1, addr:$src2)>;
1529 def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1530           (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1531 def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1532           (ADD64ri32 GR64:$src1, imm:$src2)>;
1533
1534 def : Pat<(subc GR64:$src1, GR64:$src2),
1535           (SUB64rr GR64:$src1, GR64:$src2)>;
1536 def : Pat<(subc GR64:$src1, (load addr:$src2)),
1537           (SUB64rm GR64:$src1, addr:$src2)>;
1538 def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1539           (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1540 def : Pat<(subc GR64:$src1, imm:$src2),
1541           (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1542
1543 //===----------------------------------------------------------------------===//
1544 // Overflow Patterns
1545 //===----------------------------------------------------------------------===//
1546
1547 // Register-Register Addition with Overflow
1548 def : Pat<(parallel (X86add_ovf GR64:$src1, GR64:$src2),
1549                     (implicit EFLAGS)),
1550           (ADD64rr GR64:$src1, GR64:$src2)>;
1551
1552 // Register-Integer Addition with Overflow
1553 def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt8:$src2),
1554                     (implicit EFLAGS)),
1555           (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1556 def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt32:$src2),
1557                     (implicit EFLAGS)),
1558           (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
1559
1560 // Register-Memory Addition with Overflow
1561 def : Pat<(parallel (X86add_ovf GR64:$src1, (load addr:$src2)),
1562                     (implicit EFLAGS)),
1563           (ADD64rm GR64:$src1, addr:$src2)>;
1564
1565 // Memory-Register Addition with Overflow
1566 def : Pat<(parallel (store (X86add_ovf (load addr:$dst), GR64:$src2),
1567                            addr:$dst),
1568                     (implicit EFLAGS)),
1569           (ADD64mr addr:$dst, GR64:$src2)>;
1570 def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt8:$src2),
1571                            addr:$dst),
1572                     (implicit EFLAGS)),
1573           (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
1574 def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt32:$src2),
1575                            addr:$dst),
1576                     (implicit EFLAGS)),
1577           (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
1578
1579 // Register-Register Subtraction with Overflow
1580 def : Pat<(parallel (X86sub_ovf GR64:$src1, GR64:$src2),
1581                     (implicit EFLAGS)),
1582           (SUB64rr GR64:$src1, GR64:$src2)>;
1583
1584 // Register-Memory Subtraction with Overflow
1585 def : Pat<(parallel (X86sub_ovf GR64:$src1, (load addr:$src2)),
1586                     (implicit EFLAGS)),
1587           (SUB64rm GR64:$src1, addr:$src2)>;
1588
1589 // Register-Integer Subtraction with Overflow
1590 def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt8:$src2),
1591                     (implicit EFLAGS)),
1592           (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1593 def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt32:$src2),
1594                     (implicit EFLAGS)),
1595           (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1596
1597 // Memory-Register Subtraction with Overflow
1598 def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), GR64:$src2),
1599                            addr:$dst),
1600                     (implicit EFLAGS)),
1601           (SUB64mr addr:$dst, GR64:$src2)>;
1602
1603 // Memory-Integer Subtraction with Overflow
1604 def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt8:$src2),
1605                            addr:$dst),
1606                     (implicit EFLAGS)),
1607           (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
1608 def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt32:$src2),
1609                            addr:$dst),
1610                     (implicit EFLAGS)),
1611           (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
1612
1613 // Register-Register Signed Integer Multiplication with Overflow
1614 def : Pat<(parallel (X86smul_ovf GR64:$src1, GR64:$src2),
1615                     (implicit EFLAGS)),
1616           (IMUL64rr GR64:$src1, GR64:$src2)>;
1617
1618 // Register-Memory Signed Integer Multiplication with Overflow
1619 def : Pat<(parallel (X86smul_ovf GR64:$src1, (load addr:$src2)),
1620                     (implicit EFLAGS)),
1621           (IMUL64rm GR64:$src1, addr:$src2)>;
1622
1623 // Register-Integer Signed Integer Multiplication with Overflow
1624 def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt8:$src2),
1625                     (implicit EFLAGS)),
1626           (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
1627 def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt32:$src2),
1628                     (implicit EFLAGS)),
1629           (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
1630
1631 // Memory-Integer Signed Integer Multiplication with Overflow
1632 def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt8:$src2),
1633                     (implicit EFLAGS)),
1634           (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
1635 def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt32:$src2),
1636                     (implicit EFLAGS)),
1637           (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
1638
1639 //===----------------------------------------------------------------------===//
1640 // X86-64 SSE Instructions
1641 //===----------------------------------------------------------------------===//
1642
1643 // Move instructions...
1644
1645 def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
1646                         "mov{d|q}\t{$src, $dst|$dst, $src}",
1647                         [(set VR128:$dst,
1648                           (v2i64 (scalar_to_vector GR64:$src)))]>;
1649 def MOVPQIto64rr  : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
1650                          "mov{d|q}\t{$src, $dst|$dst, $src}",
1651                          [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1652                                            (iPTR 0)))]>;
1653
1654 def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
1655                        "mov{d|q}\t{$src, $dst|$dst, $src}",
1656                        [(set FR64:$dst, (bitconvert GR64:$src))]>;
1657 def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
1658                        "movq\t{$src, $dst|$dst, $src}",
1659                        [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1660
1661 def MOVSDto64rr  : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
1662                         "mov{d|q}\t{$src, $dst|$dst, $src}",
1663                         [(set GR64:$dst, (bitconvert FR64:$src))]>;
1664 def MOVSDto64mr  : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
1665                         "movq\t{$src, $dst|$dst, $src}",
1666                         [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
1667
1668 //===----------------------------------------------------------------------===//
1669 // X86-64 SSE4.1 Instructions
1670 //===----------------------------------------------------------------------===//
1671
1672 /// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1673 multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
1674   def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
1675                  (ins VR128:$src1, i32i8imm:$src2),
1676                  !strconcat(OpcodeStr, 
1677                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1678                  [(set GR64:$dst,
1679                   (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
1680   def mr : SS4AIi8<opc, MRMDestMem, (outs),
1681                  (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1682                  !strconcat(OpcodeStr, 
1683                   "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1684                  [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1685                           addr:$dst)]>, OpSize, REX_W;
1686 }
1687
1688 defm PEXTRQ      : SS41I_extract64<0x16, "pextrq">;
1689
1690 let isTwoAddress = 1 in {
1691   multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
1692     def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
1693                    (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1694                    !strconcat(OpcodeStr, 
1695                     "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1696                    [(set VR128:$dst, 
1697                      (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1698                    OpSize, REX_W;
1699     def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
1700                    (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1701                    !strconcat(OpcodeStr,
1702                     "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1703                    [(set VR128:$dst, 
1704                      (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1705                                        imm:$src3)))]>, OpSize, REX_W;
1706   }
1707 }
1708
1709 defm PINSRQ      : SS41I_insert64<0x22, "pinsrq">;