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