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