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