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