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