e32fb9c4b53b9e3a84dc610cc572f7c301727a10
[oota-llvm.git] / lib / Target / X86 / X86InstrInfo.td
1 //===- X86InstrInfo.td - Describe the X86 Instruction Set --*- 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 instruction set, defining the instructions, and
11 // properties of the instructions which are needed for code generation, machine
12 // code emission, and analysis.
13 //
14 //===----------------------------------------------------------------------===//
15
16 //===----------------------------------------------------------------------===//
17 // X86 specific DAG Nodes.
18 //
19
20 def SDTIntShiftDOp: SDTypeProfile<1, 3,
21                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
22                                    SDTCisInt<0>, SDTCisInt<3>]>;
23
24 def SDTX86CmpTest : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
25
26 def SDTX86Cmov    : SDTypeProfile<1, 4,
27                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
28                                    SDTCisVT<3, i8>, SDTCisVT<4, i32>]>;
29
30 def SDTX86BrCond  : SDTypeProfile<0, 3,
31                                   [SDTCisVT<0, OtherVT>,
32                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
33
34 def SDTX86SetCC   : SDTypeProfile<1, 2,
35                                   [SDTCisVT<0, i8>,
36                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
37
38 def SDTX86cas : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisInt<1>, 
39                                      SDTCisVT<2, i8>]>;
40 def SDTX86cas8 : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
41
42 def SDTX86Ret     : SDTypeProfile<0, -1, [SDTCisVT<0, i16>]>;
43
44 def SDT_X86CallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
45 def SDT_X86CallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>,
46                                          SDTCisVT<1, i32> ]>;
47
48 def SDT_X86Call   : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
49
50 def SDTX86RepStr  : SDTypeProfile<0, 1, [SDTCisVT<0, OtherVT>]>;
51
52 def SDTX86RdTsc   : SDTypeProfile<0, 0, []>;
53
54 def SDTX86Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
55
56 def SDT_X86TLSADDR : SDTypeProfile<1, 1, [SDTCisPtrTy<0>, SDTCisInt<1>]>;
57
58 def SDT_X86TLSTP : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
59
60 def SDT_X86EHRET : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
61
62 def SDT_X86TCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>;
63
64 def X86bsf     : SDNode<"X86ISD::BSF",      SDTIntUnaryOp>;
65 def X86bsr     : SDNode<"X86ISD::BSR",      SDTIntUnaryOp>;
66 def X86shld    : SDNode<"X86ISD::SHLD",     SDTIntShiftDOp>;
67 def X86shrd    : SDNode<"X86ISD::SHRD",     SDTIntShiftDOp>;
68
69 def X86cmp     : SDNode<"X86ISD::CMP" ,     SDTX86CmpTest>;
70
71 def X86cmov    : SDNode<"X86ISD::CMOV",     SDTX86Cmov>;
72 def X86brcond  : SDNode<"X86ISD::BRCOND",   SDTX86BrCond,
73                         [SDNPHasChain]>;
74 def X86setcc   : SDNode<"X86ISD::SETCC",    SDTX86SetCC>;
75
76 def X86cas : SDNode<"X86ISD::LCMPXCHG_DAG", SDTX86cas,
77                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
78                          SDNPMayLoad]>;
79 def X86cas8 : SDNode<"X86ISD::LCMPXCHG8_DAG", SDTX86cas8,
80                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
81                          SDNPMayLoad]>;
82
83 def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
84                         [SDNPHasChain, SDNPOptInFlag]>;
85
86 def X86callseq_start :
87                  SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
88                         [SDNPHasChain, SDNPOutFlag]>;
89 def X86callseq_end :
90                  SDNode<"ISD::CALLSEQ_END",   SDT_X86CallSeqEnd,
91                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;       
92
93 def X86call    : SDNode<"X86ISD::CALL",     SDT_X86Call,
94                         [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag]>;
95
96 def X86tailcall: SDNode<"X86ISD::TAILCALL",     SDT_X86Call,
97                         [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag]>;
98
99 def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr,
100                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore]>;
101 def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr,
102                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
103                          SDNPMayLoad]>;
104
105 def X86rdtsc   : SDNode<"X86ISD::RDTSC_DAG",SDTX86RdTsc,
106                         [SDNPHasChain, SDNPOutFlag, SDNPSideEffect]>;
107
108 def X86Wrapper    : SDNode<"X86ISD::Wrapper",     SDTX86Wrapper>;
109 def X86WrapperRIP : SDNode<"X86ISD::WrapperRIP",  SDTX86Wrapper>;
110
111 def X86tlsaddr : SDNode<"X86ISD::TLSADDR", SDT_X86TLSADDR,
112                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
113 def X86TLStp : SDNode<"X86ISD::THREAD_POINTER", SDT_X86TLSTP, []>;
114
115 def X86ehret : SDNode<"X86ISD::EH_RETURN", SDT_X86EHRET,
116                         [SDNPHasChain]>;
117
118 def X86tcret : SDNode<"X86ISD::TC_RETURN", SDT_X86TCRET, 
119                         [SDNPHasChain,  SDNPOptInFlag]>;
120
121 //===----------------------------------------------------------------------===//
122 // X86 Operand Definitions.
123 //
124
125 // *mem - Operand definitions for the funky X86 addressing mode operands.
126 //
127 class X86MemOperand<string printMethod> : Operand<iPTR> {
128   let PrintMethod = printMethod;
129   let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
130 }
131
132 def i8mem   : X86MemOperand<"printi8mem">;
133 def i16mem  : X86MemOperand<"printi16mem">;
134 def i32mem  : X86MemOperand<"printi32mem">;
135 def i64mem  : X86MemOperand<"printi64mem">;
136 def i128mem : X86MemOperand<"printi128mem">;
137 def f32mem  : X86MemOperand<"printf32mem">;
138 def f64mem  : X86MemOperand<"printf64mem">;
139 def f80mem  : X86MemOperand<"printf80mem">;
140 def f128mem : X86MemOperand<"printf128mem">;
141
142 def lea32mem : Operand<i32> {
143   let PrintMethod = "printi32mem";
144   let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
145 }
146
147 def SSECC : Operand<i8> {
148   let PrintMethod = "printSSECC";
149 }
150
151 def piclabel: Operand<i32> {
152   let PrintMethod = "printPICLabel";
153 }
154
155 // A couple of more descriptive operand definitions.
156 // 16-bits but only 8 bits are significant.
157 def i16i8imm  : Operand<i16>;
158 // 32-bits but only 8 bits are significant.
159 def i32i8imm  : Operand<i32>;
160
161 // Branch targets have OtherVT type.
162 def brtarget : Operand<OtherVT>;
163
164 //===----------------------------------------------------------------------===//
165 // X86 Complex Pattern Definitions.
166 //
167
168 // Define X86 specific addressing mode.
169 def addr      : ComplexPattern<iPTR, 4, "SelectAddr", [], []>;
170 def lea32addr : ComplexPattern<i32, 4, "SelectLEAAddr",
171                                [add, mul, shl, or, frameindex], []>;
172
173 //===----------------------------------------------------------------------===//
174 // X86 Instruction Predicate Definitions.
175 def HasMMX       : Predicate<"Subtarget->hasMMX()">;
176 def HasSSE1      : Predicate<"Subtarget->hasSSE1()">;
177 def HasSSE2      : Predicate<"Subtarget->hasSSE2()">;
178 def HasSSE3      : Predicate<"Subtarget->hasSSE3()">;
179 def HasSSSE3     : Predicate<"Subtarget->hasSSSE3()">;
180 def HasSSE41     : Predicate<"Subtarget->hasSSE41()">;
181 def HasSSE42     : Predicate<"Subtarget->hasSSE42()">;
182 def FPStackf32   : Predicate<"!Subtarget->hasSSE1()">;
183 def FPStackf64   : Predicate<"!Subtarget->hasSSE2()">;
184 def In32BitMode  : Predicate<"!Subtarget->is64Bit()">;
185 def In64BitMode  : Predicate<"Subtarget->is64Bit()">;
186 def SmallCode    : Predicate<"TM.getCodeModel() == CodeModel::Small">;
187 def NotSmallCode : Predicate<"TM.getCodeModel() != CodeModel::Small">;
188 def IsStatic     : Predicate<"TM.getRelocationModel() == Reloc::Static">;
189
190 //===----------------------------------------------------------------------===//
191 // X86 Instruction Format Definitions.
192 //
193
194 include "X86InstrFormats.td"
195
196 //===----------------------------------------------------------------------===//
197 // Pattern fragments...
198 //
199
200 // X86 specific condition code. These correspond to CondCode in
201 // X86InstrInfo.h. They must be kept in synch.
202 def X86_COND_A   : PatLeaf<(i8 0)>;
203 def X86_COND_AE  : PatLeaf<(i8 1)>;
204 def X86_COND_B   : PatLeaf<(i8 2)>;
205 def X86_COND_BE  : PatLeaf<(i8 3)>;
206 def X86_COND_E   : PatLeaf<(i8 4)>;
207 def X86_COND_G   : PatLeaf<(i8 5)>;
208 def X86_COND_GE  : PatLeaf<(i8 6)>;
209 def X86_COND_L   : PatLeaf<(i8 7)>;
210 def X86_COND_LE  : PatLeaf<(i8 8)>;
211 def X86_COND_NE  : PatLeaf<(i8 9)>;
212 def X86_COND_NO  : PatLeaf<(i8 10)>;
213 def X86_COND_NP  : PatLeaf<(i8 11)>;
214 def X86_COND_NS  : PatLeaf<(i8 12)>;
215 def X86_COND_O   : PatLeaf<(i8 13)>;
216 def X86_COND_P   : PatLeaf<(i8 14)>;
217 def X86_COND_S   : PatLeaf<(i8 15)>;
218
219 def i16immSExt8  : PatLeaf<(i16 imm), [{
220   // i16immSExt8 predicate - True if the 16-bit immediate fits in a 8-bit
221   // sign extended field.
222   return (int16_t)N->getValue() == (int8_t)N->getValue();
223 }]>;
224
225 def i32immSExt8  : PatLeaf<(i32 imm), [{
226   // i32immSExt8 predicate - True if the 32-bit immediate fits in a 8-bit
227   // sign extended field.
228   return (int32_t)N->getValue() == (int8_t)N->getValue();
229 }]>;
230
231 // Helper fragments for loads.
232 def loadi8  : PatFrag<(ops node:$ptr), (i8  (load node:$ptr))>;
233 def loadi16 : PatFrag<(ops node:$ptr), (i16 (load node:$ptr))>;
234 def loadi32 : PatFrag<(ops node:$ptr), (i32 (load node:$ptr))>;
235 def loadi64 : PatFrag<(ops node:$ptr), (i64 (load node:$ptr))>;
236
237 def loadf32 : PatFrag<(ops node:$ptr), (f32 (load node:$ptr))>;
238 def loadf64 : PatFrag<(ops node:$ptr), (f64 (load node:$ptr))>;
239 def loadf80 : PatFrag<(ops node:$ptr), (f80 (load node:$ptr))>;
240
241 def sextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>;
242 def sextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>;
243 def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>;
244
245 def zextloadi8i1   : PatFrag<(ops node:$ptr), (i8  (zextloadi1 node:$ptr))>;
246 def zextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>;
247 def zextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>;
248 def zextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
249 def zextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>;
250 def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>;
251
252 def extloadi8i1    : PatFrag<(ops node:$ptr), (i8  (extloadi1 node:$ptr))>;
253 def extloadi16i1   : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>;
254 def extloadi32i1   : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>;
255 def extloadi16i8   : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>;
256 def extloadi32i8   : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>;
257 def extloadi32i16  : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>;
258
259
260 // An 'and' node with a single use.
261 def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
262   return N->hasOneUse();
263 }]>;
264
265 //===----------------------------------------------------------------------===//
266 // Instruction list...
267 //
268
269 // ADJCALLSTACKDOWN/UP implicitly use/def ESP because they may be expanded into
270 // a stack adjustment and the codegen must know that they may modify the stack
271 // pointer before prolog-epilog rewriting occurs.
272 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
273 // sub / add which can clobber EFLAGS.
274 let Defs = [ESP, EFLAGS], Uses = [ESP] in {
275 def ADJCALLSTACKDOWN : I<0, Pseudo, (outs), (ins i32imm:$amt),
276                          "#ADJCALLSTACKDOWN",
277                          [(X86callseq_start imm:$amt)]>;
278 def ADJCALLSTACKUP   : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
279                          "#ADJCALLSTACKUP",
280                          [(X86callseq_end imm:$amt1, imm:$amt2)]>;
281 }
282 let isImplicitDef = 1 in {
283 def IMPLICIT_DEF_GR8  : I<0, Pseudo, (outs GR8:$dst), (ins),
284                          "#IMPLICIT_DEF $dst",
285                          [(set GR8:$dst, (undef))]>;
286 def IMPLICIT_DEF_GR16  : I<0, Pseudo, (outs GR16:$dst), (ins),
287                          "#IMPLICIT_DEF $dst",
288                          [(set GR16:$dst, (undef))]>;
289 def IMPLICIT_DEF_GR32  : I<0, Pseudo, (outs GR32:$dst), (ins),
290                          "#IMPLICIT_DEF $dst",
291                          [(set GR32:$dst, (undef))]>;
292 }
293
294 // Nop
295 let neverHasSideEffects = 1 in
296   def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", []>;
297
298 // PIC base
299 let neverHasSideEffects = 1, isNotDuplicable = 1 in
300   def MOVPC32r : Ii32<0xE8, Pseudo, (outs GR32:$reg), (ins piclabel:$label),
301                       "call\t$label\n\tpop{l}\t$reg", []>;
302
303 //===----------------------------------------------------------------------===//
304 //  Control Flow Instructions...
305 //
306
307 // Return instructions.
308 let isTerminator = 1, isReturn = 1, isBarrier = 1,
309     hasCtrlDep = 1, FPForm = SpecialFP, FPFormBits = SpecialFP.Value in {
310   def RET    : I   <0xC3, RawFrm, (outs), (ins variable_ops),
311                     "ret",
312                     [/*(X86retflag 0)*/ /*FIXME: Disabled: rdar://5791600*/]>;
313   def RETI   : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
314                     "ret\t$amt",
315                     [(X86retflag imm:$amt)]>;
316 }
317
318 // All branches are RawFrm, Void, Branch, and Terminators
319 let isBranch = 1, isTerminator = 1 in
320   class IBr<bits<8> opcode, dag ins, string asm, list<dag> pattern> :
321         I<opcode, RawFrm, (outs), ins, asm, pattern>;
322
323 let isBranch = 1, isBarrier = 1 in
324   def JMP : IBr<0xE9, (ins brtarget:$dst), "jmp\t$dst", [(br bb:$dst)]>;
325
326 // Indirect branches
327 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
328   def JMP32r     : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
329                      [(brind GR32:$dst)]>;
330   def JMP32m     : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
331                      [(brind (loadi32 addr:$dst))]>;
332 }
333
334 // Conditional branches
335 let Uses = [EFLAGS] in {
336 def JE  : IBr<0x84, (ins brtarget:$dst), "je\t$dst",
337               [(X86brcond bb:$dst, X86_COND_E, EFLAGS)]>, TB;
338 def JNE : IBr<0x85, (ins brtarget:$dst), "jne\t$dst",
339               [(X86brcond bb:$dst, X86_COND_NE, EFLAGS)]>, TB;
340 def JL  : IBr<0x8C, (ins brtarget:$dst), "jl\t$dst",
341               [(X86brcond bb:$dst, X86_COND_L, EFLAGS)]>, TB;
342 def JLE : IBr<0x8E, (ins brtarget:$dst), "jle\t$dst",
343               [(X86brcond bb:$dst, X86_COND_LE, EFLAGS)]>, TB;
344 def JG  : IBr<0x8F, (ins brtarget:$dst), "jg\t$dst",
345               [(X86brcond bb:$dst, X86_COND_G, EFLAGS)]>, TB;
346 def JGE : IBr<0x8D, (ins brtarget:$dst), "jge\t$dst",
347               [(X86brcond bb:$dst, X86_COND_GE, EFLAGS)]>, TB;
348
349 def JB  : IBr<0x82, (ins brtarget:$dst), "jb\t$dst",
350               [(X86brcond bb:$dst, X86_COND_B, EFLAGS)]>, TB;
351 def JBE : IBr<0x86, (ins brtarget:$dst), "jbe\t$dst",
352               [(X86brcond bb:$dst, X86_COND_BE, EFLAGS)]>, TB;
353 def JA  : IBr<0x87, (ins brtarget:$dst), "ja\t$dst",
354               [(X86brcond bb:$dst, X86_COND_A, EFLAGS)]>, TB;
355 def JAE : IBr<0x83, (ins brtarget:$dst), "jae\t$dst",
356               [(X86brcond bb:$dst, X86_COND_AE, EFLAGS)]>, TB;
357
358 def JS  : IBr<0x88, (ins brtarget:$dst), "js\t$dst",
359               [(X86brcond bb:$dst, X86_COND_S, EFLAGS)]>, TB;
360 def JNS : IBr<0x89, (ins brtarget:$dst), "jns\t$dst",
361               [(X86brcond bb:$dst, X86_COND_NS, EFLAGS)]>, TB;
362 def JP  : IBr<0x8A, (ins brtarget:$dst), "jp\t$dst",
363               [(X86brcond bb:$dst, X86_COND_P, EFLAGS)]>, TB;
364 def JNP : IBr<0x8B, (ins brtarget:$dst), "jnp\t$dst",
365               [(X86brcond bb:$dst, X86_COND_NP, EFLAGS)]>, TB;
366 def JO  : IBr<0x80, (ins brtarget:$dst), "jo\t$dst",
367               [(X86brcond bb:$dst, X86_COND_O, EFLAGS)]>, TB;
368 def JNO : IBr<0x81, (ins brtarget:$dst), "jno\t$dst",
369               [(X86brcond bb:$dst, X86_COND_NO, EFLAGS)]>, TB;
370 } // Uses = [EFLAGS]
371
372 //===----------------------------------------------------------------------===//
373 //  Call Instructions...
374 //
375 let isCall = 1 in
376   // All calls clobber the non-callee saved registers...
377   let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
378               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
379               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, EFLAGS] in {
380     def CALLpcrel32 : Ii32<0xE8, RawFrm, (outs), (ins i32imm:$dst,variable_ops),
381                            "call\t${dst:call}", []>;
382     def CALL32r     : I<0xFF, MRM2r, (outs), (ins GR32:$dst, variable_ops),
383                         "call\t{*}$dst", [(X86call GR32:$dst)]>;
384     def CALL32m     : I<0xFF, MRM2m, (outs), (ins i32mem:$dst, variable_ops),
385                         "call\t{*}$dst", []>;
386   }
387
388 // Tail call stuff.
389
390 def TAILCALL : I<0, Pseudo, (outs), (ins),
391                          "#TAILCALL",
392                          []>;
393
394 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
395 def TCRETURNdi : I<0, Pseudo, (outs), (ins i32imm:$dst, i32imm:$offset),
396                  "#TC_RETURN $dst $offset",
397                  []>;
398
399 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
400 def TCRETURNri : I<0, Pseudo, (outs), (ins GR32:$dst, i32imm:$offset),
401                  "#TC_RETURN $dst $offset",
402                  []>;
403
404 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
405   def TAILJMPd : IBr<0xE9, (ins i32imm:$dst), "jmp\t${dst:call}  # TAILCALL",
406                  []>;
407 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
408   def TAILJMPr : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst  # TAILCALL",
409                  []>;     
410 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
411   def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem:$dst),
412                    "jmp\t{*}$dst  # TAILCALL", []>;
413
414 //===----------------------------------------------------------------------===//
415 //  Miscellaneous Instructions...
416 //
417 let Defs = [EBP, ESP], Uses = [EBP, ESP], mayLoad = 1, neverHasSideEffects=1 in
418 def LEAVE    : I<0xC9, RawFrm,
419                  (outs), (ins), "leave", []>;
420
421 let Defs = [ESP], Uses = [ESP], neverHasSideEffects=1 in {
422 let mayLoad = 1 in
423 def POP32r   : I<0x58, AddRegFrm, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
424
425 let mayStore = 1 in
426 def PUSH32r  : I<0x50, AddRegFrm, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
427 }
428
429 let Defs = [ESP, EFLAGS], Uses = [ESP], mayLoad = 1, neverHasSideEffects=1 in
430 def POPFD    : I<0x9D, RawFrm, (outs), (ins), "popf", []>;
431 let Defs = [ESP], Uses = [ESP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in
432 def PUSHFD   : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
433
434 let isTwoAddress = 1 in                               // GR32 = bswap GR32
435   def BSWAP32r : I<0xC8, AddRegFrm,
436                    (outs GR32:$dst), (ins GR32:$src),
437                    "bswap{l}\t$dst", 
438                    [(set GR32:$dst, (bswap GR32:$src))]>, TB;
439
440
441 // Bit scan instructions.
442 let Defs = [EFLAGS] in {
443 def BSF16rr  : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
444                  "bsf{w}\t{$src, $dst|$dst, $src}",
445                  [(set GR16:$dst, (X86bsf GR16:$src)), (implicit EFLAGS)]>, TB;
446 def BSF16rm  : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
447                  "bsf{w}\t{$src, $dst|$dst, $src}",
448                  [(set GR16:$dst, (X86bsf (loadi16 addr:$src))),
449                   (implicit EFLAGS)]>, TB;
450 def BSF32rr  : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
451                  "bsf{l}\t{$src, $dst|$dst, $src}",
452                  [(set GR32:$dst, (X86bsf GR32:$src)), (implicit EFLAGS)]>, TB;
453 def BSF32rm  : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
454                  "bsf{l}\t{$src, $dst|$dst, $src}",
455                  [(set GR32:$dst, (X86bsf (loadi32 addr:$src))),
456                   (implicit EFLAGS)]>, TB;
457
458 def BSR16rr  : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
459                  "bsr{w}\t{$src, $dst|$dst, $src}",
460                  [(set GR16:$dst, (X86bsr GR16:$src)), (implicit EFLAGS)]>, TB;
461 def BSR16rm  : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
462                  "bsr{w}\t{$src, $dst|$dst, $src}",
463                  [(set GR16:$dst, (X86bsr (loadi16 addr:$src))),
464                   (implicit EFLAGS)]>, TB;
465 def BSR32rr  : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
466                  "bsr{l}\t{$src, $dst|$dst, $src}",
467                  [(set GR32:$dst, (X86bsr GR32:$src)), (implicit EFLAGS)]>, TB;
468 def BSR32rm  : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
469                  "bsr{l}\t{$src, $dst|$dst, $src}",
470                  [(set GR32:$dst, (X86bsr (loadi32 addr:$src))),
471                   (implicit EFLAGS)]>, TB;
472 } // Defs = [EFLAGS]
473
474 let neverHasSideEffects = 1 in
475 def LEA16r   : I<0x8D, MRMSrcMem,
476                  (outs GR16:$dst), (ins i32mem:$src),
477                  "lea{w}\t{$src|$dst}, {$dst|$src}", []>, OpSize;
478 def LEA32r   : I<0x8D, MRMSrcMem,
479                  (outs GR32:$dst), (ins lea32mem:$src),
480                  "lea{l}\t{$src|$dst}, {$dst|$src}",
481                  [(set GR32:$dst, lea32addr:$src)]>, Requires<[In32BitMode]>;
482
483 let Defs = [ECX,EDI,ESI], Uses = [ECX,EDI,ESI] in {
484 def REP_MOVSB : I<0xA4, RawFrm, (outs), (ins), "{rep;movsb|rep movsb}",
485                   [(X86rep_movs i8)]>, REP;
486 def REP_MOVSW : I<0xA5, RawFrm, (outs), (ins), "{rep;movsw|rep movsw}",
487                   [(X86rep_movs i16)]>, REP, OpSize;
488 def REP_MOVSD : I<0xA5, RawFrm, (outs), (ins), "{rep;movsl|rep movsd}",
489                   [(X86rep_movs i32)]>, REP;
490 }
491
492 let Defs = [ECX,EDI], Uses = [AL,ECX,EDI] in
493 def REP_STOSB : I<0xAA, RawFrm, (outs), (ins), "{rep;stosb|rep stosb}",
494                   [(X86rep_stos i8)]>, REP;
495 let Defs = [ECX,EDI], Uses = [AX,ECX,EDI] in
496 def REP_STOSW : I<0xAB, RawFrm, (outs), (ins), "{rep;stosw|rep stosw}",
497                   [(X86rep_stos i16)]>, REP, OpSize;
498 let Defs = [ECX,EDI], Uses = [EAX,ECX,EDI] in
499 def REP_STOSD : I<0xAB, RawFrm, (outs), (ins), "{rep;stosl|rep stosd}",
500                   [(X86rep_stos i32)]>, REP;
501
502 let Defs = [RAX, RDX] in
503 def RDTSC : I<0x31, RawFrm, (outs), (ins), "rdtsc", [(X86rdtsc)]>,
504             TB;
505
506 let isBarrier = 1, hasCtrlDep = 1 in {
507 def TRAP    : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
508 }
509
510 //===----------------------------------------------------------------------===//
511 //  Input/Output Instructions...
512 //
513 let Defs = [AL], Uses = [DX] in
514 def IN8rr  : I<0xEC, RawFrm, (outs), (ins),
515                "in{b}\t{%dx, %al|%AL, %DX}", []>;
516 let Defs = [AX], Uses = [DX] in
517 def IN16rr : I<0xED, RawFrm, (outs), (ins),
518                "in{w}\t{%dx, %ax|%AX, %DX}", []>,  OpSize;
519 let Defs = [EAX], Uses = [DX] in
520 def IN32rr : I<0xED, RawFrm, (outs), (ins),
521                "in{l}\t{%dx, %eax|%EAX, %DX}", []>;
522
523 let Defs = [AL] in
524 def IN8ri  : Ii8<0xE4, RawFrm, (outs), (ins i16i8imm:$port),
525                   "in{b}\t{$port, %al|%AL, $port}", []>;
526 let Defs = [AX] in
527 def IN16ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
528                   "in{w}\t{$port, %ax|%AX, $port}", []>, OpSize;
529 let Defs = [EAX] in
530 def IN32ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
531                   "in{l}\t{$port, %eax|%EAX, $port}", []>;
532
533 let Uses = [DX, AL] in
534 def OUT8rr  : I<0xEE, RawFrm, (outs), (ins),
535                 "out{b}\t{%al, %dx|%DX, %AL}", []>;
536 let Uses = [DX, AX] in
537 def OUT16rr : I<0xEF, RawFrm, (outs), (ins),
538                 "out{w}\t{%ax, %dx|%DX, %AX}", []>, OpSize;
539 let Uses = [DX, EAX] in
540 def OUT32rr : I<0xEF, RawFrm, (outs), (ins),
541                 "out{l}\t{%eax, %dx|%DX, %EAX}", []>;
542
543 let Uses = [AL] in
544 def OUT8ir  : Ii8<0xE6, RawFrm, (outs), (ins i16i8imm:$port),
545                    "out{b}\t{%al, $port|$port, %AL}", []>;
546 let Uses = [AX] in
547 def OUT16ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
548                    "out{w}\t{%ax, $port|$port, %AX}", []>, OpSize;
549 let Uses = [EAX] in
550 def OUT32ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
551                    "out{l}\t{%eax, $port|$port, %EAX}", []>;
552
553 //===----------------------------------------------------------------------===//
554 //  Move Instructions...
555 //
556 let neverHasSideEffects = 1 in {
557 def MOV8rr  : I<0x88, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src),
558                 "mov{b}\t{$src, $dst|$dst, $src}", []>;
559 def MOV16rr : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
560                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
561 def MOV32rr : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
562                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
563 }
564 let isReMaterializable = 1 in {
565 def MOV8ri  : Ii8 <0xB0, AddRegFrm, (outs GR8 :$dst), (ins i8imm :$src),
566                    "mov{b}\t{$src, $dst|$dst, $src}",
567                    [(set GR8:$dst, imm:$src)]>;
568 def MOV16ri : Ii16<0xB8, AddRegFrm, (outs GR16:$dst), (ins i16imm:$src),
569                    "mov{w}\t{$src, $dst|$dst, $src}",
570                    [(set GR16:$dst, imm:$src)]>, OpSize;
571 def MOV32ri : Ii32<0xB8, AddRegFrm, (outs GR32:$dst), (ins i32imm:$src),
572                    "mov{l}\t{$src, $dst|$dst, $src}",
573                    [(set GR32:$dst, imm:$src)]>;
574 }
575 def MOV8mi  : Ii8 <0xC6, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src),
576                    "mov{b}\t{$src, $dst|$dst, $src}",
577                    [(store (i8 imm:$src), addr:$dst)]>;
578 def MOV16mi : Ii16<0xC7, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src),
579                    "mov{w}\t{$src, $dst|$dst, $src}",
580                    [(store (i16 imm:$src), addr:$dst)]>, OpSize;
581 def MOV32mi : Ii32<0xC7, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src),
582                    "mov{l}\t{$src, $dst|$dst, $src}",
583                    [(store (i32 imm:$src), addr:$dst)]>;
584
585 let isSimpleLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in {
586 def MOV8rm  : I<0x8A, MRMSrcMem, (outs GR8 :$dst), (ins i8mem :$src),
587                 "mov{b}\t{$src, $dst|$dst, $src}",
588                 [(set GR8:$dst, (load addr:$src))]>;
589 def MOV16rm : I<0x8B, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
590                 "mov{w}\t{$src, $dst|$dst, $src}",
591                 [(set GR16:$dst, (load addr:$src))]>, OpSize;
592 def MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
593                 "mov{l}\t{$src, $dst|$dst, $src}",
594                 [(set GR32:$dst, (load addr:$src))]>;
595 }
596
597 def MOV8mr  : I<0x88, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src),
598                 "mov{b}\t{$src, $dst|$dst, $src}",
599                 [(store GR8:$src, addr:$dst)]>;
600 def MOV16mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
601                 "mov{w}\t{$src, $dst|$dst, $src}",
602                 [(store GR16:$src, addr:$dst)]>, OpSize;
603 def MOV32mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
604                 "mov{l}\t{$src, $dst|$dst, $src}",
605                 [(store GR32:$src, addr:$dst)]>;
606                 
607 //===----------------------------------------------------------------------===//
608 //  Fixed-Register Multiplication and Division Instructions...
609 //
610
611 // Extra precision multiplication
612 let Defs = [AL,AH,EFLAGS], Uses = [AL] in
613 def MUL8r  : I<0xF6, MRM4r, (outs),  (ins GR8:$src), "mul{b}\t$src",
614                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
615                // This probably ought to be moved to a def : Pat<> if the
616                // syntax can be accepted.
617                [(set AL, (mul AL, GR8:$src))]>;               // AL,AH = AL*GR8
618 let Defs = [AX,DX,EFLAGS], Uses = [AX], neverHasSideEffects = 1 in
619 def MUL16r : I<0xF7, MRM4r, (outs),  (ins GR16:$src), "mul{w}\t$src", []>,
620              OpSize;    // AX,DX = AX*GR16
621 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX], neverHasSideEffects = 1 in
622 def MUL32r : I<0xF7, MRM4r, (outs),  (ins GR32:$src), "mul{l}\t$src", []>;
623                        // EAX,EDX = EAX*GR32
624 let Defs = [AL,AH,EFLAGS], Uses = [AL] in
625 def MUL8m  : I<0xF6, MRM4m, (outs), (ins i8mem :$src),
626                "mul{b}\t$src",
627                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
628                // This probably ought to be moved to a def : Pat<> if the
629                // syntax can be accepted.
630                [(set AL, (mul AL, (loadi8 addr:$src)))]>;   // AL,AH = AL*[mem8]
631 let mayLoad = 1, neverHasSideEffects = 1 in {
632 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
633 def MUL16m : I<0xF7, MRM4m, (outs), (ins i16mem:$src),
634                "mul{w}\t$src", []>, OpSize; // AX,DX = AX*[mem16]
635 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
636 def MUL32m : I<0xF7, MRM4m, (outs), (ins i32mem:$src),
637               "mul{l}\t$src", []>;          // EAX,EDX = EAX*[mem32]
638 }
639
640 let neverHasSideEffects = 1 in {
641 let Defs = [AL,AH,EFLAGS], Uses = [AL] in
642 def IMUL8r  : I<0xF6, MRM5r, (outs),  (ins GR8:$src), "imul{b}\t$src", []>;
643               // AL,AH = AL*GR8
644 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
645 def IMUL16r : I<0xF7, MRM5r, (outs),  (ins GR16:$src), "imul{w}\t$src", []>,
646               OpSize;    // AX,DX = AX*GR16
647 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
648 def IMUL32r : I<0xF7, MRM5r, (outs),  (ins GR32:$src), "imul{l}\t$src", []>;
649               // EAX,EDX = EAX*GR32
650 let mayLoad = 1 in {
651 let Defs = [AL,AH,EFLAGS], Uses = [AL] in
652 def IMUL8m  : I<0xF6, MRM5m, (outs), (ins i8mem :$src),
653                 "imul{b}\t$src", []>;    // AL,AH = AL*[mem8]
654 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
655 def IMUL16m : I<0xF7, MRM5m, (outs), (ins i16mem:$src),
656                 "imul{w}\t$src", []>, OpSize; // AX,DX = AX*[mem16]
657 let Defs = [EAX,EDX], Uses = [EAX] in
658 def IMUL32m : I<0xF7, MRM5m, (outs), (ins i32mem:$src),
659                 "imul{l}\t$src", []>;  // EAX,EDX = EAX*[mem32]
660 }
661
662 // unsigned division/remainder
663 let Defs = [AX,EFLAGS], Uses = [AL,AH] in
664 def DIV8r  : I<0xF6, MRM6r, (outs),  (ins GR8:$src),          // AX/r8 = AL,AH
665                "div{b}\t$src", []>;
666 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
667 def DIV16r : I<0xF7, MRM6r, (outs),  (ins GR16:$src),         // DX:AX/r16 = AX,DX
668                "div{w}\t$src", []>, OpSize;
669 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
670 def DIV32r : I<0xF7, MRM6r, (outs),  (ins GR32:$src),         // EDX:EAX/r32 = EAX,EDX
671                "div{l}\t$src", []>;
672 let mayLoad = 1 in {
673 let Defs = [AX,EFLAGS], Uses = [AL,AH] in
674 def DIV8m  : I<0xF6, MRM6m, (outs), (ins i8mem:$src),       // AX/[mem8] = AL,AH
675                "div{b}\t$src", []>;
676 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
677 def DIV16m : I<0xF7, MRM6m, (outs), (ins i16mem:$src),      // DX:AX/[mem16] = AX,DX
678                "div{w}\t$src", []>, OpSize;
679 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
680 def DIV32m : I<0xF7, MRM6m, (outs), (ins i32mem:$src),      // EDX:EAX/[mem32] = EAX,EDX
681                "div{l}\t$src", []>;
682 }
683
684 // Signed division/remainder.
685 let Defs = [AX,EFLAGS], Uses = [AL,AH] in
686 def IDIV8r : I<0xF6, MRM7r, (outs),  (ins GR8:$src),          // AX/r8 = AL,AH
687                "idiv{b}\t$src", []>;
688 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
689 def IDIV16r: I<0xF7, MRM7r, (outs),  (ins GR16:$src),         // DX:AX/r16 = AX,DX
690                "idiv{w}\t$src", []>, OpSize;
691 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
692 def IDIV32r: I<0xF7, MRM7r, (outs),  (ins GR32:$src),         // EDX:EAX/r32 = EAX,EDX
693                "idiv{l}\t$src", []>;
694 let mayLoad = 1, mayLoad = 1 in {
695 let Defs = [AX,EFLAGS], Uses = [AL,AH] in
696 def IDIV8m : I<0xF6, MRM7m, (outs), (ins i8mem:$src),      // AX/[mem8] = AL,AH
697                "idiv{b}\t$src", []>;
698 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
699 def IDIV16m: I<0xF7, MRM7m, (outs), (ins i16mem:$src),     // DX:AX/[mem16] = AX,DX
700                "idiv{w}\t$src", []>, OpSize;
701 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
702 def IDIV32m: I<0xF7, MRM7m, (outs), (ins i32mem:$src),     // EDX:EAX/[mem32] = EAX,EDX
703                "idiv{l}\t$src", []>;
704 }
705 } // neverHasSideEffects
706
707 //===----------------------------------------------------------------------===//
708 //  Two address Instructions.
709 //
710 let isTwoAddress = 1 in {
711
712 // Conditional moves
713 let Uses = [EFLAGS] in {
714 let isCommutable = 1 in {
715 def CMOVB16rr : I<0x42, MRMSrcReg,       // if <u, GR16 = GR16
716                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
717                   "cmovb\t{$src2, $dst|$dst, $src2}",
718                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
719                                    X86_COND_B, EFLAGS))]>,
720                   TB, OpSize;
721 def CMOVB32rr : I<0x42, MRMSrcReg,       // if <u, GR32 = GR32
722                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
723                   "cmovb\t{$src2, $dst|$dst, $src2}",
724                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
725                                    X86_COND_B, EFLAGS))]>,
726                    TB;
727
728 def CMOVAE16rr: I<0x43, MRMSrcReg,       // if >=u, GR16 = GR16
729                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
730                   "cmovae\t{$src2, $dst|$dst, $src2}",
731                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
732                                    X86_COND_AE, EFLAGS))]>,
733                    TB, OpSize;
734 def CMOVAE32rr: I<0x43, MRMSrcReg,       // if >=u, GR32 = GR32
735                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
736                   "cmovae\t{$src2, $dst|$dst, $src2}",
737                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
738                                    X86_COND_AE, EFLAGS))]>,
739                    TB;
740 def CMOVE16rr : I<0x44, MRMSrcReg,       // if ==, GR16 = GR16
741                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
742                   "cmove\t{$src2, $dst|$dst, $src2}",
743                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
744                                    X86_COND_E, EFLAGS))]>,
745                    TB, OpSize;
746 def CMOVE32rr : I<0x44, MRMSrcReg,       // if ==, GR32 = GR32
747                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
748                   "cmove\t{$src2, $dst|$dst, $src2}",
749                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
750                                    X86_COND_E, EFLAGS))]>,
751                    TB;
752 def CMOVNE16rr: I<0x45, MRMSrcReg,       // if !=, GR16 = GR16
753                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
754                   "cmovne\t{$src2, $dst|$dst, $src2}",
755                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
756                                    X86_COND_NE, EFLAGS))]>,
757                    TB, OpSize;
758 def CMOVNE32rr: I<0x45, MRMSrcReg,       // if !=, GR32 = GR32
759                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
760                   "cmovne\t{$src2, $dst|$dst, $src2}",
761                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
762                                    X86_COND_NE, EFLAGS))]>,
763                    TB;
764 def CMOVBE16rr: I<0x46, MRMSrcReg,       // if <=u, GR16 = GR16
765                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
766                   "cmovbe\t{$src2, $dst|$dst, $src2}",
767                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
768                                    X86_COND_BE, EFLAGS))]>,
769                    TB, OpSize;
770 def CMOVBE32rr: I<0x46, MRMSrcReg,       // if <=u, GR32 = GR32
771                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
772                   "cmovbe\t{$src2, $dst|$dst, $src2}",
773                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
774                                    X86_COND_BE, EFLAGS))]>,
775                    TB;
776 def CMOVA16rr : I<0x47, MRMSrcReg,       // if >u, GR16 = GR16
777                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
778                   "cmova\t{$src2, $dst|$dst, $src2}",
779                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
780                                    X86_COND_A, EFLAGS))]>,
781                    TB, OpSize;
782 def CMOVA32rr : I<0x47, MRMSrcReg,       // if >u, GR32 = GR32
783                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
784                   "cmova\t{$src2, $dst|$dst, $src2}",
785                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
786                                    X86_COND_A, EFLAGS))]>,
787                    TB;
788 def CMOVL16rr : I<0x4C, MRMSrcReg,       // if <s, GR16 = GR16
789                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
790                   "cmovl\t{$src2, $dst|$dst, $src2}",
791                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
792                                    X86_COND_L, EFLAGS))]>,
793                    TB, OpSize;
794 def CMOVL32rr : I<0x4C, MRMSrcReg,       // if <s, GR32 = GR32
795                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
796                   "cmovl\t{$src2, $dst|$dst, $src2}",
797                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
798                                    X86_COND_L, EFLAGS))]>,
799                    TB;
800 def CMOVGE16rr: I<0x4D, MRMSrcReg,       // if >=s, GR16 = GR16
801                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
802                   "cmovge\t{$src2, $dst|$dst, $src2}",
803                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
804                                    X86_COND_GE, EFLAGS))]>,
805                    TB, OpSize;
806 def CMOVGE32rr: I<0x4D, MRMSrcReg,       // if >=s, GR32 = GR32
807                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
808                   "cmovge\t{$src2, $dst|$dst, $src2}",
809                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
810                                    X86_COND_GE, EFLAGS))]>,
811                    TB;
812 def CMOVLE16rr: I<0x4E, MRMSrcReg,       // if <=s, GR16 = GR16
813                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
814                   "cmovle\t{$src2, $dst|$dst, $src2}",
815                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
816                                    X86_COND_LE, EFLAGS))]>,
817                    TB, OpSize;
818 def CMOVLE32rr: I<0x4E, MRMSrcReg,       // if <=s, GR32 = GR32
819                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
820                   "cmovle\t{$src2, $dst|$dst, $src2}",
821                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
822                                    X86_COND_LE, EFLAGS))]>,
823                    TB;
824 def CMOVG16rr : I<0x4F, MRMSrcReg,       // if >s, GR16 = GR16
825                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
826                   "cmovg\t{$src2, $dst|$dst, $src2}",
827                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
828                                    X86_COND_G, EFLAGS))]>,
829                    TB, OpSize;
830 def CMOVG32rr : I<0x4F, MRMSrcReg,       // if >s, GR32 = GR32
831                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
832                   "cmovg\t{$src2, $dst|$dst, $src2}",
833                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
834                                    X86_COND_G, EFLAGS))]>,
835                    TB;
836 def CMOVS16rr : I<0x48, MRMSrcReg,       // if signed, GR16 = GR16
837                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
838                   "cmovs\t{$src2, $dst|$dst, $src2}",
839                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
840                                    X86_COND_S, EFLAGS))]>,
841                   TB, OpSize;
842 def CMOVS32rr : I<0x48, MRMSrcReg,       // if signed, GR32 = GR32
843                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
844                   "cmovs\t{$src2, $dst|$dst, $src2}",
845                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
846                                    X86_COND_S, EFLAGS))]>,
847                   TB;
848 def CMOVNS16rr: I<0x49, MRMSrcReg,       // if !signed, GR16 = GR16
849                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
850                   "cmovns\t{$src2, $dst|$dst, $src2}",
851                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
852                                    X86_COND_NS, EFLAGS))]>,
853                   TB, OpSize;
854 def CMOVNS32rr: I<0x49, MRMSrcReg,       // if !signed, GR32 = GR32
855                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
856                   "cmovns\t{$src2, $dst|$dst, $src2}",
857                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
858                                    X86_COND_NS, EFLAGS))]>,
859                   TB;
860 def CMOVP16rr : I<0x4A, MRMSrcReg,       // if parity, GR16 = GR16
861                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
862                   "cmovp\t{$src2, $dst|$dst, $src2}",
863                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
864                                    X86_COND_P, EFLAGS))]>,
865                   TB, OpSize;
866 def CMOVP32rr : I<0x4A, MRMSrcReg,       // if parity, GR32 = GR32
867                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
868                   "cmovp\t{$src2, $dst|$dst, $src2}",
869                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
870                                    X86_COND_P, EFLAGS))]>,
871                   TB;
872 def CMOVNP16rr : I<0x4B, MRMSrcReg,       // if !parity, GR16 = GR16
873                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
874                   "cmovnp\t{$src2, $dst|$dst, $src2}",
875                    [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
876                                     X86_COND_NP, EFLAGS))]>,
877                   TB, OpSize;
878 def CMOVNP32rr : I<0x4B, MRMSrcReg,       // if !parity, GR32 = GR32
879                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
880                   "cmovnp\t{$src2, $dst|$dst, $src2}",
881                    [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
882                                     X86_COND_NP, EFLAGS))]>,
883                   TB;
884 } // isCommutable = 1
885
886 def CMOVNP32rm : I<0x4B, MRMSrcMem,       // if !parity, GR32 = [mem32]
887                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
888                   "cmovnp\t{$src2, $dst|$dst, $src2}",
889                    [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
890                                     X86_COND_NP, EFLAGS))]>,
891                   TB;
892
893 def CMOVB16rm : I<0x42, MRMSrcMem,       // if <u, GR16 = [mem16]
894                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
895                   "cmovb\t{$src2, $dst|$dst, $src2}",
896                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
897                                    X86_COND_B, EFLAGS))]>,
898                   TB, OpSize;
899 def CMOVB32rm : I<0x42, MRMSrcMem,       // if <u, GR32 = [mem32]
900                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
901                   "cmovb\t{$src2, $dst|$dst, $src2}",
902                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
903                                    X86_COND_B, EFLAGS))]>,
904                    TB;
905 def CMOVAE16rm: I<0x43, MRMSrcMem,       // if >=u, GR16 = [mem16]
906                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
907                   "cmovae\t{$src2, $dst|$dst, $src2}",
908                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
909                                    X86_COND_AE, EFLAGS))]>,
910                    TB, OpSize;
911 def CMOVAE32rm: I<0x43, MRMSrcMem,       // if >=u, GR32 = [mem32]
912                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
913                   "cmovae\t{$src2, $dst|$dst, $src2}",
914                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
915                                    X86_COND_AE, EFLAGS))]>,
916                    TB;
917 def CMOVE16rm : I<0x44, MRMSrcMem,       // if ==, GR16 = [mem16]
918                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
919                   "cmove\t{$src2, $dst|$dst, $src2}",
920                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
921                                    X86_COND_E, EFLAGS))]>,
922                    TB, OpSize;
923 def CMOVE32rm : I<0x44, MRMSrcMem,       // if ==, GR32 = [mem32]
924                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
925                   "cmove\t{$src2, $dst|$dst, $src2}",
926                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
927                                    X86_COND_E, EFLAGS))]>,
928                    TB;
929 def CMOVNE16rm: I<0x45, MRMSrcMem,       // if !=, GR16 = [mem16]
930                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
931                   "cmovne\t{$src2, $dst|$dst, $src2}",
932                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
933                                    X86_COND_NE, EFLAGS))]>,
934                    TB, OpSize;
935 def CMOVNE32rm: I<0x45, MRMSrcMem,       // if !=, GR32 = [mem32]
936                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
937                   "cmovne\t{$src2, $dst|$dst, $src2}",
938                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
939                                    X86_COND_NE, EFLAGS))]>,
940                    TB;
941 def CMOVBE16rm: I<0x46, MRMSrcMem,       // if <=u, GR16 = [mem16]
942                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
943                   "cmovbe\t{$src2, $dst|$dst, $src2}",
944                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
945                                    X86_COND_BE, EFLAGS))]>,
946                    TB, OpSize;
947 def CMOVBE32rm: I<0x46, MRMSrcMem,       // if <=u, GR32 = [mem32]
948                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
949                   "cmovbe\t{$src2, $dst|$dst, $src2}",
950                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
951                                    X86_COND_BE, EFLAGS))]>,
952                    TB;
953 def CMOVA16rm : I<0x47, MRMSrcMem,       // if >u, GR16 = [mem16]
954                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
955                   "cmova\t{$src2, $dst|$dst, $src2}",
956                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
957                                    X86_COND_A, EFLAGS))]>,
958                    TB, OpSize;
959 def CMOVA32rm : I<0x47, MRMSrcMem,       // if >u, GR32 = [mem32]
960                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
961                   "cmova\t{$src2, $dst|$dst, $src2}",
962                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
963                                    X86_COND_A, EFLAGS))]>,
964                    TB;
965 def CMOVL16rm : I<0x4C, MRMSrcMem,       // if <s, GR16 = [mem16]
966                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
967                   "cmovl\t{$src2, $dst|$dst, $src2}",
968                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
969                                    X86_COND_L, EFLAGS))]>,
970                    TB, OpSize;
971 def CMOVL32rm : I<0x4C, MRMSrcMem,       // if <s, GR32 = [mem32]
972                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
973                   "cmovl\t{$src2, $dst|$dst, $src2}",
974                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
975                                    X86_COND_L, EFLAGS))]>,
976                    TB;
977 def CMOVGE16rm: I<0x4D, MRMSrcMem,       // if >=s, GR16 = [mem16]
978                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
979                   "cmovge\t{$src2, $dst|$dst, $src2}",
980                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
981                                    X86_COND_GE, EFLAGS))]>,
982                    TB, OpSize;
983 def CMOVGE32rm: I<0x4D, MRMSrcMem,       // if >=s, GR32 = [mem32]
984                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
985                   "cmovge\t{$src2, $dst|$dst, $src2}",
986                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
987                                    X86_COND_GE, EFLAGS))]>,
988                    TB;
989 def CMOVLE16rm: I<0x4E, MRMSrcMem,       // if <=s, GR16 = [mem16]
990                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
991                   "cmovle\t{$src2, $dst|$dst, $src2}",
992                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
993                                    X86_COND_LE, EFLAGS))]>,
994                    TB, OpSize;
995 def CMOVLE32rm: I<0x4E, MRMSrcMem,       // if <=s, GR32 = [mem32]
996                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
997                   "cmovle\t{$src2, $dst|$dst, $src2}",
998                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
999                                    X86_COND_LE, EFLAGS))]>,
1000                    TB;
1001 def CMOVG16rm : I<0x4F, MRMSrcMem,       // if >s, GR16 = [mem16]
1002                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1003                   "cmovg\t{$src2, $dst|$dst, $src2}",
1004                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1005                                    X86_COND_G, EFLAGS))]>,
1006                    TB, OpSize;
1007 def CMOVG32rm : I<0x4F, MRMSrcMem,       // if >s, GR32 = [mem32]
1008                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1009                   "cmovg\t{$src2, $dst|$dst, $src2}",
1010                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1011                                    X86_COND_G, EFLAGS))]>,
1012                    TB;
1013 def CMOVS16rm : I<0x48, MRMSrcMem,       // if signed, GR16 = [mem16]
1014                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1015                   "cmovs\t{$src2, $dst|$dst, $src2}",
1016                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1017                                    X86_COND_S, EFLAGS))]>,
1018                   TB, OpSize;
1019 def CMOVS32rm : I<0x48, MRMSrcMem,       // if signed, GR32 = [mem32]
1020                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1021                   "cmovs\t{$src2, $dst|$dst, $src2}",
1022                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1023                                    X86_COND_S, EFLAGS))]>,
1024                   TB;
1025 def CMOVNS16rm: I<0x49, MRMSrcMem,       // if !signed, GR16 = [mem16]
1026                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1027                   "cmovns\t{$src2, $dst|$dst, $src2}",
1028                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1029                                    X86_COND_NS, EFLAGS))]>,
1030                   TB, OpSize;
1031 def CMOVNS32rm: I<0x49, MRMSrcMem,       // if !signed, GR32 = [mem32]
1032                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1033                   "cmovns\t{$src2, $dst|$dst, $src2}",
1034                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1035                                    X86_COND_NS, EFLAGS))]>,
1036                   TB;
1037 def CMOVP16rm : I<0x4A, MRMSrcMem,       // if parity, GR16 = [mem16]
1038                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1039                   "cmovp\t{$src2, $dst|$dst, $src2}",
1040                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1041                                    X86_COND_P, EFLAGS))]>,
1042                   TB, OpSize;
1043 def CMOVP32rm : I<0x4A, MRMSrcMem,       // if parity, GR32 = [mem32]
1044                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1045                   "cmovp\t{$src2, $dst|$dst, $src2}",
1046                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1047                                    X86_COND_P, EFLAGS))]>,
1048                   TB;
1049 def CMOVNP16rm : I<0x4B, MRMSrcMem,       // if !parity, GR16 = [mem16]
1050                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1051                   "cmovnp\t{$src2, $dst|$dst, $src2}",
1052                    [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1053                                     X86_COND_NP, EFLAGS))]>,
1054                   TB, OpSize;
1055 } // Uses = [EFLAGS]
1056
1057
1058 // unary instructions
1059 let CodeSize = 2 in {
1060 let Defs = [EFLAGS] in {
1061 def NEG8r  : I<0xF6, MRM3r, (outs GR8 :$dst), (ins GR8 :$src), "neg{b}\t$dst",
1062                [(set GR8:$dst, (ineg GR8:$src))]>;
1063 def NEG16r : I<0xF7, MRM3r, (outs GR16:$dst), (ins GR16:$src), "neg{w}\t$dst",
1064                [(set GR16:$dst, (ineg GR16:$src))]>, OpSize;
1065 def NEG32r : I<0xF7, MRM3r, (outs GR32:$dst), (ins GR32:$src), "neg{l}\t$dst",
1066                [(set GR32:$dst, (ineg GR32:$src))]>;
1067 let isTwoAddress = 0 in {
1068   def NEG8m  : I<0xF6, MRM3m, (outs), (ins i8mem :$dst), "neg{b}\t$dst",
1069                  [(store (ineg (loadi8 addr:$dst)), addr:$dst)]>;
1070   def NEG16m : I<0xF7, MRM3m, (outs), (ins i16mem:$dst), "neg{w}\t$dst",
1071                  [(store (ineg (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
1072   def NEG32m : I<0xF7, MRM3m, (outs), (ins i32mem:$dst), "neg{l}\t$dst",
1073                  [(store (ineg (loadi32 addr:$dst)), addr:$dst)]>;
1074
1075 }
1076 } // Defs = [EFLAGS]
1077
1078 def NOT8r  : I<0xF6, MRM2r, (outs GR8 :$dst), (ins GR8 :$src), "not{b}\t$dst",
1079                [(set GR8:$dst, (not GR8:$src))]>;
1080 def NOT16r : I<0xF7, MRM2r, (outs GR16:$dst), (ins GR16:$src), "not{w}\t$dst",
1081                [(set GR16:$dst, (not GR16:$src))]>, OpSize;
1082 def NOT32r : I<0xF7, MRM2r, (outs GR32:$dst), (ins GR32:$src), "not{l}\t$dst",
1083                [(set GR32:$dst, (not GR32:$src))]>;
1084 let isTwoAddress = 0 in {
1085   def NOT8m  : I<0xF6, MRM2m, (outs), (ins i8mem :$dst), "not{b}\t$dst",
1086                  [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
1087   def NOT16m : I<0xF7, MRM2m, (outs), (ins i16mem:$dst), "not{w}\t$dst",
1088                  [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
1089   def NOT32m : I<0xF7, MRM2m, (outs), (ins i32mem:$dst), "not{l}\t$dst",
1090                  [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
1091 }
1092 } // CodeSize
1093
1094 // TODO: inc/dec is slow for P4, but fast for Pentium-M.
1095 let Defs = [EFLAGS] in {
1096 let CodeSize = 2 in
1097 def INC8r  : I<0xFE, MRM0r, (outs GR8 :$dst), (ins GR8 :$src), "inc{b}\t$dst",
1098                [(set GR8:$dst, (add GR8:$src, 1))]>;
1099 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {  // Can xform into LEA.
1100 def INC16r : I<0x40, AddRegFrm, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
1101                [(set GR16:$dst, (add GR16:$src, 1))]>,
1102              OpSize, Requires<[In32BitMode]>;
1103 def INC32r : I<0x40, AddRegFrm, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
1104                [(set GR32:$dst, (add GR32:$src, 1))]>, Requires<[In32BitMode]>;
1105 }
1106 let isTwoAddress = 0, CodeSize = 2 in {
1107   def INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), "inc{b}\t$dst",
1108                [(store (add (loadi8 addr:$dst), 1), addr:$dst)]>;
1109   def INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
1110                [(store (add (loadi16 addr:$dst), 1), addr:$dst)]>,
1111                OpSize, Requires<[In32BitMode]>;
1112   def INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
1113                [(store (add (loadi32 addr:$dst), 1), addr:$dst)]>,
1114                Requires<[In32BitMode]>;
1115 }
1116
1117 let CodeSize = 2 in
1118 def DEC8r  : I<0xFE, MRM1r, (outs GR8 :$dst), (ins GR8 :$src), "dec{b}\t$dst",
1119                [(set GR8:$dst, (add GR8:$src, -1))]>;
1120 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {   // Can xform into LEA.
1121 def DEC16r : I<0x48, AddRegFrm, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
1122                [(set GR16:$dst, (add GR16:$src, -1))]>,
1123              OpSize, Requires<[In32BitMode]>;
1124 def DEC32r : I<0x48, AddRegFrm, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
1125                [(set GR32:$dst, (add GR32:$src, -1))]>, Requires<[In32BitMode]>;
1126 }
1127
1128 let isTwoAddress = 0, CodeSize = 2 in {
1129   def DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), "dec{b}\t$dst",
1130                [(store (add (loadi8 addr:$dst), -1), addr:$dst)]>;
1131   def DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
1132                [(store (add (loadi16 addr:$dst), -1), addr:$dst)]>,
1133                OpSize, Requires<[In32BitMode]>;
1134   def DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
1135                [(store (add (loadi32 addr:$dst), -1), addr:$dst)]>,
1136                Requires<[In32BitMode]>;
1137 }
1138 } // Defs = [EFLAGS]
1139
1140 // Logical operators...
1141 let Defs = [EFLAGS] in {
1142 let isCommutable = 1 in {   // X = AND Y, Z   --> X = AND Z, Y
1143 def AND8rr   : I<0x20, MRMDestReg,
1144                 (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1145                 "and{b}\t{$src2, $dst|$dst, $src2}",
1146                 [(set GR8:$dst, (and GR8:$src1, GR8:$src2))]>;
1147 def AND16rr  : I<0x21, MRMDestReg,
1148                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1149                  "and{w}\t{$src2, $dst|$dst, $src2}",
1150                  [(set GR16:$dst, (and GR16:$src1, GR16:$src2))]>, OpSize;
1151 def AND32rr  : I<0x21, MRMDestReg, 
1152                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1153                  "and{l}\t{$src2, $dst|$dst, $src2}",
1154                  [(set GR32:$dst, (and GR32:$src1, GR32:$src2))]>;
1155 }
1156
1157 def AND8rm   : I<0x22, MRMSrcMem, 
1158                  (outs GR8 :$dst), (ins GR8 :$src1, i8mem :$src2),
1159                  "and{b}\t{$src2, $dst|$dst, $src2}",
1160                 [(set GR8:$dst, (and GR8:$src1, (load addr:$src2)))]>;
1161 def AND16rm  : I<0x23, MRMSrcMem, 
1162                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1163                  "and{w}\t{$src2, $dst|$dst, $src2}",
1164                 [(set GR16:$dst, (and GR16:$src1, (load addr:$src2)))]>, OpSize;
1165 def AND32rm  : I<0x23, MRMSrcMem,
1166                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1167                  "and{l}\t{$src2, $dst|$dst, $src2}",
1168                 [(set GR32:$dst, (and GR32:$src1, (load addr:$src2)))]>;
1169
1170 def AND8ri   : Ii8<0x80, MRM4r, 
1171                    (outs GR8 :$dst), (ins GR8 :$src1, i8imm :$src2),
1172                    "and{b}\t{$src2, $dst|$dst, $src2}",
1173                    [(set GR8:$dst, (and GR8:$src1, imm:$src2))]>;
1174 def AND16ri  : Ii16<0x81, MRM4r, 
1175                     (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
1176                     "and{w}\t{$src2, $dst|$dst, $src2}",
1177                     [(set GR16:$dst, (and GR16:$src1, imm:$src2))]>, OpSize;
1178 def AND32ri  : Ii32<0x81, MRM4r, 
1179                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
1180                     "and{l}\t{$src2, $dst|$dst, $src2}",
1181                     [(set GR32:$dst, (and GR32:$src1, imm:$src2))]>;
1182 def AND16ri8 : Ii8<0x83, MRM4r, 
1183                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1184                    "and{w}\t{$src2, $dst|$dst, $src2}",
1185                    [(set GR16:$dst, (and GR16:$src1, i16immSExt8:$src2))]>,
1186                    OpSize;
1187 def AND32ri8 : Ii8<0x83, MRM4r, 
1188                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1189                    "and{l}\t{$src2, $dst|$dst, $src2}",
1190                    [(set GR32:$dst, (and GR32:$src1, i32immSExt8:$src2))]>;
1191
1192 let isTwoAddress = 0 in {
1193   def AND8mr   : I<0x20, MRMDestMem,
1194                    (outs), (ins i8mem :$dst, GR8 :$src),
1195                    "and{b}\t{$src, $dst|$dst, $src}",
1196                    [(store (and (load addr:$dst), GR8:$src), addr:$dst)]>;
1197   def AND16mr  : I<0x21, MRMDestMem,
1198                    (outs), (ins i16mem:$dst, GR16:$src),
1199                    "and{w}\t{$src, $dst|$dst, $src}",
1200                    [(store (and (load addr:$dst), GR16:$src), addr:$dst)]>,
1201                    OpSize;
1202   def AND32mr  : I<0x21, MRMDestMem,
1203                    (outs), (ins i32mem:$dst, GR32:$src),
1204                    "and{l}\t{$src, $dst|$dst, $src}",
1205                    [(store (and (load addr:$dst), GR32:$src), addr:$dst)]>;
1206   def AND8mi   : Ii8<0x80, MRM4m,
1207                      (outs), (ins i8mem :$dst, i8imm :$src),
1208                      "and{b}\t{$src, $dst|$dst, $src}",
1209                       [(store (and (loadi8 addr:$dst), imm:$src), addr:$dst)]>;
1210   def AND16mi  : Ii16<0x81, MRM4m,
1211                       (outs), (ins i16mem:$dst, i16imm:$src),
1212                       "and{w}\t{$src, $dst|$dst, $src}",
1213                       [(store (and (loadi16 addr:$dst), imm:$src), addr:$dst)]>,
1214                       OpSize;
1215   def AND32mi  : Ii32<0x81, MRM4m,
1216                       (outs), (ins i32mem:$dst, i32imm:$src),
1217                       "and{l}\t{$src, $dst|$dst, $src}",
1218                       [(store (and (loadi32 addr:$dst), imm:$src), addr:$dst)]>;
1219   def AND16mi8 : Ii8<0x83, MRM4m,
1220                      (outs), (ins i16mem:$dst, i16i8imm :$src),
1221                      "and{w}\t{$src, $dst|$dst, $src}",
1222                 [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
1223                      OpSize;
1224   def AND32mi8 : Ii8<0x83, MRM4m,
1225                      (outs), (ins i32mem:$dst, i32i8imm :$src),
1226                      "and{l}\t{$src, $dst|$dst, $src}",
1227                 [(store (and (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
1228 }
1229
1230
1231 let isCommutable = 1 in {   // X = OR Y, Z   --> X = OR Z, Y
1232 def OR8rr    : I<0x08, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1233                  "or{b}\t{$src2, $dst|$dst, $src2}",
1234                  [(set GR8:$dst, (or GR8:$src1, GR8:$src2))]>;
1235 def OR16rr   : I<0x09, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1236                  "or{w}\t{$src2, $dst|$dst, $src2}",
1237                  [(set GR16:$dst, (or GR16:$src1, GR16:$src2))]>, OpSize;
1238 def OR32rr   : I<0x09, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1239                  "or{l}\t{$src2, $dst|$dst, $src2}",
1240                  [(set GR32:$dst, (or GR32:$src1, GR32:$src2))]>;
1241 }
1242 def OR8rm    : I<0x0A, MRMSrcMem , (outs GR8 :$dst), (ins GR8 :$src1, i8mem :$src2),
1243                  "or{b}\t{$src2, $dst|$dst, $src2}",
1244                 [(set GR8:$dst, (or GR8:$src1, (load addr:$src2)))]>;
1245 def OR16rm   : I<0x0B, MRMSrcMem , (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1246                  "or{w}\t{$src2, $dst|$dst, $src2}",
1247                 [(set GR16:$dst, (or GR16:$src1, (load addr:$src2)))]>, OpSize;
1248 def OR32rm   : I<0x0B, MRMSrcMem , (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1249                  "or{l}\t{$src2, $dst|$dst, $src2}",
1250                 [(set GR32:$dst, (or GR32:$src1, (load addr:$src2)))]>;
1251
1252 def OR8ri    : Ii8 <0x80, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1253                     "or{b}\t{$src2, $dst|$dst, $src2}",
1254                     [(set GR8:$dst, (or GR8:$src1, imm:$src2))]>;
1255 def OR16ri   : Ii16<0x81, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
1256                     "or{w}\t{$src2, $dst|$dst, $src2}", 
1257                     [(set GR16:$dst, (or GR16:$src1, imm:$src2))]>, OpSize;
1258 def OR32ri   : Ii32<0x81, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
1259                     "or{l}\t{$src2, $dst|$dst, $src2}",
1260                     [(set GR32:$dst, (or GR32:$src1, imm:$src2))]>;
1261
1262 def OR16ri8  : Ii8<0x83, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1263                    "or{w}\t{$src2, $dst|$dst, $src2}",
1264                    [(set GR16:$dst, (or GR16:$src1, i16immSExt8:$src2))]>, OpSize;
1265 def OR32ri8  : Ii8<0x83, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1266                    "or{l}\t{$src2, $dst|$dst, $src2}",
1267                    [(set GR32:$dst, (or GR32:$src1, i32immSExt8:$src2))]>;
1268 let isTwoAddress = 0 in {
1269   def OR8mr  : I<0x08, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
1270                  "or{b}\t{$src, $dst|$dst, $src}",
1271                  [(store (or (load addr:$dst), GR8:$src), addr:$dst)]>;
1272   def OR16mr : I<0x09, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
1273                  "or{w}\t{$src, $dst|$dst, $src}",
1274                  [(store (or (load addr:$dst), GR16:$src), addr:$dst)]>, OpSize;
1275   def OR32mr : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1276                  "or{l}\t{$src, $dst|$dst, $src}",
1277                  [(store (or (load addr:$dst), GR32:$src), addr:$dst)]>;
1278   def OR8mi    : Ii8<0x80, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
1279                  "or{b}\t{$src, $dst|$dst, $src}",
1280                  [(store (or (loadi8 addr:$dst), imm:$src), addr:$dst)]>;
1281   def OR16mi   : Ii16<0x81, MRM1m, (outs), (ins i16mem:$dst, i16imm:$src),
1282                  "or{w}\t{$src, $dst|$dst, $src}",
1283                  [(store (or (loadi16 addr:$dst), imm:$src), addr:$dst)]>,
1284                  OpSize;
1285   def OR32mi   : Ii32<0x81, MRM1m, (outs), (ins i32mem:$dst, i32imm:$src),
1286                  "or{l}\t{$src, $dst|$dst, $src}",
1287                  [(store (or (loadi32 addr:$dst), imm:$src), addr:$dst)]>;
1288   def OR16mi8  : Ii8<0x83, MRM1m, (outs), (ins i16mem:$dst, i16i8imm:$src),
1289                  "or{w}\t{$src, $dst|$dst, $src}",
1290                  [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
1291                      OpSize;
1292   def OR32mi8  : Ii8<0x83, MRM1m, (outs), (ins i32mem:$dst, i32i8imm:$src),
1293                  "or{l}\t{$src, $dst|$dst, $src}",
1294                  [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
1295 }
1296
1297
1298 let isCommutable = 1 in {   // X = XOR Y, Z   --> X = XOR Z, Y
1299 def XOR8rr   : I<0x30, MRMDestReg,
1300                  (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1301                  "xor{b}\t{$src2, $dst|$dst, $src2}",
1302                  [(set GR8:$dst, (xor GR8:$src1, GR8:$src2))]>;
1303 def XOR16rr  : I<0x31, MRMDestReg, 
1304                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2), 
1305                  "xor{w}\t{$src2, $dst|$dst, $src2}",
1306                  [(set GR16:$dst, (xor GR16:$src1, GR16:$src2))]>, OpSize;
1307 def XOR32rr  : I<0x31, MRMDestReg, 
1308                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2), 
1309                  "xor{l}\t{$src2, $dst|$dst, $src2}",
1310                  [(set GR32:$dst, (xor GR32:$src1, GR32:$src2))]>;
1311 }
1312
1313 def XOR8rm   : I<0x32, MRMSrcMem , 
1314                  (outs GR8 :$dst), (ins GR8:$src1, i8mem :$src2), 
1315                  "xor{b}\t{$src2, $dst|$dst, $src2}",
1316                  [(set GR8:$dst, (xor GR8:$src1, (load addr:$src2)))]>;
1317 def XOR16rm  : I<0x33, MRMSrcMem , 
1318                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2), 
1319                  "xor{w}\t{$src2, $dst|$dst, $src2}",
1320                  [(set GR16:$dst, (xor GR16:$src1, (load addr:$src2)))]>, OpSize;
1321 def XOR32rm  : I<0x33, MRMSrcMem , 
1322                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2), 
1323                  "xor{l}\t{$src2, $dst|$dst, $src2}",
1324                  [(set GR32:$dst, (xor GR32:$src1, (load addr:$src2)))]>;
1325
1326 def XOR8ri   : Ii8<0x80, MRM6r, 
1327                    (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2), 
1328                    "xor{b}\t{$src2, $dst|$dst, $src2}",
1329                    [(set GR8:$dst, (xor GR8:$src1, imm:$src2))]>;
1330 def XOR16ri  : Ii16<0x81, MRM6r, 
1331                     (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2), 
1332                     "xor{w}\t{$src2, $dst|$dst, $src2}",
1333                     [(set GR16:$dst, (xor GR16:$src1, imm:$src2))]>, OpSize;
1334 def XOR32ri  : Ii32<0x81, MRM6r, 
1335                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2), 
1336                     "xor{l}\t{$src2, $dst|$dst, $src2}",
1337                     [(set GR32:$dst, (xor GR32:$src1, imm:$src2))]>;
1338 def XOR16ri8 : Ii8<0x83, MRM6r, 
1339                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1340                    "xor{w}\t{$src2, $dst|$dst, $src2}",
1341                    [(set GR16:$dst, (xor GR16:$src1, i16immSExt8:$src2))]>,
1342                    OpSize;
1343 def XOR32ri8 : Ii8<0x83, MRM6r, 
1344                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1345                    "xor{l}\t{$src2, $dst|$dst, $src2}",
1346                    [(set GR32:$dst, (xor GR32:$src1, i32immSExt8:$src2))]>;
1347 let isTwoAddress = 0 in {
1348   def XOR8mr   : I<0x30, MRMDestMem,
1349                    (outs), (ins i8mem :$dst, GR8 :$src),
1350                    "xor{b}\t{$src, $dst|$dst, $src}",
1351                    [(store (xor (load addr:$dst), GR8:$src), addr:$dst)]>;
1352   def XOR16mr  : I<0x31, MRMDestMem,
1353                    (outs), (ins i16mem:$dst, GR16:$src),
1354                    "xor{w}\t{$src, $dst|$dst, $src}",
1355                    [(store (xor (load addr:$dst), GR16:$src), addr:$dst)]>,
1356                    OpSize;
1357   def XOR32mr  : I<0x31, MRMDestMem,
1358                    (outs), (ins i32mem:$dst, GR32:$src),
1359                    "xor{l}\t{$src, $dst|$dst, $src}",
1360                    [(store (xor (load addr:$dst), GR32:$src), addr:$dst)]>;
1361   def XOR8mi   : Ii8<0x80, MRM6m,
1362                      (outs), (ins i8mem :$dst, i8imm :$src),
1363                      "xor{b}\t{$src, $dst|$dst, $src}",
1364                     [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst)]>;
1365   def XOR16mi  : Ii16<0x81, MRM6m,
1366                       (outs), (ins i16mem:$dst, i16imm:$src),
1367                       "xor{w}\t{$src, $dst|$dst, $src}",
1368                    [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst)]>,
1369                       OpSize;
1370   def XOR32mi  : Ii32<0x81, MRM6m,
1371                       (outs), (ins i32mem:$dst, i32imm:$src),
1372                       "xor{l}\t{$src, $dst|$dst, $src}",
1373                    [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst)]>;
1374   def XOR16mi8 : Ii8<0x83, MRM6m,
1375                      (outs), (ins i16mem:$dst, i16i8imm :$src),
1376                      "xor{w}\t{$src, $dst|$dst, $src}",
1377                  [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
1378                      OpSize;
1379   def XOR32mi8 : Ii8<0x83, MRM6m,
1380                      (outs), (ins i32mem:$dst, i32i8imm :$src),
1381                      "xor{l}\t{$src, $dst|$dst, $src}",
1382                  [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
1383 }
1384 } // Defs = [EFLAGS]
1385
1386 // Shift instructions
1387 let Defs = [EFLAGS] in {
1388 let Uses = [CL] in {
1389 def SHL8rCL  : I<0xD2, MRM4r, (outs GR8 :$dst), (ins GR8 :$src),
1390                  "shl{b}\t{%cl, $dst|$dst, %CL}",
1391                  [(set GR8:$dst, (shl GR8:$src, CL))]>;
1392 def SHL16rCL : I<0xD3, MRM4r, (outs GR16:$dst), (ins GR16:$src),
1393                  "shl{w}\t{%cl, $dst|$dst, %CL}",
1394                  [(set GR16:$dst, (shl GR16:$src, CL))]>, OpSize;
1395 def SHL32rCL : I<0xD3, MRM4r, (outs GR32:$dst), (ins GR32:$src),
1396                  "shl{l}\t{%cl, $dst|$dst, %CL}",
1397                  [(set GR32:$dst, (shl GR32:$src, CL))]>;
1398 }
1399
1400 def SHL8ri   : Ii8<0xC0, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1401                    "shl{b}\t{$src2, $dst|$dst, $src2}",
1402                    [(set GR8:$dst, (shl GR8:$src1, (i8 imm:$src2)))]>;
1403 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1404 def SHL16ri  : Ii8<0xC1, MRM4r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1405                    "shl{w}\t{$src2, $dst|$dst, $src2}",
1406                    [(set GR16:$dst, (shl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
1407 def SHL32ri  : Ii8<0xC1, MRM4r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1408                    "shl{l}\t{$src2, $dst|$dst, $src2}",
1409                    [(set GR32:$dst, (shl GR32:$src1, (i8 imm:$src2)))]>;
1410 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
1411 // cheaper.
1412 }
1413
1414 let isTwoAddress = 0 in {
1415   let Uses = [CL] in {
1416   def SHL8mCL  : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
1417                    "shl{b}\t{%cl, $dst|$dst, %CL}",
1418                    [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>;
1419   def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
1420                    "shl{w}\t{%cl, $dst|$dst, %CL}",
1421                    [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1422   def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
1423                    "shl{l}\t{%cl, $dst|$dst, %CL}",
1424                    [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>;
1425   }
1426   def SHL8mi   : Ii8<0xC0, MRM4m, (outs), (ins i8mem :$dst, i8imm:$src),
1427                      "shl{b}\t{$src, $dst|$dst, $src}",
1428                   [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1429   def SHL16mi  : Ii8<0xC1, MRM4m, (outs), (ins i16mem:$dst, i8imm:$src),
1430                      "shl{w}\t{$src, $dst|$dst, $src}",
1431                  [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1432                      OpSize;
1433   def SHL32mi  : Ii8<0xC1, MRM4m, (outs), (ins i32mem:$dst, i8imm:$src),
1434                      "shl{l}\t{$src, $dst|$dst, $src}",
1435                  [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1436
1437   // Shift by 1
1438   def SHL8m1   : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
1439                    "shl{b}\t$dst",
1440                   [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1441   def SHL16m1  : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
1442                    "shl{w}\t$dst",
1443                  [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1444                      OpSize;
1445   def SHL32m1  : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
1446                    "shl{l}\t$dst",
1447                  [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1448 }
1449
1450 let Uses = [CL] in {
1451 def SHR8rCL  : I<0xD2, MRM5r, (outs GR8 :$dst), (ins GR8 :$src),
1452                  "shr{b}\t{%cl, $dst|$dst, %CL}",
1453                  [(set GR8:$dst, (srl GR8:$src, CL))]>;
1454 def SHR16rCL : I<0xD3, MRM5r, (outs GR16:$dst), (ins GR16:$src),
1455                  "shr{w}\t{%cl, $dst|$dst, %CL}",
1456                  [(set GR16:$dst, (srl GR16:$src, CL))]>, OpSize;
1457 def SHR32rCL : I<0xD3, MRM5r, (outs GR32:$dst), (ins GR32:$src),
1458                  "shr{l}\t{%cl, $dst|$dst, %CL}",
1459                  [(set GR32:$dst, (srl GR32:$src, CL))]>;
1460 }
1461
1462 def SHR8ri   : Ii8<0xC0, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
1463                    "shr{b}\t{$src2, $dst|$dst, $src2}",
1464                    [(set GR8:$dst, (srl GR8:$src1, (i8 imm:$src2)))]>;
1465 def SHR16ri  : Ii8<0xC1, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1466                    "shr{w}\t{$src2, $dst|$dst, $src2}",
1467                    [(set GR16:$dst, (srl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
1468 def SHR32ri  : Ii8<0xC1, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1469                    "shr{l}\t{$src2, $dst|$dst, $src2}",
1470                    [(set GR32:$dst, (srl GR32:$src1, (i8 imm:$src2)))]>;
1471
1472 // Shift by 1
1473 def SHR8r1   : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
1474                  "shr{b}\t$dst",
1475                  [(set GR8:$dst, (srl GR8:$src1, (i8 1)))]>;
1476 def SHR16r1  : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
1477                  "shr{w}\t$dst",
1478                  [(set GR16:$dst, (srl GR16:$src1, (i8 1)))]>, OpSize;
1479 def SHR32r1  : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
1480                  "shr{l}\t$dst",
1481                  [(set GR32:$dst, (srl GR32:$src1, (i8 1)))]>;
1482
1483 let isTwoAddress = 0 in {
1484   let Uses = [CL] in {
1485   def SHR8mCL  : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
1486                    "shr{b}\t{%cl, $dst|$dst, %CL}",
1487                    [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>;
1488   def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
1489                    "shr{w}\t{%cl, $dst|$dst, %CL}",
1490                    [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
1491                    OpSize;
1492   def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
1493                    "shr{l}\t{%cl, $dst|$dst, %CL}",
1494                    [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>;
1495   }
1496   def SHR8mi   : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src),
1497                      "shr{b}\t{$src, $dst|$dst, $src}",
1498                   [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1499   def SHR16mi  : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, i8imm:$src),
1500                      "shr{w}\t{$src, $dst|$dst, $src}",
1501                  [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1502                      OpSize;
1503   def SHR32mi  : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, i8imm:$src),
1504                      "shr{l}\t{$src, $dst|$dst, $src}",
1505                  [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1506
1507   // Shift by 1
1508   def SHR8m1   : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
1509                    "shr{b}\t$dst",
1510                   [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1511   def SHR16m1  : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
1512                    "shr{w}\t$dst",
1513                  [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,OpSize;
1514   def SHR32m1  : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
1515                    "shr{l}\t$dst",
1516                  [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1517 }
1518
1519 let Uses = [CL] in {
1520 def SAR8rCL  : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src),
1521                  "sar{b}\t{%cl, $dst|$dst, %CL}",
1522                  [(set GR8:$dst, (sra GR8:$src, CL))]>;
1523 def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src),
1524                  "sar{w}\t{%cl, $dst|$dst, %CL}",
1525                  [(set GR16:$dst, (sra GR16:$src, CL))]>, OpSize;
1526 def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src),
1527                  "sar{l}\t{%cl, $dst|$dst, %CL}",
1528                  [(set GR32:$dst, (sra GR32:$src, CL))]>;
1529 }
1530
1531 def SAR8ri   : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1532                    "sar{b}\t{$src2, $dst|$dst, $src2}",
1533                    [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))]>;
1534 def SAR16ri  : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1535                    "sar{w}\t{$src2, $dst|$dst, $src2}",
1536                    [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))]>,
1537                    OpSize;
1538 def SAR32ri  : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1539                    "sar{l}\t{$src2, $dst|$dst, $src2}",
1540                    [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))]>;
1541
1542 // Shift by 1
1543 def SAR8r1   : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
1544                  "sar{b}\t$dst",
1545                  [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
1546 def SAR16r1  : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
1547                  "sar{w}\t$dst",
1548                  [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize;
1549 def SAR32r1  : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
1550                  "sar{l}\t$dst",
1551                  [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>;
1552
1553 let isTwoAddress = 0 in {
1554   let Uses = [CL] in {
1555   def SAR8mCL  : I<0xD2, MRM7m, (outs), (ins i8mem :$dst),
1556                    "sar{b}\t{%cl, $dst|$dst, %CL}",
1557                    [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>;
1558   def SAR16mCL : I<0xD3, MRM7m, (outs), (ins i16mem:$dst),
1559                    "sar{w}\t{%cl, $dst|$dst, %CL}",
1560                    [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1561   def SAR32mCL : I<0xD3, MRM7m, (outs), (ins i32mem:$dst), 
1562                    "sar{l}\t{%cl, $dst|$dst, %CL}",
1563                    [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>;
1564   }
1565   def SAR8mi   : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, i8imm:$src),
1566                      "sar{b}\t{$src, $dst|$dst, $src}",
1567                   [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1568   def SAR16mi  : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, i8imm:$src),
1569                      "sar{w}\t{$src, $dst|$dst, $src}",
1570                  [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1571                      OpSize;
1572   def SAR32mi  : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, i8imm:$src),
1573                      "sar{l}\t{$src, $dst|$dst, $src}",
1574                  [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1575
1576   // Shift by 1
1577   def SAR8m1   : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
1578                    "sar{b}\t$dst",
1579                   [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1580   def SAR16m1  : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
1581                    "sar{w}\t$dst",
1582                  [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1583                      OpSize;
1584   def SAR32m1  : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
1585                    "sar{l}\t$dst",
1586                  [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1587 }
1588
1589 // Rotate instructions
1590 // FIXME: provide shorter instructions when imm8 == 1
1591 let Uses = [CL] in {
1592 def ROL8rCL  : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src),
1593                  "rol{b}\t{%cl, $dst|$dst, %CL}",
1594                  [(set GR8:$dst, (rotl GR8:$src, CL))]>;
1595 def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src),
1596                  "rol{w}\t{%cl, $dst|$dst, %CL}",
1597                  [(set GR16:$dst, (rotl GR16:$src, CL))]>, OpSize;
1598 def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src),
1599                  "rol{l}\t{%cl, $dst|$dst, %CL}",
1600                  [(set GR32:$dst, (rotl GR32:$src, CL))]>;
1601 }
1602
1603 def ROL8ri   : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1604                    "rol{b}\t{$src2, $dst|$dst, $src2}",
1605                    [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))]>;
1606 def ROL16ri  : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1607                    "rol{w}\t{$src2, $dst|$dst, $src2}",
1608                    [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
1609 def ROL32ri  : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1610                    "rol{l}\t{$src2, $dst|$dst, $src2}",
1611                    [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))]>;
1612
1613 // Rotate by 1
1614 def ROL8r1   : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
1615                  "rol{b}\t$dst",
1616                  [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
1617 def ROL16r1  : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
1618                  "rol{w}\t$dst",
1619                  [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize;
1620 def ROL32r1  : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
1621                  "rol{l}\t$dst",
1622                  [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>;
1623
1624 let isTwoAddress = 0 in {
1625   let Uses = [CL] in {
1626   def ROL8mCL  : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
1627                    "rol{b}\t{%cl, $dst|$dst, %CL}",
1628                    [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>;
1629   def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
1630                    "rol{w}\t{%cl, $dst|$dst, %CL}",
1631                    [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1632   def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
1633                    "rol{l}\t{%cl, $dst|$dst, %CL}",
1634                    [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>;
1635   }
1636   def ROL8mi   : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, i8imm:$src),
1637                      "rol{b}\t{$src, $dst|$dst, $src}",
1638                  [(store (rotl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1639   def ROL16mi  : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, i8imm:$src),
1640                      "rol{w}\t{$src, $dst|$dst, $src}",
1641                 [(store (rotl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1642                      OpSize;
1643   def ROL32mi  : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, i8imm:$src),
1644                      "rol{l}\t{$src, $dst|$dst, $src}",
1645                 [(store (rotl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1646
1647   // Rotate by 1
1648   def ROL8m1   : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
1649                    "rol{b}\t$dst",
1650                  [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1651   def ROL16m1  : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
1652                    "rol{w}\t$dst",
1653                 [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1654                      OpSize;
1655   def ROL32m1  : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
1656                    "rol{l}\t$dst",
1657                 [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1658 }
1659
1660 let Uses = [CL] in {
1661 def ROR8rCL  : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src),
1662                  "ror{b}\t{%cl, $dst|$dst, %CL}",
1663                  [(set GR8:$dst, (rotr GR8:$src, CL))]>;
1664 def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src),
1665                  "ror{w}\t{%cl, $dst|$dst, %CL}",
1666                  [(set GR16:$dst, (rotr GR16:$src, CL))]>, OpSize;
1667 def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src),
1668                  "ror{l}\t{%cl, $dst|$dst, %CL}",
1669                  [(set GR32:$dst, (rotr GR32:$src, CL))]>;
1670 }
1671
1672 def ROR8ri   : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1673                    "ror{b}\t{$src2, $dst|$dst, $src2}",
1674                    [(set GR8:$dst, (rotr GR8:$src1, (i8 imm:$src2)))]>;
1675 def ROR16ri  : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1676                    "ror{w}\t{$src2, $dst|$dst, $src2}",
1677                    [(set GR16:$dst, (rotr GR16:$src1, (i8 imm:$src2)))]>, OpSize;
1678 def ROR32ri  : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1679                    "ror{l}\t{$src2, $dst|$dst, $src2}",
1680                    [(set GR32:$dst, (rotr GR32:$src1, (i8 imm:$src2)))]>;
1681
1682 // Rotate by 1
1683 def ROR8r1   : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
1684                  "ror{b}\t$dst",
1685                  [(set GR8:$dst, (rotr GR8:$src1, (i8 1)))]>;
1686 def ROR16r1  : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
1687                  "ror{w}\t$dst",
1688                  [(set GR16:$dst, (rotr GR16:$src1, (i8 1)))]>, OpSize;
1689 def ROR32r1  : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
1690                  "ror{l}\t$dst",
1691                  [(set GR32:$dst, (rotr GR32:$src1, (i8 1)))]>;
1692
1693 let isTwoAddress = 0 in {
1694   let Uses = [CL] in {
1695   def ROR8mCL  : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
1696                    "ror{b}\t{%cl, $dst|$dst, %CL}",
1697                    [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>;
1698   def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
1699                    "ror{w}\t{%cl, $dst|$dst, %CL}",
1700                    [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1701   def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst), 
1702                    "ror{l}\t{%cl, $dst|$dst, %CL}",
1703                    [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>;
1704   }
1705   def ROR8mi   : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
1706                      "ror{b}\t{$src, $dst|$dst, $src}",
1707                  [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1708   def ROR16mi  : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, i8imm:$src),
1709                      "ror{w}\t{$src, $dst|$dst, $src}",
1710                 [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1711                      OpSize;
1712   def ROR32mi  : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, i8imm:$src),
1713                      "ror{l}\t{$src, $dst|$dst, $src}",
1714                 [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1715
1716   // Rotate by 1
1717   def ROR8m1   : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
1718                    "ror{b}\t$dst",
1719                  [(store (rotr (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1720   def ROR16m1  : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
1721                    "ror{w}\t$dst",
1722                 [(store (rotr (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1723                      OpSize;
1724   def ROR32m1  : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
1725                    "ror{l}\t$dst",
1726                 [(store (rotr (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1727 }
1728
1729
1730
1731 // Double shift instructions (generalizations of rotate)
1732 let Uses = [CL] in {
1733 def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1734                    "shld{l}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1735                    [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))]>, TB;
1736 def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1737                    "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1738                    [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))]>, TB;
1739 def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1740                    "shld{w}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1741                    [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))]>,
1742                    TB, OpSize;
1743 def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1744                    "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1745                    [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))]>,
1746                    TB, OpSize;
1747 }
1748
1749 let isCommutable = 1 in {  // These instructions commute to each other.
1750 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
1751                      (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, i8imm:$src3),
1752                      "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1753                      [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
1754                                       (i8 imm:$src3)))]>,
1755                  TB;
1756 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
1757                      (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, i8imm:$src3),
1758                      "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1759                      [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
1760                                       (i8 imm:$src3)))]>,
1761                  TB;
1762 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
1763                      (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$src3),
1764                      "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1765                      [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
1766                                       (i8 imm:$src3)))]>,
1767                      TB, OpSize;
1768 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
1769                      (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$src3),
1770                      "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1771                      [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
1772                                       (i8 imm:$src3)))]>,
1773                      TB, OpSize;
1774 }
1775
1776 let isTwoAddress = 0 in {
1777   let Uses = [CL] in {
1778   def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
1779                      "shld{l}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1780                      [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
1781                        addr:$dst)]>, TB;
1782   def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
1783                     "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1784                     [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
1785                       addr:$dst)]>, TB;
1786   }
1787   def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
1788                       (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
1789                       "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1790                       [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
1791                                         (i8 imm:$src3)), addr:$dst)]>,
1792                       TB;
1793   def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
1794                        (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
1795                        "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1796                        [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
1797                                          (i8 imm:$src3)), addr:$dst)]>,
1798                        TB;
1799
1800   let Uses = [CL] in {
1801   def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
1802                      "shld{w}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1803                      [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
1804                        addr:$dst)]>, TB, OpSize;
1805   def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
1806                     "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1807                     [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
1808                       addr:$dst)]>, TB, OpSize;
1809   }
1810   def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
1811                       (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
1812                       "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1813                       [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
1814                                         (i8 imm:$src3)), addr:$dst)]>,
1815                       TB, OpSize;
1816   def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
1817                        (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
1818                        "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1819                       [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
1820                                         (i8 imm:$src3)), addr:$dst)]>,
1821                        TB, OpSize;
1822 }
1823 } // Defs = [EFLAGS]
1824
1825
1826 // Arithmetic.
1827 let Defs = [EFLAGS] in {
1828 let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
1829 def ADD8rr   : I<0x00, MRMDestReg, (outs GR8 :$dst),
1830                                    (ins GR8 :$src1, GR8 :$src2),
1831                  "add{b}\t{$src2, $dst|$dst, $src2}",
1832                  [(set GR8:$dst, (add GR8:$src1, GR8:$src2))]>;
1833 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1834 def ADD16rr  : I<0x01, MRMDestReg, (outs GR16:$dst),
1835                                    (ins GR16:$src1, GR16:$src2),
1836                  "add{w}\t{$src2, $dst|$dst, $src2}",
1837                  [(set GR16:$dst, (add GR16:$src1, GR16:$src2))]>, OpSize;
1838 def ADD32rr  : I<0x01, MRMDestReg, (outs GR32:$dst),
1839                                    (ins GR32:$src1, GR32:$src2),
1840                  "add{l}\t{$src2, $dst|$dst, $src2}",
1841                  [(set GR32:$dst, (add GR32:$src1, GR32:$src2))]>;
1842 } // end isConvertibleToThreeAddress
1843 } // end isCommutable
1844 def ADD8rm   : I<0x02, MRMSrcMem, (outs GR8 :$dst),
1845                                   (ins GR8 :$src1, i8mem :$src2),
1846                  "add{b}\t{$src2, $dst|$dst, $src2}",
1847                  [(set GR8:$dst, (add GR8:$src1, (load addr:$src2)))]>;
1848 def ADD16rm  : I<0x03, MRMSrcMem, (outs GR16:$dst),
1849                                   (ins GR16:$src1, i16mem:$src2),
1850                  "add{w}\t{$src2, $dst|$dst, $src2}",
1851                  [(set GR16:$dst, (add GR16:$src1, (load addr:$src2)))]>,OpSize;
1852 def ADD32rm  : I<0x03, MRMSrcMem, (outs GR32:$dst),
1853                                   (ins GR32:$src1, i32mem:$src2),
1854                  "add{l}\t{$src2, $dst|$dst, $src2}",
1855                  [(set GR32:$dst, (add GR32:$src1, (load addr:$src2)))]>;
1856
1857 def ADD8ri   : Ii8<0x80, MRM0r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
1858                    "add{b}\t{$src2, $dst|$dst, $src2}",
1859                    [(set GR8:$dst, (add GR8:$src1, imm:$src2))]>;
1860
1861 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1862 def ADD16ri  : Ii16<0x81, MRM0r, (outs GR16:$dst),
1863                                  (ins GR16:$src1, i16imm:$src2),
1864                     "add{w}\t{$src2, $dst|$dst, $src2}",
1865                     [(set GR16:$dst, (add GR16:$src1, imm:$src2))]>, OpSize;
1866 def ADD32ri  : Ii32<0x81, MRM0r, (outs GR32:$dst),
1867                                  (ins GR32:$src1, i32imm:$src2),
1868                     "add{l}\t{$src2, $dst|$dst, $src2}",
1869                     [(set GR32:$dst, (add GR32:$src1, imm:$src2))]>;
1870 def ADD16ri8 : Ii8<0x83, MRM0r, (outs GR16:$dst),
1871                                 (ins GR16:$src1, i16i8imm:$src2),
1872                    "add{w}\t{$src2, $dst|$dst, $src2}",
1873                 [(set GR16:$dst, (add GR16:$src1, i16immSExt8:$src2))]>, OpSize;
1874 def ADD32ri8 : Ii8<0x83, MRM0r, (outs GR32:$dst),
1875                                 (ins GR32:$src1, i32i8imm:$src2),
1876                    "add{l}\t{$src2, $dst|$dst, $src2}",
1877                 [(set GR32:$dst, (add GR32:$src1, i32immSExt8:$src2))]>;
1878 }
1879
1880 let isTwoAddress = 0 in {
1881   def ADD8mr   : I<0x00, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
1882                    "add{b}\t{$src2, $dst|$dst, $src2}",
1883                    [(store (add (load addr:$dst), GR8:$src2), addr:$dst)]>;
1884   def ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
1885                    "add{w}\t{$src2, $dst|$dst, $src2}",
1886                    [(store (add (load addr:$dst), GR16:$src2), addr:$dst)]>,
1887                  OpSize;
1888   def ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
1889                    "add{l}\t{$src2, $dst|$dst, $src2}",
1890                    [(store (add (load addr:$dst), GR32:$src2), addr:$dst)]>;
1891   def ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
1892                      "add{b}\t{$src2, $dst|$dst, $src2}",
1893                    [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
1894   def ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
1895                       "add{w}\t{$src2, $dst|$dst, $src2}",
1896                   [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
1897                  OpSize;
1898   def ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
1899                       "add{l}\t{$src2, $dst|$dst, $src2}",
1900                   [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1901   def ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
1902                      "add{w}\t{$src2, $dst|$dst, $src2}",
1903                 [(store (add (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1904                  OpSize;
1905   def ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
1906                      "add{l}\t{$src2, $dst|$dst, $src2}",
1907                 [(store (add (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1908 }
1909
1910 let Uses = [EFLAGS] in {
1911 let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
1912 def ADC32rr  : I<0x11, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1913                  "adc{l}\t{$src2, $dst|$dst, $src2}",
1914                  [(set GR32:$dst, (adde GR32:$src1, GR32:$src2))]>;
1915 }
1916 def ADC32rm  : I<0x13, MRMSrcMem , (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1917                  "adc{l}\t{$src2, $dst|$dst, $src2}",
1918                  [(set GR32:$dst, (adde GR32:$src1, (load addr:$src2)))]>;
1919 def ADC32ri  : Ii32<0x81, MRM2r, (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
1920                     "adc{l}\t{$src2, $dst|$dst, $src2}",
1921                  [(set GR32:$dst, (adde GR32:$src1, imm:$src2))]>;
1922 def ADC32ri8 : Ii8<0x83, MRM2r, (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1923                    "adc{l}\t{$src2, $dst|$dst, $src2}",
1924                  [(set GR32:$dst, (adde GR32:$src1, i32immSExt8:$src2))]>;
1925
1926 let isTwoAddress = 0 in {
1927   def ADC32mr  : I<0x11, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
1928                    "adc{l}\t{$src2, $dst|$dst, $src2}",
1929                    [(store (adde (load addr:$dst), GR32:$src2), addr:$dst)]>;
1930   def ADC32mi  : Ii32<0x81, MRM2m, (outs), (ins i32mem:$dst, i32imm:$src2),
1931                       "adc{l}\t{$src2, $dst|$dst, $src2}",
1932                   [(store (adde (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1933   def ADC32mi8 : Ii8<0x83, MRM2m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
1934                      "adc{l}\t{$src2, $dst|$dst, $src2}",
1935              [(store (adde (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1936 }
1937 } // Uses = [EFLAGS]
1938
1939 def SUB8rr   : I<0x28, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1940                  "sub{b}\t{$src2, $dst|$dst, $src2}",
1941                  [(set GR8:$dst, (sub GR8:$src1, GR8:$src2))]>;
1942 def SUB16rr  : I<0x29, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1943                  "sub{w}\t{$src2, $dst|$dst, $src2}",
1944                  [(set GR16:$dst, (sub GR16:$src1, GR16:$src2))]>, OpSize;
1945 def SUB32rr  : I<0x29, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1946                  "sub{l}\t{$src2, $dst|$dst, $src2}",
1947                  [(set GR32:$dst, (sub GR32:$src1, GR32:$src2))]>;
1948 def SUB8rm   : I<0x2A, MRMSrcMem, (outs GR8 :$dst), (ins GR8 :$src1, i8mem :$src2),
1949                  "sub{b}\t{$src2, $dst|$dst, $src2}",
1950                  [(set GR8:$dst, (sub GR8:$src1, (load addr:$src2)))]>;
1951 def SUB16rm  : I<0x2B, MRMSrcMem, (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1952                  "sub{w}\t{$src2, $dst|$dst, $src2}",
1953                  [(set GR16:$dst, (sub GR16:$src1, (load addr:$src2)))]>, OpSize;
1954 def SUB32rm  : I<0x2B, MRMSrcMem, (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1955                  "sub{l}\t{$src2, $dst|$dst, $src2}",
1956                  [(set GR32:$dst, (sub GR32:$src1, (load addr:$src2)))]>;
1957
1958 def SUB8ri   : Ii8 <0x80, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
1959                     "sub{b}\t{$src2, $dst|$dst, $src2}",
1960                     [(set GR8:$dst, (sub GR8:$src1, imm:$src2))]>;
1961 def SUB16ri  : Ii16<0x81, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
1962                     "sub{w}\t{$src2, $dst|$dst, $src2}",
1963                     [(set GR16:$dst, (sub GR16:$src1, imm:$src2))]>, OpSize;
1964 def SUB32ri  : Ii32<0x81, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
1965                     "sub{l}\t{$src2, $dst|$dst, $src2}",
1966                     [(set GR32:$dst, (sub GR32:$src1, imm:$src2))]>;
1967 def SUB16ri8 : Ii8<0x83, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1968                    "sub{w}\t{$src2, $dst|$dst, $src2}",
1969                    [(set GR16:$dst, (sub GR16:$src1, i16immSExt8:$src2))]>,
1970                OpSize;
1971 def SUB32ri8 : Ii8<0x83, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1972                    "sub{l}\t{$src2, $dst|$dst, $src2}",
1973                    [(set GR32:$dst, (sub GR32:$src1, i32immSExt8:$src2))]>;
1974 let isTwoAddress = 0 in {
1975   def SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
1976                    "sub{b}\t{$src2, $dst|$dst, $src2}",
1977                    [(store (sub (load addr:$dst), GR8:$src2), addr:$dst)]>;
1978   def SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
1979                    "sub{w}\t{$src2, $dst|$dst, $src2}",
1980                    [(store (sub (load addr:$dst), GR16:$src2), addr:$dst)]>,
1981                  OpSize;
1982   def SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
1983                    "sub{l}\t{$src2, $dst|$dst, $src2}",
1984                    [(store (sub (load addr:$dst), GR32:$src2), addr:$dst)]>;
1985   def SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
1986                      "sub{b}\t{$src2, $dst|$dst, $src2}",
1987                    [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
1988   def SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
1989                       "sub{w}\t{$src2, $dst|$dst, $src2}",
1990                   [(store (sub (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
1991                  OpSize;
1992   def SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
1993                       "sub{l}\t{$src2, $dst|$dst, $src2}",
1994                   [(store (sub (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1995   def SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
1996                      "sub{w}\t{$src2, $dst|$dst, $src2}",
1997                 [(store (sub (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1998                  OpSize;
1999   def SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2), 
2000                      "sub{l}\t{$src2, $dst|$dst, $src2}",
2001                 [(store (sub (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2002 }
2003
2004 let Uses = [EFLAGS] in {
2005 def SBB32rr    : I<0x19, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
2006                   "sbb{l}\t{$src2, $dst|$dst, $src2}",
2007                  [(set GR32:$dst, (sube GR32:$src1, GR32:$src2))]>;
2008
2009 let isTwoAddress = 0 in {
2010   def SBB32mr  : I<0x19, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
2011                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
2012                    [(store (sube (load addr:$dst), GR32:$src2), addr:$dst)]>;
2013   def SBB8mi  : Ii32<0x80, MRM3m, (outs), (ins i8mem:$dst, i8imm:$src2), 
2014                       "sbb{b}\t{$src2, $dst|$dst, $src2}",
2015                    [(store (sube (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2016   def SBB32mi  : Ii32<0x81, MRM3m, (outs), (ins i32mem:$dst, i32imm:$src2), 
2017                       "sbb{l}\t{$src2, $dst|$dst, $src2}",
2018                   [(store (sube (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2019   def SBB32mi8 : Ii8<0x83, MRM3m, (outs), (ins i32mem:$dst, i32i8imm :$src2), 
2020                      "sbb{l}\t{$src2, $dst|$dst, $src2}",
2021                [(store (sube (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2022 }
2023 def SBB32rm  : I<0x1B, MRMSrcMem, (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
2024                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
2025                     [(set GR32:$dst, (sube GR32:$src1, (load addr:$src2)))]>;
2026 def SBB32ri  : Ii32<0x81, MRM3r, (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
2027                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
2028                     [(set GR32:$dst, (sube GR32:$src1, imm:$src2))]>;
2029 def SBB32ri8 : Ii8<0x83, MRM3r, (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
2030                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
2031                    [(set GR32:$dst, (sube GR32:$src1, i32immSExt8:$src2))]>;
2032 } // Uses = [EFLAGS]
2033 } // Defs = [EFLAGS]
2034
2035 let Defs = [EFLAGS] in {
2036 let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
2037 def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
2038                  "imul{w}\t{$src2, $dst|$dst, $src2}",
2039                  [(set GR16:$dst, (mul GR16:$src1, GR16:$src2))]>, TB, OpSize;
2040 def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
2041                  "imul{l}\t{$src2, $dst|$dst, $src2}",
2042                  [(set GR32:$dst, (mul GR32:$src1, GR32:$src2))]>, TB;
2043 }
2044 def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
2045                  "imul{w}\t{$src2, $dst|$dst, $src2}",
2046                  [(set GR16:$dst, (mul GR16:$src1, (load addr:$src2)))]>,
2047                  TB, OpSize;
2048 def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
2049                  "imul{l}\t{$src2, $dst|$dst, $src2}",
2050                  [(set GR32:$dst, (mul GR32:$src1, (load addr:$src2)))]>, TB;
2051 } // Defs = [EFLAGS]
2052 } // end Two Address instructions
2053
2054 // Suprisingly enough, these are not two address instructions!
2055 let Defs = [EFLAGS] in {
2056 def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // GR16 = GR16*I16
2057                       (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
2058                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2059                       [(set GR16:$dst, (mul GR16:$src1, imm:$src2))]>, OpSize;
2060 def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // GR32 = GR32*I32
2061                       (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
2062                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2063                       [(set GR32:$dst, (mul GR32:$src1, imm:$src2))]>;
2064 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // GR16 = GR16*I8
2065                      (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
2066                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2067                      [(set GR16:$dst, (mul GR16:$src1, i16immSExt8:$src2))]>,
2068                      OpSize;
2069 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // GR32 = GR32*I8
2070                      (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
2071                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2072                      [(set GR32:$dst, (mul GR32:$src1, i32immSExt8:$src2))]>;
2073
2074 def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                      // GR16 = [mem16]*I16
2075                       (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
2076                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2077                       [(set GR16:$dst, (mul (load addr:$src1), imm:$src2))]>,
2078                       OpSize;
2079 def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                      // GR32 = [mem32]*I32
2080                       (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
2081                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2082                       [(set GR32:$dst, (mul (load addr:$src1), imm:$src2))]>;
2083 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR16 = [mem16]*I8
2084                      (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
2085                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2086                   [(set GR16:$dst, (mul (load addr:$src1), i16immSExt8:$src2))]>,
2087                      OpSize;
2088 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR32 = [mem32]*I8
2089                      (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
2090                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2091                   [(set GR32:$dst, (mul (load addr:$src1), i32immSExt8:$src2))]>;
2092 } // Defs = [EFLAGS]
2093
2094 //===----------------------------------------------------------------------===//
2095 // Test instructions are just like AND, except they don't generate a result.
2096 //
2097 let Defs = [EFLAGS] in {
2098 let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
2099 def TEST8rr  : I<0x84, MRMDestReg, (outs),  (ins GR8:$src1, GR8:$src2),
2100                      "test{b}\t{$src2, $src1|$src1, $src2}",
2101                      [(X86cmp (and_su GR8:$src1, GR8:$src2), 0),
2102                       (implicit EFLAGS)]>;
2103 def TEST16rr : I<0x85, MRMDestReg, (outs),  (ins GR16:$src1, GR16:$src2),
2104                      "test{w}\t{$src2, $src1|$src1, $src2}",
2105                      [(X86cmp (and_su GR16:$src1, GR16:$src2), 0),
2106                       (implicit EFLAGS)]>,
2107                  OpSize;
2108 def TEST32rr : I<0x85, MRMDestReg, (outs),  (ins GR32:$src1, GR32:$src2),
2109                      "test{l}\t{$src2, $src1|$src1, $src2}",
2110                      [(X86cmp (and_su GR32:$src1, GR32:$src2), 0),
2111                       (implicit EFLAGS)]>;
2112 }
2113
2114 def TEST8rm  : I<0x84, MRMSrcMem, (outs),  (ins GR8 :$src1, i8mem :$src2),
2115                      "test{b}\t{$src2, $src1|$src1, $src2}",
2116                      [(X86cmp (and GR8:$src1, (loadi8 addr:$src2)), 0),
2117                       (implicit EFLAGS)]>;
2118 def TEST16rm : I<0x85, MRMSrcMem, (outs),  (ins GR16:$src1, i16mem:$src2),
2119                      "test{w}\t{$src2, $src1|$src1, $src2}",
2120                      [(X86cmp (and GR16:$src1, (loadi16 addr:$src2)), 0),
2121                       (implicit EFLAGS)]>, OpSize;
2122 def TEST32rm : I<0x85, MRMSrcMem, (outs),  (ins GR32:$src1, i32mem:$src2),
2123                      "test{l}\t{$src2, $src1|$src1, $src2}",
2124                      [(X86cmp (and GR32:$src1, (loadi32 addr:$src2)), 0),
2125                       (implicit EFLAGS)]>;
2126
2127 def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = GR8  & imm8
2128                     (outs),  (ins GR8:$src1, i8imm:$src2),
2129                     "test{b}\t{$src2, $src1|$src1, $src2}",
2130                     [(X86cmp (and_su GR8:$src1, imm:$src2), 0),
2131                      (implicit EFLAGS)]>;
2132 def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = GR16 & imm16
2133                     (outs),  (ins GR16:$src1, i16imm:$src2),
2134                     "test{w}\t{$src2, $src1|$src1, $src2}",
2135                     [(X86cmp (and_su GR16:$src1, imm:$src2), 0),
2136                      (implicit EFLAGS)]>, OpSize;
2137 def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = GR32 & imm32
2138                     (outs),  (ins GR32:$src1, i32imm:$src2),
2139                     "test{l}\t{$src2, $src1|$src1, $src2}",
2140                     [(X86cmp (and_su GR32:$src1, imm:$src2), 0),
2141                      (implicit EFLAGS)]>;
2142
2143 def TEST8mi  : Ii8 <0xF6, MRM0m,                   // flags = [mem8]  & imm8
2144                     (outs), (ins i8mem:$src1, i8imm:$src2),
2145                     "test{b}\t{$src2, $src1|$src1, $src2}",
2146                     [(X86cmp (and (loadi8 addr:$src1), imm:$src2), 0),
2147                      (implicit EFLAGS)]>;
2148 def TEST16mi : Ii16<0xF7, MRM0m,                   // flags = [mem16] & imm16
2149                     (outs), (ins i16mem:$src1, i16imm:$src2),
2150                     "test{w}\t{$src2, $src1|$src1, $src2}",
2151                     [(X86cmp (and (loadi16 addr:$src1), imm:$src2), 0),
2152                      (implicit EFLAGS)]>, OpSize;
2153 def TEST32mi : Ii32<0xF7, MRM0m,                   // flags = [mem32] & imm32
2154                     (outs), (ins i32mem:$src1, i32imm:$src2),
2155                     "test{l}\t{$src2, $src1|$src1, $src2}",
2156                     [(X86cmp (and (loadi32 addr:$src1), imm:$src2), 0),
2157                      (implicit EFLAGS)]>;
2158 } // Defs = [EFLAGS]
2159
2160
2161 // Condition code ops, incl. set if equal/not equal/...
2162 let Defs = [EFLAGS], Uses = [AH], neverHasSideEffects = 1 in
2163 def SAHF     : I<0x9E, RawFrm, (outs),  (ins), "sahf", []>;  // flags = AH
2164 let Defs = [AH], Uses = [EFLAGS], neverHasSideEffects = 1 in
2165 def LAHF     : I<0x9F, RawFrm, (outs),  (ins), "lahf", []>;  // AH = flags
2166
2167 let Uses = [EFLAGS] in {
2168 def SETEr    : I<0x94, MRM0r, 
2169                  (outs GR8   :$dst), (ins),
2170                  "sete\t$dst",
2171                  [(set GR8:$dst, (X86setcc X86_COND_E, EFLAGS))]>,
2172                TB;                        // GR8 = ==
2173 def SETEm    : I<0x94, MRM0m, 
2174                  (outs), (ins i8mem:$dst),
2175                  "sete\t$dst",
2176                  [(store (X86setcc X86_COND_E, EFLAGS), addr:$dst)]>,
2177                TB;                        // [mem8] = ==
2178 def SETNEr   : I<0x95, MRM0r, 
2179                  (outs GR8   :$dst), (ins),
2180                  "setne\t$dst",
2181                  [(set GR8:$dst, (X86setcc X86_COND_NE, EFLAGS))]>,
2182                TB;                        // GR8 = !=
2183 def SETNEm   : I<0x95, MRM0m, 
2184                  (outs), (ins i8mem:$dst),
2185                  "setne\t$dst",
2186                  [(store (X86setcc X86_COND_NE, EFLAGS), addr:$dst)]>,
2187                TB;                        // [mem8] = !=
2188 def SETLr    : I<0x9C, MRM0r, 
2189                  (outs GR8   :$dst), (ins),
2190                  "setl\t$dst",
2191                  [(set GR8:$dst, (X86setcc X86_COND_L, EFLAGS))]>,
2192                TB;                        // GR8 = <  signed
2193 def SETLm    : I<0x9C, MRM0m, 
2194                  (outs), (ins i8mem:$dst),
2195                  "setl\t$dst",
2196                  [(store (X86setcc X86_COND_L, EFLAGS), addr:$dst)]>,
2197                TB;                        // [mem8] = <  signed
2198 def SETGEr   : I<0x9D, MRM0r, 
2199                  (outs GR8   :$dst), (ins),
2200                  "setge\t$dst",
2201                  [(set GR8:$dst, (X86setcc X86_COND_GE, EFLAGS))]>,
2202                TB;                        // GR8 = >= signed
2203 def SETGEm   : I<0x9D, MRM0m, 
2204                  (outs), (ins i8mem:$dst),
2205                  "setge\t$dst",
2206                  [(store (X86setcc X86_COND_GE, EFLAGS), addr:$dst)]>,
2207                TB;                        // [mem8] = >= signed
2208 def SETLEr   : I<0x9E, MRM0r, 
2209                  (outs GR8   :$dst), (ins),
2210                  "setle\t$dst",
2211                  [(set GR8:$dst, (X86setcc X86_COND_LE, EFLAGS))]>,
2212                TB;                        // GR8 = <= signed
2213 def SETLEm   : I<0x9E, MRM0m, 
2214                  (outs), (ins i8mem:$dst),
2215                  "setle\t$dst",
2216                  [(store (X86setcc X86_COND_LE, EFLAGS), addr:$dst)]>,
2217                TB;                        // [mem8] = <= signed
2218 def SETGr    : I<0x9F, MRM0r, 
2219                  (outs GR8   :$dst), (ins),
2220                  "setg\t$dst",
2221                  [(set GR8:$dst, (X86setcc X86_COND_G, EFLAGS))]>,
2222                TB;                        // GR8 = >  signed
2223 def SETGm    : I<0x9F, MRM0m, 
2224                  (outs), (ins i8mem:$dst),
2225                  "setg\t$dst",
2226                  [(store (X86setcc X86_COND_G, EFLAGS), addr:$dst)]>,
2227                TB;                        // [mem8] = >  signed
2228
2229 def SETBr    : I<0x92, MRM0r,
2230                  (outs GR8   :$dst), (ins),
2231                  "setb\t$dst",
2232                  [(set GR8:$dst, (X86setcc X86_COND_B, EFLAGS))]>,
2233                TB;                        // GR8 = <  unsign
2234 def SETBm    : I<0x92, MRM0m,
2235                  (outs), (ins i8mem:$dst),
2236                  "setb\t$dst",
2237                  [(store (X86setcc X86_COND_B, EFLAGS), addr:$dst)]>,
2238                TB;                        // [mem8] = <  unsign
2239 def SETAEr   : I<0x93, MRM0r, 
2240                  (outs GR8   :$dst), (ins),
2241                  "setae\t$dst",
2242                  [(set GR8:$dst, (X86setcc X86_COND_AE, EFLAGS))]>,
2243                TB;                        // GR8 = >= unsign
2244 def SETAEm   : I<0x93, MRM0m, 
2245                  (outs), (ins i8mem:$dst),
2246                  "setae\t$dst",
2247                  [(store (X86setcc X86_COND_AE, EFLAGS), addr:$dst)]>,
2248                TB;                        // [mem8] = >= unsign
2249 def SETBEr   : I<0x96, MRM0r, 
2250                  (outs GR8   :$dst), (ins),
2251                  "setbe\t$dst",
2252                  [(set GR8:$dst, (X86setcc X86_COND_BE, EFLAGS))]>,
2253                TB;                        // GR8 = <= unsign
2254 def SETBEm   : I<0x96, MRM0m, 
2255                  (outs), (ins i8mem:$dst),
2256                  "setbe\t$dst",
2257                  [(store (X86setcc X86_COND_BE, EFLAGS), addr:$dst)]>,
2258                TB;                        // [mem8] = <= unsign
2259 def SETAr    : I<0x97, MRM0r, 
2260                  (outs GR8   :$dst), (ins),
2261                  "seta\t$dst",
2262                  [(set GR8:$dst, (X86setcc X86_COND_A, EFLAGS))]>,
2263                TB;                        // GR8 = >  signed
2264 def SETAm    : I<0x97, MRM0m, 
2265                  (outs), (ins i8mem:$dst),
2266                  "seta\t$dst",
2267                  [(store (X86setcc X86_COND_A, EFLAGS), addr:$dst)]>,
2268                TB;                        // [mem8] = >  signed
2269
2270 def SETSr    : I<0x98, MRM0r, 
2271                  (outs GR8   :$dst), (ins),
2272                  "sets\t$dst",
2273                  [(set GR8:$dst, (X86setcc X86_COND_S, EFLAGS))]>,
2274                TB;                        // GR8 = <sign bit>
2275 def SETSm    : I<0x98, MRM0m, 
2276                  (outs), (ins i8mem:$dst),
2277                  "sets\t$dst",
2278                  [(store (X86setcc X86_COND_S, EFLAGS), addr:$dst)]>,
2279                TB;                        // [mem8] = <sign bit>
2280 def SETNSr   : I<0x99, MRM0r, 
2281                  (outs GR8   :$dst), (ins),
2282                  "setns\t$dst",
2283                  [(set GR8:$dst, (X86setcc X86_COND_NS, EFLAGS))]>,
2284                TB;                        // GR8 = !<sign bit>
2285 def SETNSm   : I<0x99, MRM0m, 
2286                  (outs), (ins i8mem:$dst),
2287                  "setns\t$dst",
2288                  [(store (X86setcc X86_COND_NS, EFLAGS), addr:$dst)]>,
2289                TB;                        // [mem8] = !<sign bit>
2290 def SETPr    : I<0x9A, MRM0r, 
2291                  (outs GR8   :$dst), (ins),
2292                  "setp\t$dst",
2293                  [(set GR8:$dst, (X86setcc X86_COND_P, EFLAGS))]>,
2294                TB;                        // GR8 = parity
2295 def SETPm    : I<0x9A, MRM0m, 
2296                  (outs), (ins i8mem:$dst),
2297                  "setp\t$dst",
2298                  [(store (X86setcc X86_COND_P, EFLAGS), addr:$dst)]>,
2299                TB;                        // [mem8] = parity
2300 def SETNPr   : I<0x9B, MRM0r, 
2301                  (outs GR8   :$dst), (ins),
2302                  "setnp\t$dst",
2303                  [(set GR8:$dst, (X86setcc X86_COND_NP, EFLAGS))]>,
2304                TB;                        // GR8 = not parity
2305 def SETNPm   : I<0x9B, MRM0m, 
2306                  (outs), (ins i8mem:$dst),
2307                  "setnp\t$dst",
2308                  [(store (X86setcc X86_COND_NP, EFLAGS), addr:$dst)]>,
2309                TB;                        // [mem8] = not parity
2310 } // Uses = [EFLAGS]
2311
2312
2313 // Integer comparisons
2314 let Defs = [EFLAGS] in {
2315 def CMP8rr  : I<0x38, MRMDestReg,
2316                 (outs), (ins GR8 :$src1, GR8 :$src2),
2317                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
2318                 [(X86cmp GR8:$src1, GR8:$src2), (implicit EFLAGS)]>;
2319 def CMP16rr : I<0x39, MRMDestReg,
2320                 (outs), (ins GR16:$src1, GR16:$src2),
2321                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
2322                 [(X86cmp GR16:$src1, GR16:$src2), (implicit EFLAGS)]>, OpSize;
2323 def CMP32rr : I<0x39, MRMDestReg,
2324                 (outs), (ins GR32:$src1, GR32:$src2),
2325                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
2326                 [(X86cmp GR32:$src1, GR32:$src2), (implicit EFLAGS)]>;
2327 def CMP8mr  : I<0x38, MRMDestMem,
2328                 (outs), (ins i8mem :$src1, GR8 :$src2),
2329                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
2330                 [(X86cmp (loadi8 addr:$src1), GR8:$src2),
2331                  (implicit EFLAGS)]>;
2332 def CMP16mr : I<0x39, MRMDestMem,
2333                 (outs), (ins i16mem:$src1, GR16:$src2),
2334                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
2335                 [(X86cmp (loadi16 addr:$src1), GR16:$src2),
2336                  (implicit EFLAGS)]>, OpSize;
2337 def CMP32mr : I<0x39, MRMDestMem,
2338                 (outs), (ins i32mem:$src1, GR32:$src2),
2339                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
2340                 [(X86cmp (loadi32 addr:$src1), GR32:$src2),
2341                  (implicit EFLAGS)]>;
2342 def CMP8rm  : I<0x3A, MRMSrcMem,
2343                 (outs), (ins GR8 :$src1, i8mem :$src2),
2344                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
2345                 [(X86cmp GR8:$src1, (loadi8 addr:$src2)),
2346                  (implicit EFLAGS)]>;
2347 def CMP16rm : I<0x3B, MRMSrcMem,
2348                 (outs), (ins GR16:$src1, i16mem:$src2),
2349                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
2350                 [(X86cmp GR16:$src1, (loadi16 addr:$src2)),
2351                  (implicit EFLAGS)]>, OpSize;
2352 def CMP32rm : I<0x3B, MRMSrcMem,
2353                 (outs), (ins GR32:$src1, i32mem:$src2),
2354                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
2355                 [(X86cmp GR32:$src1, (loadi32 addr:$src2)),
2356                  (implicit EFLAGS)]>;
2357 def CMP8ri  : Ii8<0x80, MRM7r,
2358                   (outs), (ins GR8:$src1, i8imm:$src2),
2359                   "cmp{b}\t{$src2, $src1|$src1, $src2}",
2360                   [(X86cmp GR8:$src1, imm:$src2), (implicit EFLAGS)]>;
2361 def CMP16ri : Ii16<0x81, MRM7r,
2362                    (outs), (ins GR16:$src1, i16imm:$src2),
2363                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
2364                    [(X86cmp GR16:$src1, imm:$src2),
2365                     (implicit EFLAGS)]>, OpSize;
2366 def CMP32ri : Ii32<0x81, MRM7r,
2367                    (outs), (ins GR32:$src1, i32imm:$src2),
2368                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
2369                    [(X86cmp GR32:$src1, imm:$src2), (implicit EFLAGS)]>;
2370 def CMP8mi  : Ii8 <0x80, MRM7m,
2371                    (outs), (ins i8mem :$src1, i8imm :$src2),
2372                    "cmp{b}\t{$src2, $src1|$src1, $src2}",
2373                    [(X86cmp (loadi8 addr:$src1), imm:$src2),
2374                     (implicit EFLAGS)]>;
2375 def CMP16mi : Ii16<0x81, MRM7m,
2376                    (outs), (ins i16mem:$src1, i16imm:$src2),
2377                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
2378                    [(X86cmp (loadi16 addr:$src1), imm:$src2),
2379                     (implicit EFLAGS)]>, OpSize;
2380 def CMP32mi : Ii32<0x81, MRM7m,
2381                    (outs), (ins i32mem:$src1, i32imm:$src2),
2382                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
2383                    [(X86cmp (loadi32 addr:$src1), imm:$src2),
2384                     (implicit EFLAGS)]>;
2385 def CMP16ri8 : Ii8<0x83, MRM7r,
2386                    (outs), (ins GR16:$src1, i16i8imm:$src2),
2387                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
2388                    [(X86cmp GR16:$src1, i16immSExt8:$src2),
2389                     (implicit EFLAGS)]>, OpSize;
2390 def CMP16mi8 : Ii8<0x83, MRM7m,
2391                    (outs), (ins i16mem:$src1, i16i8imm:$src2),
2392                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
2393                    [(X86cmp (loadi16 addr:$src1), i16immSExt8:$src2),
2394                     (implicit EFLAGS)]>, OpSize;
2395 def CMP32mi8 : Ii8<0x83, MRM7m,
2396                    (outs), (ins i32mem:$src1, i32i8imm:$src2),
2397                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
2398                    [(X86cmp (loadi32 addr:$src1), i32immSExt8:$src2),
2399                     (implicit EFLAGS)]>;
2400 def CMP32ri8 : Ii8<0x83, MRM7r,
2401                    (outs), (ins GR32:$src1, i32i8imm:$src2),
2402                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
2403                    [(X86cmp GR32:$src1, i32immSExt8:$src2),
2404                     (implicit EFLAGS)]>;
2405 } // Defs = [EFLAGS]
2406
2407 // Sign/Zero extenders
2408 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
2409                    "movs{bw|x}\t{$src, $dst|$dst, $src}",
2410                    [(set GR16:$dst, (sext GR8:$src))]>, TB, OpSize;
2411 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
2412                    "movs{bw|x}\t{$src, $dst|$dst, $src}",
2413                    [(set GR16:$dst, (sextloadi16i8 addr:$src))]>, TB, OpSize;
2414 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
2415                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
2416                    [(set GR32:$dst, (sext GR8:$src))]>, TB;
2417 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
2418                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
2419                    [(set GR32:$dst, (sextloadi32i8 addr:$src))]>, TB;
2420 def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
2421                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
2422                    [(set GR32:$dst, (sext GR16:$src))]>, TB;
2423 def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
2424                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
2425                    [(set GR32:$dst, (sextloadi32i16 addr:$src))]>, TB;
2426
2427 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
2428                    "movz{bw|x}\t{$src, $dst|$dst, $src}",
2429                    [(set GR16:$dst, (zext GR8:$src))]>, TB, OpSize;
2430 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
2431                    "movz{bw|x}\t{$src, $dst|$dst, $src}",
2432                    [(set GR16:$dst, (zextloadi16i8 addr:$src))]>, TB, OpSize;
2433 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
2434                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
2435                    [(set GR32:$dst, (zext GR8:$src))]>, TB;
2436 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
2437                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
2438                    [(set GR32:$dst, (zextloadi32i8 addr:$src))]>, TB;
2439 def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
2440                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
2441                    [(set GR32:$dst, (zext GR16:$src))]>, TB;
2442 def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
2443                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
2444                    [(set GR32:$dst, (zextloadi32i16 addr:$src))]>, TB;
2445
2446 let neverHasSideEffects = 1 in {
2447   let Defs = [AX], Uses = [AL] in
2448   def CBW : I<0x98, RawFrm, (outs), (ins),
2449               "{cbtw|cbw}", []>, OpSize;   // AX = signext(AL)
2450   let Defs = [EAX], Uses = [AX] in
2451   def CWDE : I<0x98, RawFrm, (outs), (ins),
2452               "{cwtl|cwde}", []>;   // EAX = signext(AX)
2453
2454   let Defs = [AX,DX], Uses = [AX] in
2455   def CWD : I<0x99, RawFrm, (outs), (ins),
2456               "{cwtd|cwd}", []>, OpSize; // DX:AX = signext(AX)
2457   let Defs = [EAX,EDX], Uses = [EAX] in
2458   def CDQ : I<0x99, RawFrm, (outs), (ins),
2459               "{cltd|cdq}", []>; // EDX:EAX = signext(EAX)
2460 }
2461
2462 //===----------------------------------------------------------------------===//
2463 // Alias Instructions
2464 //===----------------------------------------------------------------------===//
2465
2466 // Alias instructions that map movr0 to xor.
2467 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
2468 let Defs = [EFLAGS], isReMaterializable = 1 in {
2469 def MOV8r0   : I<0x30, MRMInitReg, (outs GR8 :$dst), (ins),
2470                  "xor{b}\t$dst, $dst",
2471                  [(set GR8:$dst, 0)]>;
2472 def MOV16r0  : I<0x31, MRMInitReg,  (outs GR16:$dst), (ins),
2473                  "xor{w}\t$dst, $dst",
2474                  [(set GR16:$dst, 0)]>, OpSize;
2475 def MOV32r0  : I<0x31, MRMInitReg,  (outs GR32:$dst), (ins),
2476                  "xor{l}\t$dst, $dst",
2477                  [(set GR32:$dst, 0)]>;
2478 }
2479
2480 // Basic operations on GR16 / GR32 subclasses GR16_ and GR32_ which contains only
2481 // those registers that have GR8 sub-registers (i.e. AX - DX, EAX - EDX).
2482 let neverHasSideEffects = 1 in {
2483 def MOV16to16_ : I<0x89, MRMDestReg, (outs GR16_:$dst), (ins GR16:$src),
2484                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
2485 def MOV32to32_ : I<0x89, MRMDestReg, (outs GR32_:$dst), (ins GR32:$src),
2486                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
2487                 
2488 def MOV16_rr : I<0x89, MRMDestReg, (outs GR16_:$dst), (ins GR16_:$src),
2489                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
2490 def MOV32_rr : I<0x89, MRMDestReg, (outs GR32_:$dst), (ins GR32_:$src),
2491                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
2492 } // neverHasSideEffects
2493
2494 let isSimpleLoad = 1, mayLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in {
2495 def MOV16_rm : I<0x8B, MRMSrcMem, (outs GR16_:$dst), (ins i16mem:$src),
2496                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
2497 def MOV32_rm : I<0x8B, MRMSrcMem, (outs GR32_:$dst), (ins i32mem:$src),
2498                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
2499 }
2500 let mayStore = 1, neverHasSideEffects = 1 in {
2501 def MOV16_mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16_:$src),
2502                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
2503 def MOV32_mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32_:$src),
2504                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
2505 }
2506
2507 //===----------------------------------------------------------------------===//
2508 // Thread Local Storage Instructions
2509 //
2510
2511 let Uses = [EBX] in
2512 def TLS_addr : I<0, Pseudo, (outs GR32:$dst), (ins i32imm:$sym),
2513                "leal\t${sym:mem}(,%ebx,1), $dst",
2514                [(set GR32:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
2515
2516 let AddedComplexity = 10 in
2517 def TLS_gs_rr : I<0, Pseudo, (outs GR32:$dst), (ins GR32:$src),
2518                   "movl\t%gs:($src), $dst",
2519                   [(set GR32:$dst, (load (add X86TLStp, GR32:$src)))]>;
2520
2521 let AddedComplexity = 15 in
2522 def TLS_gs_ri : I<0, Pseudo, (outs GR32:$dst), (ins i32imm:$src),
2523                   "movl\t%gs:${src:mem}, $dst",
2524                   [(set GR32:$dst,
2525                     (load (add X86TLStp, (X86Wrapper tglobaltlsaddr:$src))))]>;
2526
2527 def TLS_tp : I<0, Pseudo, (outs GR32:$dst), (ins),
2528                "movl\t%gs:0, $dst",
2529                [(set GR32:$dst, X86TLStp)]>;
2530
2531 //===----------------------------------------------------------------------===//
2532 // DWARF Pseudo Instructions
2533 //
2534
2535 def DWARF_LOC   : I<0, Pseudo, (outs),
2536                     (ins i32imm:$line, i32imm:$col, i32imm:$file),
2537                     ".loc\t${file:debug} ${line:debug} ${col:debug}",
2538                     [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
2539                       (i32 imm:$file))]>;
2540
2541 //===----------------------------------------------------------------------===//
2542 // EH Pseudo Instructions
2543 //
2544 let isTerminator = 1, isReturn = 1, isBarrier = 1,
2545     hasCtrlDep = 1 in {
2546 def EH_RETURN   : I<0xC3, RawFrm, (outs), (ins GR32:$addr),
2547                     "ret\t#eh_return, addr: $addr",
2548                     [(X86ehret GR32:$addr)]>;
2549
2550 }
2551
2552 //===----------------------------------------------------------------------===//
2553 // Atomic support
2554 //
2555
2556 //FIXME: Please check the format Pseudo is certainly wrong, but the opcode and
2557 //       prefixes should be correct
2558
2559 let Defs = [EAX, EFLAGS], Uses = [EAX] in {
2560 def CMPXCHG32 : I<0xB1, Pseudo, (outs), (ins i32mem:$ptr, GR32:$swap),
2561                "cmpxchgl $swap,$ptr", []>, TB;
2562 def LCMPXCHG32 : I<0xB1, Pseudo, (outs), (ins i32mem:$ptr, GR32:$swap),
2563                "lock cmpxchgl $swap,$ptr",
2564                [(X86cas addr:$ptr, GR32:$swap, 4)]>, TB, LOCK;
2565 }
2566 let Defs = [EAX, EBX, ECX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in {
2567 def CMPXCHG8B : I<0xC7, Pseudo, (outs), (ins i32mem:$ptr),
2568                "cmpxchg8b $ptr", []>, TB;
2569 def LCMPXCHG8B : I<0xC7, Pseudo, (outs), (ins i32mem:$ptr),
2570                "lock cmpxchg8b $ptr",
2571                [(X86cas8 addr:$ptr)]>, TB, LOCK;
2572 }
2573
2574 let Defs = [AX, EFLAGS], Uses = [AX] in {
2575 def CMPXCHG16 : I<0xB1, Pseudo, (outs), (ins i16mem:$ptr, GR16:$swap),
2576                "cmpxchgw $swap,($ptr)", []>, TB, OpSize;
2577 def LCMPXCHG16 : I<0xB1, Pseudo, (outs), (ins i16mem:$ptr, GR16:$swap),
2578                "lock cmpxchgw $swap,$ptr",
2579                [(X86cas addr:$ptr, GR16:$swap, 2)]>, TB, OpSize, LOCK;
2580 }
2581 let Defs = [AL, EFLAGS], Uses = [AL] in {
2582 def CMPXCHG8 : I<0xB0, Pseudo, (outs), (ins i8mem:$ptr, GR8:$swap),
2583                "cmpxchgb $swap,($ptr)", []>, TB;
2584 def LCMPXCHG8 : I<0xB0, Pseudo, (outs), (ins i8mem:$ptr, GR8:$swap),
2585                "lock cmpxchgb $swap,$ptr",
2586                [(X86cas addr:$ptr, GR8:$swap, 1)]>, TB, LOCK;
2587 }
2588
2589 let Constraints = "$val = $dst", Defs = [EFLAGS] in {
2590 def LXADD32 : I<0xC1, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
2591                "lock xadd $val, $ptr", 
2592                [(set GR32:$dst, (atomic_las_32 addr:$ptr, GR32:$val))]>,
2593                 TB, LOCK;
2594 def LXADD16 : I<0xC1, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
2595                "lock xadd $val, $ptr", 
2596                [(set GR16:$dst, (atomic_las_16 addr:$ptr, GR16:$val))]>,
2597                 TB, OpSize, LOCK;
2598 def LXADD8  : I<0xC0, Pseudo, (outs GR8:$dst), (ins i8mem:$ptr, GR8:$val),
2599                "lock xadd $val, $ptr", 
2600                [(set GR8:$dst, (atomic_las_8 addr:$ptr, GR8:$val))]>,
2601                 TB, LOCK;
2602 def XADD32 : I<0xC1, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
2603                "xadd $val, $ptr", []>, TB;
2604 def XADD16 : I<0xC1, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
2605                "xadd $val, $ptr", []>, TB, OpSize;
2606 def XADD8  : I<0xC0, Pseudo, (outs GR8:$dst), (ins i8mem:$ptr, GR8:$val),
2607                "xadd $val, $ptr", []>, TB;
2608
2609 def LXCHG32 : I<0x87, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
2610                "lock xchg $val, $ptr", 
2611                [(set GR32:$dst, (atomic_swap_32 addr:$ptr, GR32:$val))]>, LOCK;
2612 def LXCHG16 : I<0x87, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
2613                "lock xchg $val, $ptr", 
2614                [(set GR16:$dst, (atomic_swap_16 addr:$ptr, GR16:$val))]>, 
2615                 OpSize, LOCK;
2616 def LXCHG8  : I<0x86, Pseudo, (outs GR8:$dst), (ins i8mem:$ptr, GR8:$val),
2617                "lock xchg $val, $ptr", 
2618                [(set GR8:$dst, (atomic_swap_8 addr:$ptr, GR8:$val))]>, LOCK;
2619 def XCHG32 : I<0x87, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
2620                "xchg $val, $ptr", []>;
2621 def XCHG16 : I<0x87, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
2622                "xchg $val, $ptr", []>, OpSize;
2623 def XCHG8  : I<0x86, Pseudo, (outs GR8:$dst), (ins i8mem:$ptr, GR8:$val),
2624                "xchg $val, $ptr", []>;
2625 }
2626
2627 //===----------------------------------------------------------------------===//
2628 // Non-Instruction Patterns
2629 //===----------------------------------------------------------------------===//
2630
2631 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
2632 def : Pat<(i32 (X86Wrapper tconstpool  :$dst)), (MOV32ri tconstpool  :$dst)>;
2633 def : Pat<(i32 (X86Wrapper tjumptable  :$dst)), (MOV32ri tjumptable  :$dst)>;
2634 def : Pat<(i32 (X86Wrapper tglobaltlsaddr:$dst)), (MOV32ri tglobaltlsaddr:$dst)>;
2635 def : Pat<(i32 (X86Wrapper tglobaladdr :$dst)), (MOV32ri tglobaladdr :$dst)>;
2636 def : Pat<(i32 (X86Wrapper texternalsym:$dst)), (MOV32ri texternalsym:$dst)>;
2637
2638 def : Pat<(add GR32:$src1, (X86Wrapper tconstpool:$src2)),
2639           (ADD32ri GR32:$src1, tconstpool:$src2)>;
2640 def : Pat<(add GR32:$src1, (X86Wrapper tjumptable:$src2)),
2641           (ADD32ri GR32:$src1, tjumptable:$src2)>;
2642 def : Pat<(add GR32:$src1, (X86Wrapper tglobaladdr :$src2)),
2643           (ADD32ri GR32:$src1, tglobaladdr:$src2)>;
2644 def : Pat<(add GR32:$src1, (X86Wrapper texternalsym:$src2)),
2645           (ADD32ri GR32:$src1, texternalsym:$src2)>;
2646
2647 def : Pat<(store (i32 (X86Wrapper tglobaladdr:$src)), addr:$dst),
2648           (MOV32mi addr:$dst, tglobaladdr:$src)>;
2649 def : Pat<(store (i32 (X86Wrapper texternalsym:$src)), addr:$dst),
2650           (MOV32mi addr:$dst, texternalsym:$src)>;
2651
2652 // Calls
2653 // tailcall stuff
2654 def : Pat<(X86tailcall GR32:$dst),
2655           (TAILCALL)>;
2656
2657 def : Pat<(X86tailcall (i32 tglobaladdr:$dst)),
2658           (TAILCALL)>;
2659 def : Pat<(X86tailcall (i32 texternalsym:$dst)),
2660           (TAILCALL)>;
2661
2662 def : Pat<(X86tcret GR32:$dst, imm:$off),
2663           (TCRETURNri GR32:$dst, imm:$off)>;
2664
2665 def : Pat<(X86tcret (i32 tglobaladdr:$dst), imm:$off),
2666           (TCRETURNdi texternalsym:$dst, imm:$off)>;
2667
2668 def : Pat<(X86tcret (i32 texternalsym:$dst), imm:$off),
2669           (TCRETURNdi texternalsym:$dst, imm:$off)>;
2670
2671 def : Pat<(X86call (i32 tglobaladdr:$dst)),
2672           (CALLpcrel32 tglobaladdr:$dst)>;
2673 def : Pat<(X86call (i32 texternalsym:$dst)),
2674           (CALLpcrel32 texternalsym:$dst)>;
2675
2676 // X86 specific add which produces a flag.
2677 def : Pat<(addc GR32:$src1, GR32:$src2),
2678           (ADD32rr GR32:$src1, GR32:$src2)>;
2679 def : Pat<(addc GR32:$src1, (load addr:$src2)),
2680           (ADD32rm GR32:$src1, addr:$src2)>;
2681 def : Pat<(addc GR32:$src1, imm:$src2),
2682           (ADD32ri GR32:$src1, imm:$src2)>;
2683 def : Pat<(addc GR32:$src1, i32immSExt8:$src2),
2684           (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
2685
2686 def : Pat<(subc GR32:$src1, GR32:$src2),
2687           (SUB32rr GR32:$src1, GR32:$src2)>;
2688 def : Pat<(subc GR32:$src1, (load addr:$src2)),
2689           (SUB32rm GR32:$src1, addr:$src2)>;
2690 def : Pat<(subc GR32:$src1, imm:$src2),
2691           (SUB32ri GR32:$src1, imm:$src2)>;
2692 def : Pat<(subc GR32:$src1, i32immSExt8:$src2),
2693           (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
2694
2695 // Comparisons.
2696
2697 // TEST R,R is smaller than CMP R,0
2698 def : Pat<(parallel (X86cmp GR8:$src1, 0), (implicit EFLAGS)),
2699           (TEST8rr GR8:$src1, GR8:$src1)>;
2700 def : Pat<(parallel (X86cmp GR16:$src1, 0), (implicit EFLAGS)),
2701           (TEST16rr GR16:$src1, GR16:$src1)>;
2702 def : Pat<(parallel (X86cmp GR32:$src1, 0), (implicit EFLAGS)),
2703           (TEST32rr GR32:$src1, GR32:$src1)>;
2704
2705 // zextload bool -> zextload byte
2706 def : Pat<(zextloadi8i1  addr:$src), (MOV8rm     addr:$src)>;
2707 def : Pat<(zextloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>;
2708 def : Pat<(zextloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>;
2709
2710 // extload bool -> extload byte
2711 def : Pat<(extloadi8i1 addr:$src),   (MOV8rm      addr:$src)>;
2712 def : Pat<(extloadi16i1 addr:$src),  (MOVZX16rm8  addr:$src)>;
2713 def : Pat<(extloadi32i1 addr:$src),  (MOVZX32rm8  addr:$src)>;
2714 def : Pat<(extloadi16i8 addr:$src),  (MOVZX16rm8  addr:$src)>;
2715 def : Pat<(extloadi32i8 addr:$src),  (MOVZX32rm8  addr:$src)>;
2716 def : Pat<(extloadi32i16 addr:$src), (MOVZX32rm16 addr:$src)>;
2717
2718 // anyext -> zext
2719 def : Pat<(i16 (anyext GR8 :$src)), (MOVZX16rr8  GR8 :$src)>;
2720 def : Pat<(i32 (anyext GR8 :$src)), (MOVZX32rr8  GR8 :$src)>;
2721 def : Pat<(i32 (anyext GR16:$src)), (MOVZX32rr16 GR16:$src)>;
2722 def : Pat<(i16 (anyext (loadi8  addr:$src))), (MOVZX16rm8  addr:$src)>;
2723 def : Pat<(i32 (anyext (loadi8  addr:$src))), (MOVZX32rm8  addr:$src)>;
2724 def : Pat<(i32 (anyext (loadi16 addr:$src))), (MOVZX32rm16 addr:$src)>;
2725
2726 // (and (i32 load), 255) -> (zextload i8)
2727 def : Pat<(i32 (and (loadi32 addr:$src), (i32 255))), (MOVZX32rm8 addr:$src)>;
2728 def : Pat<(i32 (and (loadi32 addr:$src), (i32 65535))),(MOVZX32rm16 addr:$src)>;
2729
2730 //===----------------------------------------------------------------------===//
2731 // Some peepholes
2732 //===----------------------------------------------------------------------===//
2733
2734 // (shl x, 1) ==> (add x, x)
2735 def : Pat<(shl GR8 :$src1, (i8 1)), (ADD8rr  GR8 :$src1, GR8 :$src1)>;
2736 def : Pat<(shl GR16:$src1, (i8 1)), (ADD16rr GR16:$src1, GR16:$src1)>;
2737 def : Pat<(shl GR32:$src1, (i8 1)), (ADD32rr GR32:$src1, GR32:$src1)>;
2738
2739 // (or (x >> c) | (y << (32 - c))) ==> (shrd32 x, y, c)
2740 def : Pat<(or (srl GR32:$src1, CL:$amt),
2741               (shl GR32:$src2, (sub 32, CL:$amt))),
2742           (SHRD32rrCL GR32:$src1, GR32:$src2)>;
2743
2744 def : Pat<(store (or (srl (loadi32 addr:$dst), CL:$amt),
2745                      (shl GR32:$src2, (sub 32, CL:$amt))), addr:$dst),
2746           (SHRD32mrCL addr:$dst, GR32:$src2)>;
2747
2748 // (or (x << c) | (y >> (32 - c))) ==> (shld32 x, y, c)
2749 def : Pat<(or (shl GR32:$src1, CL:$amt),
2750               (srl GR32:$src2, (sub 32, CL:$amt))),
2751           (SHLD32rrCL GR32:$src1, GR32:$src2)>;
2752
2753 def : Pat<(store (or (shl (loadi32 addr:$dst), CL:$amt),
2754                      (srl GR32:$src2, (sub 32, CL:$amt))), addr:$dst),
2755           (SHLD32mrCL addr:$dst, GR32:$src2)>;
2756
2757 // (or (x >> c) | (y << (16 - c))) ==> (shrd16 x, y, c)
2758 def : Pat<(or (srl GR16:$src1, CL:$amt),
2759               (shl GR16:$src2, (sub 16, CL:$amt))),
2760           (SHRD16rrCL GR16:$src1, GR16:$src2)>;
2761
2762 def : Pat<(store (or (srl (loadi16 addr:$dst), CL:$amt),
2763                      (shl GR16:$src2, (sub 16, CL:$amt))), addr:$dst),
2764           (SHRD16mrCL addr:$dst, GR16:$src2)>;
2765
2766 // (or (x << c) | (y >> (16 - c))) ==> (shld16 x, y, c)
2767 def : Pat<(or (shl GR16:$src1, CL:$amt),
2768               (srl GR16:$src2, (sub 16, CL:$amt))),
2769           (SHLD16rrCL GR16:$src1, GR16:$src2)>;
2770
2771 def : Pat<(store (or (shl (loadi16 addr:$dst), CL:$amt),
2772                      (srl GR16:$src2, (sub 16, CL:$amt))), addr:$dst),
2773           (SHLD16mrCL addr:$dst, GR16:$src2)>;
2774
2775 //===----------------------------------------------------------------------===//
2776 // Floating Point Stack Support
2777 //===----------------------------------------------------------------------===//
2778
2779 include "X86InstrFPStack.td"
2780
2781 //===----------------------------------------------------------------------===//
2782 // X86-64 Support
2783 //===----------------------------------------------------------------------===//
2784
2785 include "X86Instr64bit.td"
2786
2787 //===----------------------------------------------------------------------===//
2788 // MMX and XMM Packed Integer support (requires MMX, SSE, and SSE2)
2789 //===----------------------------------------------------------------------===//
2790
2791 include "X86InstrMMX.td"
2792
2793 //===----------------------------------------------------------------------===//
2794 // XMM Floating point support (requires SSE / SSE2)
2795 //===----------------------------------------------------------------------===//
2796
2797 include "X86InstrSSE.td"